Skip to content

Commit 5b5cc4d

Browse files
author
Dianne Hackborn
committed
Have the stable layout take into account the window's fullscreen flag.
When using stable layouts, you are typically expected to hide and show the status bar through the system UI fullscreen flag. This hides both the status bar and the action bar. The stable layout assumed that when not hiding the status bar through the system UI flags, that the status bar would be visible. This change makes things a little smarter, also looking at the window's fullscreen flag (which only hides the status bar). If this flag is set on the window, then the stable layout now assumes that the status bar will never be shown. This allows us to position the action bar correctly in the situation where the application has set the window to fullscreen and requested a stable layout, instead of always leaving room for the status bar above it. Change-Id: I757072ae99cd3741753af7210dbf51afe94d3db5
1 parent a0e0d58 commit 5b5cc4d

File tree

2 files changed

+75
-32
lines changed

2 files changed

+75
-32
lines changed

core/java/android/view/View.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,9 +2255,27 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
22552255
* flags, we would like a stable view of the content insets given to
22562256
* {@link #fitSystemWindows(Rect)}. This means that the insets seen there
22572257
* will always represent the worst case that the application can expect
2258-
* as a continue state. In practice this means with any of system bar,
2259-
* nav bar, and status bar shown, but not the space that would be needed
2260-
* for an input method.
2258+
* as a continuous state. In the stock Android UI this is the space for
2259+
* the system bar, nav bar, and status bar, but not more transient elements
2260+
* such as an input method.
2261+
*
2262+
* The stable layout your UI sees is based on the system UI modes you can
2263+
* switch to. That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}
2264+
* then you will get a stable layout for changes of the
2265+
* {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify
2266+
* {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and
2267+
* {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition
2268+
* to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}
2269+
* with a stable layout. (Note that you should avoid using
2270+
* {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.)
2271+
*
2272+
* If you have set the window flag {@ WindowManager.LayoutParams#FLAG_FULLSCREEN}
2273+
* to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}),
2274+
* then a hidden status bar will be considered a "stable" state for purposes
2275+
* here. This allows your UI to continually hide the status bar, while still
2276+
* using the system UI flags to hide the action bar while still retaining
2277+
* a stable layout. Note that changing the window fullscreen flag will never
2278+
* provide a stable layout for a clean transition.
22612279
*
22622280
* <p>If you are using ActionBar in
22632281
* overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ public void onInputEvent(InputEvent event) {
410410
int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
411411
// For applications requesting stable content insets, these are them.
412412
int mStableLeft, mStableTop, mStableRight, mStableBottom;
413+
// For applications requesting stable content insets but have also set the
414+
// fullscreen window flag, these are the stable dimensions without the status bar.
415+
int mStableFullscreenLeft, mStableFullscreenTop;
416+
int mStableFullscreenRight, mStableFullscreenBottom;
413417
// During layout, the current screen borders with all outer decoration
414418
// (status bar, input method dock) accounted for.
415419
int mCurLeft, mCurTop, mCurRight, mCurBottom;
@@ -2153,22 +2157,31 @@ public int adjustSystemUiVisibilityLw(int visibility) {
21532157

21542158
public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
21552159
final int fl = attrs.flags;
2160+
final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
21562161

2157-
if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
2162+
if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
21582163
== (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
21592164
int availRight, availBottom;
21602165
if (mCanHideNavigationBar &&
2161-
(attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
2166+
(systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
21622167
availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
21632168
availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
21642169
} else {
21652170
availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
21662171
availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
21672172
}
2168-
if ((attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2169-
contentInset.set(mStableLeft, mStableTop,
2170-
availRight - mStableRight, availBottom - mStableBottom);
2171-
} else if ((attrs.systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
2173+
if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2174+
if ((fl & FLAG_FULLSCREEN) != 0) {
2175+
contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2176+
availRight - mStableFullscreenRight,
2177+
availBottom - mStableFullscreenBottom);
2178+
} else {
2179+
contentInset.set(mStableLeft, mStableTop,
2180+
availRight - mStableRight, availBottom - mStableBottom);
2181+
}
2182+
} else if ((fl & FLAG_FULLSCREEN) != 0) {
2183+
contentInset.setEmpty();
2184+
} else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
21722185
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
21732186
contentInset.set(mCurLeft, mCurTop,
21742187
availRight - mCurRight, availBottom - mCurBottom);
@@ -2189,10 +2202,14 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
21892202
mRestrictedScreenLeft = mRestrictedScreenTop = 0;
21902203
mRestrictedScreenWidth = displayWidth;
21912204
mRestrictedScreenHeight = displayHeight;
2192-
mDockLeft = mContentLeft = mStableLeft = mSystemLeft = mCurLeft = 0;
2193-
mDockTop = mContentTop = mStableTop = mSystemTop = mCurTop = 0;
2194-
mDockRight = mContentRight = mStableRight = mSystemRight = mCurRight = displayWidth;
2195-
mDockBottom = mContentBottom = mStableBottom = mSystemBottom = mCurBottom = displayHeight;
2205+
mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
2206+
= mSystemLeft = mCurLeft = 0;
2207+
mDockTop = mContentTop = mStableTop = mStableFullscreenTop
2208+
= mSystemTop = mCurTop = 0;
2209+
mDockRight = mContentRight = mStableRight = mStableFullscreenRight
2210+
= mSystemRight = mCurRight = displayWidth;
2211+
mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
2212+
= mSystemBottom = mCurBottom = displayHeight;
21962213
mDockLayer = 0x10000000;
21972214
mStatusBarLayer = -1;
21982215

@@ -2245,7 +2262,7 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
22452262
}
22462263
}
22472264
mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2248-
mStableBottom = mTmpNavigationFrame.top;
2265+
mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
22492266
if (navVisible) {
22502267
mNavigationBar.showLw(true);
22512268
mDockBottom = mTmpNavigationFrame.top;
@@ -2269,7 +2286,7 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
22692286
}
22702287
}
22712288
mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2272-
mStableRight = mTmpNavigationFrame.left;
2289+
mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
22732290
if (navVisible) {
22742291
mNavigationBar.showLw(true);
22752292
mDockRight = mTmpNavigationFrame.left;
@@ -2407,7 +2424,25 @@ void setAttachedWindowFrames(WindowState win, int fl, int adjust,
24072424
pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
24082425
? attached.getFrameLw() : df);
24092426
}
2410-
2427+
2428+
private void applyStableConstraints(int sysui, int fl, Rect r) {
2429+
if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2430+
// If app is requesting a stable layout, don't let the
2431+
// content insets go below the stable values.
2432+
if ((fl & FLAG_FULLSCREEN) != 0) {
2433+
if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2434+
if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2435+
if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2436+
if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2437+
} else {
2438+
if (r.left < mStableLeft) r.left = mStableLeft;
2439+
if (r.top < mStableTop) r.top = mStableTop;
2440+
if (r.right > mStableRight) r.right = mStableRight;
2441+
if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2442+
}
2443+
}
2444+
}
2445+
24112446
/** {@inheritDoc} */
24122447
public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
24132448
WindowState attached) {
@@ -2514,14 +2549,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
25142549
cf.right = mContentRight;
25152550
cf.bottom = mContentBottom;
25162551
}
2517-
if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2518-
// If app is requesting a stable layout, don't let the
2519-
// content insets go below the stable values.
2520-
if (cf.left < mStableLeft) cf.left = mStableLeft;
2521-
if (cf.top < mStableTop) cf.top = mStableTop;
2522-
if (cf.right > mStableRight) cf.right = mStableRight;
2523-
if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2524-
}
2552+
applyStableConstraints(sysUiFl, fl, cf);
25252553
if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
25262554
vf.left = mCurLeft;
25272555
vf.top = mCurTop;
@@ -2603,14 +2631,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
26032631
pf.bottom = df.bottom = cf.bottom
26042632
= mRestrictedScreenTop+mRestrictedScreenHeight;
26052633
}
2606-
if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2607-
// If app is requesting a stable layout, don't let the
2608-
// content insets go below the stable values.
2609-
if (cf.left < mStableLeft) cf.left = mStableLeft;
2610-
if (cf.top < mStableTop) cf.top = mStableTop;
2611-
if (cf.right > mStableRight) cf.right = mStableRight;
2612-
if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2613-
}
2634+
applyStableConstraints(sysUiFl, fl, cf);
26142635
if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
26152636
vf.left = mCurLeft;
26162637
vf.top = mCurTop;
@@ -4258,6 +4279,10 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args
42584279
pw.print(","); pw.print(mRestrictedScreenTop);
42594280
pw.print(") "); pw.print(mRestrictedScreenWidth);
42604281
pw.print("x"); pw.println(mRestrictedScreenHeight);
4282+
pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4283+
pw.print(","); pw.print(mStableFullscreenTop);
4284+
pw.print(")-("); pw.print(mStableFullscreenRight);
4285+
pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
42614286
pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
42624287
pw.print(","); pw.print(mStableTop);
42634288
pw.print(")-("); pw.print(mStableRight);

0 commit comments

Comments
 (0)