diff options
author | Ram Peri <ramperi@google.com> | 2023-03-13 10:13:47 -0400 |
---|---|---|
committer | Ram Peri <ramperi@google.com> | 2023-03-13 11:43:26 -0400 |
commit | 32189e13d2db52e3703d29d97bb031ff01e393a7 (patch) | |
tree | d8911908bc0e5287490c781d8240cc9b96093bac /annotations | |
parent | 2339e88f72c1a816a1cac4ef3c55c984b855d2c7 (diff) | |
parent | 9e4ab89b53937cb0e4e15d73dd87d3e02abac1dd (diff) | |
download | robolectric-32189e13d2db52e3703d29d97bb031ff01e393a7.tar.gz |
Test: atest MyRoboTests,
Bug: 271629031
Change-Id: Iaa6a372dd56811c2dcc7e165cecebce6bc280108
Diffstat (limited to 'annotations')
-rw-r--r-- | annotations/src/main/java/org/robolectric/annotation/Config.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/annotations/src/main/java/org/robolectric/annotation/Config.java b/annotations/src/main/java/org/robolectric/annotation/Config.java index fed003253..1553e6d96 100644 --- a/annotations/src/main/java/org/robolectric/annotation/Config.java +++ b/annotations/src/main/java/org/robolectric/annotation/Config.java @@ -33,6 +33,7 @@ public @interface Config { String DEFAULT_VALUE_STRING = "--default"; int DEFAULT_VALUE_INT = -1; + float DEFAULT_FONT_SCALE = 1.0f; String DEFAULT_MANIFEST_NAME = "AndroidManifest.xml"; Class<? extends Application> DEFAULT_APPLICATION = DefaultApplication.class; @@ -56,6 +57,13 @@ public @interface Config { int maxSdk() default -1; /** + * The default font scale. In U+, users will have a slider to determine font scale. In all + * previous APIs, font scales are either small (0.85f), normal (1.0f), large (1.15f) or huge + * (1.3f) + */ + float fontScale() default 1.0f; + + /** * The Android manifest file to load; Robolectric will look relative to the current directory. * Resources and assets will be loaded relative to the manifest. * @@ -166,6 +174,7 @@ public @interface Config { private final int[] sdk; private final int minSdk; private final int maxSdk; + private final float fontScale; private final String manifest; private final String qualifiers; private final String resourceDir; @@ -184,6 +193,7 @@ public @interface Config { parseSdkInt(properties.getProperty("maxSdk", "-1")), properties.getProperty("manifest", DEFAULT_VALUE_STRING), properties.getProperty("qualifiers", DEFAULT_QUALIFIERS), + Float.parseFloat(properties.getProperty("fontScale", "1.0f")), properties.getProperty("packageName", DEFAULT_PACKAGE_NAME), properties.getProperty("resourceDir", DEFAULT_RES_FOLDER), properties.getProperty("assetDir", DEFAULT_ASSET_FOLDER), @@ -284,6 +294,7 @@ public @interface Config { int maxSdk, String manifest, String qualifiers, + float fontScale, String packageName, String resourceDir, String assetDir, @@ -296,6 +307,7 @@ public @interface Config { this.maxSdk = maxSdk; this.manifest = manifest; this.qualifiers = qualifiers; + this.fontScale = fontScale; this.packageName = packageName; this.resourceDir = resourceDir; this.assetDir = assetDir; @@ -328,6 +340,11 @@ public @interface Config { } @Override + public float fontScale() { + return fontScale; + } + + @Override public Class<? extends Application> application() { return application; } @@ -413,6 +430,7 @@ public @interface Config { protected int[] sdk = new int[0]; protected int minSdk = -1; protected int maxSdk = -1; + protected float fontScale = 1.0f; protected String manifest = Config.DEFAULT_VALUE_STRING; protected String qualifiers = Config.DEFAULT_QUALIFIERS; protected String packageName = Config.DEFAULT_PACKAGE_NAME; @@ -431,6 +449,7 @@ public @interface Config { maxSdk = config.maxSdk(); manifest = config.manifest(); qualifiers = config.qualifiers(); + fontScale = config.fontScale(); packageName = config.packageName(); resourceDir = config.resourceDir(); assetDir = config.assetDir(); @@ -475,6 +494,11 @@ public @interface Config { return this; } + public Builder setFontScale(float fontScale) { + this.fontScale = fontScale; + return this; + } + public Builder setAssetDir(String assetDir) { this.assetDir = assetDir; return this; @@ -515,6 +539,7 @@ public @interface Config { int[] overlaySdk = overlayConfig.sdk(); int overlayMinSdk = overlayConfig.minSdk(); int overlayMaxSdk = overlayConfig.maxSdk(); + float overlayFontScale = overlayConfig.fontScale(); //noinspection ConstantConditions if (overlaySdk != null && overlaySdk.length > 0) { @@ -532,6 +557,8 @@ public @interface Config { } this.manifest = pick(this.manifest, overlayConfig.manifest(), DEFAULT_VALUE_STRING); + this.fontScale = pick(this.fontScale, overlayFontScale, DEFAULT_FONT_SCALE); + String qualifiersOverlayValue = overlayConfig.qualifiers(); if (qualifiersOverlayValue != null && !qualifiersOverlayValue.equals("")) { if (qualifiersOverlayValue.startsWith("+")) { @@ -583,6 +610,7 @@ public @interface Config { maxSdk, manifest, qualifiers, + fontScale, packageName, resourceDir, assetDir, |