Making call log scroll to top in some cases

It will scroll to the top in all cases except
navigation between tabs in the contacts app.

Bug: 3066840
Change-Id: Id92e2c99880b45c27ea5964fbe45083ed6fbf02c
diff --git a/src/com/android/contacts/RecentCallsListActivity.java b/src/com/android/contacts/RecentCallsListActivity.java
index 145ff69..dad5491 100644
--- a/src/com/android/contacts/RecentCallsListActivity.java
+++ b/src/com/android/contacts/RecentCallsListActivity.java
@@ -135,6 +135,8 @@
     private QueryHandler mQueryHandler;
     String mVoiceMailNumber;
 
+    private boolean mScrollToTop;
+
     static final class ContactInfo {
         public long personId;
         public String name;
@@ -817,6 +819,13 @@
                 final RecentCallsListActivity.RecentCallsAdapter callsAdapter = activity.mAdapter;
                 callsAdapter.setLoading(false);
                 callsAdapter.changeCursor(cursor);
+                if (activity.mScrollToTop) {
+                    if (activity.mList.getFirstVisiblePosition() > 5) {
+                        activity.mList.setSelection(5);
+                    }
+                    activity.mList.smoothScrollToPosition(0);
+                    activity.mScrollToTop = false;
+                }
             } else {
                 cursor.close();
             }
@@ -845,6 +854,12 @@
     }
 
     @Override
+    protected void onStart() {
+        mScrollToTop = true;
+        super.onStart();
+    }
+
+    @Override
     protected void onResume() {
         // The adapter caches looked up numbers, clear it so they will get
         // looked up again.