From bd95740648372449a4d5c164d7050eee352d4c24 Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Thu, 3 Oct 2013 11:38:39 -0400 Subject: Transparent system ui flags -> Translucent WM flags. Migrate View.SYSTEM_UI_FLAG_TRANSPARENT_(STATUS/NAVIGATION) to WindowManager.LayoutParams.FLAG_TRANSLUCENT_(STATUS|NAVIGATION). Add associated public attrs for both new window flags: windowTranslucentStatus windowTranslucentNavigation Introduce convenient four new themes that set translucent decor: Theme.Holo.NoActionBar.TranslucentDecor Theme.Holo.Light.NoActionBar.TranslucentDecor Theme.DeviceDefault.NoActionBar.TranslucentDecor Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor Update PhoneWindowManager mechanism to plumb these values back to SystemUI to drive bar mode state. The new translucent flags come from the top fullscreen window, not the focused window, so translucency does not change when opening dialogs. Imply some window-level system-ui visibility if one or both of these new flags are present, specifically: FLAG_TRANSLUCENT_STATUS implies LAYOUT_STABLE, LAYOUT_FULLSCREEN FLAG_TRANSLUCENT_NAVIGATION implies LAYOUT STABLE, LAYOUT_HIDE_NAV Rename all associated variable & resource names to use the term translucent instead of transparent. (Retain the term semi-transparent for the transient bar style). Recents activity allowed to inherit translucent decor state via the new PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR. Compensating changes to use the full screen area more appropriately. Update keyguard to use new WM flags. Update docs and various api artifacts. Sanity-check fixes: - Toasts and alerts given stable layout. - Suppress nu-gradient when in transient (hidey) mode. - New translucent flags use top-fullscreen window, dialogs don't clear. Bug:10674960 Bug:11062108 Bug:10987178 Bug:10786445 Bug:10781433 Change-Id: If667a55bea4cf5e008549524b9899197fab55ebe --- core/java/android/view/View.java | 46 +++++++++++++------------- core/java/android/view/ViewRootImpl.java | 18 ++++++++++ core/java/android/view/WindowManager.java | 55 ++++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 25 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f763d19b2bc6..caeb1d8cfc80 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -2447,24 +2447,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public static final int SYSTEM_UI_FLAG_IMMERSIVE = 0x00000800; - /** - * Flag for {@link #setSystemUiVisibility(int)}: View would like the status bar to have - * transparency. - * - *

The transparency request may be denied if the bar is in another mode with a specific - * style, like {@link #SYSTEM_UI_FLAG_IMMERSIVE immersive mode}. - */ - public static final int SYSTEM_UI_FLAG_TRANSPARENT_STATUS = 0x00001000; - - /** - * Flag for {@link #setSystemUiVisibility(int)}: View would like the navigation bar to have - * transparency. - * - *

The transparency request may be denied if the bar is in another mode with a specific - * style, like {@link #SYSTEM_UI_FLAG_IMMERSIVE immersive mode}. - */ - public static final int SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION = 0x00002000; - /** * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. */ @@ -2624,6 +2606,26 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public static final int NAVIGATION_BAR_UNHIDE = 0x20000000; + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to specify that the status bar is displayed in translucent mode. + */ + public static final int STATUS_BAR_TRANSLUCENT = 0x40000000; + + /** + * @hide + * + * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked + * out of the public fields to keep the undefined bits out of the developer's way. + * + * Flag to specify that the navigation bar is displayed in translucent mode. + */ + public static final int NAVIGATION_BAR_TRANSLUCENT = 0x80000000; + /** * @hide */ @@ -16934,9 +16936,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, - * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE}, - * {@link #SYSTEM_UI_FLAG_TRANSPARENT_STATUS}, - * and {@link #SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION}. + * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, and {@link #SYSTEM_UI_FLAG_IMMERSIVE}. */ public void setSystemUiVisibility(int visibility) { if (visibility != mSystemUiVisibility) { @@ -16952,9 +16952,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, - * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE}, - * {@link #SYSTEM_UI_FLAG_TRANSPARENT_STATUS}, - * and {@link #SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION}. + * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, and {@link #SYSTEM_UI_FLAG_IMMERSIVE}. */ public int getSystemUiVisibility() { return mSystemUiVisibility; diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 7e3ee5f64057..beb7366ec965 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -754,6 +754,11 @@ public final class ViewRootImpl implements ViewParent, attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); + if ((mWindowAttributesChangesFlag + & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { + // Recompute system ui visibility. + mAttachInfo.mRecomputeGlobalAttributes = true; + } if (mWindowAttributes.packageName == null) { mWindowAttributes.packageName = mBasePackageName; } @@ -1026,6 +1031,7 @@ public final class ViewRootImpl implements ViewParent, mView.dispatchCollectViewAttributes(attachInfo, 0); attachInfo.mSystemUiVisibility &= ~attachInfo.mDisabledSystemUiVisibility; WindowManager.LayoutParams params = mWindowAttributes; + attachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); if (attachInfo.mKeepScreenOn != oldScreenOn || attachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility || attachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { @@ -1039,6 +1045,18 @@ public final class ViewRootImpl implements ViewParent, return false; } + private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { + int vis = 0; + // Translucent decor window flags imply stable system ui visibility. + if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { + vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } + if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { + vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; + } + return vis; + } + private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { int childWidthMeasureSpec; diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 815b97c60657..ea3c9311c4df 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -838,6 +838,44 @@ public interface WindowManager extends ViewManager { */ public static final int FLAG_LAYOUT_IN_OVERSCAN = 0x02000000; + /** + * Window flag: request a translucent status bar with minimal system-provided + * background protection. + * + *

This flag can be controlled in your theme through the + * {@link android.R.attr#windowTranslucentStatus} attribute; this attribute + * is automatically set for you in the standard translucent decor themes + * such as + * {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor}, + * {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor}, + * {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and + * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.

+ * + *

When this flag is enabled for a window, it automatically sets + * the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and + * {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.

+ */ + public static final int FLAG_TRANSLUCENT_STATUS = 0x04000000; + + /** + * Window flag: request a translucent navigation bar with minimal system-provided + * background protection. + * + *

This flag can be controlled in your theme through the + * {@link android.R.attr#windowTranslucentNavigation} attribute; this attribute + * is automatically set for you in the standard translucent decor themes + * such as + * {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor}, + * {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor}, + * {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and + * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.

+ * + *

When this flag is enabled for a window, it automatically sets + * the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and + * {@link View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.

+ */ + public static final int FLAG_TRANSLUCENT_NAVIGATION = 0x08000000; + // ----- HIDDEN FLAGS. // These start at the high bit and go down. @@ -956,7 +994,11 @@ public interface WindowManager extends ViewManager { @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED, equals = FLAG_HARDWARE_ACCELERATED, name = "FLAG_HARDWARE_ACCELERATED"), @ViewDebug.FlagToString(mask = FLAG_LOCAL_FOCUS_MODE, equals = FLAG_LOCAL_FOCUS_MODE, - name = "FLAG_LOCAL_FOCUS_MODE") + name = "FLAG_LOCAL_FOCUS_MODE"), + @ViewDebug.FlagToString(mask = FLAG_TRANSLUCENT_STATUS, equals = FLAG_TRANSLUCENT_STATUS, + name = "FLAG_TRANSLUCENT_STATUS"), + @ViewDebug.FlagToString(mask = FLAG_TRANSLUCENT_NAVIGATION, equals = FLAG_TRANSLUCENT_NAVIGATION, + name = "FLAG_TRANSLUCENT_NAVIGATION") }) public int flags; @@ -1046,6 +1088,11 @@ public interface WindowManager extends ViewManager { * {@hide} */ public static final int PRIVATE_FLAG_SYSTEM_ERROR = 0x00000100; + /** Window flag: maintain the previous transparent decor state when this window + * becomes top-most. + * {@hide} */ + public static final int PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR = 0x00000200; + /** * Control flags that are private to the platform. * @hide @@ -1576,6 +1623,8 @@ public interface WindowManager extends ViewManager { /** {@hide} */ public static final int USER_ACTIVITY_TIMEOUT_CHANGED = 1<<18; /** {@hide} */ + public static final int TRANSLUCENT_FLAGS_CHANGED = 1<<19; + /** {@hide} */ public static final int EVERYTHING_CHANGED = 0xffffffff; // internal buffer to backup/restore parameters under compatibility mode. @@ -1621,6 +1670,10 @@ public interface WindowManager extends ViewManager { changes |= TYPE_CHANGED; } if (flags != o.flags) { + final int diff = flags ^ o.flags; + if ((diff & (FLAG_TRANSLUCENT_STATUS | FLAG_TRANSLUCENT_NAVIGATION)) != 0) { + changes |= TRANSLUCENT_FLAGS_CHANGED; + } flags = o.flags; changes |= FLAGS_CHANGED; } -- cgit v1.2.3