diff options
author | David A. Madore <david@procyon.(none)> | 2010-04-27 19:53:14 +0200 |
---|---|---|
committer | David A. Madore <david@procyon.(none)> | 2010-04-27 19:53:14 +0200 |
commit | 9df4bb4fa30a0c05ccd484d6b59521bfca665854 (patch) | |
tree | 41c2e0a5f515c86ec46c707558a04d01c7002a35 | |
parent | 51fcac04a29c1f1789cbb2414664c783d69ed940 (diff) | |
download | UnicodeMap-9df4bb4fa30a0c05ccd484d6b59521bfca665854.tar.gz UnicodeMap-9df4bb4fa30a0c05ccd484d6b59521bfca665854.tar.bz2 UnicodeMap-9df4bb4fa30a0c05ccd484d6b59521bfca665854.zip |
Dynamically generate subranges on large character zones.
4 files changed, 51 insertions, 19 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java b/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java index 691d525..ecf7348 100644 --- a/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java +++ b/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java @@ -49,14 +49,14 @@ public class UnicodeArrayAdapter } ((TextView)charTextView).setText(((UnicodeCharacter)item).getChar()); ((TextView)labelTextView).setText(((UnicodeCharacter)item).getLabel()); - } else if ( item instanceof UnicodeCharacter.Range ) { + } else if ( item instanceof UnicodeRangeable ) { if ( convertView != null && convertView instanceof TextView ) { view = convertView; } if ( view == null ) view = inflater.inflate(R.layout.range_item, parent, false); - ((TextView)view).setText(((UnicodeCharacter.Range)item).getDescr()); + ((TextView)view).setText(((UnicodeRangeable)item).getDescr()); } else throw new AssertionError("unknown UnicodeDisplayable"); return view; diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java index 6fa8496..552b43c 100644 --- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -13,7 +13,7 @@ import java.io.IOException; public class UnicodeCharacter implements UnicodeDisplayable { - public static enum Range implements UnicodeDisplayable { + public static enum Range implements UnicodeDisplayable, UnicodeRangeable { BASIC_LATIN(0x0000, 0x007F, "Basic Latin"), LATIN_1_SUPPLEMENT(0x0080, 0x00FF, "Latin-1 Supplement"), LATIN_EXTENDED_A(0x0100, 0x017F, "Latin Extended-A"), diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index e633006..b48c771 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -48,17 +48,18 @@ public final class UnicodeMapActivity extends ListActivity { public RootDisplay() { super(null); } } protected static class RangeDisplay extends Display { - protected int from; protected int to; - public RangeDisplay(String title, int from, int to) { + protected int from; protected int to; protected int limit; + public RangeDisplay(String title, int from, int to, int limit) { super(title); - this.from = from; this.to = to; + this.from = from; this.to = to; this.limit = limit; } - public RangeDisplay(UnicodeCharacter.Range rng) { + public RangeDisplay(UnicodeRangeable rng, int limit) { super(rng.getDescr()); - this.from = rng.getFrom(); this.to = rng.getTo(); + this.from = rng.getFrom(); this.to = rng.getTo(); this.limit = limit; } public int getFrom() { return this.from; } public int getTo() { return this.to; } + public int getLimit() { return this.limit; } } protected static class SearchDisplay extends Display { protected String like; protected int limit; @@ -165,9 +166,26 @@ public final class UnicodeMapActivity extends ListActivity { } else if ( disp instanceof RangeDisplay ) { int from = ((RangeDisplay)disp).getFrom(); int to = ((RangeDisplay)disp).getTo(); - list = new ArrayList<UnicodeDisplayable>(db.countRange(from,to)); - for ( UnicodeCharacter ch : db.getRange(from,to) ) - list.add(ch); + int count = db.countRange(from,to); + if ( count > 1024 ) { + list = new ArrayList<UnicodeDisplayable>(count/128 + 1); + int from0 = from&(~127); + int to0 = ((to-1)|127)+1; + for ( int base=from0 ; base<to0 ; base+=128 ) { + final int from1 = base<from?from:base; + final int to1 = base+128>to?to:base+128; + final String str = String.format("%04X\u2013%04X", from1, to1-1); + list.add(new UnicodeRangeable() { + public int getFrom() { return from1; } + public int getTo() { return to1; } + public String getDescr() { return str; } + }); + } + } else { + list = new ArrayList<UnicodeDisplayable>(count); + for ( UnicodeCharacter ch : db.getRange(from,to) ) + list.add(ch); + } disp.setListCache(list); adapter = new UnicodeArrayAdapter(this, list); setListAdapter(adapter); @@ -201,6 +219,8 @@ public final class UnicodeMapActivity extends ListActivity { setTitle(getResources().getString(R.string.app_name)); } + final static int rangeLimit = 1024; + protected class MapItemClickListener implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { @@ -210,8 +230,8 @@ public final class UnicodeMapActivity extends ListActivity { = (UnicodeDisplayable)parent.getItemAtPosition(position); if ( it instanceof UnicodeCharacter ) textForm.append(((UnicodeCharacter)it).getChar()); - else if ( it instanceof UnicodeCharacter.Range ) { - Display newDisp = new RangeDisplay((UnicodeCharacter.Range)it); + else if ( it instanceof UnicodeRangeable ) { + Display newDisp = new RangeDisplay((UnicodeRangeable)it, rangeLimit); saveDisplay(view, position); doDisplay(newDisp, true); } else @@ -246,8 +266,8 @@ public final class UnicodeMapActivity extends ListActivity { text.setText(new String(s)); dialog.show(); return true; - } else if ( it instanceof UnicodeCharacter.Range ) { - UnicodeCharacter.Range itr = (UnicodeCharacter.Range)it; + } else if ( it instanceof UnicodeRangeable ) { + UnicodeRangeable itr = (UnicodeRangeable)it; Dialog dialog = new Dialog(UnicodeMapActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setOwnerActivity(UnicodeMapActivity.this); @@ -259,10 +279,15 @@ public final class UnicodeMapActivity extends ListActivity { text = (TextView) dialog.findViewById(R.id.rangeRangeLabel); StringBuilder s = new StringBuilder(); Formatter fmt = new Formatter(s); - fmt.format("%04X\u2013%04X (%d slots, %d chars)", - itr.getFrom(), itr.getTo()-1, - itr.getTo()-itr.getFrom(), - db.countRange(itr.getFrom(), itr.getTo())); + if ( itr instanceof UnicodeCharacter.Range ) + fmt.format("%04X\u2013%04X (%d slots, %d chars)", + itr.getFrom(), itr.getTo()-1, + itr.getTo()-itr.getFrom(), + db.countRange(itr.getFrom(), itr.getTo())); + else + fmt.format("(%d slots, %d chars)", + itr.getTo()-itr.getFrom(), + db.countRange(itr.getFrom(), itr.getTo())); text.setText(new String(s)); dialog.show(); return true; diff --git a/src/org/madore/android/unicodeMap/UnicodeRangeable.java b/src/org/madore/android/unicodeMap/UnicodeRangeable.java new file mode 100644 index 0000000..c3a7825 --- /dev/null +++ b/src/org/madore/android/unicodeMap/UnicodeRangeable.java @@ -0,0 +1,7 @@ +package org.madore.android.unicodeMap; + +public interface UnicodeRangeable extends UnicodeDisplayable { + public int getFrom(); + public int getTo(); + public String getDescr(); +} |