Java Code Examples for android.content.ClipboardManager#setPrimaryClip()

The following examples show how to use android.content.ClipboardManager#setPrimaryClip() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void copyLocationText(String string) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard != null) {
        ClipData clip = ClipData.newPlainText(getString(R.string.app_name), string);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getApplicationContext(), R.string.copied, Toast.LENGTH_SHORT).show();
    } else {
        Log.e(TAG, "Failed to get the clipboard service");
        Toast.makeText(getApplicationContext(), R.string.clipboard_error, Toast.LENGTH_SHORT).show();
    }
}
 
Example 2
private void copyDeviceInfoToClipBoard() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getString(R.string.device_info), deviceInfo.toMarkdown());
    clipboard.setPrimaryClip(clip);

    Toast.makeText(BugReportActivity.this, R.string.copied_device_info_to_clipboard, Toast.LENGTH_LONG).show();
}
 
Example 3
Source Project: Spyglass   File: MentionsEditText.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Save the selected text and intent in ClipboardManager
 */
private void saveToClipboard(@NonNull CharSequence selectedText, @Nullable Intent intent) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData.Item item = new ClipData.Item(selectedText, intent, null);
    ClipData clip = new ClipData(null, new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
    clipboard.setPrimaryClip(clip);
}
 
Example 4
/**
 * Copies text to keyboard.
 *
 * @param activity Activity where CLIPBOARD_SERVICE can be fetched.
 * @param text     Text to copy.
 */
public static void copyToClipboard(Activity activity, String text) {
    ClipboardManager clipboardManager = (ClipboardManager) activity
            .getSystemService(Context.CLIPBOARD_SERVICE);

    ClipData clipData = ClipData.newPlainText(null, text);
    if (clipboardManager != null) {
        clipboardManager.setPrimaryClip(clipData);
    }
}
 
Example 5
private void copyText(String text) {
    ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard != null) {
        ClipData clip = ClipData.newPlainText("simple text", text);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(activity, R.string.copy_success, Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(activity, R.string.copy_link_failed, Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source Project: Chimee   File: ReaderActivity.java    License: MIT License 5 votes vote down vote up
private void onCopyClick() {
    String text = adapter.extractFullText();
    if (TextUtils.isEmpty(text)) return;
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(null, text);
    if (clipboard == null) return;
    clipboard.setPrimaryClip(clip);
    MongolToast.makeText(this, getString(R.string.text_copied), MongolToast.LENGTH_SHORT).show();
}
 
Example 7
public static void copyToClipboard(@NonNull Context context, @NonNull String uri) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(context.getString(R.string.app_name), uri);
    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
        AlertUtils.showToastShortMessage(context, context.getString(R.string.success_copied));
    }
}
 
Example 8
@Override
public void putAddressToClipboard(String address) {
    Activity activity = getActivity();
    if (activity != null){
        ClipData clip = ClipData.newPlainText("addressView", address);
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(CLIPBOARD_SERVICE);

        if(clipboard != null){
            clipboard.setPrimaryClip(clip);
            Toast.makeText(activity.getApplicationContext(), R.string.address_was_copied, Toast.LENGTH_LONG).show();
        }
    }
}
 
Example 9
public static void copyToClipBoard(Context context, String text, String success) {
  ClipData clipData = ClipData.newPlainText("girl_copy", text);
  ClipboardManager manager = (ClipboardManager) context.getSystemService(
      Context.CLIPBOARD_SERVICE);
  manager.setPrimaryClip(clipData);
  Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}
 
Example 10
public void passwordToClipboard(boolean clipboardEnabled, String password) {
    if (clipboardEnabled) {
        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Password", password);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getActivity(), getActivity().getString(R.string.password_copied), Toast.LENGTH_SHORT).show();
    }
}
 
Example 11
@Override
public void onClick(View v) {
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Address", mAddress);
    clipboard.setPrimaryClip(clip);
    
    Toast.makeText(getActivity(), getString(R.string.copy_success), Toast.LENGTH_SHORT).show();
}
 
Example 12
Source Project: NiceRead   File: CopyUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static void copy(Context context, String plaintText) {
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(ClipData.newPlainText(null, plaintText));
}
 
Example 13
private void setClipboard(String text) {
	ClipboardManager clipMan = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
	clipMan.setPrimaryClip(ClipData.newPlainText(null, text));
}
 
Example 14
Source Project: ForPDA   File: Utils.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void copyToClipBoard(String s) {
    ClipboardManager clipboard = (ClipboardManager) App.getContext().getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("label", s);
    clipboard.setPrimaryClip(clip);
}
 
Example 15
public static void copyTextToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("text", text);
    if(clipboard!=null)
        clipboard.setPrimaryClip(clip);
}
 
Example 16
public static void writeTextToClipboard(@NonNull Context context, @NonNull String text) {
  {
    ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setPrimaryClip(ClipData.newPlainText("Safety numbers", text));
  }
}
 
Example 17
Source Project: WanAndroid   File: DetailFragment.java    License: Apache License 2.0 4 votes vote down vote up
private void copyLink() {
    ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText("text", Html.fromHtml(url).toString());
    manager.setPrimaryClip(data);

}
 
Example 18
Source Project: stynico   File: AppCompatDlalog.java    License: MIT License 4 votes vote down vote up
private boolean findEditText(AccessibilityNodeInfo rootNode, String content)
   {
       int count = rootNode.getChildCount();

    //   android.util.Log.d("maptrix", "root class=" + rootNode.getClassName() + "," + rootNode.getText() + "," + count);
       for (int i = 0; i < count; i++)
{
           AccessibilityNodeInfo nodeInfo = rootNode.getChild(i);
           if (nodeInfo == null)
    {
    //           android.util.Log.d("maptrix", "nodeinfo = null");
               continue;
           }

     //      android.util.Log.d("maptrix", "class=" + nodeInfo.getClassName());
   //        android.util.Log.e("maptrix", "ds=" + nodeInfo.getContentDescription());
           if (nodeInfo.getContentDescription() != null)
    {
               int nindex = nodeInfo.getContentDescription().toString().indexOf(name);
               int cindex = nodeInfo.getContentDescription().toString().indexOf(scontent);
     //          android.util.Log.e("maptrix", "nindex=" + nindex + " cindex=" + cindex);
               if (nindex != -1)
	{
                   itemNodeinfo = nodeInfo;
                  // android.util.Log.i("maptrix", "find node info");
               }
           }
           if ("android.widget.EditText".equals(nodeInfo.getClassName()))
    {
    //           android.util.Log.i("maptrix", "==================");
               Bundle arguments = new Bundle();
               arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
			 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
               arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
			     true);
               nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
			       arguments);
               nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
               ClipData clip = ClipData.newPlainText("label", content);
               ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
               clipboardManager.setPrimaryClip(clip);
               nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
               return true;
           }

           if (findEditText(nodeInfo, content))
    {
               return true;
           }
       }

       return false;
   }
 
Example 19
private void donate_dialog() {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager clipboard = (ClipboardManager)
                    getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip;

            switch (i) {
                case 0: // Yandex.Money
                    startActivity(new Intent(SettingsActivity.this, SafeViewActivity.class)
                            .putExtra("data", getString(R.string.donate_yandex_data))
                    );
                    break;

                case 1: // Bitcoin
                    clip = ClipData.newPlainText("", getString(R.string.donate_bitcoin_data));
                    clipboard.setPrimaryClip(clip);

                    Toast.makeText(SettingsActivity.this,
                            R.string.clipboard_copy,
                            Toast.LENGTH_SHORT
                    ).show();
                    break;

                case 2: // Ethereum
                    clip = ClipData.newPlainText("", getString(R.string.donate_ethereum_data));
                    clipboard.setPrimaryClip(clip);

                    Toast.makeText(SettingsActivity.this,
                            R.string.clipboard_copy,
                            Toast.LENGTH_SHORT
                    ).show();
                    break;

                case 3: // Communities
                    replaceFragment("about", new AboutFragment());
                    break;
            }
        }
    };

    new AlertDialog.Builder(this)
            .setTitle(R.string.action_donate)
            .setItems(R.array.donate_options, listener)
            .show();
}
 
Example 20
Source Project: AndroidUtilCode   File: ClipboardUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 复制文本到剪贴板
 *
 * @param text 文本
 */
public static void copyText(final CharSequence text) {
    ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);
    cm.setPrimaryClip(ClipData.newPlainText("text", text));
}