Skip to content

Commit e312c61

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Improve fitSystemWindows() documentation." into jb-dev
2 parents 787c9ec + d5333f9 commit e312c61

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

core/java/android/view/View.java

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,12 +5255,25 @@ public boolean isShown() {
52555255
* which you would like to ensure are not being covered.
52565256
*
52575257
* <p>The default implementation of this method simply applies the content
5258-
* inset's to the view's padding. This can be enabled through
5259-
* {@link #setFitsSystemWindows(boolean)}. Alternatively, you can override
5260-
* the method and handle the insets however you would like. Note that the
5261-
* insets provided by the framework are always relative to the far edges
5262-
* of the window, not accounting for the location of the called view within
5263-
* that window. (In fact when this method is called you do not yet know
5258+
* inset's to the view's padding, consuming that content (modifying the
5259+
* insets to be 0), and returning true. This behavior is off by default, but can
5260+
* be enabled through {@link #setFitsSystemWindows(boolean)}.
5261+
*
5262+
* <p>This function's traversal down the hierarchy is depth-first. The same content
5263+
* insets object is propagated down the hierarchy, so any changes made to it will
5264+
* be seen by all following views (including potentially ones above in
5265+
* the hierarchy since this is a depth-first traversal). The first view
5266+
* that returns true will abort the entire traversal.
5267+
*
5268+
* <p>The default implementation works well for a situation where it is
5269+
* used with a container that covers the entire window, allowing it to
5270+
* apply the appropriate insets to its content on all edges. If you need
5271+
* a more complicated layout (such as two different views fitting system
5272+
* windows, one on the top of the window, and one on the bottom),
5273+
* you can override the method and handle the insets however you would like.
5274+
* Note that the insets provided by the framework are always relative to the
5275+
* far edges of the window, not accounting for the location of the called view
5276+
* within that window. (In fact when this method is called you do not yet know
52645277
* where the layout will place the view, as it is done before layout happens.)
52655278
*
52665279
* <p>Note: unlike many View methods, there is no dispatch phase to this
@@ -5281,6 +5294,9 @@ public boolean isShown() {
52815294
*
52825295
* @return Return true if this view applied the insets and it should not
52835296
* continue propagating further down the hierarchy, false otherwise.
5297+
* @see #getFitsSystemWindows()
5298+
* @see #setFitsSystemWindows()
5299+
* @see #setSystemUiVisibility(int)
52845300
*/
52855301
protected boolean fitSystemWindows(Rect insets) {
52865302
if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) {
@@ -5301,31 +5317,40 @@ protected boolean fitSystemWindows(Rect insets) {
53015317
}
53025318

53035319
/**
5304-
* Set whether or not this view should account for system screen decorations
5305-
* such as the status bar and inset its content. This allows this view to be
5306-
* positioned in absolute screen coordinates and remain visible to the user.
5320+
* Sets whether or not this view should account for system screen decorations
5321+
* such as the status bar and inset its content; that is, controlling whether
5322+
* the default implementation of {@link #fitSystemWindows(Rect)} will be
5323+
* executed. See that method for more details.
53075324
*
5308-
* <p>This should only be used by top-level window decor views.
5325+
* <p>Note that if you are providing your own implementation of
5326+
* {@link #fitSystemWindows(Rect)}, then there is no need to set this
5327+
* flag to true -- your implementation will be overriding the default
5328+
* implementation that checks this flag.
53095329
*
5310-
* @param fitSystemWindows true to inset content for system screen decorations, false for
5311-
* default behavior.
5330+
* @param fitSystemWindows If true, then the default implementation of
5331+
* {@link #fitSystemWindows(Rect)} will be executed.
53125332
*
53135333
* @attr ref android.R.styleable#View_fitsSystemWindows
5334+
* @see #getFitsSystemWindows()
5335+
* @see #fitSystemWindows(Rect)
5336+
* @see #setSystemUiVisibility(int)
53145337
*/
53155338
public void setFitsSystemWindows(boolean fitSystemWindows) {
53165339
setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS);
53175340
}
53185341

53195342
/**
53205343
* Check for state of {@link #setFitsSystemWindows(boolean). If this method
5321-
* returns true, this view
5322-
* will account for system screen decorations such as the status bar and inset its
5323-
* content. This allows the view to be positioned in absolute screen coordinates
5324-
* and remain visible to the user.
5344+
* returns true, the default implementation of {@link #fitSystemWindows(Rect)}
5345+
* will be executed.
53255346
*
5326-
* @return true if this view will adjust its content bounds for system screen decorations.
5347+
* @return Returns true if the default implementation of
5348+
* {@link #fitSystemWindows(Rect)} will be executed.
53275349
*
53285350
* @attr ref android.R.styleable#View_fitsSystemWindows
5351+
* @see #setFitsSystemWindows()
5352+
* @see #fitSystemWindows(Rect)
5353+
* @see #setSystemUiVisibility(int)
53295354
*/
53305355
public boolean getFitsSystemWindows() {
53315356
return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS;

0 commit comments

Comments
 (0)