Reset insets when inset computer is removed.

When an inset computer is registered with the view tree observer,
we report content insets to the window manager.  When an inset computer
is subsequently unregistered, we must take care to clear these insets.

This patch remembers whether the previously computed insets were
non-empty so that it can force insets to be reset when needed.

Bug: 10840662
Change-Id: I4cce5ba64cc5234b98363b025ac4bb42e64349f1
This commit is contained in:
Jeff Brown
2013-09-30 15:57:43 -07:00
parent 8b3bc51c8f
commit 2e05ec3235
3 changed files with 18 additions and 1 deletions

View File

@@ -18724,6 +18724,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets
= new ViewTreeObserver.InternalInsetsInfo();
/**
* Set to true when mGivenInternalInsets is non-empty.
*/
boolean mHasNonEmptyGivenInternalInsets;
/**
* All views in the window's hierarchy that serve as scroll containers,
* used to determine if the window can be resized or must be panned

View File

@@ -1348,8 +1348,12 @@ public final class ViewRootImpl implements ViewParent,
|| (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT &&
frame.height() < desiredWindowHeight && frame.height() != mHeight));
// Determine whether to compute insets.
// If there are no inset listeners remaining then we may still need to compute
// insets in case the old insets were non-empty and must be reset.
final boolean computesInternalInsets =
attachInfo.mTreeObserver.hasComputeInternalInsetsListeners();
attachInfo.mTreeObserver.hasComputeInternalInsetsListeners()
|| attachInfo.mHasNonEmptyGivenInternalInsets;
boolean insetsPending = false;
int relayoutResult = 0;
@@ -1764,6 +1768,7 @@ public final class ViewRootImpl implements ViewParent,
// Compute new insets in place.
attachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets);
attachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty();
// Tell the window manager.
if (insetsPending || !mLastGivenInsets.equals(insets)) {

View File

@@ -241,6 +241,13 @@ public final class ViewTreeObserver {
mTouchableInsets = TOUCHABLE_INSETS_FRAME;
}
boolean isEmpty() {
return contentInsets.isEmpty()
&& visibleInsets.isEmpty()
&& touchableRegion.isEmpty()
&& mTouchableInsets == TOUCHABLE_INSETS_FRAME;
}
@Override
public int hashCode() {
int result = contentInsets.hashCode();