Skip to content

Commit f6ddb75

Browse files
author
Jin Cao
committed
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
1 parent fcaf986 commit f6ddb75

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/com/android/ex/chips/RecipientEditTextView.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package com.android.ex.chips;
1919

20-
import android.app.Activity;
2120
import android.app.Dialog;
2221
import android.content.ClipData;
2322
import android.content.ClipDescription;
@@ -63,7 +62,6 @@
6362
import android.text.util.Rfc822Tokenizer;
6463
import android.util.AttributeSet;
6564
import android.util.Log;
66-
import android.util.TypedValue;
6765
import android.view.ActionMode;
6866
import android.view.ActionMode.Callback;
6967
import android.view.DragEvent;
@@ -141,7 +139,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
141139
private static final int MAX_CHIPS_PARSED = 50;
142140

143141
private static int sSelectedTextColor = -1;
144-
private static int sVisibleDisplayFrameTop = -1;
145142

146143
// Work variables to avoid re-allocation on every typed character.
147144
private final Rect mRect = new Rect();
@@ -497,24 +494,6 @@ public void onFocusChanged(boolean hasFocus, int direction, Rect previous) {
497494
}
498495
}
499496

500-
// sVisibleDisplayFrameTop is computed on a on-demand basis because the view needs to be fully
501-
// measured and created in order to calculate the visible display frame.
502-
private int getVisibleDisplayFrameTop() {
503-
if (sVisibleDisplayFrameTop == -1) {
504-
final TypedValue tv = new TypedValue();
505-
final Context context = getContext();
506-
// Visible top is our visible display (due to status bar) plus the height of action bar.
507-
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
508-
sVisibleDisplayFrameTop = TypedValue.complexToDimensionPixelSize(tv.data,
509-
getResources().getDisplayMetrics());
510-
}
511-
// Compute the status bar height, or rather where our visible display starts
512-
getWindowVisibleDisplayFrame(mRect);
513-
sVisibleDisplayFrameTop += mRect.top;
514-
}
515-
return sVisibleDisplayFrameTop;
516-
}
517-
518497
@Override
519498
public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
520499
super.setAdapter(adapter);
@@ -568,7 +547,8 @@ protected void scrollBottomIntoView() {
568547
// content.
569548
final int height = getHeight();
570549
final int currentPos = mCoords[1] + height;
571-
final int desiredPos = getVisibleDisplayFrameTop() + height / getLineCount();
550+
mScrollView.getLocationInWindow(mCoords);
551+
final int desiredPos = mCoords[1] + height / getLineCount();
572552
if (currentPos > desiredPos) {
573553
mScrollView.scrollBy(0, currentPos - desiredPos);
574554
}

0 commit comments

Comments
 (0)