From 43c9cdffb619f93d9d4525dffd05701dc9c8c4bf Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 27 Jan 2010 13:53:55 -0800 Subject: [PATCH] New View.dispatchDisplayHint() API. Bug #2399147 This new API will be used by scrollable containers to tell children that they are/are not displayed. This will allow lists to hide their filter popup window for instance. --- api/current.xml | 26 ++++++++++++++++ core/java/android/view/View.java | 31 +++++++++++++++++-- core/java/android/view/ViewGroup.java | 13 ++++++++ core/java/android/widget/AbsListView.java | 19 +++++++++++- .../android/widget/AutoCompleteTextView.java | 12 +++++++ 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/api/current.xml b/api/current.xml index 12504612860a7..b65434a4fa614 100644 --- a/api/current.xml +++ b/api/current.xml @@ -169579,6 +169579,19 @@ visibility="public" > + + + + + + + + rely on this hint + * as there is no guarantee that they will receive one. + * + * @param hint A hint about whether or not this view is displayed: + * {@link #VISIBLE} or {@link #INVISIBLE}. + */ + public void dispatchDisplayHint(int hint) { + onDisplayHint(hint); + } + + /** + * Gives this view a hint about whether is displayed or not. For instance, when + * a View moves out of the screen, it might receives a display hint indicating + * the view is not displayed. Applications should not rely on this hint + * as there is no guarantee that they will receive one. + * + * @param hint A hint about whether or not this view is displayed: + * {@link #VISIBLE} or {@link #INVISIBLE}. + */ + protected void onDisplayHint(int hint) { + } + /** * Dispatch a window visibility change down the view hierarchy. * ViewGroups should override to route to their children. diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 49c2d0e16a6ad..cdf9eb0c513a6 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -679,6 +679,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } } } + + /** + * {@inheritDoc} + */ + @Override + public void dispatchDisplayHint(int hint) { + super.dispatchDisplayHint(hint); + final int count = mChildrenCount; + final View[] children = mChildren; + for (int i = 0; i < count; i++) { + children[i].dispatchDisplayHint(hint); + } + } /** * {@inheritDoc} diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index b795080ae863e..3a4b92dd50286 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -2852,6 +2852,23 @@ public abstract class AbsListView extends AdapterView implements Te checkSelectionChanged(); } + @Override + protected void onDisplayHint(int hint) { + super.onDisplayHint(hint); + switch (hint) { + case INVISIBLE: + if (mPopup != null && mPopup.isShowing()) { + dismissPopup(); + } + break; + case VISIBLE: + if (mFiltered && mPopup != null && !mPopup.isShowing()) { + showPopup(); + } + break; + } + } + /** * Removes the filter window */ @@ -3140,7 +3157,7 @@ public abstract class AbsListView extends AdapterView implements Te } } else { // Hide the popup when we are no longer visible - if (mPopup.isShowing()) { + if (mPopup != null && mPopup.isShowing()) { dismissPopup(); } } diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index d53a4426683ad..0f47b96e715d5 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -1032,6 +1032,18 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe } } + @Override + protected void onDisplayHint(int hint) { + super.onDisplayHint(hint); + switch (hint) { + case INVISIBLE: + if (!mDropDownAlwaysVisible) { + dismissDropDown(); + } + break; + } + } + @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(focused, direction, previouslyFocusedRect);