Use dropdown anchor to compute dropdown height

In case the dropdown anchor is not set to itself, use
the anchor to properly compute the remaining height
from the bottom of the view to bottom of the screen.

b/17824127

Change-Id: Ic588f4ad6cede7ed22074ff7ed91843dca00a689
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 6b25b8f..9310639 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -175,6 +175,7 @@
     private TextWatcher mTextWatcher;
     private DropdownChipLayouter mDropdownChipLayouter;
 
+    private View mDropdownAnchor = this;
     private ListPopupWindow mAlternatesPopup;
     private ListPopupWindow mAddressPopup;
     private View mAlternatePopupAnchor;
@@ -346,6 +347,11 @@
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
         mAttachedToWindow = true;
+
+        final int anchorId = getDropDownAnchor();
+        if (anchorId != View.NO_ID) {
+            mDropdownAnchor = getRootView().findViewById(anchorId);
+        }
     }
 
     @Override
@@ -529,12 +535,13 @@
                                 R.string.accessbility_suggestion_dropdown_opened));
                     }
                 }
-                // Set the dropdown height to be the remaining height
+
+                // Set the dropdown height to be the remaining height from the anchor to the bottom.
                 final int[] coords = new int[2];
-                getLocationInWindow(coords);
+                mDropdownAnchor.getLocationInWindow(coords);
                 final Rect displayFrame = new Rect();
                 getWindowVisibleDisplayFrame(displayFrame);
-                setDropDownHeight(displayFrame.bottom - coords[1] - getHeight());
+                setDropDownHeight(displayFrame.bottom - coords[1] - mDropdownAnchor.getHeight());
 
                 mCurrentSuggestionCount = entries == null ? 0 : entries.size();
             }