Fixed contacts tab reset to top after lock/unlock
+ save and restore list view position in ContactEntryListFragment
when the fragment is not recreated.
Bug:19982820
Change-Id: I65f8f42f0088f8507e81990d73c301e5697055ae
diff --git a/src/com/android/contacts/common/list/ContactEntryListFragment.java b/src/com/android/contacts/common/list/ContactEntryListFragment.java
index 8d1cede..f7c5e55 100644
--- a/src/com/android/contacts/common/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/common/list/ContactEntryListFragment.java
@@ -114,6 +114,12 @@
private ListView mListView;
/**
+ * Used to save the scrolling state of the list when the fragment is not recreated.
+ */
+ private int mListViewTopIndex;
+ private int mListViewTopOffset;
+
+ /**
* Used for keeping track of the scroll state of the list.
*/
private Parcelable mListState;
@@ -873,6 +879,11 @@
@Override
public void onPause() {
+ // Save the scrolling state of the list view
+ mListViewTopIndex = mListView.getFirstVisiblePosition();
+ View v = mListView.getChildAt(0);
+ mListViewTopOffset = (v == null) ? 0 : (v.getTop() - mListView.getPaddingTop());
+
super.onPause();
removePendingDirectorySearchRequests();
}
@@ -884,6 +895,11 @@
if (mListState != null) {
mListView.onRestoreInstanceState(mListState);
mListState = null;
+ } else {
+ // Restore the scrolling state of the list view.
+ // This has to be done manually be cause if the list view have its' emptyView set,
+ // the scrolling state will be reset when clearPartitions() is called on the adapter.
+ mListView.setSelectionFromTop(mListViewTopIndex, mListViewTopOffset);
}
}