Fix search back behavior.
This is the final issue: we remove the intermediate activity when
searching. After this, back at search results goes directly to the Inbox.
Change-Id: I437d7bd7b08da1d7befdd873b43edaeee6ac99ee
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 8fee6a3..5aeb055 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -62,7 +62,6 @@
import com.android.mail.providers.UIProvider.AutoAdvance;
import com.android.mail.providers.UIProvider.ConversationColumns;
import com.android.mail.providers.UIProvider.FolderCapabilities;
-import com.android.mail.ui.UndoBarView.OnUndoCancelListener;
import com.android.mail.utils.LogUtils;
import com.android.mail.utils.Utils;
import com.google.common.collect.ImmutableList;
@@ -72,7 +71,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
@@ -1397,6 +1395,13 @@
}
}
+ @Override
+ public void exitSearchMode() {
+ if (mViewMode.getMode() == ViewMode.SEARCH_RESULTS_LIST) {
+ mActivity.finish();
+ }
+ }
+
/**
* Supports dragging conversations to a folder.
*/
diff --git a/src/com/android/mail/ui/ActionBarView.java b/src/com/android/mail/ui/ActionBarView.java
index f021db7..31bdbbc 100644
--- a/src/com/android/mail/ui/ActionBarView.java
+++ b/src/com/android/mail/ui/ActionBarView.java
@@ -53,7 +53,8 @@
* TODO(viki): Include ConversationSubjectDisplayer here as well.
*/
public final class ActionBarView extends LinearLayout implements OnNavigationListener,
- ViewMode.ModeChangeListener, OnQueryTextListener, OnSuggestionListener {
+ ViewMode.ModeChangeListener, OnQueryTextListener, OnSuggestionListener,
+ MenuItem.OnActionExpandListener {
private ActionBar mActionBar;
private RestrictedActivity mActivity;
private ActivityController mController;
@@ -107,7 +108,7 @@
}
/**
- * Collapses the search action view.
+ * Close the search view if it is expanded.
*/
public void collapseSearch() {
if (mSearch != null) {
@@ -123,6 +124,7 @@
mSearch = menu.findItem(R.id.search);
if (mSearch != null) {
mSearchWidget = (SearchView) mSearch.getActionView();
+ mSearch.setOnActionExpandListener(this);
SearchManager searchManager = (SearchManager) mActivity.getActivityContext()
.getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null && mSearchWidget != null) {
@@ -130,6 +132,7 @@
mSearchWidget.setSearchableInfo(info);
mSearchWidget.setOnQueryTextListener(this);
mSearchWidget.setOnSuggestionListener(this);
+ mSearchWidget.setIconifiedByDefault(true);
}
}
mHelpItem = menu.findItem(R.id.help_info_menu_item);
@@ -459,4 +462,24 @@
public void onFolderUpdated(Folder folder) {
mSpinner.onFolderUpdated(folder);
}
+
+ @Override
+ public boolean onMenuItemActionExpand(MenuItem item) {
+ // Do nothing. Required as part of the interface, we ar only interested in
+ // onMenuItemActionCollapse(MenuItem).
+ // Have to return true here. Unlike other callbacks, the return value here is whether
+ // we want to suppress the action (rather than consume the action). We don't want to
+ // suppress the action.
+ return true;
+ }
+
+ @Override
+ public boolean onMenuItemActionCollapse(MenuItem item) {
+ // When the action menu is collapsed, we have performed a search, pop the search fragment.
+ mController.exitSearchMode();
+ // Have to return true here. Unlike other callbacks, the return value here is whether
+ // we want to suppress the action (rather than consume the action). We don't want to
+ // suppress the action.
+ return true;
+ }
}
diff --git a/src/com/android/mail/ui/ActivityController.java b/src/com/android/mail/ui/ActivityController.java
index a86dbcb..8cc3b91 100644
--- a/src/com/android/mail/ui/ActivityController.java
+++ b/src/com/android/mail/ui/ActivityController.java
@@ -268,6 +268,11 @@
void startSearch();
/**
+ * Exit the search mode, popping off one activity so that the back stack is fine.
+ */
+ void exitSearchMode();
+
+ /**
* Supports dragging conversations to a folder.
*/
boolean supportsDrag(DragEvent event, Folder folder);
@@ -278,4 +283,5 @@
void handleDrop(DragEvent event, Folder folder);
void onUndoCancel();
+
}