Extract and store raw value of ResScalarValue.

Many attr values in axml files store their raw string value. Now it's extracted, so any ResScalarValue could make some use of it.
This commit is contained in:
Ryszard Wiśniewski 2011-05-09 10:41:29 +02:00
parent 7d4edce7ee
commit 5740064cee
16 changed files with 49 additions and 57 deletions

View File

@ -99,7 +99,7 @@ public class ResAttr extends ResBagValue implements ResValuesXmlSerializable {
int resId = items[i].m1;
pkg.addSynthesizedRes(resId);
attrItems[j++] = new Duo<ResReferenceValue, ResIntValue>(
factory.newReference(resId), (ResIntValue) items[i].m2);
factory.newReference(resId, null), (ResIntValue) items[i].m2);
}
switch (type & 0xff0000) {
case TYPE_ENUM:

View File

@ -22,8 +22,8 @@ package brut.androlib.res.data.value;
public class ResBoolValue extends ResScalarValue implements ResValuesXmlSerializable {
private final boolean mValue;
public ResBoolValue(boolean value) {
super("bool");
public ResBoolValue(boolean value, String rawValue) {
super("bool", rawValue);
this.mValue = value;
}

View File

@ -20,8 +20,8 @@ package brut.androlib.res.data.value;
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
*/
public class ResColorValue extends ResIntValue {
public ResColorValue(int value) {
super(value, "color");
public ResColorValue(int value, String rawValue) {
super(value, rawValue, "color");
}
@Override

View File

@ -26,8 +26,8 @@ import org.xmlpull.v1.XmlSerializer;
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
*/
public class ResDimenValue extends ResIntValue {
public ResDimenValue(int value) {
super(value, "dimen");
public ResDimenValue(int value, String rawValue) {
super(value, rawValue, "dimen");
}
@Override

View File

@ -22,8 +22,8 @@ package brut.androlib.res.data.value;
public class ResFloatValue extends ResScalarValue {
private final float mValue;
public ResFloatValue(float value) {
super("float");
public ResFloatValue(float value, String rawValue) {
super("float", rawValue);
this.mValue = value;
}

View File

@ -23,8 +23,8 @@ import brut.androlib.AndrolibException;
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
*/
public class ResFractionValue extends ResIntValue {
public ResFractionValue(int value) {
super(value, "fraction");
public ResFractionValue(int value, String rawValue) {
super(value, rawValue, "fraction");
}
@Override

View File

@ -24,12 +24,12 @@ import brut.androlib.AndrolibException;
public class ResIntValue extends ResScalarValue implements ResValuesXmlSerializable {
protected final int mValue;
public ResIntValue(int value) {
this(value, "integer");
public ResIntValue(int value, String rawValue) {
this(value, rawValue, "integer");
}
public ResIntValue(int value, String type) {
super(type);
public ResIntValue(int value, String rawValue, String type) {
super(type, rawValue);
this.mValue = value;
}

View File

@ -27,12 +27,13 @@ public class ResReferenceValue extends ResIntValue {
private final ResPackage mPackage;
private final boolean mTheme;
public ResReferenceValue(ResPackage package_, int value) {
this(package_, value, false);
public ResReferenceValue(ResPackage package_, int value, String rawValue) {
this(package_, value, rawValue, false);
}
public ResReferenceValue(ResPackage package_, int value, boolean theme) {
super(value, "reference");
public ResReferenceValue(ResPackage package_, int value, String rawValue,
boolean theme) {
super(value, rawValue, "reference");
mPackage = package_;
mTheme = theme;
}

View File

@ -28,9 +28,11 @@ import org.xmlpull.v1.XmlSerializer;
public abstract class ResScalarValue extends ResValue
implements ResXmlEncodable, ResValuesXmlSerializable {
protected final String mType;
protected final String mRawValue;
protected ResScalarValue(String type) {
protected ResScalarValue(String type, String rawValue) {
mType = type;
mRawValue = rawValue;
}
public abstract String toResXmlFormat() throws AndrolibException;

View File

@ -30,7 +30,7 @@ public class ResStringValue extends ResScalarValue
}
public ResStringValue(String value, String type) {
super(type);
super(type, value);
this.mValue = value;
}

View File

@ -34,7 +34,7 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
mItems = new Duo[items.length];
for (int i = 0; i < items.length; i++) {
mItems[i] = new Duo<ResReferenceValue, ResScalarValue>(
factory.newReference(items[i].m1), items[i].m2);
factory.newReference(items[i].m1, null), items[i].m2);
}
}

View File

@ -31,30 +31,30 @@ public class ResValueFactory {
this.mPackage = pakage_;
}
public ResScalarValue factory(int type, int value)
public ResScalarValue factory(int type, int value, String rawValue)
throws AndrolibException {
switch (type) {
case TypedValue.TYPE_REFERENCE:
return newReference(value);
return newReference(value, rawValue);
case TypedValue.TYPE_ATTRIBUTE:
return newReference(value, true);
return newReference(value, rawValue, true);
case TypedValue.TYPE_FLOAT:
return new ResFloatValue(Float.intBitsToFloat(value));
return new ResFloatValue(Float.intBitsToFloat(value), rawValue);
case TypedValue.TYPE_DIMENSION:
return new ResDimenValue(value);
return new ResDimenValue(value, rawValue);
case TypedValue.TYPE_FRACTION:
return new ResFractionValue(value);
return new ResFractionValue(value, rawValue);
case TypedValue.TYPE_INT_BOOLEAN:
return new ResBoolValue(value != 0);
return new ResBoolValue(value != 0, rawValue);
}
if (type >= TypedValue.TYPE_FIRST_COLOR_INT
&& type <= TypedValue.TYPE_LAST_COLOR_INT) {
return new ResColorValue(value);
return new ResColorValue(value, rawValue);
}
if (type >= TypedValue.TYPE_FIRST_INT
&& type <= TypedValue.TYPE_LAST_INT) {
return new ResIntValue(value);
return new ResIntValue(value, rawValue);
}
throw new AndrolibException("Invalid value type: "+ type);
@ -69,7 +69,7 @@ public class ResValueFactory {
public ResBagValue bagFactory(int parent,
Duo<Integer, ResScalarValue>[] items) throws AndrolibException {
ResReferenceValue parentVal = newReference(parent);
ResReferenceValue parentVal = newReference(parent, null);
if (items.length == 0) {
return new ResBagValue(parentVal);
@ -88,11 +88,12 @@ public class ResValueFactory {
return new ResStyleValue(parentVal, items, this);
}
public ResReferenceValue newReference(int resID) {
return newReference(resID, false);
public ResReferenceValue newReference(int resID, String rawValue) {
return newReference(resID, rawValue, false);
}
public ResReferenceValue newReference(int resID, boolean theme) {
return new ResReferenceValue(mPackage, resID, theme);
public ResReferenceValue newReference(int resID, String rawValue,
boolean theme) {
return new ResReferenceValue(mPackage, resID, rawValue, theme);
}
}

View File

@ -221,7 +221,7 @@ public class ARSCDecoder {
return type == TypedValue.TYPE_STRING ?
mPkg.getValueFactory().factory(mTableStrings.getHTML(data)) :
mPkg.getValueFactory().factory(type, data);
mPkg.getValueFactory().factory(type, data, null);
}
private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
@ -300,7 +300,7 @@ public class ARSCDecoder {
mPkg.addResSpec(spec);
mType.addResSpec(spec);
ResValue value = new ResBoolValue(false);
ResValue value = new ResBoolValue(false, null);
ResResource res = new ResResource(
mPkg.getOrCreateConfig(new ResConfigFlags()), spec, value);
mPkg.addResource(res);

View File

@ -308,20 +308,13 @@ public class AXmlResourceParser implements XmlResourceParser {
int offset = getAttributeOffset(index);
int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
int valueData = m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
int valueString = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING];
int valueRaw = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING];
if (mAttrDecoder != null && (
valueString == -1
|| valueType == TypedValue.TYPE_REFERENCE
|| valueType == TypedValue.TYPE_ATTRIBUTE
|| (
valueType >= TypedValue.TYPE_FIRST_COLOR_INT
&& valueType <= TypedValue.TYPE_LAST_COLOR_INT
)
)) {
if (mAttrDecoder != null) {
try {
return mAttrDecoder.decode(valueType, valueData,
getAttributeNameResource(index));
valueRaw == -1 ? null : m_strings.getString(valueRaw),
getAttributeNameResource(index));
} catch (AndrolibException ex) {
setFirstError(ex);
LOGGER.log(Level.WARNING, String.format(
@ -333,11 +326,6 @@ public class AXmlResourceParser implements XmlResourceParser {
}
}
if (valueString != -1) {
return AndrolibResources.escapeTextForResXml(
m_strings.getString(valueString));
}
return TypedValue.coerceToString(valueType, valueData);
}

View File

@ -25,10 +25,10 @@ import brut.androlib.res.data.value.ResScalarValue;
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
*/
public class ResAttrDecoder {
public String decode(int type, int value, int attrResId)
public String decode(int type, int value, String rawValue, int attrResId)
throws AndrolibException {
ResScalarValue resValue = mCurrentPackage.getValueFactory()
.factory(type, value);
.factory(type, value, rawValue);
if (attrResId == 0) {
return resValue.toResXmlFormat();
}

View File

@ -88,7 +88,7 @@ public class ResFileDecoder {
LOGGER.log(Level.SEVERE, String.format(
"Could not decode file, replacing by FALSE value: %s",
inFileName, outFileName), ex);
res.replace(new ResBoolValue(false));
res.replace(new ResBoolValue(false, null));
}
}