Fix bug 3413800 - Revise AutoCompleteTextView dropdown behavior

Be more conservative with when we let an AutoCompleteTextView's
dropdown box of completion suggestions cover the IME.

Disable the expand-when-touched behavior of the dropdown list when
more than 3 items can be seen at a time without it.

Don't let a ListPopupWindow that is expanding in response to touch
scroll the anchor view within its parent and slide the dropdown out
from under the user's finger.

Change-Id: I009accfd4e841c9a5e1072735d8a0b067a0bc06a
This commit is contained in:
Adam Powell
2011-02-16 16:49:50 -08:00
parent 5a5b4ba9fe
commit 348e69cfab
3 changed files with 34 additions and 3 deletions

View File

@@ -92,6 +92,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
static final boolean DEBUG = false;
static final String TAG = "AutoCompleteTextView";
static final int EXPAND_MAX = 3;
private CharSequence mHintText;
private TextView mHintView;
private int mHintResource;
@@ -1057,8 +1059,10 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
if (!isPopupShowing()) {
// Make sure the list does not obscure the IME when shown for the first time.
mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
mPopup.setListItemExpandMax(EXPAND_MAX);
}
mPopup.show();
mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);
}
/**

View File

@@ -65,6 +65,7 @@ public class ListPopupWindow {
private boolean mDropDownAlwaysVisible = false;
private boolean mForceIgnoreOutsideTouch = false;
int mListItemExpandMaximum = Integer.MAX_VALUE;
private View mPromptView;
private int mPromptPosition = POSITION_PROMPT_ABOVE;
@@ -519,6 +520,7 @@ public class ListPopupWindow {
int heightSpec = 0;
boolean noInputMethod = isInputMethodNotNeeded();
mPopup.setAllowScrollingAnchorParent(!noInputMethod);
if (mPopup.isShowing()) {
if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
@@ -774,6 +776,16 @@ public class ListPopupWindow {
return mDropDownList;
}
/**
* The maximum number of list items that can be visible and still have
* the list expand when touched.
*
* @param max Max number of items that can be visible and still allow the list to expand.
*/
void setListItemExpandMax(int max) {
mListItemExpandMaximum = max;
}
/**
* Filter key down events. By forwarding key down events to this function,
* views using non-modal ListPopupWindow can have it handle key selection of items.
@@ -1210,8 +1222,11 @@ public class ListPopupWindow {
private class ResizePopupRunnable implements Runnable {
public void run() {
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
show();
if (mDropDownList != null && mDropDownList.getCount() > mDropDownList.getChildCount() &&
mDropDownList.getChildCount() <= mListItemExpandMaximum) {
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
show();
}
}
}

View File

@@ -90,6 +90,7 @@ public class PopupWindow {
private int mSplitTouchEnabled = -1;
private boolean mLayoutInScreen;
private boolean mClipToScreen;
private boolean mAllowScrollingAnchorParent = true;
private OnTouchListener mTouchInterceptor;
@@ -592,6 +593,16 @@ public class PopupWindow {
mClipToScreen = enabled;
setClippingEnabled(!enabled);
}
/**
* Allow PopupWindow to scroll the anchor's parent to provide more room
* for the popup. Enabled by default.
*
* @param enabled True to scroll the anchor's parent when more room is desired by the popup.
*/
void setAllowScrollingAnchorParent(boolean enabled) {
mAllowScrollingAnchorParent = enabled;
}
/**
* <p>Indicates whether the popup window supports splitting touches.</p>
@@ -1045,7 +1056,8 @@ public class PopupWindow {
anchor.getWindowVisibleDisplayFrame(displayFrame);
final View root = anchor.getRootView();
if (p.y + mPopupHeight > displayFrame.bottom || p.x + mPopupWidth - root.getWidth() > 0) {
if (mAllowScrollingAnchorParent && (p.y + mPopupHeight > displayFrame.bottom ||
p.x + mPopupWidth - root.getWidth() > 0)) {
// if the drop down disappears at the bottom of the screen. we try to
// scroll a parent scrollview or move the drop down back up on top of
// the edit box