From b821157b9f0f9a2b5479fbdf9a2bb75d287892c9 Mon Sep 17 00:00:00 2001
From: "David A. Madore" <david+git@madore.org>
Date: Fri, 16 Mar 2012 19:58:08 +0100
Subject: Make various text widgets selectable on sufficiently recent Android
 versions.

---
 src/org/madore/android/unicodeMap/UnicodeMapActivity.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

(limited to 'src')

diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
index aecea78..1358246 100644
--- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
@@ -27,6 +27,17 @@ import android.app.ProgressDialog;
 
 public final class UnicodeMapActivity extends ListActivity {
 
+    protected static void textMakeSelectableIfPossible(TextView text) {
+	// .setTextIsSelectable() method is only available on Android
+	// Honeycomb (API 11) and later.
+	try {
+	    java.lang.reflect.Method m = TextView.class.getMethod("setTextIsSelectable", new Class[] { boolean.class });
+	    m.invoke(text, true);
+	} catch (Exception e) {
+	    // Ignore
+	}
+    }
+
     protected UnicodeDatabase db;
     protected ListView lv;
     protected ClipboardManager cmgr;
@@ -313,6 +324,7 @@ public final class UnicodeMapActivity extends ListActivity {
 		TextView text;
 		text = (TextView) dialog.findViewById(R.id.detailsLabel);
 		text.setText(itch.getLabel());
+		textMakeSelectableIfPossible(text);
 		text = (TextView) dialog.findViewById(R.id.encodingLabel);
 		StringBuilder s = new StringBuilder();
 		Formatter fmt = new Formatter(s);
@@ -326,6 +338,7 @@ public final class UnicodeMapActivity extends ListActivity {
 		for ( int i=0 ; i<bytes.length ; i++ )
 		    fmt.format(" 0x%02x", bytes[i]);
 		text.setText(new String(s));
+		textMakeSelectableIfPossible(text);
 		text = (TextView) dialog.findViewById(R.id.categoryLabel);
 		text.setText(itch.getCategory().getDescr());
 		final Button copyCharButton = (Button) dialog.findViewById(R.id.copyCharButton);
@@ -391,6 +404,7 @@ public final class UnicodeMapActivity extends ListActivity {
 		TextView text;
 		text = (TextView) dialog.findViewById(R.id.rangeDescrLabel);
 		text.setText(itr.getDescr());
+		textMakeSelectableIfPossible(text);
 		text = (TextView) dialog.findViewById(R.id.rangeRangeLabel);
 		StringBuilder s = new StringBuilder();
 		Formatter fmt = new Formatter(s);
@@ -404,6 +418,7 @@ public final class UnicodeMapActivity extends ListActivity {
 			       itr.getTo()-itr.getFrom(),
 			       db.countRange(itr.getFrom(), itr.getTo()));
 		text.setText(new String(s));
+		textMakeSelectableIfPossible(text);
 		dialog.show();
 		return true;
 	    } else
-- 
cgit v1.2.3