summaryrefslogtreecommitdiffstats
path: root/src/org
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-27 18:47:48 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-27 18:47:48 +0200
commit3ead365d73d7e1674b3afee8e943249fee4a3b48 (patch)
tree7c721262dc64f0581a6afe6cc8c87e61602e50c4 /src/org
parentaa9f0171298ffd173b927f7e288593a88e0038ee (diff)
downloadUnicodeMap-3ead365d73d7e1674b3afee8e943249fee4a3b48.tar.gz
UnicodeMap-3ead365d73d7e1674b3afee8e943249fee4a3b48.tar.bz2
UnicodeMap-3ead365d73d7e1674b3afee8e943249fee4a3b48.zip
Retain display (and display history) on configuration change.
This works surprisingly well: there must be a grue hiding in the darkness waiting to eat me. :-)
Diffstat (limited to 'src/org')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
index 9f8194f..687493e 100644
--- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
@@ -136,7 +136,7 @@ public final class UnicodeMapActivity extends ListActivity {
dispHistory.add(new DisplayAndPosition(curDisp, position, yOffset));
}
- protected void doDisplay(Display disp) {
+ protected void doDisplay(Display disp, boolean isNew) {
curDisp = disp;
List<UnicodeDisplayable> list;
UnicodeArrayAdapter adapter;
@@ -168,7 +168,7 @@ public final class UnicodeMapActivity extends ListActivity {
list.remove(list.size()-1);
adapter = new UnicodeArrayAdapter(this, list);
setListAdapter(adapter);
- if ( overflowed ) {
+ if ( overflowed && isNew ) {
String str = getResources().getString(R.string.list_too_long);
Toast.makeText(UnicodeMapActivity.this,
String.format(str, limit),
@@ -195,7 +195,7 @@ public final class UnicodeMapActivity extends ListActivity {
else if ( it instanceof UnicodeCharacter.Range ) {
Display newDisp = new RangeDisplay((UnicodeCharacter.Range)it);
saveDisplay(view, position);
- doDisplay(newDisp);
+ doDisplay(newDisp, true);
} else
throw new AssertionError("unknown UnicodeDisplayable");
}
@@ -262,7 +262,19 @@ public final class UnicodeMapActivity extends ListActivity {
final boolean needPopulate = db.needPopulate();
if ( needPopulate )
launchPopulation();
- doDisplay(new RootDisplay());
+ lv = getListView();
+ Object testament = getLastNonConfigurationInstance();
+ if ( testament != null ) {
+ @SuppressWarnings("unchecked")
+ List<DisplayAndPosition> oldDispHistory = (List<DisplayAndPosition>)testament;
+ dispHistory.clear();
+ dispHistory.addAll(oldDispHistory);
+ assert(dispHistory.size() > 0);
+ DisplayAndPosition saved = dispHistory.remove(dispHistory.size()-1);
+ doDisplay(saved.getDisp(), false);
+ lv.setSelectionFromTop(saved.getSelPosition(), saved.getYOffset());
+ } else
+ doDisplay(new RootDisplay(), true);
final ClipboardManager cmgr
= (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
final Button btn = (Button) findViewById(R.id.copyButton);
@@ -275,20 +287,32 @@ public final class UnicodeMapActivity extends ListActivity {
Toast.LENGTH_SHORT).show();
}
});
- lv = getListView();
lv.setTextFilterEnabled(true);
MapItemClickListener listener = new MapItemClickListener();
lv.setOnItemClickListener(listener);
lv.setOnItemLongClickListener(listener);
}
+ @Override
+ public void onDestroy() {
+ db.close();
+ db = null;
+ super.onDestroy();
+ }
+
+ @Override
+ public Object onRetainNonConfigurationInstance() {
+ saveDisplay();
+ return dispHistory;
+ }
+
final static int searchLimit = 1000;
protected void doSearch(String s) {
Display newDisp = new SearchDisplay(getResources().getString(R.string.search_results),
s, searchLimit);
saveDisplay();
- doDisplay(newDisp);
+ doDisplay(newDisp, true);
}
protected void querySearch() {
@@ -347,7 +371,7 @@ public final class UnicodeMapActivity extends ListActivity {
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( ( keyCode == KeyEvent.KEYCODE_BACK ) && dispHistory.size() > 0 ) {
DisplayAndPosition saved = dispHistory.remove(dispHistory.size()-1);
- doDisplay(saved.getDisp());
+ doDisplay(saved.getDisp(), false);
lv.setSelectionFromTop(saved.getSelPosition(), saved.getYOffset());
return true;
} else if ( keyCode == KeyEvent.KEYCODE_SEARCH ) {