Skip to content

Commit 20c0cdb

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Have the stable layout take into account the window's fullscreen flag." into jb-dev
2 parents a4c1b0a + 5b5cc4d commit 20c0cdb

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;
@@ -2143,22 +2147,31 @@ public int adjustSystemUiVisibilityLw(int visibility) {
21432147

21442148
public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
21452149
final int fl = attrs.flags;
2150+
final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
21462151

2147-
if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
2152+
if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
21482153
== (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
21492154
int availRight, availBottom;
21502155
if (mCanHideNavigationBar &&
2151-
(attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
2156+
(systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
21522157
availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
21532158
availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
21542159
} else {
21552160
availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
21562161
availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
21572162
}
2158-
if ((attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2159-
contentInset.set(mStableLeft, mStableTop,
2160-
availRight - mStableRight, availBottom - mStableBottom);
2161-
} else if ((attrs.systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
2163+
if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2164+
if ((fl & FLAG_FULLSCREEN) != 0) {
2165+
contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2166+
availRight - mStableFullscreenRight,
2167+
availBottom - mStableFullscreenBottom);
2168+
} else {
2169+
contentInset.set(mStableLeft, mStableTop,
2170+
availRight - mStableRight, availBottom - mStableBottom);
2171+
}
2172+
} else if ((fl & FLAG_FULLSCREEN) != 0) {
2173+
contentInset.setEmpty();
2174+
} else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
21622175
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
21632176
contentInset.set(mCurLeft, mCurTop,
21642177
availRight - mCurRight, availBottom - mCurBottom);
@@ -2179,10 +2192,14 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
21792192
mRestrictedScreenLeft = mRestrictedScreenTop = 0;
21802193
mRestrictedScreenWidth = displayWidth;
21812194
mRestrictedScreenHeight = displayHeight;
2182-
mDockLeft = mContentLeft = mStableLeft = mSystemLeft = mCurLeft = 0;
2183-
mDockTop = mContentTop = mStableTop = mSystemTop = mCurTop = 0;
2184-
mDockRight = mContentRight = mStableRight = mSystemRight = mCurRight = displayWidth;
2185-
mDockBottom = mContentBottom = mStableBottom = mSystemBottom = mCurBottom = displayHeight;
2195+
mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
2196+
= mSystemLeft = mCurLeft = 0;
2197+
mDockTop = mContentTop = mStableTop = mStableFullscreenTop
2198+
= mSystemTop = mCurTop = 0;
2199+
mDockRight = mContentRight = mStableRight = mStableFullscreenRight
2200+
= mSystemRight = mCurRight = displayWidth;
2201+
mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
2202+
= mSystemBottom = mCurBottom = displayHeight;
21862203
mDockLayer = 0x10000000;
21872204
mStatusBarLayer = -1;
21882205

@@ -2235,7 +2252,7 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
22352252
}
22362253
}
22372254
mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2238-
mStableBottom = mTmpNavigationFrame.top;
2255+
mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
22392256
if (navVisible) {
22402257
mNavigationBar.showLw(true);
22412258
mDockBottom = mTmpNavigationFrame.top;
@@ -2259,7 +2276,7 @@ public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotati
22592276
}
22602277
}
22612278
mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2262-
mStableRight = mTmpNavigationFrame.left;
2279+
mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
22632280
if (navVisible) {
22642281
mNavigationBar.showLw(true);
22652282
mDockRight = mTmpNavigationFrame.left;
@@ -2397,7 +2414,25 @@ void setAttachedWindowFrames(WindowState win, int fl, int adjust,
23972414
pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
23982415
? attached.getFrameLw() : df);
23992416
}
2400-
2417+
2418+
private void applyStableConstraints(int sysui, int fl, Rect r) {
2419+
if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2420+
// If app is requesting a stable layout, don't let the
2421+
// content insets go below the stable values.
2422+
if ((fl & FLAG_FULLSCREEN) != 0) {
2423+
if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2424+
if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2425+
if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2426+
if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2427+
} else {
2428+
if (r.left < mStableLeft) r.left = mStableLeft;
2429+
if (r.top < mStableTop) r.top = mStableTop;
2430+
if (r.right > mStableRight) r.right = mStableRight;
2431+
if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2432+
}
2433+
}
2434+
}
2435+
24012436
/** {@inheritDoc} */
24022437
public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
24032438
WindowState attached) {
@@ -2504,14 +2539,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
25042539
cf.right = mContentRight;
25052540
cf.bottom = mContentBottom;
25062541
}
2507-
if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2508-
// If app is requesting a stable layout, don't let the
2509-
// content insets go below the stable values.
2510-
if (cf.left < mStableLeft) cf.left = mStableLeft;
2511-
if (cf.top < mStableTop) cf.top = mStableTop;
2512-
if (cf.right > mStableRight) cf.right = mStableRight;
2513-
if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2514-
}
2542+
applyStableConstraints(sysUiFl, fl, cf);
25152543
if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
25162544
vf.left = mCurLeft;
25172545
vf.top = mCurTop;
@@ -2593,14 +2621,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
25932621
pf.bottom = df.bottom = cf.bottom
25942622
= mRestrictedScreenTop+mRestrictedScreenHeight;
25952623
}
2596-
if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2597-
// If app is requesting a stable layout, don't let the
2598-
// content insets go below the stable values.
2599-
if (cf.left < mStableLeft) cf.left = mStableLeft;
2600-
if (cf.top < mStableTop) cf.top = mStableTop;
2601-
if (cf.right > mStableRight) cf.right = mStableRight;
2602-
if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2603-
}
2624+
applyStableConstraints(sysUiFl, fl, cf);
26042625
if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
26052626
vf.left = mCurLeft;
26062627
vf.top = mCurTop;
@@ -4248,6 +4269,10 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args
42484269
pw.print(","); pw.print(mRestrictedScreenTop);
42494270
pw.print(") "); pw.print(mRestrictedScreenWidth);
42504271
pw.print("x"); pw.println(mRestrictedScreenHeight);
4272+
pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4273+
pw.print(","); pw.print(mStableFullscreenTop);
4274+
pw.print(")-("); pw.print(mStableFullscreenRight);
4275+
pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
42514276
pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
42524277
pw.print(","); pw.print(mStableTop);
42534278
pw.print(")-("); pw.print(mStableRight);

0 commit comments

Comments
 (0)