From e18c29676c04f22044a759cbaa854560ba227a4f Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Mon, 2 Jul 2012 13:11:16 -0700 Subject: [PATCH] Text message scrolling broken again Bug 6740178 ComposeMessageActivity needs to keep track of whether it was scrolled to the end when paused so it can rescroll to the end when resumed. Change-Id: Ib7e7a5e13df354c45a0eddaaa96a5c0f66c05873 --- .../mms/ui/ComposeMessageActivity.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/com/android/mms/ui/ComposeMessageActivity.java b/src/com/android/mms/ui/ComposeMessageActivity.java index d782b3c70..2ba2ef28b 100644 --- a/src/com/android/mms/ui/ComposeMessageActivity.java +++ b/src/com/android/mms/ui/ComposeMessageActivity.java @@ -302,6 +302,8 @@ public class ComposeMessageActivity extends Activity private int mSavedScrollPosition = -1; // we save the ListView's scroll position in onPause(), // so we can remember it after re-entering the activity. + // If the value >= 0, then we jump to that line. If the + // value is maxint, then we jump to the end. /** * Whether this activity is currently running (i.e. not paused) @@ -2176,7 +2178,14 @@ protected void onPause() { MessagingNotification.setCurrentlyDisplayedThreadId(MessagingNotification.THREAD_NONE); - mSavedScrollPosition = mMsgListView.getFirstVisiblePosition(); + // Remember whether the list is scrolled to the end when we're paused so we can rescroll + // to the end when resumed. + if (mMsgListAdapter != null && + mMsgListView.getLastVisiblePosition() >= mMsgListAdapter.getCount() - 1) { + mSavedScrollPosition = Integer.MAX_VALUE; + } else { + mSavedScrollPosition = mMsgListView.getFirstVisiblePosition(); + } if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { Log.v(TAG, "onPause: mSavedScrollPosition=" + mSavedScrollPosition); } @@ -3850,15 +3859,31 @@ protected void onQueryComplete(int token, Object cookie, Cursor cursor) { } } } else if (mSavedScrollPosition != -1) { - // remember the saved scroll position before the activity is paused. - // reset it after the message list query is done - newSelectionPos = mSavedScrollPosition; - mSavedScrollPosition = -1; + // mSavedScrollPosition is set when this activity pauses. If equals maxint, + // it means the message list was scrolled to the end. Meanwhile, messages + // could have been received. When the activity resumes and we were + // previously scrolled to the end, jump the list so any new messages are + // visible. + if (mSavedScrollPosition == Integer.MAX_VALUE) { + int cnt = mMsgListAdapter.getCount(); + if (cnt > 0) { + // Have to wait until the adapter is loaded before jumping to + // the end. + newSelectionPos = cnt - 1; + mSavedScrollPosition = -1; + } + } else { + // remember the saved scroll position before the activity is paused. + // reset it after the message list query is done + newSelectionPos = mSavedScrollPosition; + mSavedScrollPosition = -1; + } } mMsgListAdapter.changeCursor(cursor); + if (newSelectionPos != -1) { - mMsgListView.setSelection(newSelectionPos); + mMsgListView.setSelection(newSelectionPos); // jump the list to the pos } else { // mScrollOnSend is set when we send a message. We always want to scroll // the message list to the end when we send a message, but have to wait