From 1ee686acab53146f5dbe922ed68abd10caace2c8 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 24 Apr 2010 20:41:11 +0200 Subject: Create a two-tiered menu system. UnicodeMapActivity is the root activity, which launches UnicodeListActivity for the desired range. --- .../android/unicodeMap/UnicodeListActivity.java | 52 ++++++++++++++++++++++ .../android/unicodeMap/UnicodeMapActivity.java | 45 ++++++++++++------- 2 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 src/org/madore/android/unicodeMap/UnicodeListActivity.java (limited to 'src') 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 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(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(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 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 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(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(this, R.layout.list_item, list)); + 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()))); + 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); } }); -- cgit v1.2.3