aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-04-07 15:36:16 +0200
committersteckbrief <steckbrief@chefmail.de>2016-04-07 15:36:16 +0200
commit36f3bed2eccb3dfd5266304c482497eff0d25c7c (patch)
treea43598541a1a4ea92142d17e02c02033e49fa8a3 /src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java
parent4ace80d39ade18934d310ba37559c9c7ec8004dd (diff)
parent8c3245dd1f257053b8ec2bf7c5e03a3a98b282c3 (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Conflicts: src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java
new file mode 100644
index 00000000..4d6220e0
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ClipboardUtil.java
@@ -0,0 +1,48 @@
+package de.thedevstack.conversationsplus.utils;
+
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.widget.Toast;
+
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+
+import eu.siacs.conversations.R;
+
+/**
+ * Util class to work with the Clipboard.
+ */
+public final class ClipboardUtil {
+ private static final String CLIPBOARD_LABEL = "c+clipboard";
+
+ /**
+ * Copies a text to the clipboard.
+ * @param clipboardLabel the label to show to a user to allow identifying the text in clipboard.
+ * @param text the text to copy
+ */
+ public static void copyToClipboard(String clipboardLabel, String text) {
+ Context context = ConversationsPlusApplication.getAppContext();
+ if (null != text && !text.isEmpty()) {
+ String label = (null == clipboardLabel) ? CLIPBOARD_LABEL : clipboardLabel;
+ ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText(label, text);
+ clipboard.setPrimaryClip(clip);
+ Toast.makeText(context, R.string.cplus_copied_to_clipboard, Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(context, R.string.cplus_not_copied_to_clipboard_empty, Toast.LENGTH_LONG).show();
+ }
+
+ }
+
+ /**
+ * Copies a text to the clipboard.
+ * @param text the text to copy
+ */
+ public static void copyToClipboard(String text) {
+ copyToClipboard(CLIPBOARD_LABEL, text);
+ }
+
+ private ClipboardUtil() {
+ // helper class - avoid instantiation
+ }
+}