summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-24 18:41:11 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-24 18:41:11 (GMT)
commit1ee686acab53146f5dbe922ed68abd10caace2c8 (patch)
treed37092824f109c60fe432830b219322bce83ba2d
parentfa539907328dc02ba49b79f51a0e060bf42d85ee (diff)
downloadUnicodeMap-1ee686acab53146f5dbe922ed68abd10caace2c8.zip
UnicodeMap-1ee686acab53146f5dbe922ed68abd10caace2c8.tar.gz
UnicodeMap-1ee686acab53146f5dbe922ed68abd10caace2c8.tar.bz2
Create a two-tiered menu system.
UnicodeMapActivity is the root activity, which launches UnicodeListActivity for the desired range.
-rw-r--r--AndroidManifest.xml4
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeListActivity.java52
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java45
3 files changed, 83 insertions, 18 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ce77c30..104ba58 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4,12 +4,12 @@
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name">
- <activity android:name=".UnicodeMapActivity"
- android:label="@string/app_name">
+ <activity android:name=".UnicodeMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name=".UnicodeListActivity" />
</application>
</manifest>
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);
}
});