diff options
author | David A. Madore <david+git@madore.org> | 2010-04-27 03:13:53 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2010-04-27 03:13:53 +0200 |
commit | c919a3c99166c812a1aa91e7df5023b22265b2b1 (patch) | |
tree | 2ae9ec9dceb7a64ad1a9dd63ffb430c3ee0c44d7 /src/org/madore | |
parent | 221e994358da9d5e18fe490a19389093dfe4e755 (diff) | |
download | UnicodeMap-c919a3c99166c812a1aa91e7df5023b22265b2b1.tar.gz UnicodeMap-c919a3c99166c812a1aa91e7df5023b22265b2b1.tar.bz2 UnicodeMap-c919a3c99166c812a1aa91e7df5023b22265b2b1.zip |
Clean up saving of view history.
Diffstat (limited to 'src/org/madore')
-rw-r--r-- | src/org/madore/android/unicodeMap/UnicodeMapActivity.java | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index 74dca91..a13f73a 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -27,15 +27,20 @@ public final class UnicodeMapActivity extends ListActivity { protected UnicodeDatabase db; - protected final List<UnicodeDisplayable> rootList - = new ArrayList<UnicodeDisplayable>(200); + protected class ViewHistory { + public final UnicodeArrayAdapter adapter; + public final int selPosition; + public final int yOffset; + public ViewHistory(UnicodeArrayAdapter adapter, + int selPosition, int yOffset) { + this.adapter = adapter; + this.selPosition = selPosition; + this.yOffset = yOffset; + } + } - protected final List<UnicodeArrayAdapter> stack - = new ArrayList<UnicodeArrayAdapter>(10); - protected final List<Integer> positionStack - = new ArrayList<Integer>(10); - protected final List<Integer> positionYStack - = new ArrayList<Integer>(10); + protected final List<ViewHistory> historyStack + = new ArrayList<ViewHistory>(10); EditText textForm; @@ -67,6 +72,37 @@ public final class UnicodeMapActivity extends ListActivity { thr.start(); } + protected void saveView(View selView, int selPosition) { + final ListView lv = getListView(); + lv.clearTextFilter(); + final UnicodeArrayAdapter adapter + = (UnicodeArrayAdapter) lv.getAdapter(); + final int yOffset; + if ( selView != null ) + yOffset = selView.getTop(); + else + yOffset = 0; + historyStack.add(new ViewHistory(adapter, selPosition, yOffset)); + } + + protected void saveView() { + final ListView lv = getListView(); + lv.clearTextFilter(); + final UnicodeArrayAdapter adapter + = (UnicodeArrayAdapter) lv.getAdapter(); + int position = lv.getSelectedItemPosition(); + int position0 = lv.getFirstVisiblePosition(); + if ( position == AdapterView.INVALID_POSITION ) + position = position0; + View view = lv.getChildAt(position-position0); + final int yOffset; + if ( view != null ) + yOffset = view.getTop(); + else + yOffset = 0; + historyStack.add(new ViewHistory(adapter, position, yOffset)); + } + protected class MapItemClickListener implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { @@ -86,12 +122,7 @@ public final class UnicodeMapActivity extends ListActivity { UnicodeArrayAdapter adapter = new UnicodeArrayAdapter(UnicodeMapActivity.this, list); - stack.add(adapter); - positionStack.add(position); - if ( view != null ) - positionYStack.add(view.getTop()); - else - positionYStack.add(0); + saveView(view, position); setListAdapter(adapter); } else throw new AssertionError("unknown UnicodeDisplayable"); @@ -159,11 +190,12 @@ public final class UnicodeMapActivity extends ListActivity { final boolean needPopulate = db.needPopulate(); if ( needPopulate ) launchPopulation(); + List<UnicodeDisplayable> rootList + = new ArrayList<UnicodeDisplayable>(UnicodeCharacter.Range.values().length); for ( UnicodeCharacter.Range rng : UnicodeCharacter.Range.values() ) rootList.add(rng); UnicodeArrayAdapter rootAdapter = new UnicodeArrayAdapter(this, rootList); - stack.add(rootAdapter); setListAdapter(rootAdapter); final ClipboardManager cmgr = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); @@ -197,18 +229,7 @@ public final class UnicodeMapActivity extends ListActivity { UnicodeArrayAdapter adapter = new UnicodeArrayAdapter(UnicodeMapActivity.this, list); - stack.add(adapter); - final ListView lv = getListView(); - int position = lv.getSelectedItemPosition(); - int position0 = lv.getFirstVisiblePosition(); - if ( position == AdapterView.INVALID_POSITION ) - position = position0; - positionStack.add(position); - View view = lv.getChildAt(position-position0); - if ( view != null ) - positionYStack.add(view.getTop()); - else - positionYStack.add(0); + saveView(); setListAdapter(adapter); if ( overflowed ) { String str = getResources().getString(R.string.list_too_long); @@ -258,12 +279,12 @@ public final class UnicodeMapActivity extends ListActivity { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if ( ( keyCode == KeyEvent.KEYCODE_BACK ) && stack.size() > 1 ) { + if ( ( keyCode == KeyEvent.KEYCODE_BACK ) + && historyStack.size() > 0 ) { final ListView lv = getListView(); - stack.remove(stack.size()-1); - setListAdapter(stack.get(stack.size()-1)); - lv.setSelectionFromTop(positionStack.remove(positionStack.size()-1), - positionYStack.remove(positionYStack.size()-1)); + ViewHistory saved = historyStack.remove(historyStack.size()-1); + setListAdapter(saved.adapter); + lv.setSelectionFromTop(saved.selPosition, saved.yOffset); return true; } else if ( keyCode == KeyEvent.KEYCODE_SEARCH ) { querySearch(); |