Bug 740306 - Back button does not dismiss the keyboard in awesomebar. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 30 Mar 2012 17:00:41 -0700
changeset 90693 41600364e780b7bdfe51d22b7ce2be1985891fdf
parent 90692 7d59ec72a07c72e1509eebe9ccd5f23cf1474f7c
child 90694 883536e3b5da574643c6e72f3eb3a18e579894da
push id1069
push usermfinkle@mozilla.com
push dateWed, 04 Apr 2012 14:22:33 +0000
treeherdermozilla-aurora@883536e3b5da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs740306
milestone13.0a2
Bug 740306 - Back button does not dismiss the keyboard in awesomebar. r=mfinkle
mobile/android/base/AwesomeBarTabs.java
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -314,20 +314,28 @@ public class AwesomeBarTabs extends TabH
         public void setHeaderView(LinearLayout titleView) {
             mBookmarksTitleView = titleView;
         }
     }
 
     // This method checks to see if we're in a bookmark sub-folder. If we are,
     // it will go up a level and return true. Otherwise it will return false.
     public boolean onBackPressed() {
+        // If the soft keyboard is visible in the bookmarks or history tab, the user
+        // must have explictly brought it up, so we should try hiding it instead of
+        // exiting the activity or going up a bookmarks folder level.
+        if (getCurrentTabTag().equals(BOOKMARKS_TAB) || getCurrentTabTag().equals(HISTORY_TAB)) {
+            View tabView = getCurrentTabView();
+            if (hideSoftInput(tabView))
+                return true;
+        }
+
         // If we're not in the bookmarks tab, we have nothing to do. We should
         // also return false if mBookmarksAdapter hasn't been initialized yet.
-        if (!getCurrentTabTag().equals(BOOKMARKS_TAB) ||
-                mBookmarksAdapter == null)
+        if (!getCurrentTabTag().equals(BOOKMARKS_TAB) || mBookmarksAdapter == null)
             return false;
 
         return mBookmarksAdapter.moveToParentFolder();
     }
      
     private class BookmarksQueryTask extends AsyncTask<Void, Void, Cursor> {
         private int mFolderId;
         private String mFolderTitle;
@@ -841,21 +849,21 @@ public class AwesomeBarTabs extends TabH
 
         ListView historyList = (ListView) findViewById(R.id.history_list);
         historyList.setOnTouchListener(mListTouchListener);
 
         // Only load history list when tab is actually used.
         // See OnTabChangeListener above.
     }
 
-    private void hideSoftInput(View view) {
+    private boolean hideSoftInput(View view) {
         InputMethodManager imm =
                 (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
 
-        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+        return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
     }
 
     private void handleBookmarkItemClick(AdapterView<?> parent, View view, int position, long id) {
         int headerCount = ((ListView) parent).getHeaderViewsCount();
         // If we tap on the header view, there's nothing to do
         if (headerCount == 1 && position == 0)
             return;