added a copyToClipboard method to ShareUtils, and modified CommentsMiniInfoItemHolder and VideoDetailFragment to use the new method.
This commit is contained in:
parent
b5375396d2
commit
267e114354
3 changed files with 29 additions and 15 deletions
|
|
@ -1,10 +1,13 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
|
|
@ -78,4 +81,27 @@ public final class ShareUtils {
|
|||
context.startActivity(Intent.createChooser(
|
||||
intent, context.getString(R.string.share_dialog_title)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the text to clipboard, and indicate to the user whether the operation was completed
|
||||
* successfully using a Toast.
|
||||
*
|
||||
* @param context the context to use
|
||||
* @param text the text to copy
|
||||
*/
|
||||
public static void copyToClipboard(final Context context, final String text) {
|
||||
ClipboardManager clipboardManager =
|
||||
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
if (clipboardManager == null) {
|
||||
Toast.makeText(context,
|
||||
R.string.permission_denied,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText(null, text));
|
||||
Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue