aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/ClipboardUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/utils/ClipboardUtils.java')
-rw-r--r--main/src/cgeo/geocaching/utils/ClipboardUtils.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/utils/ClipboardUtils.java b/main/src/cgeo/geocaching/utils/ClipboardUtils.java
index 77250f3..fb30886 100644
--- a/main/src/cgeo/geocaching/utils/ClipboardUtils.java
+++ b/main/src/cgeo/geocaching/utils/ClipboardUtils.java
@@ -2,6 +2,8 @@ package cgeo.geocaching.utils;
import cgeo.geocaching.CgeoApplication;
+import org.eclipse.jdt.annotation.Nullable;
+
import android.content.Context;
/**
@@ -9,7 +11,6 @@ import android.content.Context;
* This class uses the deprecated function ClipboardManager.setText(CharSequence).
* API 11 introduced setPrimaryClip(ClipData)
*/
-@SuppressWarnings("deprecation")
public final class ClipboardUtils {
private ClipboardUtils() {
@@ -22,10 +23,24 @@ public final class ClipboardUtils {
* @param text
* The text to place in the clipboard.
*/
+ @SuppressWarnings("deprecation")
public static void copyToClipboard(final CharSequence text) {
// fully qualified name used here to avoid buggy deprecation warning (of javac) on the import statement
final android.text.ClipboardManager clipboard = (android.text.ClipboardManager) CgeoApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
+ /**
+ * get clipboard content
+ *
+ */
+ @SuppressWarnings("deprecation")
+ @Nullable
+ public static String getText() {
+ // fully qualified name used here to avoid buggy deprecation warning (of javac) on the import statement
+ final android.text.ClipboardManager clipboard = (android.text.ClipboardManager) CgeoApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);
+ final CharSequence text = clipboard.getText();
+ return text != null ? text.toString() : null;
+ }
+
}