From f9f34a0b9fb283c55c129091fed9f13a3be27782 Mon Sep 17 00:00:00 2001 From: Fedor Kudasov Date: Tue, 3 Oct 2023 13:57:07 +0000 Subject: Allow floats that end with the '.' Floats like 9999.are allowed in Android and should be correctly parsed. Bug: 299149585 Test: added case to BridgeTypedArrayTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:282976a50ef9c99bf2e6d8484d8123a3decda0c1) Merged-In: I28fabe0d9ff8e29e5e545d64cb706945d9c587ac Change-Id: I28fabe0d9ff8e29e5e545d64cb706945d9c587ac --- bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java | 2 +- bridge/tests/src/android/content/res/BridgeTypedArrayTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java index 4200537f40..358795f256 100644 --- a/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +++ b/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java @@ -111,7 +111,7 @@ import static android.content.res.AssetManager.ACCESS_STREAMING; public final class ResourceHelper { private static final Key> KEY_GET_DRAWABLE = Key.create("ResourceHelper.getDrawable"); - private static final Pattern sFloatPattern = Pattern.compile("(-?[0-9]*(?:\\.[0-9]+)?)(.*)"); + private static final Pattern sFloatPattern = Pattern.compile("(-?[0-9]*(?:\\.[0-9]*)?)(.*)"); private static final float[] sFloatOut = new float[1]; private static final TypedValue mValue = new TypedValue(); diff --git a/bridge/tests/src/android/content/res/BridgeTypedArrayTest.java b/bridge/tests/src/android/content/res/BridgeTypedArrayTest.java index 39759279a3..dba0f76ee8 100644 --- a/bridge/tests/src/android/content/res/BridgeTypedArrayTest.java +++ b/bridge/tests/src/android/content/res/BridgeTypedArrayTest.java @@ -52,6 +52,7 @@ public class BridgeTypedArrayTest { assertEquals(TYPE_STRING, BridgeTypedArray.getType("#notacolor")); assertEquals(TYPE_DIMENSION, BridgeTypedArray.getType("16dp")); assertEquals(TYPE_DIMENSION, BridgeTypedArray.getType(".16dp")); + assertEquals(TYPE_DIMENSION, BridgeTypedArray.getType("9999.dp")); assertEquals(TYPE_STRING, BridgeTypedArray.getType("16notaunit")); assertEquals(TYPE_INT_DEC, BridgeTypedArray.getType("98543")); assertEquals(TYPE_FLOAT, BridgeTypedArray.getType("43.364")); -- cgit v1.2.3 From 2aad4bb7a40586aa62188c285afa34e4ed09e102 Mon Sep 17 00:00:00 2001 From: Jerome Gaillard Date: Thu, 24 Aug 2023 15:52:49 +0100 Subject: Apply image transformation coming through layoutlib-api As part of SessionParams, an image transformation can be passed to layoutlib. It is meant to apply to the rendered image before it is passes to ATF so that ATF analyses the modified image, and the modified image is the one returned by RenderSession.getImage. Bug: 291874189 Test: N/A (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d4bf1e4f1d5a6fdce3a291449b0b8c41f9bd2fdf) Merged-In: I55cb76238adf0d4924fc927cfb9c41cbb649807a Change-Id: I55cb76238adf0d4924fc927cfb9c41cbb649807a --- bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index ec775b2ec9..de7f651bab 100644 --- a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -91,6 +91,7 @@ import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; import static android.os._Original_Build.VERSION.SDK_INT; @@ -590,6 +591,11 @@ public class RenderSessionImpl extends RenderAction { mSystemViewInfoList = visitAllChildren(mViewRoot, 0, 0, params, false); + Consumer imageTransformation = getParams().getImageTransformation(); + if (imageTransformation != null) { + imageTransformation.accept(mImage); + } + boolean enableLayoutValidation = Boolean.TRUE.equals(params.getFlag(RenderParamsFlags.FLAG_ENABLE_LAYOUT_VALIDATOR)); boolean enableLayoutValidationImageCheck = Boolean.TRUE.equals( params.getFlag(RenderParamsFlags.FLAG_ENABLE_LAYOUT_VALIDATOR_IMAGE_CHECK)); -- cgit v1.2.3