Don't rely on action bar height

When computing the scroll offset to scroll the edittext's bottom
line into view (to maximize the space for the dropdown), don't
rely on the statis status bar + action bar height calculation
because action bar's height changes depending on platform version
and orientation. Instead, use the scroll view's location in window
as the "top" of the visible display frame.

b/17824127

Change-Id: I35fd04201a11e5ba47de84eb4a1c5d309e08c203
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 400f049..cb0ef51 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -17,7 +17,6 @@
 
 package com.android.ex.chips;
 
-import android.app.Activity;
 import android.app.Dialog;
 import android.content.ClipData;
 import android.content.ClipDescription;
@@ -63,7 +62,6 @@
 import android.text.util.Rfc822Tokenizer;
 import android.util.AttributeSet;
 import android.util.Log;
-import android.util.TypedValue;
 import android.view.ActionMode;
 import android.view.ActionMode.Callback;
 import android.view.DragEvent;
@@ -141,7 +139,6 @@
     private static final int MAX_CHIPS_PARSED = 50;
 
     private static int sSelectedTextColor = -1;
-    private static int sVisibleDisplayFrameTop = -1;
 
     // Work variables to avoid re-allocation on every typed character.
     private final Rect mRect = new Rect();
@@ -497,24 +494,6 @@
         }
     }
 
-    // sVisibleDisplayFrameTop is computed on a on-demand basis because the view needs to be fully
-    // measured and created in order to calculate the visible display frame.
-    private int getVisibleDisplayFrameTop() {
-        if (sVisibleDisplayFrameTop == -1) {
-            final TypedValue tv = new TypedValue();
-            final Context context = getContext();
-            // Visible top is our visible display (due to status bar) plus the height of action bar.
-            if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
-                sVisibleDisplayFrameTop = TypedValue.complexToDimensionPixelSize(tv.data,
-                        getResources().getDisplayMetrics());
-            }
-            // Compute the status bar height, or rather where our visible display starts
-            getWindowVisibleDisplayFrame(mRect);
-            sVisibleDisplayFrameTop += mRect.top;
-        }
-        return sVisibleDisplayFrameTop;
-    }
-
     @Override
     public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
         super.setAdapter(adapter);
@@ -568,7 +547,8 @@
             // content.
             final int height = getHeight();
             final int currentPos = mCoords[1] + height;
-            final int desiredPos = getVisibleDisplayFrameTop() + height / getLineCount();
+            mScrollView.getLocationInWindow(mCoords);
+            final int desiredPos = mCoords[1] + height / getLineCount();
             if (currentPos > desiredPos) {
                 mScrollView.scrollBy(0, currentPos - desiredPos);
             }