summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-25 21:54:54 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-25 21:54:54 +0200
commitdfccb7883425392290f5bf9afc845bae776320e9 (patch)
tree45716bdd91ba06d8c525e072c9738705643c08d4
parent8d56c5f19480646445fc277ee14addad597617c6 (diff)
downloadUnicodeMap-dfccb7883425392290f5bf9afc845bae776320e9.tar.gz
UnicodeMap-dfccb7883425392290f5bf9afc845bae776320e9.tar.bz2
UnicodeMap-dfccb7883425392290f5bf9afc845bae776320e9.zip
List layout: display characters differently from their labels.
This is done by making UnicodeCharacter implement Map<String,String> so as to use it in a SimpleAdapter, but really, this is ugly.
-rw-r--r--res/layout/list_item.xml18
-rw-r--r--res/layout/map_item.xml8
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeCharacter.java85
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeListActivity.java4
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java2
5 files changed, 110 insertions, 7 deletions
diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml
index 383895f..3b8c592 100644
--- a/res/layout/list_item.xml
+++ b/res/layout/list_item.xml
@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:padding="10dp"
- android:textSize="16sp"
- />
+ android:orientation="horizontal"
+ android:padding="10dp">
+ <TextView android:id="@+id/charText"
+ android:layout_width="32sp"
+ android:layout_height="fill_parent"
+ android:textSize="18sp"
+ android:textColor="#ffffff80" />
+ <TextView android:id="@+id/labelText"
+ android:layout_width="0dip"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:textSize="16sp" />
+</LinearLayout>
diff --git a/res/layout/map_item.xml b/res/layout/map_item.xml
new file mode 100644
index 0000000..fcaf32d
--- /dev/null
+++ b/res/layout/map_item.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="10dp"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ />
diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
index 11d8d3e..7fad75d 100644
--- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java
+++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
@@ -1,13 +1,14 @@
package org.madore.android.unicodeMap;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Set;
import java.util.Map;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Formatter;
-public class UnicodeCharacter {
+public class UnicodeCharacter implements Map<String,String> {
enum Category {
UPPERCASE_LETTER("Lu", Character.UPPERCASE_LETTER),
@@ -97,6 +98,20 @@ public class UnicodeCharacter {
return name;
}
+ public String getChar() {
+ return new String(Character.toChars(codePoint));
+ }
+
+ public String getLabel() {
+ StringBuilder s = new StringBuilder();
+ Formatter fmt = new Formatter(s);
+ if ( codePoint < 0x10000 )
+ fmt.format("U+%04X %s", codePoint, name);
+ else
+ fmt.format("U+%X %s", codePoint, name);
+ return new String(s);
+ }
+
public boolean isPrintable() {
return printable.contains(this.category);
}
@@ -116,4 +131,72 @@ public class UnicodeCharacter {
return new String(s);
}
+ public final static String KEY_CHAR = "char";
+ public final static String KEY_LABEL = "label";
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsKey(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsValue(Object value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Set<Map.Entry<String,String>> entrySet() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean equals(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String get(Object key) {
+ if ( key == null )
+ throw new NullPointerException();
+ else if ( key instanceof String && key.equals(KEY_CHAR) )
+ return getChar();
+ else if ( key instanceof String && key.equals(KEY_LABEL) )
+ return getLabel();
+ else if ( key instanceof String )
+ return null;
+ else
+ throw new ClassCastException();
+ }
+
+ public int hashCode() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isEmpty() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Set<String> keySet() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String put(String key, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void putAll(Map<? extends String,? extends String> t) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String remove(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> values() {
+ throw new UnsupportedOperationException();
+ }
+
}
diff --git a/src/org/madore/android/unicodeMap/UnicodeListActivity.java b/src/org/madore/android/unicodeMap/UnicodeListActivity.java
index a08dbe2..2e37d6f 100644
--- a/src/org/madore/android/unicodeMap/UnicodeListActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeListActivity.java
@@ -35,7 +35,9 @@ public final class UnicodeListActivity extends ListActivity {
list.add(ch);
final ClipboardManager cmgr
= (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
- setListAdapter(new ArrayAdapter<UnicodeCharacter>(this, R.layout.list_item, list));
+ setListAdapter(new SimpleAdapter(this, list, R.layout.list_item,
+ new String[] { "char", "label" },
+ new int[] { R.id.charText, R.id.labelText }));
final Button btn = (Button) findViewById(R.id.button);
final EditText txt = (EditText) findViewById(R.id.edit);
btn.setOnClickListener(new View.OnClickListener() {
diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
index de026de..7ef9b68 100644
--- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
@@ -237,7 +237,7 @@ public final class UnicodeMapActivity extends ListActivity {
};
thr.start();
}
- setListAdapter(new ArrayAdapter<UnicodeRange>(this, R.layout.list_item, list));
+ setListAdapter(new ArrayAdapter<UnicodeRange>(this, R.layout.map_item, list));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {