Debian Codegraph @

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResPluralsValue.java

raw
1 /*
2 * Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
3 * Copyright (C) 2010 Connor Tumbleson <[email protected]>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package brut.androlib.res.data.value;
18
19 import brut.androlib.AndrolibException;
20 import brut.androlib.res.data.ResResource;
21 import brut.androlib.res.xml.ResValuesXmlSerializable;
22 import brut.androlib.res.xml.ResXmlEncoders;
23 import brut.util.Duo;
24 import org.xmlpull.v1.XmlSerializer;
25
26 import java.io.IOException;
27
28 public class ResPluralsValue extends ResBagValue implements
29 ResValuesXmlSerializable {
30 ResPluralsValue(ResReferenceValue parent,
31 Duo<Integer, ResScalarValue>[] items) {
32 super(parent);
33
34 mItems = new ResScalarValue[6];
35 for (Duo<Integer, ResScalarValue> item : items) {
36 mItems[item.m1 - BAG_KEY_PLURALS_START] = item.m2;
37 }
38 }
39
40 @Override
41 public void serializeToResValuesXml(XmlSerializer serializer,
42 ResResource res) throws IOException, AndrolibException {
43 serializer.startTag(null, "plurals");
44 serializer.attribute(null, "name", res.getResSpec().getName());
45 for (int i = 0; i < mItems.length; i++) {
46 ResScalarValue item = mItems[i];
47 if (item == null) {
48 continue;
49 }
50
51 serializer.startTag(null, "item");
52 serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
53 serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlNonEscapedItemValue()));
54 serializer.endTag(null, "item");
55 }
56 serializer.endTag(null, "plurals");
57 }
58
59 private final ResScalarValue[] mItems;
60
61 public static final int BAG_KEY_PLURALS_START = 0x01000004;
62 public static final int BAG_KEY_PLURALS_END = 0x01000009;
63 private static final String[] QUANTITY_MAP = new String[] { "other", "zero", "one", "two", "few", "many" };
64 }