Skip to content

Commit

Permalink
fix: rework towards ResScalarValue instead of ResIntValue
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Sep 11, 2023
1 parent bf6220e commit d28e408
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,39 @@ public void serializeToResValuesXml(XmlSerializer serializer, ResResource res) t
public static ResAttr factory(ResReferenceValue parent,
Duo<Integer, ResScalarValue>[] items, ResValueFactory factory,
ResPackage pkg) throws AndrolibException {

int type = ((ResIntValue) items[0].m2).getValue();
int scalarType = type & 0xffff;
Integer min = null, max = null;
Boolean l10n = null;
int i;
for (i = 1; i < items.length; i++) {
switch (items[i].m1) {
case BAG_KEY_ATTR_MIN:
min = ((ResIntValue) items[i].m2).getValue();
min = (items[i].m2).getRawIntValue();
continue;
case BAG_KEY_ATTR_MAX:
max = ((ResIntValue) items[i].m2).getValue();
max = (items[i].m2).getRawIntValue();
continue;
case BAG_KEY_ATTR_L10N:
l10n = ((ResIntValue) items[i].m2).getValue() != 0;
l10n = (items[i].m2).getRawIntValue() != 0;
continue;
}
break;
}

// #2806 - Make sure we handle int-based values and not just ResIntValue
int rawValue = items[0].m2.getRawIntValue();
int scalarType = rawValue & 0xffff;

if (i == items.length) {
return new ResAttr(parent, scalarType, min, max, l10n);
}
Duo<ResReferenceValue, ResIntValue>[] attrItems = new Duo[items.length - i];
Duo<ResReferenceValue, ResScalarValue>[] attrItems = new Duo[items.length - i];
int j = 0;
for (; i < items.length; i++) {
int resId = items[i].m1;
pkg.addSynthesizedRes(resId);
attrItems[j++] = new Duo<>(factory.newReference(resId, null), (ResIntValue) items[i].m2);
attrItems[j++] = new Duo<>(factory.newReference(resId, null), items[i].m2);
}
switch (type & 0xff0000) {
switch (rawValue & 0xff0000) {
case TYPE_ENUM:
return new ResEnumAttr(parent, scalarType, min, max, l10n, attrItems);
case TYPE_FLAGS:
Expand Down Expand Up @@ -145,7 +146,6 @@ protected String getTypeAsString() {
private final Integer mMax;
private final Boolean mL10n;

public static final int BAG_KEY_ATTR_TYPE = 0x01000000;
private static final int BAG_KEY_ATTR_MIN = 0x01000001;
private static final int BAG_KEY_ATTR_MAX = 0x01000002;
private static final int BAG_KEY_ATTR_L10N = 0x01000003;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class ResEnumAttr extends ResAttr {
ResEnumAttr(ResReferenceValue parent, int type, Integer min, Integer max,
Boolean l10n, Duo<ResReferenceValue, ResIntValue>[] items) {
Boolean l10n, Duo<ResReferenceValue, ResScalarValue>[] items) {
super(parent, type, min, max, l10n);
mItems = items;
}
Expand All @@ -48,8 +48,8 @@ public String convertToResXmlFormat(ResScalarValue value)

@Override
protected void serializeBody(XmlSerializer serializer, ResResource res) throws AndrolibException, IOException {
for (Duo<ResReferenceValue, ResIntValue> duo : mItems) {
int intVal = duo.m2.getValue();
for (Duo<ResReferenceValue, ResScalarValue> duo : mItems) {
int intVal = duo.m2.getRawIntValue();

// #2836 - Support skipping items if the resource cannot be identified.
ResResSpec m1Referent = duo.m1.getReferent();
Expand All @@ -72,8 +72,8 @@ private String decodeValue(int value) throws AndrolibException {
String value2 = mItemsCache.get(value);
if (value2 == null) {
ResReferenceValue ref = null;
for (Duo<ResReferenceValue, ResIntValue> duo : mItems) {
if (duo.m2.getValue() == value) {
for (Duo<ResReferenceValue, ResScalarValue> duo : mItems) {
if (duo.m2.getRawIntValue() == value) {
ref = duo.m1;
break;
}
Expand All @@ -86,7 +86,7 @@ private String decodeValue(int value) throws AndrolibException {
return value2;
}

private final Duo<ResReferenceValue, ResIntValue>[] mItems;
private final Duo<ResReferenceValue, ResScalarValue>[] mItems;
private final Map<Integer, String> mItemsCache = new HashMap<>();

private static final Logger LOGGER = Logger.getLogger(ResEnumAttr.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

public class ResFlagsAttr extends ResAttr {
ResFlagsAttr(ResReferenceValue parent, int type, Integer min, Integer max,
Boolean l10n, Duo<ResReferenceValue, ResIntValue>[] items) {
Boolean l10n, Duo<ResReferenceValue, ResScalarValue>[] items) {
super(parent, type, min, max, l10n);

mItems = new FlagItem[items.length];
for (int i = 0; i < items.length; i++) {
mItems[i] = new FlagItem(items[i].m1, items[i].m2.getValue());
mItems[i] = new FlagItem(items[i].m1, items[i].m2.getRawIntValue());
}
}

Expand Down

0 comments on commit d28e408

Please sign in to comment.