diff options
Diffstat (limited to 'src/org/madore')
-rw-r--r-- | src/org/madore/android/unicodeMap/UnicodeListActivity.java | 52 | ||||
-rw-r--r-- | src/org/madore/android/unicodeMap/UnicodeMapActivity.java | 45 |
2 files changed, 81 insertions, 16 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeListActivity.java b/src/org/madore/android/unicodeMap/UnicodeListActivity.java new file mode 100644 index 0000000..8f962f0 --- /dev/null +++ b/src/org/madore/android/unicodeMap/UnicodeListActivity.java @@ -0,0 +1,52 @@ +package org.madore.android.unicodeMap; + +import java.util.List; +import java.util.ArrayList; +import android.content.Context; +import android.content.Intent; +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 final class UnicodeListActivity extends ListActivity { + + public static final String EXTRA_FROM + = "org.madore.android.unicodeMap.range.From"; + public static final String EXTRA_TO + = "org.madore.android.unicodeMap.range.To"; + + protected UnicodeDatabase db; + protected List<UnicodeCharacter> list; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.db = new UnicodeDatabase(getApplicationContext()); + Intent intent = getIntent(); + int from = intent.getIntExtra(EXTRA_FROM, 0); + int to = intent.getIntExtra(EXTRA_TO, from+128); + this.list = new ArrayList<UnicodeCharacter>(db.countRange(from,to)); + for ( UnicodeCharacter ch : db.getRange(from,to) ) + list.add(ch); + 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()))); + } + }); + + } + +} diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index f4c7dc6..fbaced4 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -1,40 +1,53 @@ package org.madore.android.unicodeMap; +import java.util.Arrays; import java.util.List; -import java.util.ArrayList; import android.content.Context; -import android.content.res.AssetManager; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.*; -import android.text.ClipboardManager; import android.app.ListActivity; public final class UnicodeMapActivity extends ListActivity { - protected UnicodeDatabase db; - protected List<UnicodeCharacter> list; + protected static enum UnicodeRange { + BASIC_LATIN(0x0000, 0x0080, "Basic Latin"), + LATIN_1_SUPPLEMENT(0x0080, 0x0100, "Latin-1 Supplement"), + LATIN_EXTENDED_A(0x0100, 0x0180, "Latin Extended-A"), + LATIN_EXTENDED_B(0x0180, 0x0250, "Latin Extended-B"), + IPA_EXTENSIONS(0x0250, 0x02b0, "IPA Extensions"); + protected final int from; protected final int to; + protected final String descr; + UnicodeRange(int from, int to, String descr) { + this.from = from; + this.to = to; + this.descr = descr; + } + public String toString() { return this.descr; } + public int getFrom() { return this.from; } + public int getTo() { return this.to; } + } + + protected final List<UnicodeRange> list + = Arrays.asList(UnicodeRange.values()); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.db = new UnicodeDatabase(getApplicationContext()); - this.list = new ArrayList<UnicodeCharacter>(db.countRange(0,1024)); - for ( UnicodeCharacter ch : db.getRange(0,1024) ) - list.add(ch); - final ClipboardManager cmgr - = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); - setListAdapter(new ArrayAdapter<UnicodeCharacter>(this, R.layout.list_item, list)); + setListAdapter(new ArrayAdapter<UnicodeRange>(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()))); + UnicodeRange it = (UnicodeRange)parent.getItemAtPosition(position); + Intent intent = new Intent(UnicodeMapActivity.this, + UnicodeListActivity.class); + intent.putExtra(UnicodeListActivity.EXTRA_FROM, it.getFrom()); + intent.putExtra(UnicodeListActivity.EXTRA_TO, it.getTo()); + startActivity(intent); } }); |