From 3085300f7c21306ab6f6a3ef28c2d672b67e9dce Mon Sep 17 00:00:00 2001 From: Matvei Malkov Date: Thu, 7 Feb 2019 15:22:10 +0000 Subject: Changes in PopupWindow API Restriced access to private mScrollChangedListener private field and to private invokePopup method. Removed @hide annotation for several methods to allow deeper customization of PopupWindow and it's transitions. Bug: 123768397 Bug: 123769350 Bug: 123769516 Bug: 123768511 Bug: 123768510 Bug: 123768589 Test: Tests has been added to PopupWindowTest in I468b592a3ba2e5f2f895210d21843d328a454794 Change-Id: I7fb4d8e28f0de889e110b7b90f71ebec9ab4cc9d --- api/current.txt | 8 +++ core/java/android/widget/PopupWindow.java | 103 +++++++++++++++++++++++------- 2 files changed, 87 insertions(+), 24 deletions(-) diff --git a/api/current.txt b/api/current.txt index 66a4bd096aea..f8a164da3143 100644 --- a/api/current.txt +++ b/api/current.txt @@ -56297,6 +56297,7 @@ package android.widget { method public android.view.View getContentView(); method public float getElevation(); method @Nullable public android.transition.Transition getEnterTransition(); + method @Nullable public android.graphics.Rect getEpicenterBounds(); method @Nullable public android.transition.Transition getExitTransition(); method public int getHeight(); method public int getInputMethodMode(); @@ -56309,30 +56310,37 @@ package android.widget { method public int getWindowLayoutType(); method public boolean isAboveAnchor(); method public boolean isAttachedInDecor(); + method public boolean isClipToScreenEnabled(); method public boolean isClippingEnabled(); method public boolean isFocusable(); + method public boolean isLayoutInScreenEnabled(); method public boolean isOutsideTouchable(); method public boolean isShowing(); method public boolean isSplitTouchEnabled(); + method public boolean isTouchModal(); method public boolean isTouchable(); method public void setAnimationStyle(int); method public void setAttachedInDecor(boolean); method public void setBackgroundDrawable(android.graphics.drawable.Drawable); + method public void setClipToScreenEnabled(boolean); method public void setClippingEnabled(boolean); method public void setContentView(android.view.View); method public void setElevation(float); method public void setEnterTransition(@Nullable android.transition.Transition); + method public void setEpicenterBounds(@Nullable android.graphics.Rect); method public void setExitTransition(@Nullable android.transition.Transition); method public void setFocusable(boolean); method public void setHeight(int); method public void setIgnoreCheekPress(); method public void setInputMethodMode(int); + method public void setLayoutInScreenEnabled(boolean); method public void setOnDismissListener(android.widget.PopupWindow.OnDismissListener); method public void setOutsideTouchable(boolean); method public void setOverlapAnchor(boolean); method public void setSoftInputMode(int); method public void setSplitTouchEnabled(boolean); method public void setTouchInterceptor(android.view.View.OnTouchListener); + method public void setTouchModal(boolean); method public void setTouchable(boolean); method public void setWidth(int); method @Deprecated public void setWindowLayoutMode(int, int); diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 705a371e483e..88d938082b05 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -264,7 +264,7 @@ public class PopupWindow { private WeakReference mAnchorRoot; private boolean mIsAnchorRootAttached; - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) private final OnScrollChangedListener mOnScrollChangedListener = this::alignToAnchor; private final View.OnLayoutChangeListener mOnLayoutChangeListener = @@ -476,22 +476,39 @@ public class PopupWindow { } /** - * Sets the bounds used as the epicenter of the enter and exit transitions. - *

- * Transitions use a point or Rect, referred to as the epicenter, to orient + *

Returns bounds which are used as a center of the enter and exit transitions.

+ * + *

Transitions use Rect, referred to as the epicenter, to orient * the direction of travel. For popup windows, the anchor view bounds are - * used as the default epicenter. - *

- * See {@link Transition#setEpicenterCallback(EpicenterCallback)} for more - * information about how transition epicenters. + * used as the default epicenter.

+ * + *

See {@link Transition#setEpicenterCallback(EpicenterCallback)} for more + * information about how transition epicenters work.

+ * + * @return bounds relative to anchor view, or {@code null} if not set + * @see #setEpicenterBounds(Rect) + */ + @Nullable + public Rect getEpicenterBounds() { + return mEpicenterBounds; + } + + /** + *

Sets the bounds used as the epicenter of the enter and exit transitions.

+ * + *

Transitions use Rect, referred to as the epicenter, to orient + * the direction of travel. For popup windows, the anchor view bounds are + * used as the default epicenter.

+ * + *

See {@link Transition#setEpicenterCallback(EpicenterCallback)} for more + * information about how transition epicenters work.

* * @param bounds the epicenter bounds relative to the anchor view, or * {@code null} to use the default epicenter - * @see #getTransitionEpicenter() - * @hide + * + * @see #getEpicenterBounds() */ - @UnsupportedAppUsage - public void setEpicenterBounds(Rect bounds) { + public void setEpicenterBounds(@Nullable Rect bounds) { mEpicenterBounds = bounds; } @@ -865,12 +882,28 @@ public class PopupWindow { } /** - * Clip this popup window to the screen, but not to the containing window. + *

Indicates whether this popup will be clipped to the screen and not to the + * containing window

* - * @param enabled True to clip to the screen. - * @hide + * @return true if popup will be clipped to the screen instead of the window, false otherwise + * + * @see #setClipToScreenEnabled(boolean) + */ + public boolean isClipToScreenEnabled() { + return mClipToScreen; + } + + /** + *

Clip this popup window to the screen, but not to the containing window.

+ * + *

If the popup is showing, calling this method will take effect only + * the next time the popup is shown or through a manual call to one of + * the {@link #update()} methods.

+ * + * @param enabled true to clip to the screen. + * + * @see #isClipToScreenEnabled() */ - @UnsupportedAppUsage public void setClipToScreenEnabled(boolean enabled) { mClipToScreen = enabled; } @@ -927,7 +960,8 @@ public class PopupWindow { * for positioning.

* * @return true if the window will always be positioned in screen coordinates. - * @hide + * + * @see #setLayoutInScreenEnabled(boolean) */ public boolean isLayoutInScreenEnabled() { return mLayoutInScreen; @@ -939,9 +973,9 @@ public class PopupWindow { * This will cause the popup to be positioned in absolute screen coordinates.

* * @param enabled true if the popup should always be positioned in screen coordinates - * @hide + * + * @see #isLayoutInScreenEnabled() */ - @UnsupportedAppUsage public void setLayoutInScreenEnabled(boolean enabled) { mLayoutInScreen = enabled; } @@ -1021,11 +1055,30 @@ public class PopupWindow { } /** - * Set whether this window is touch modal or if outside touches will be sent to - * other windows behind it. - * @hide + *

Indicates whether outside touches will be sent to this window + * or other windows behind it

+ * + * @return true if touches will be sent to this window, false otherwise + * + * @see #setTouchModal(boolean) + */ + public boolean isTouchModal() { + return !mNotTouchModal; + } + + /** + *

Set whether this window is touch modal or if outside touches will be sent to + * other windows behind it.

+ * + *

If the popup is showing, calling this method will take effect only + * the next time the popup is shown or through a manual call to one of + * the {@link #update()} methods.

+ * + * @param touchModal true to sent all outside touches to this window, + * false to other windows behind it + * + * @see #isTouchModal() */ - @UnsupportedAppUsage public void setTouchModal(boolean touchModal) { mNotTouchModal = !touchModal; } @@ -1454,7 +1507,7 @@ public class PopupWindow { * * @param p the layout parameters of the popup's content view */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) private void invokePopup(WindowManager.LayoutParams p) { if (mContext != null) { p.packageName = mContext.getPackageName(); @@ -2060,6 +2113,8 @@ public class PopupWindow { *
  • {@link #setInputMethodMode(int)}
  • *
  • {@link #setTouchable(boolean)}
  • *
  • {@link #setAnimationStyle(int)}
  • + *
  • {@link #setTouchModal(boolean)} (boolean)}
  • + *
  • {@link #setClipToScreenEnabled(boolean)}
  • * */ public void update() { -- cgit v1.2.3-59-g8ed1b