aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-11-15 11:55:15 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-15 11:57:13 -0800
commit7925d5b265249466bff385602e94509a05de6870 (patch)
tree9543038c23171dd93261a792a6f0571591e3cb09 /src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java
parent1e0b7cb49b5d22f72d9e32018d15972a9f28878c (diff)
Create merge action and data deserializer for aapt2 compiled resources.
RELNOTES: None PiperOrigin-RevId: 175858467
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java
index e3f5571c7d..fb74fd2208 100644
--- a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java
+++ b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java
@@ -13,6 +13,10 @@
// limitations under the License.
package com.google.devtools.build.android.xml;
+import com.android.aapt.Resources.Array;
+import com.android.aapt.Resources.Array.Element;
+import com.android.aapt.Resources.Item;
+import com.android.aapt.Resources.Value;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
@@ -117,6 +121,29 @@ public class ArrayXmlResourceValue implements XmlResourceValue {
ImmutableMap.copyOf(proto.getAttribute()));
}
+ public static XmlResourceValue from(Value proto) {
+ Array array = proto.getCompoundValue().getArray();
+ List<String> items = new ArrayList<>();
+
+ for (Element entry : array.getElementList()) {
+ Item item = entry.getItem();
+
+ if (item.hasPrim()) {
+ String stringValue = "#" + Integer.toHexString(item.getPrim().getData());
+ items.add(stringValue);
+ } else if (item.hasRef()) {
+ items.add("@" + item.getRef().getName());
+ } else if (item.hasStr()) {
+ items.add(item.getStr().getValue());
+ }
+ }
+
+ return of(
+ ArrayType.ARRAY,
+ items,
+ ImmutableMap.of());
+ }
+
@Override
public void write(
FullyQualifiedName key, DataSource source, AndroidDataWritingVisitor mergedDataWriter) {