aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Perez <diegoperez@google.com>2018-02-14 15:57:19 +0000
committerDiego Perez <diegoperez@google.com>2018-02-15 17:39:06 +0000
commita4ac68349e730d5517187ea780b0284c7e383130 (patch)
tree2bc4acff5dad6f8e72fa939aaf6ffa4c25aa6551
parent1a5134f8db0fc88191608179a5c389b88fc89f2e (diff)
downloadlayoutlib-a4ac68349e730d5517187ea780b0284c7e383130.tar.gz
When defStyleAttr == 0 do not report missing style
If we pass the default value to defStyleAttr but we do pass a value to defStyleRes do not report it as a warning. Test: Added new test Change-Id: Ie1cbe9803bd500953b454f408b39636b0c02eeb7 (cherry picked from commit aa8025d3bfe541dfc633bd001724140f8def8f25)
-rw-r--r--bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java2
-rw-r--r--bridge/tests/src/com/android/layoutlib/bridge/android/BridgeContextTest.java39
2 files changed, 40 insertions, 1 deletions
diff --git a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index d334ba9c0e..8be28f0aae 100644
--- a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -809,7 +809,7 @@ public class BridgeContext extends Context {
}
defaultPropMap.put("style", new Property(defStyleName, item.getValue()));
}
- } else {
+ } else if (defStyleRes == 0) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR,
String.format(
"Failed to find style '%s' in current theme",
diff --git a/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeContextTest.java b/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeContextTest.java
index 77b5ba67f5..aec23a3699 100644
--- a/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeContextTest.java
+++ b/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeContextTest.java
@@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.SessionParams;
import com.android.layoutlib.bridge.impl.RenderAction;
import com.android.layoutlib.bridge.impl.RenderActionTestUtil;
import com.android.layoutlib.bridge.intensive.RenderTestBase;
+import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator;
import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
@@ -81,4 +82,42 @@ public class BridgeContextTest extends RenderTestBase {
sRenderMessages.removeIf(msg ->
msg.startsWith("Failed to find the style corresponding to the id"));
}
+
+ @Test
+ public void checkNoErrorWhenUsingDefaults() throws ClassNotFoundException {
+ // Setup
+ // Create the layout pull parser for our resources (empty.xml can not be part of the test
+ // app as it won't compile).
+ LayoutPullParser parser = LayoutPullParser.createFromPath("/empty.xml");
+ // Create LayoutLibCallback.
+ LayoutLibTestCallback layoutLibCallback =
+ new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
+ layoutLibCallback.initResources();
+ SessionParams params = getSessionParamsBuilder()
+ .setParser(parser)
+ .setCallback(layoutLibCallback)
+ .setTheme("Theme.Material", false)
+ .build();
+ DisplayMetrics metrics = new DisplayMetrics();
+ Configuration configuration = RenderAction.getConfiguration(params);
+ BridgeContext context = new BridgeContext(params.getProjectKey(), metrics, params.getResources(),
+ params.getAssets(), params.getLayoutlibCallback(), configuration,
+ params.getTargetSdkVersion(), params.isRtlSupported());
+
+ context.initResources();
+ BridgeContext oldContext = RenderActionTestUtil.setBridgeContext(context);
+ try {
+ Context themeContext = new ContextThemeWrapper(context, style.Theme_Material);
+ // First we try to get the style from the ?attr/editTextStyle fallback value.
+ // We pass an invalid value to defStyleRes
+ themeContext.obtainStyledAttributes(null,
+ new int[]{attr.clickable}, 0, style.Widget_EditText);
+ themeContext.obtainStyledAttributes(null,
+ new int[]{attr.clickable}, attr.editTextStyle, 0);
+ } finally {
+ RenderActionTestUtil.setBridgeContext(oldContext);
+ }
+
+
+ }
}