From 17380788c6e68f103c29a739cfa4282004dcb8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Tue, 23 Mar 2010 20:38:53 +0100 Subject: [PATCH] AXmlResourceParser: attribute values decoding using ResAttrDecoder. --- .../res/decoder/AXmlResourceParser.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/brut/androlib/res/decoder/AXmlResourceParser.java b/src/brut/androlib/res/decoder/AXmlResourceParser.java index 7747adde..f61fbb0b 100644 --- a/src/brut/androlib/res/decoder/AXmlResourceParser.java +++ b/src/brut/androlib/res/decoder/AXmlResourceParser.java @@ -22,8 +22,11 @@ import java.io.InputStream; import java.io.Reader; import org.xmlpull.v1.XmlPullParserException; import android.util.TypedValue; +import brut.androlib.AndrolibException; import brut.util.ExtDataInput; import com.mindprod.ledatastream.LEDataInputStream; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @author Ryszard Wiśniewski @@ -52,6 +55,10 @@ public class AXmlResourceParser implements XmlResourceParser { open(stream); } + public void setAttrDecoder(ResAttrDecoder attrDecoder) { + mAttrDecoder = attrDecoder; + } + public void open(InputStream stream) { close(); if (stream != null) { @@ -296,6 +303,22 @@ public class AXmlResourceParser implements XmlResourceParser { return m_strings.getString(valueString); } int valueData = m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA]; + + if (mAttrDecoder != null) { + try { + return mAttrDecoder.decode(valueType, valueData, + getAttributeNameResource(index)); + } catch (AndrolibException ex) { + Logger.getLogger(AXmlResourceParser.class.getName()).log( + Level.WARNING, String.format( + "Could not decode attr value, using undecoded value " + + "instead: ns=%s, name=%s, value=0x%08x", + getAttributePrefix(index), getAttributeName(index), + valueData + ), ex); + } + } + return TypedValue.coerceToString(valueType, valueData); } @@ -884,6 +907,7 @@ public class AXmlResourceParser implements XmlResourceParser { * an index of name in m_strings. */ private ExtDataInput m_reader; + private ResAttrDecoder mAttrDecoder; private boolean m_operational = false; private StringBlock m_strings; private int[] m_resourceIDs;