When the field loses focus, commit the default chip.

If there were any filterable results, this is the first entry
provided by the adapter.
If not, this is whatever the user was typing in.

Change-Id: I966382dbe38adb20d4123b53443b0fd8d8cf9c89
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 37e9066..f1ce3cd 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -132,9 +132,11 @@
     @Override
     public void onFocusChanged(boolean hasFocus, int direction, Rect previous) {
         if (!hasFocus) {
-            clearSelectedChip();
-            // TODO: commit the default when focus changes. Need an API change
-            // to be able to still get the popup suggestions when focus is lost.
+            if (mSelectedChip != null) {
+                clearSelectedChip();
+            } else {
+                commitDefault();
+            }
         } else {
             setCursorVisible(true);
             Editable text = getText();
@@ -341,7 +343,7 @@
     // If the popup is showing, the default is the first item in the popup
     // suggestions list. Otherwise, it is whatever the user had typed in.
     private boolean commitDefault() {
-        if (isPopupShowing()) {
+        if (enoughToFilter() && getAdapter().getCount() > 0) {
             // choose the first entry.
             submitItemAtPosition(0);
             dismissDropDown();