diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index 3bdba623b9b9a..27610b9fe5c25 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -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); } /** diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java index 560fc6801c125..564287785abf8 100644 --- a/core/java/android/widget/ListPopupWindow.java +++ b/core/java/android/widget/ListPopupWindow.java @@ -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(); + } } } diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 439e0cabe19ff..53932af654042 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -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; + } /** *
Indicates whether the popup window supports splitting touches.
@@ -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