From 7718ef99581a6364c1acd6e94fad5b7352c2da82 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 22 Apr 2010 20:14:51 +0200 Subject: Start a very primitive unicode character map. --- .../android/unicodeMap/UnicodeCharacter.java | 35 ++++++++++++ .../android/unicodeMap/UnicodeMapActivity.java | 64 ++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/org/madore/android/unicodeMap/UnicodeCharacter.java create mode 100644 src/org/madore/android/unicodeMap/UnicodeMapActivity.java (limited to 'src/org') diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java new file mode 100644 index 0000000..c499921 --- /dev/null +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -0,0 +1,35 @@ +package org.madore.android.unicodeMap; + +import java.util.Formatter; + +public class UnicodeCharacter { + + protected final int codePoint; + protected final String name; + + public UnicodeCharacter(int codePoint, String name) { + this.codePoint = codePoint; + this.name = name; + } + + public int getCodePoint() { + return codePoint; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + StringBuilder s = new StringBuilder(); + s.append(Character.toChars(codePoint)); + 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); + } + +} diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java new file mode 100644 index 0000000..6caad15 --- /dev/null +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -0,0 +1,64 @@ +package org.madore.android.unicodeMap; + +import java.util.List; +import java.util.ArrayList; +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import android.content.Context; +import android.content.res.AssetManager; +import android.os.Bundle; +import android.view.View; +import android.widget.*; +import android.text.ClipboardManager; +import android.app.ListActivity; + +public class UnicodeMapActivity extends ListActivity { + + static final List list = new ArrayList(12); + + protected void parseUnicodeData() { + AssetManager amgr = getAssets(); + try { + BufferedReader rd + = new BufferedReader(new InputStreamReader(amgr.open("UnicodeData.txt"), + "US-ASCII")); + String line; + while ( ( line = rd.readLine() ) != null ) { + String[] bits = line.split(";"); + int codePoint = Integer.parseInt(bits[0], 16); + String name = bits[1]; + if ( name.charAt(0) != '<' ) + list.add(new UnicodeCharacter(codePoint, name)); + } + } catch (UnsupportedEncodingException e) { + throw new AssertionError("US-ASCII encoding unsupported"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + parseUnicodeData(); + final ClipboardManager cmgr + = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); + setListAdapter(new ArrayAdapter(this, R.layout.list_item, list)); + ListView lv = getListView(); + lv.setTextFilterEnabled(true); + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, + int position, long id) { + UnicodeCharacter it = (UnicodeCharacter)parent.getItemAtPosition(position); + Toast.makeText(getApplicationContext(), it.getName(), + Toast.LENGTH_SHORT).show(); + cmgr.setText(new String(Character.toChars(it.getCodePoint()))); + } + }); + + } + +} -- cgit v1.2.3