diff options
| author | Adam Powell <adamp@google.com> | 2013-06-10 16:28:35 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2013-06-10 16:28:35 -0700 |
| commit | 2be7ec671b2aa60d4596cea559fe82616f2b3ada (patch) | |
| tree | 3ad0328d7f01519a193b9b4ccebb56e834cba6d8 /core/java/android | |
| parent | aa660a04a7691850bb4e418f9d17e8ea44c3d8e0 (diff) | |
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
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/View.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 05c82ae6afa1..e860dcaab2e4 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -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 */ @@ -6138,6 +6144,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 * View, but could be set on some View subclasses such as ViewGroup. @@ -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; } /** |
