summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-27 17:08:50 (GMT)
committerDavid A. Madore <david@procyon.(none)>2010-04-27 17:08:50 (GMT)
commit51fcac04a29c1f1789cbb2414664c783d69ed940 (patch)
treee98a6da5ec5d3082c8ad584973f51c0767591f0b
parent3ead365d73d7e1674b3afee8e943249fee4a3b48 (diff)
downloadUnicodeMap-51fcac04a29c1f1789cbb2414664c783d69ed940.zip
UnicodeMap-51fcac04a29c1f1789cbb2414664c783d69ed940.tar.gz
UnicodeMap-51fcac04a29c1f1789cbb2414664c783d69ed940.tar.bz2
Use soft references to cache result lists from history.
-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 );