diff options
| author | Adam Powell <adamp@google.com> | 2010-03-23 13:29:34 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2010-03-23 13:29:34 -0700 |
| commit | 387d8f8a62d6ea0932ebb498d2b1dda00a1256be (patch) | |
| tree | 5afe9dc85f90d002c301a3943d0058d4d0299aad /core/java/android/widget/AutoCompleteTextView.java | |
| parent | b978c8f8b92ff050945419be2edffb7f75e28c99 (diff) | |
Fix bug 2495033.
AutoCompleteTextView now uses different logic to expand the dropdown
list of completion choices to cover the IME if present. Previously
this would happen whenever a touch down event occurred. Resizing the
dropdown could cause the parent view to animate a scroll and thereby
move the completion list up the screen. When this happened with a
finger down it would initiate a touch scroll on the completion
list. Prior to froyo this wasn't a problem since a list positioned at
the top could not scroll up, but with the addition of overscroll this
caused undesired behavior.
The completion list now will not expand to cover the IME on initial
touch down. Instead it will only expand if the user leaves a finger in
place for the duration of a timeout (currently 250ms) or if the user
explicitly begins a touch scroll on the completion list. This also has
a nice side effect where tapping a completion choice in the initial,
smaller list does not cause a split-second list expansion before the
list is dismissed.
Change-Id: If0994c68a91b3bfc3dcef660c67fde667a9727f9
Diffstat (limited to 'core/java/android/widget/AutoCompleteTextView.java')
| -rw-r--r-- | core/java/android/widget/AutoCompleteTextView.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index eb2da7149762..e15a520ae064 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -92,6 +92,13 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe private static final int HINT_VIEW_ID = 0x17; + /** + * This value controls the length of time that the user + * must leave a pointer down without scrolling to expand + * the autocomplete dropdown list to cover the IME. + */ + private static final int EXPAND_LIST_TIMEOUT = 250; + private CharSequence mHintText; private int mHintResource; @@ -132,6 +139,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe private ListSelectorHider mHideSelector; private Runnable mShowDropDownRunnable; + private Runnable mResizePopupRunnable = new ResizePopupRunnable(); private PassThroughClickListener mPassThroughClickListener; private PopupDataSetObserver mObserver; @@ -1297,6 +1305,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe public void onNothingSelected(AdapterView<?> parent) { } }); + mDropDownList.setOnScrollListener(new PopupScrollListener()); if (mItemSelectedListener != null) { mDropDownList.setOnItemSelectedListener(mItemSelectedListener); @@ -1437,17 +1446,41 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe } } + private class ResizePopupRunnable implements Runnable { + public void run() { + mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); + showDropDown(); + } + } + private class PopupTouchInterceptor implements OnTouchListener { public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN && + final int action = event.getAction(); + if (action == MotionEvent.ACTION_DOWN && mPopup != null && mPopup.isShowing()) { - mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); - showDropDown(); + postDelayed(mResizePopupRunnable, EXPAND_LIST_TIMEOUT); + } else if (action == MotionEvent.ACTION_UP) { + removeCallbacks(mResizePopupRunnable); } return false; } } + private class PopupScrollListener implements ListView.OnScrollListener { + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, + int totalItemCount) { + + } + + public void onScrollStateChanged(AbsListView view, int scrollState) { + if (scrollState == SCROLL_STATE_TOUCH_SCROLL && + !isInputMethodNotNeeded() && mPopup.getContentView() != null) { + removeCallbacks(mResizePopupRunnable); + mResizePopupRunnable.run(); + } + } + } + private class DropDownItemClickListener implements AdapterView.OnItemClickListener { public void onItemClick(AdapterView parent, View v, int position, long id) { performCompletion(v, position, id); |
