From d4e81859457cc534f498dd1eecde7015875d937c Mon Sep 17 00:00:00 2001 From: James Landrum Date: Wed, 8 Jul 2015 11:03:51 -0400 Subject: [PATCH 1/2] Add attr resolution for view styles --- .../calligraphy/CalligraphyUtils.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java index 11737bf..ac8d0dc 100644 --- a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java +++ b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java @@ -167,7 +167,26 @@ static String pullFontPathFromView(Context context, AttributeSet attrs, int attr final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1); return stringResourceId > 0 ? context.getString(stringResourceId) - : attrs.getAttributeValue(null, attributeName); + : pullFontPathFromAttribute(context, attrs.getAttributeValue(null, attributeName)); + } + + /** + * Tries to convert from an attribute to a String + */ + static String pullFontPathFromAttribute(Context context, String attribute) { + String value = null; + if (attribute != null && attribute.startsWith("?bread")) { + try { + int identifier = context.getResources().getIdentifier(attribute.substring(1), + "attr", + context.getPackageName()); + TypedValue attr = new TypedValue(); + context.getTheme().resolveAttribute(identifier, attr, true); + value = attr.coerceToString().toString(); + } catch (NullPointerException ignore) { /* Handle a missing attr or invalid value */ } + } + if (value == null) value = attribute; // Allow this to work as it always has + return value; } /** From 0d615fae80c6c931cb29887757c7ffbf3add8da6 Mon Sep 17 00:00:00 2001 From: James Landrum Date: Wed, 8 Jul 2015 11:07:56 -0400 Subject: [PATCH 2/2] Remove debug string that breaks attr resolution --- .../main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java index ac8d0dc..c7ee78a 100644 --- a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java +++ b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyUtils.java @@ -175,7 +175,7 @@ static String pullFontPathFromView(Context context, AttributeSet attrs, int attr */ static String pullFontPathFromAttribute(Context context, String attribute) { String value = null; - if (attribute != null && attribute.startsWith("?bread")) { + if (attribute != null && attribute.startsWith("?")) { try { int identifier = context.getResources().getIdentifier(attribute.substring(1), "attr",