Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Text message scrolling broken again
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tom Taylor committed Jul 2, 2012
1 parent 11818d7 commit e18c296
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/com/android/mms/ui/ComposeMessageActivity.java
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e18c296

Please sign in to comment.