Merge "Hide autofill popup if anchor removed" into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-09-25 22:24:25 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 4 deletions

View File

@@ -47,6 +47,19 @@ public class AutofillPopupWindow extends PopupWindow {
private final WindowPresenter mWindowPresenter;
private WindowManager.LayoutParams mWindowLayoutParams;
private final View.OnAttachStateChangeListener mOnAttachStateChangeListener =
new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
/* ignore - handled by the super class */
}
@Override
public void onViewDetachedFromWindow(View v) {
dismiss();
}
};
/**
* Creates a popup window with a presenter owning the window and responsible for
* showing/hiding/updating the backing window. This can be useful of the window is
@@ -208,7 +221,21 @@ public class AutofillPopupWindow extends PopupWindow {
p.packageName = anchor.getContext().getPackageName();
mWindowPresenter.show(p, getTransitionEpicenter(), isLayoutInsetDecor(),
anchor.getLayoutDirection());
return;
}
@Override
protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
super.attachToAnchor(anchor, xoff, yoff, gravity);
anchor.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
}
@Override
protected void detachFromAnchor() {
final View anchor = getAnchor();
if (anchor != null) {
anchor.removeOnAttachStateChangeListener(mOnAttachStateChangeListener);
}
super.detachFromAnchor();
}
@Override

View File

@@ -2296,8 +2296,8 @@ public class PopupWindow {
}
/** @hide */
protected final void detachFromAnchor() {
final View anchor = mAnchor != null ? mAnchor.get() : null;
protected void detachFromAnchor() {
final View anchor = getAnchor();
if (anchor != null) {
final ViewTreeObserver vto = anchor.getViewTreeObserver();
vto.removeOnScrollChangedListener(mOnScrollChangedListener);
@@ -2316,7 +2316,7 @@ public class PopupWindow {
}
/** @hide */
protected final void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
detachFromAnchor();
final ViewTreeObserver vto = anchor.getViewTreeObserver();
@@ -2339,6 +2339,11 @@ public class PopupWindow {
mAnchoredGravity = gravity;
}
/** @hide */
protected @Nullable View getAnchor() {
return mAnchor != null ? mAnchor.get() : null;
}
private void alignToAnchor() {
final View anchor = mAnchor != null ? mAnchor.get() : null;
if (anchor != null && anchor.isAttachedToWindow() && hasDecorView()) {