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.
This commit is contained in:
@ -3789,7 +3789,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
* ViewGroups should override to route to their children.
|
||||
* @param changedView The view whose visibility changed. Could be 'this' or
|
||||
* an ancestor view.
|
||||
* @param visibility The new visibility of changedView.
|
||||
* @param visibility The new visibility of changedView: {@link #VISIBLE},
|
||||
* {@link #INVISIBLE} or {@link #GONE}.
|
||||
*/
|
||||
protected void dispatchVisibilityChanged(View changedView, int visibility) {
|
||||
onVisibilityChanged(changedView, visibility);
|
||||
@ -3799,11 +3800,37 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
* Called when the visibility of the view or an ancestor of the view is changed.
|
||||
* @param changedView The view whose visibility changed. Could be 'this' or
|
||||
* an ancestor view.
|
||||
* @param visibility The new visibility of changedView.
|
||||
* @param visibility The new visibility of changedView: {@link #VISIBLE},
|
||||
* {@link #INVISIBLE} or {@link #GONE}.
|
||||
*/
|
||||
protected void onVisibilityChanged(View changedView, int visibility) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a hint about whether this view is displayed. 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 <em>rely</em> 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 <em>rely</em> 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.
|
||||
|
@ -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}
|
||||
|
@ -2852,6 +2852,23 @@ public abstract class AbsListView extends AdapterView<ListAdapter> 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<ListAdapter> implements Te
|
||||
}
|
||||
} else {
|
||||
// Hide the popup when we are no longer visible
|
||||
if (mPopup.isShowing()) {
|
||||
if (mPopup != null && mPopup.isShowing()) {
|
||||
dismissPopup();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user