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()))); } }); } }