From db439f2b8c6e18b76f4cc5da3486988401bedf85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Mon, 14 Jun 2010 11:16:06 +0200 Subject: [PATCH] ResEnumAttr: added support for many enum names with same int value. --- .../androlib/res/data/value/ResEnumAttr.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/brut/androlib/res/data/value/ResEnumAttr.java b/src/brut/androlib/res/data/value/ResEnumAttr.java index 973577b7..6efe5902 100644 --- a/src/brut/androlib/res/data/value/ResEnumAttr.java +++ b/src/brut/androlib/res/data/value/ResEnumAttr.java @@ -34,11 +34,7 @@ public class ResEnumAttr extends ResAttr { ResEnumAttr(ResReferenceValue parent, int type, Integer min, Integer max, Boolean l10n, Duo[] items) { super(parent, type, min, max, l10n); - - mItems = new LinkedHashMap(); - for (int i = 0; i < items.length; i++) { - mItems.put(items[i].m2.getValue(), items[i].m1); - } + mItems = items; } @Override @@ -56,9 +52,11 @@ public class ResEnumAttr extends ResAttr { @Override protected void serializeBody(XmlSerializer serializer, ResResource res) throws AndrolibException, IOException { - for (int intVal : mItems.keySet()) { + for (Duo duo : mItems) { + int intVal = duo.m2.getValue(); + serializer.startTag(null, "enum"); - serializer.attribute(null, "name", decodeValue(intVal)); + serializer.attribute(null, "name", duo.m1.getReferent().getName()); serializer.attribute(null, "value", String.valueOf(intVal)); serializer.endTag(null, "enum"); } @@ -67,7 +65,13 @@ public class ResEnumAttr extends ResAttr { private String decodeValue(int value) throws AndrolibException { String value2 = mItemsCache.get(value); if (value2 == null) { - ResReferenceValue ref = mItems.get(value); + ResReferenceValue ref = null; + for (Duo duo : mItems) { + if (duo.m2.getValue() == value) { + ref = duo.m1; + break; + } + } if (ref != null) { value2 = ref.getReferent().getName(); mItemsCache.put(value, value2); @@ -77,7 +81,7 @@ public class ResEnumAttr extends ResAttr { } - private final Map mItems; + private final Duo[] mItems; private final Map mItemsCache = new HashMap(); }