summaryrefslogtreecommitdiffstats
path: root/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
blob: 6caad153cbbf3c940333db98b05d221adfd44dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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<UnicodeCharacter> list = new ArrayList<UnicodeCharacter>(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<UnicodeCharacter>(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())));
		}
	    });

    }

}