Hide types when the associated (empty) edit text loses focus

Bug 20299183

Change-Id: If6b4fa10957b52a84c0f8a77c8eeebaa220f42db
diff --git a/src/com/android/contacts/editor/EditorAnimator.java b/src/com/android/contacts/editor/EditorAnimator.java
index 2e17e23..251357a 100644
--- a/src/com/android/contacts/editor/EditorAnimator.java
+++ b/src/com/android/contacts/editor/EditorAnimator.java
@@ -47,7 +47,15 @@
 
     private AnimatorRunner mRunner = new AnimatorRunner();
 
+    public void hideEditorView(final View victim) {
+        removeEditorView(victim, /* removeVictimFromParent =*/ false);
+    }
+
     public void removeEditorView(final View victim) {
+        removeEditorView(victim, /* removeVictimFromParent =*/ true);
+    }
+
+    private void removeEditorView(final View victim, final boolean removeVictimFromParent) {
         mRunner.endOldAnimation();
         final int offset = victim.getHeight();
 
@@ -71,11 +79,15 @@
                     final View view = viewsToMove.get(i);
                     view.setTranslationY(0.0f);
                 }
-                // Remove our target view (if parent is null, we were run several times by quick
-                // fingers. Just ignore)
-                final ViewGroup victimParent = (ViewGroup) victim.getParent();
-                if (victimParent != null) {
-                    victimParent.removeView(victim);
+                if (removeVictimFromParent) {
+                    // Remove our target view (if parent is null, we were run several times by quick
+                    // fingers. Just ignore)
+                    final ViewGroup victimParent = (ViewGroup) victim.getParent();
+                    if (victimParent != null) {
+                        victimParent.removeView(victim);
+                    }
+                } else {
+                    victim.setVisibility(View.GONE);
                 }
             }
         });
diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java
index b60ae5c..cf94d8f 100644
--- a/src/com/android/contacts/editor/LabeledEditorView.java
+++ b/src/com/android/contacts/editor/LabeledEditorView.java
@@ -254,7 +254,16 @@
      */
     public void showType() {
         if (mHasTypes && mLabel != null && mLabel.getVisibility() != View.VISIBLE) {
-            mLabel.setVisibility(View.VISIBLE);
+            EditorAnimator.getInstance().slideAndFadeIn(mLabel, mLabel.getHeight());
+        }
+    }
+
+    /**
+     * Hides the type drop down if there are types to display and it is not already hidden.
+     */
+    public void hideType() {
+        if (mHasTypes && mLabel != null && mLabel.getVisibility() != View.GONE) {
+            EditorAnimator.getInstance().hideEditorView(mLabel);
         }
     }
 
diff --git a/src/com/android/contacts/editor/TextFieldsEditorView.java b/src/com/android/contacts/editor/TextFieldsEditorView.java
index 6f24bb9..9345434 100644
--- a/src/com/android/contacts/editor/TextFieldsEditorView.java
+++ b/src/com/android/contacts/editor/TextFieldsEditorView.java
@@ -159,7 +159,11 @@
                 getEditorListener().onRequest(EditorListener.EDITOR_FOCUS_CHANGED);
             }
             if (foundFocus && !isTypeVisible()) {
+                // We just got focus and the types are not visible
                 showType();
+            } else if (isEmpty()) {
+                // We just lost focus and the field is empty
+                hideType();
             }
             // Rebuild the label spinner using the new colors.
             rebuildLabel();