Merge "Support dynamic material color for letterbox background." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
61b023c44a
@@ -4862,9 +4862,8 @@
|
|||||||
- Option 3 is selected for R.integer.config_letterboxBackgroundType and blur requested
|
- Option 3 is selected for R.integer.config_letterboxBackgroundType and blur requested
|
||||||
but isn't supported on the device or both dark scrim alpha and blur radius aren't
|
but isn't supported on the device or both dark scrim alpha and blur radius aren't
|
||||||
provided.
|
provided.
|
||||||
Defaults to black if not specified.
|
|
||||||
-->
|
-->
|
||||||
<color name="config_letterboxBackgroundColor">#000</color>
|
<color name="config_letterboxBackgroundColor">@android:color/system_neutral2_500</color>
|
||||||
|
|
||||||
<!-- Horizonal position of a center of the letterboxed app window.
|
<!-- Horizonal position of a center of the letterboxed app window.
|
||||||
0 corresponds to the left side of the screen and 1 to the right side. If given value < 0
|
0 corresponds to the left side of the screen and 1 to the right side. If given value < 0
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server.wm;
|
package com.android.server.wm;
|
||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
|
||||||
@@ -63,7 +64,10 @@ final class LetterboxConfiguration {
|
|||||||
private int mLetterboxActivityCornersRadius;
|
private int mLetterboxActivityCornersRadius;
|
||||||
|
|
||||||
// Color for {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} letterbox background type.
|
// Color for {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} letterbox background type.
|
||||||
private Color mLetterboxBackgroundColor;
|
@Nullable private Color mLetterboxBackgroundColorOverride;
|
||||||
|
|
||||||
|
// Color resource id for {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} letterbox background type.
|
||||||
|
@Nullable private Integer mLetterboxBackgroundColorResourceIdOverride;
|
||||||
|
|
||||||
@LetterboxBackgroundType
|
@LetterboxBackgroundType
|
||||||
private int mLetterboxBackgroundType;
|
private int mLetterboxBackgroundType;
|
||||||
@@ -81,20 +85,18 @@ final class LetterboxConfiguration {
|
|||||||
// side of the screen and 1.0 to the right side.
|
// side of the screen and 1.0 to the right side.
|
||||||
private float mLetterboxHorizontalPositionMultiplier;
|
private float mLetterboxHorizontalPositionMultiplier;
|
||||||
|
|
||||||
LetterboxConfiguration(Context context) {
|
LetterboxConfiguration(Context systemUiContext) {
|
||||||
mContext = context;
|
mContext = systemUiContext;
|
||||||
mFixedOrientationLetterboxAspectRatio = context.getResources().getFloat(
|
mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
|
||||||
R.dimen.config_fixedOrientationLetterboxAspectRatio);
|
R.dimen.config_fixedOrientationLetterboxAspectRatio);
|
||||||
mLetterboxActivityCornersRadius = context.getResources().getInteger(
|
mLetterboxActivityCornersRadius = mContext.getResources().getInteger(
|
||||||
R.integer.config_letterboxActivityCornersRadius);
|
R.integer.config_letterboxActivityCornersRadius);
|
||||||
mLetterboxBackgroundColor = Color.valueOf(context.getResources().getColor(
|
mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
|
||||||
R.color.config_letterboxBackgroundColor));
|
mLetterboxBackgroundWallpaperBlurRadius = mContext.getResources().getDimensionPixelSize(
|
||||||
mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(context);
|
|
||||||
mLetterboxBackgroundWallpaperBlurRadius = context.getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.config_letterboxBackgroundWallpaperBlurRadius);
|
R.dimen.config_letterboxBackgroundWallpaperBlurRadius);
|
||||||
mLetterboxBackgroundWallpaperDarkScrimAlpha = context.getResources().getFloat(
|
mLetterboxBackgroundWallpaperDarkScrimAlpha = mContext.getResources().getFloat(
|
||||||
R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha);
|
R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha);
|
||||||
mLetterboxHorizontalPositionMultiplier = context.getResources().getFloat(
|
mLetterboxHorizontalPositionMultiplier = mContext.getResources().getFloat(
|
||||||
R.dimen.config_letterboxHorizontalPositionMultiplier);
|
R.dimen.config_letterboxHorizontalPositionMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +165,15 @@ final class LetterboxConfiguration {
|
|||||||
* fallback for other backfround types.
|
* fallback for other backfround types.
|
||||||
*/
|
*/
|
||||||
Color getLetterboxBackgroundColor() {
|
Color getLetterboxBackgroundColor() {
|
||||||
return mLetterboxBackgroundColor;
|
if (mLetterboxBackgroundColorOverride != null) {
|
||||||
|
return mLetterboxBackgroundColorOverride;
|
||||||
|
}
|
||||||
|
int colorId = mLetterboxBackgroundColorResourceIdOverride != null
|
||||||
|
? mLetterboxBackgroundColorResourceIdOverride
|
||||||
|
: R.color.config_letterboxBackgroundColor;
|
||||||
|
// Query color dynamically because material colors extracted from wallpaper are updated
|
||||||
|
// when wallpaper is changed.
|
||||||
|
return Color.valueOf(mContext.getResources().getColor(colorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,7 +183,16 @@ final class LetterboxConfiguration {
|
|||||||
* fallback for other backfround types.
|
* fallback for other backfround types.
|
||||||
*/
|
*/
|
||||||
void setLetterboxBackgroundColor(Color color) {
|
void setLetterboxBackgroundColor(Color color) {
|
||||||
mLetterboxBackgroundColor = color;
|
mLetterboxBackgroundColorOverride = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets color ID of letterbox background which is used when {@link
|
||||||
|
* #getLetterboxBackgroundType()} is {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} or as
|
||||||
|
* fallback for other backfround types.
|
||||||
|
*/
|
||||||
|
void setLetterboxBackgroundColorResourceId(int colorId) {
|
||||||
|
mLetterboxBackgroundColorResourceIdOverride = colorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,8 +200,8 @@ final class LetterboxConfiguration {
|
|||||||
* com.android.internal.R.color.config_letterboxBackgroundColor}.
|
* com.android.internal.R.color.config_letterboxBackgroundColor}.
|
||||||
*/
|
*/
|
||||||
void resetLetterboxBackgroundColor() {
|
void resetLetterboxBackgroundColor() {
|
||||||
mLetterboxBackgroundColor = Color.valueOf(mContext.getResources().getColor(
|
mLetterboxBackgroundColorOverride = null;
|
||||||
com.android.internal.R.color.config_letterboxBackgroundColor));
|
mLetterboxBackgroundColorResourceIdOverride = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1217,7 +1217,9 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
mAssistantOnTopOfDream = context.getResources().getBoolean(
|
mAssistantOnTopOfDream = context.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_assistantOnTopOfDream);
|
com.android.internal.R.bool.config_assistantOnTopOfDream);
|
||||||
|
|
||||||
mLetterboxConfiguration = new LetterboxConfiguration(context);
|
mLetterboxConfiguration = new LetterboxConfiguration(
|
||||||
|
// Using SysUI context to have access to Material colors extracted from Wallpaper.
|
||||||
|
ActivityThread.currentActivityThread().getSystemUiContext());
|
||||||
|
|
||||||
mInputManager = inputManager; // Must be before createDisplayContentLocked.
|
mInputManager = inputManager; // Must be before createDisplayContentLocked.
|
||||||
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
|
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_
|
|||||||
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR;
|
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR;
|
||||||
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_WALLPAPER;
|
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_WALLPAPER;
|
||||||
|
|
||||||
|
import android.content.res.Resources.NotFoundException;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
@@ -606,7 +607,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or aspect ratio should be provided as an argument " + e);
|
"Error: aspect ratio should be provided as an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
synchronized (mInternal.mGlobalLock) {
|
synchronized (mInternal.mGlobalLock) {
|
||||||
@@ -625,7 +626,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or corners radius should be provided as an argument " + e);
|
"Error: corners radius should be provided as an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
synchronized (mInternal.mGlobalLock) {
|
synchronized (mInternal.mGlobalLock) {
|
||||||
@@ -653,13 +654,13 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset', 'solid_color', 'app_color_background' or "
|
"Error: 'solid_color', 'app_color_background' or "
|
||||||
+ "'wallpaper' should be provided as an argument");
|
+ "'wallpaper' should be provided as an argument");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset', 'solid_color', 'app_color_background' or "
|
"Error: 'solid_color', 'app_color_background' or "
|
||||||
+ "'wallpaper' should be provided as an argument" + e);
|
+ "'wallpaper' should be provided as an argument" + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -669,6 +670,24 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int runSetLetterboxBackgroundColorResource(PrintWriter pw) throws RemoteException {
|
||||||
|
final int colorId;
|
||||||
|
try {
|
||||||
|
String arg = getNextArgRequired();
|
||||||
|
colorId = mInternal.mContext.getResources()
|
||||||
|
.getIdentifier(arg, "color", "com.android.internal");
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
getErrPrintWriter().println(
|
||||||
|
"Error: color in '@android:color/resource_name' format should be provided as "
|
||||||
|
+ "an argument " + e);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
synchronized (mInternal.mGlobalLock) {
|
||||||
|
mLetterboxConfiguration.setLetterboxBackgroundColorResourceId(colorId);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private int runSetLetterboxBackgroundColor(PrintWriter pw) throws RemoteException {
|
private int runSetLetterboxBackgroundColor(PrintWriter pw) throws RemoteException {
|
||||||
final Color color;
|
final Color color;
|
||||||
try {
|
try {
|
||||||
@@ -676,7 +695,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
color = Color.valueOf(Color.parseColor(arg));
|
color = Color.valueOf(Color.parseColor(arg));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or color in #RRGGBB format should be provided as "
|
"Error: color in #RRGGBB format should be provided as "
|
||||||
+ "an argument " + e);
|
+ "an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -697,7 +716,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or blur radius should be provided as an argument " + e);
|
"Error: blur radius should be provided as an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
synchronized (mInternal.mGlobalLock) {
|
synchronized (mInternal.mGlobalLock) {
|
||||||
@@ -717,7 +736,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or alpha should be provided as an argument " + e);
|
"Error: alpha should be provided as an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
synchronized (mInternal.mGlobalLock) {
|
synchronized (mInternal.mGlobalLock) {
|
||||||
@@ -736,7 +755,7 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
"Error: 'reset' or multiplier should be provided as an argument " + e);
|
"Error: multiplier should be provided as an argument " + e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
synchronized (mInternal.mGlobalLock) {
|
synchronized (mInternal.mGlobalLock) {
|
||||||
@@ -764,6 +783,9 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
case "--backgroundColor":
|
case "--backgroundColor":
|
||||||
runSetLetterboxBackgroundColor(pw);
|
runSetLetterboxBackgroundColor(pw);
|
||||||
break;
|
break;
|
||||||
|
case "--backgroundColorResource":
|
||||||
|
runSetLetterboxBackgroundColorResource(pw);
|
||||||
|
break;
|
||||||
case "--wallpaperBlurRadius":
|
case "--wallpaperBlurRadius":
|
||||||
runSetLetterboxBackgroundWallpaperBlurRadius(pw);
|
runSetLetterboxBackgroundWallpaperBlurRadius(pw);
|
||||||
break;
|
break;
|
||||||
@@ -1031,6 +1053,11 @@ public class WindowManagerShellCommand extends ShellCommand {
|
|||||||
pw.println(" is 'solid-color'. Use (set)get-letterbox-style to check and control");
|
pw.println(" is 'solid-color'. Use (set)get-letterbox-style to check and control");
|
||||||
pw.println(" letterbox background type. See Color#parseColor for allowed color");
|
pw.println(" letterbox background type. See Color#parseColor for allowed color");
|
||||||
pw.println(" formats (#RRGGBB and some colors by name, e.g. magenta or olive).");
|
pw.println(" formats (#RRGGBB and some colors by name, e.g. magenta or olive).");
|
||||||
|
pw.println(" --backgroundColorResource resource_name");
|
||||||
|
pw.println(" Color resource name of letterbox background which is used when");
|
||||||
|
pw.println(" background type is 'solid-color'. Use (set)get-letterbox-style to");
|
||||||
|
pw.println(" check and control background type. Parameter is a color resource");
|
||||||
|
pw.println(" name, for example, @android:color/system_accent2_50.");
|
||||||
pw.println(" --wallpaperBlurRadius radius");
|
pw.println(" --wallpaperBlurRadius radius");
|
||||||
pw.println(" Blur radius for 'wallpaper' letterbox background. If radius <= 0");
|
pw.println(" Blur radius for 'wallpaper' letterbox background. If radius <= 0");
|
||||||
pw.println(" both it and R.dimen.config_letterboxBackgroundWallpaperBlurRadius");
|
pw.println(" both it and R.dimen.config_letterboxBackgroundWallpaperBlurRadius");
|
||||||
|
|||||||
Reference in New Issue
Block a user