summaryrefslogtreecommitdiffstats
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
index 687493e..e633006 100644
--- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
@@ -1,5 +1,6 @@
package org.madore.android.unicodeMap;
+import java.lang.ref.SoftReference;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
@@ -30,8 +31,18 @@ public final class UnicodeMapActivity extends ListActivity {
protected static abstract class Display {
protected String title;
+ protected SoftReference<List<UnicodeDisplayable>> listCacheRef;
public Display(String title) { this.title = title; }
public final String getTitle() { return this.title; }
+ public void setListCache(List<UnicodeDisplayable> list) {
+ this.listCacheRef = new SoftReference<List<UnicodeDisplayable>>(list);
+ }
+ public List<UnicodeDisplayable> getListCache() {
+ if ( this.listCacheRef != null )
+ return this.listCacheRef.get();
+ else
+ return null;
+ }
}
protected static class RootDisplay extends Display {
public RootDisplay() { super(null); }
@@ -138,12 +149,17 @@ public final class UnicodeMapActivity extends ListActivity {
protected void doDisplay(Display disp, boolean isNew) {
curDisp = disp;
- List<UnicodeDisplayable> list;
+ List<UnicodeDisplayable> list = disp.getListCache();
UnicodeArrayAdapter adapter;
- if ( disp instanceof RootDisplay ) {
+ if ( list != null ) {
+ android.util.Log.v("UnicodeMapActivity", "list was retrieved from its cache");
+ adapter = new UnicodeArrayAdapter(this, list);
+ setListAdapter(adapter);
+ } else if ( disp instanceof RootDisplay ) {
list = new ArrayList<UnicodeDisplayable>(UnicodeCharacter.Range.values().length);
for ( UnicodeCharacter.Range rng : UnicodeCharacter.Range.values() )
list.add(rng);
+ disp.setListCache(list);
adapter = new UnicodeArrayAdapter(this, list);
setListAdapter(adapter);
} else if ( disp instanceof RangeDisplay ) {
@@ -152,6 +168,7 @@ public final class UnicodeMapActivity extends ListActivity {
list = new ArrayList<UnicodeDisplayable>(db.countRange(from,to));
for ( UnicodeCharacter ch : db.getRange(from,to) )
list.add(ch);
+ disp.setListCache(list);
adapter = new UnicodeArrayAdapter(this, list);
setListAdapter(adapter);
} else if ( disp instanceof SearchDisplay ) {
@@ -161,6 +178,7 @@ public final class UnicodeMapActivity extends ListActivity {
list = new ArrayList<UnicodeDisplayable>(sizeHint);
for ( UnicodeCharacter ch : db.searchNames(s,limit+1) )
list.add(ch);
+ disp.setListCache(list);
int size = list.size();
((SearchDisplay)disp).setSizeHint(size);
boolean overflowed = ( size > limit );