Skip to content

Commit

Permalink
fix: prefer res name instead of "guessing" based on ids
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Sep 11, 2023
1 parent d28e408 commit 6ac7712
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
public final class ResTypeSpec {

public static final String RES_TYPE_NAME_ARRAY = "array";
public static final String RES_TYPE_NAME_ATTR = "attr";
public static final String RES_TYPE_NAME_ATTR_PRIVATE = "^attr-private";
public static final String RES_TYPE_NAME_PLURALS = "plurals";
public static final String RES_TYPE_NAME_STRING = "string";
public static final String RES_TYPE_NAME_STYLES = "style";
public static final String RES_TYPE_NAME_ATTR = "attr";

private final String mName;
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<>();
Expand All @@ -46,7 +48,7 @@ public int getId() {
}

public boolean isString() {
return mName.equalsIgnoreCase("string");
return mName.equalsIgnoreCase(RES_TYPE_NAME_STRING);
}

public ResResSpec getResSpec(String name) throws AndrolibException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,4 @@ public String getType() throws AndrolibException {

private final ResScalarValue[] mItems;
private final String[] AllowedArrayTypes = {"string", "integer"};

public static final int BAG_KEY_ARRAY_START = 0x02000000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ public void serializeToResValuesXml(XmlSerializer serializer,
private final ResScalarValue[] mItems;

public static final int BAG_KEY_PLURALS_START = 0x01000004;
public static final int BAG_KEY_PLURALS_END = 0x01000009;
private static final String[] QUANTITY_MAP = new String[] { "other", "zero", "one", "two", "few", "many" };
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,29 @@ public ResIntBasedValue factory(String value, int rawValue) {
return new ResStringValue(value, rawValue);
}

public ResBagValue bagFactory(int parent, Duo<Integer, ResScalarValue>[] items, ResTypeSpec resTypeSpec) throws AndrolibException {
public ResBagValue bagFactory(int parent, Duo<Integer, ResScalarValue>[] items, ResTypeSpec resTypeSpec)
throws AndrolibException {
ResReferenceValue parentVal = newReference(parent, null);

if (items.length == 0) {
return new ResBagValue(parentVal);
}
int key = items[0].m1;
if (key == ResAttr.BAG_KEY_ATTR_TYPE) {
return ResAttr.factory(parentVal, items, this, mPackage);
}

String resTypeName = resTypeSpec.getName();

// Android O Preview added an unknown enum for c. This is hardcoded as 0 for now.
if (ResTypeSpec.RES_TYPE_NAME_ARRAY.equals(resTypeName)
|| key == ResArrayValue.BAG_KEY_ARRAY_START || key == 0) {
return new ResArrayValue(parentVal, items);
}

if (ResTypeSpec.RES_TYPE_NAME_PLURALS.equals(resTypeName) ||
(key >= ResPluralsValue.BAG_KEY_PLURALS_START && key <= ResPluralsValue.BAG_KEY_PLURALS_END)) {
return new ResPluralsValue(parentVal, items);
}

if (ResTypeSpec.RES_TYPE_NAME_ATTR.equals(resTypeName)) {
return new ResAttr(parentVal, 0, null, null, null);
}

if (resTypeName.startsWith(ResTypeSpec.RES_TYPE_NAME_STYLES)) {
return new ResStyleValue(parentVal, items, this);
switch (resTypeName) {
case ResTypeSpec.RES_TYPE_NAME_ATTR:
case ResTypeSpec.RES_TYPE_NAME_ATTR_PRIVATE:
return ResAttr.factory(parentVal, items, this, mPackage);
case ResTypeSpec.RES_TYPE_NAME_ARRAY:
return new ResArrayValue(parentVal, items);
case ResTypeSpec.RES_TYPE_NAME_PLURALS:
return new ResPluralsValue(parentVal, items);
default:
if (resTypeName.startsWith(ResTypeSpec.RES_TYPE_NAME_STYLES)) {
return new ResStyleValue(parentVal, items, this);
}
throw new AndrolibException("unsupported res type name for bags. Found: " + resTypeName);
}

throw new AndrolibException("unsupported res type name for bags. Found: " + resTypeName);
}

public ResReferenceValue newReference(int resID, String rawValue) {
Expand Down

0 comments on commit 6ac7712

Please sign in to comment.