Merge "Import revised translations."
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 37cb9c5..dbdb1f0 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -28,6 +28,7 @@
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnFocusChangeListener;
 import android.widget.SearchView;
 import android.widget.SearchView.OnCloseListener;
 import android.widget.SearchView.OnQueryChangeListener;
@@ -36,8 +37,8 @@
 /**
  * Adapter for the action bar at the top of the Contacts activity.
  */
-public class ActionBarAdapter
-        implements OnQueryChangeListener, OnCloseListener, ContactListFilterListener {
+public class ActionBarAdapter implements OnQueryChangeListener, OnCloseListener,
+        ContactListFilterListener, OnFocusChangeListener {
 
     public interface Listener {
         void onAction();
@@ -94,6 +95,7 @@
         mSearchView.setIconifiedByDefault(false);
         mSearchView.setOnQueryChangeListener(this);
         mSearchView.setOnCloseListener(this);
+        mSearchView.setOnQueryTextFocusChangeListener(this);
         mSearchView.setQuery(mQueryString, false);
 
         update();
@@ -109,6 +111,13 @@
         mFilterController.addListener(this);
     }
 
+    @Override
+    public void onFocusChange(View v, boolean hasFocus) {
+        if (v == mSearchView) {
+            setSearchMode(hasFocus);
+        }
+    }
+
     public boolean isSearchMode() {
         return mSearchMode;
     }
@@ -119,6 +128,8 @@
             update();
             if (mSearchMode) {
                 mSearchView.requestFocus();
+            } else {
+                mSearchView.setQuery(null, false);
             }
             if (mListener != null) {
                 mListener.onAction();
@@ -162,15 +173,14 @@
     @Override
     public boolean onQueryTextChanged(String queryString) {
         mQueryString = queryString;
-        boolean searchMode = !TextUtils.isEmpty(queryString);
-        if (searchMode == mSearchMode) {
-            update();
-            if (mListener != null) {
-                mListener.onAction();
+        if (!mSearchMode) {
+            if (!TextUtils.isEmpty(queryString)) {
+                setSearchMode(true);
             }
-        } else {
-            setSearchMode(searchMode);
+        } else if (mListener != null) {
+            mListener.onAction();
         }
+
         return true;
     }
 
diff --git a/src/com/android/contacts/activities/ContactBrowserActivity.java b/src/com/android/contacts/activities/ContactBrowserActivity.java
index 054c50f..1c1f9b2 100644
--- a/src/com/android/contacts/activities/ContactBrowserActivity.java
+++ b/src/com/android/contacts/activities/ContactBrowserActivity.java
@@ -291,6 +291,7 @@
                 mListFragment = createContactSearchFragment();
             } else {
                 mListFragment = createListFragment(ContactsRequest.ACTION_DEFAULT);
+                mListFragment.requestSelectionOnScreen(false);
             }
         }
 
@@ -932,6 +933,15 @@
         return super.onKeyDown(keyCode, event);
     }
 
+    @Override
+    public void onBackPressed() {
+        if (mSearchMode && mActionBarAdapter != null) {
+            mActionBarAdapter.setSearchMode(false);
+        } else {
+            super.onBackPressed();
+        }
+    }
+
     private boolean deleteSelection() {
         // TODO move to the fragment
 //        if (mActionCode == ContactsRequest.ACTION_DEFAULT) {
diff --git a/src/com/android/contacts/list/ContactListItemView.java b/src/com/android/contacts/list/ContactListItemView.java
index 68560e4..ded0651 100644
--- a/src/com/android/contacts/list/ContactListItemView.java
+++ b/src/com/android/contacts/list/ContactListItemView.java
@@ -928,6 +928,10 @@
      * returns -1.
      */
     private int indexOfWordPrefix(CharArrayBuffer buffer, char[] prefix) {
+        if (prefix == null || prefix.length == 0) {
+            return -1;
+        }
+
         char[] string1 = buffer.data;
         int count1 = buffer.sizeCopied;
         int count2 = prefix.length;