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

The following examples show how to use android.content.ClipboardManager#setPrimaryClip() . 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
Source File: ReceiveFragment.java    From tron-wallet-android with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: GeneratePasswordDialog.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 5 votes vote down vote up
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 3
Source File: MainActivity.java    From LocationShare with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: AndroidUtil.java    From Gank.io with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: WalletScreen.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: AppHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: BugReportActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
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 8
Source File: MentionsEditText.java    From Spyglass with 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 9
Source File: ActivityServiceUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 10
Source File: CopyTextBottomSheetFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
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 11
Source File: ReaderActivity.java    From Chimee with 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 12
Source File: SettingsActivity.java    From mosmetro-android with GNU General Public License v3.0 4 votes vote down vote up
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 13
Source File: CopyUtil.java    From NiceRead with 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 14
Source File: AppCompatDlalog.java    From stynico with 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 15
Source File: DetailFragment.java    From WanAndroid with 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 16
Source File: Util.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
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 File: CopyToClipboardActivity.java    From NClientV2 with Apache License 2.0 4 votes vote down vote up
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 18
Source File: Utils.java    From ForPDA with 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 19
Source File: DetailsActivity.java    From ExpressHelper with GNU General Public License v3.0 4 votes vote down vote up
private void setClipboard(String text) {
	ClipboardManager clipMan = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
	clipMan.setPrimaryClip(ClipData.newPlainText(null, text));
}
 
Example 20
Source File: ClipboardUtils.java    From AndroidUtilCode with 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));
}