From 4307bce6cd10fe0e3ebb86118d2077fbd78ff1cb Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Mon, 26 Apr 2010 22:28:20 +0200 Subject: Show character details on long click. --- .../android/unicodeMap/UnicodeCharacter.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (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 34bab47..646c696 100644 --- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -6,6 +6,10 @@ import java.util.Map; import java.util.EnumSet; import java.util.HashMap; import java.util.Formatter; +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.IOException; public class UnicodeCharacter implements UnicodeDisplayable { @@ -320,4 +324,32 @@ public class UnicodeCharacter implements UnicodeDisplayable { return this.getLabel(); } + static byte[] toUtf8(String s) { + try { + ByteArrayOutputStream buf = new ByteArrayOutputStream(8); + OutputStreamWriter writer = new OutputStreamWriter(buf, "UTF-8"); + writer.write(s, 0, s.length()); + writer.close(); + return buf.toByteArray(); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-8 encoding unsupported"); + } catch (IOException e) { + throw new AssertionError("this is impossible"); + } + } + + static byte[] toUtf16(String s) { + try { + ByteArrayOutputStream buf = new ByteArrayOutputStream(8); + OutputStreamWriter writer = new OutputStreamWriter(buf, "UTF-16BE"); + writer.write(s, 0, s.length()); + writer.close(); + return buf.toByteArray(); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-16BE encoding unsupported"); + } catch (IOException e) { + throw new AssertionError("this is impossible"); + } + } + } -- cgit v1.2.3