Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2be7ec67 authored by Adam Powell's avatar Adam Powell
Browse files

Add View methods isAttachedToWindow and hasLayout

isAttachedToWindow does what it says on the label and provides a
standard, public API for checking a view's attachment state. This
removes the need for tracking this out of band in response to
onAttachedToWindow/onDetachedFromWindow in custom view
implementations.

hasLayout returns true whenever the view has been through at least one
call to layout() since the last time it was attached to or detached
from a window. This allows for standard checks in code that needs to
behave differently if first layout has not completed yet, such as
whether or not to no-op an animation in order to set up initial state.

Change-Id: I8dab70dcd5a22a32e260ed50987ccdaa4100072b
parent aa660a04
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26343,6 +26343,7 @@ package android.view {
    method public float getY();
    method public boolean hasFocus();
    method public boolean hasFocusable();
    method public boolean hasLayout();
    method public boolean hasOnClickListeners();
    method public boolean hasOverlappingRendering();
    method public boolean hasTransientState();
@@ -26355,6 +26356,7 @@ package android.view {
    method public void invalidate();
    method public void invalidateDrawable(android.graphics.drawable.Drawable);
    method public boolean isActivated();
    method public boolean isAttachedToWindow();
    method public boolean isClickable();
    method public boolean isDirty();
    method public boolean isDrawingCacheEnabled();
+25 −0
Original line number Diff line number Diff line
@@ -2195,6 +2195,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2;
    /**
     * Flag indicating that the view has been through at least one layout since it
     * was last attached to a window.
     */
    static final int PFLAG3_HAS_LAYOUT = 0x4;
    /* End of masks for mPrivateFlags3 */
@@ -6137,6 +6143,21 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    /**
     * Returns true if this view is currently attached to a window.
     */
    public boolean isAttachedToWindow() {
        return mAttachInfo != null;
    }
    /**
     * Returns true if this view has been through at least one layout since it
     * was last attached to or detached from a window.
     */
    public boolean hasLayout() {
        return (mPrivateFlags3 & PFLAG3_HAS_LAYOUT) == PFLAG3_HAS_LAYOUT;
    }
    /**
     * If this view doesn't do any drawing on its own, set this flag to
     * allow further optimizations. By default, this flag is not set on
@@ -11779,6 +11800,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            mPrivateFlags &= ~PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH;
        }
        mPrivateFlags3 &= ~PFLAG3_HAS_LAYOUT;
        jumpDrawablesToCurrentState();
        clearAccessibilityFocus();
@@ -12065,6 +12088,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    protected void onDetachedFromWindow() {
        mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT;
        mPrivateFlags3 &= ~PFLAG3_HAS_LAYOUT;
        removeUnsetPressCallback();
        removeLongPressCallback();
@@ -14371,6 +14395,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            }
        }
        mPrivateFlags &= ~PFLAG_FORCE_LAYOUT;
        mPrivateFlags3 |= PFLAG3_HAS_LAYOUT;
    }
    /**