diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index fb17baf39..48a30bdd8 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -1,6 +1,13 @@ package com.fsck.k9.activity; // import android.os.Debug; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; @@ -15,32 +22,54 @@ import android.text.style.TextAppearanceSpan; import android.util.Config; import android.util.Log; import android.util.TypedValue; -import android.view.*; +import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; -import android.view.View.OnClickListener; +import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; -import android.widget.*; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.BaseAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import com.fsck.k9.*; -import com.fsck.k9.activity.setup.Prefs; +import android.widget.ImageButton; +import android.widget.ListView; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import com.fsck.k9.Account; +import com.fsck.k9.AccountStats; +import com.fsck.k9.FontSizes; +import com.fsck.k9.K9; +import com.fsck.k9.Preferences; +import com.fsck.k9.R; +import com.fsck.k9.SearchSpecification; import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.FolderSettings; +import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.controller.MessagingController; -import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.controller.MessagingController.SORT_TYPE; +import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.helper.Utility; -import com.fsck.k9.mail.*; +import com.fsck.k9.mail.Address; +import com.fsck.k9.mail.Flag; +import com.fsck.k9.mail.Folder; +import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message.RecipientType; +import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalMessage; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** @@ -71,6 +100,7 @@ public class MessageList private static final String EXTRA_ACCOUNT_UUIDS = "accountUuids"; private static final String EXTRA_FOLDER_NAMES = "folderNames"; private static final String EXTRA_TITLE = "title"; + private static final String EXTRA_LIST_POSITION = "listPosition"; private ListView mListView; @@ -123,6 +153,8 @@ public class MessageList private FontSizes mFontSizes = K9.getFontSizes(); + private Bundle mState = null; + class MessageListHandler extends Handler { public void removeMessage(final List messages) @@ -486,8 +518,37 @@ public class MessageList super.onPause(); //Debug.stopMethodTracing(); mController.removeListener(mAdapter.mListener); + saveListState(); } + public void saveListState() + { + mState = new Bundle(); + mState.putInt(EXTRA_LIST_POSITION, mListView.getSelectedItemPosition()); + } + + public void restoreListState() { + if (mState == null) + { + return; + } + + int pos = mState.getInt(EXTRA_LIST_POSITION, ListView.INVALID_POSITION); + + if (pos >= mListView.getCount()) + { + pos = mListView.getCount() - 1; + } + + if (pos == ListView.INVALID_POSITION) + { + mListView.setSelected(false); + } + else + { + mListView.setSelection(pos); + } + } /** * On resume we refresh @@ -526,6 +587,7 @@ public class MessageList mHandler.refreshTitle(); + restoreListState(); } private void initializeLayout()