From dfccb7883425392290f5bf9afc845bae776320e9 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 25 Apr 2010 21:54:54 +0200 Subject: List layout: display characters differently from their labels. This is done by making UnicodeCharacter implement Map so as to use it in a SimpleAdapter, but really, this is ugly. --- .../android/unicodeMap/UnicodeCharacter.java | 85 +++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) (limited to 'src/org/madore/android/unicodeMap/UnicodeCharacter.java') 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 { 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> 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 keySet() { + throw new UnsupportedOperationException(); + } + + public String put(String key, String value) { + throw new UnsupportedOperationException(); + } + + public void putAll(Map t) { + throw new UnsupportedOperationException(); + } + + public String remove(Object key) { + throw new UnsupportedOperationException(); + } + + public int size() { + throw new UnsupportedOperationException(); + } + + public Collection values() { + throw new UnsupportedOperationException(); + } + } -- cgit v1.2.3