handles <string-array> / <array> that require formatted="false" attributes

This commit is contained in:
Connor Tumbleson 2014-09-22 18:27:25 -05:00
parent 394bb25b7c
commit ce15b50c1c
6 changed files with 26 additions and 1 deletions

View File

@ -41,6 +41,7 @@ v2.0.0 (TBA)
-Fixed (issue #630) - Fixed handling renamed manifests with ("com.lge")
-Fixed (issue #409) - Fixed array items incorrectly typed.
-Fixed (issue #512) - Fixed AndroidManifest missing attributes.
-Fixed (issue #677) - Fixed ignoring formatted attribute in <string-array>.
-Fixed issue with APKs with multiple dex files.
-Fixed issue with using Apktool without smali/baksmali for ApktoolProperties (Thanks teprrr)
-Fixed issue with non-URI standard characters in apk name (Thanks rover12421)

View File

@ -53,6 +53,16 @@ public class ResArrayValue extends ResBagValue implements
type = (type == null ? "" : type + "-") + "array";
serializer.startTag(null, type);
serializer.attribute(null, "name", res.getResSpec().getName());
// lets check if we need to add formatted="false" to this array
for (int i = 0; i < mItems.length; i++) {
if (mItems[i].hasMultipleNonPositionalSubstitutions()) {
serializer.attribute(null, "formatted", "false");
break;
}
}
// add <item>'s
for (int i = 0; i < mItems.length; i++) {
serializer.startTag(null, "item");
serializer.text(mItems[i].encodeAsResXmlNonEscapedItemValue());

View File

@ -61,6 +61,10 @@ public abstract class ResScalarValue extends ResValue implements
return encodeAsResXmlValue().replace("&amp;", "&").replace("&lt;","<");
}
public boolean hasMultipleNonPositionalSubstitutions() throws AndrolibException {
return ResXmlEncoders.hasMultipleNonPositionalSubstitutions(mRawValue);
}
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException {

View File

@ -175,9 +175,15 @@ public final class ResXmlEncoders {
}
int pos;
int pos2 = 0;
int length = str.length();
List<Integer> nonPositional = new ArrayList<>();
List<Integer> positional = new ArrayList<>();
if (str == null) {
return new Duo<>(nonPositional, positional);
}
int length = str.length();
while ((pos = str.indexOf('%', pos2)) != -1) {
pos2 = pos + 1;
if (pos2 == length) {

View File

@ -28,4 +28,7 @@
<item>foo</item>
<item>foo2</item>
</string-array>
<string-array name="issue_677" formatted="false">
<item>category=temp%temp%foo</item>
</string-array>
</resources>

View File

@ -28,4 +28,5 @@ bar"</string>
<string name="test_string26">賞金鬥士14</string>
<string name="test_string27">{id:65538,v:2,tid:20003,mst:1,x:-1,y:-1,a:6000,b:3000,lm:{chp:1000,rep:0,bt:0,mp:[[101,0,1,0],[101,0,1,1],[101,0,1,2],[101,0,1,3],[101,0,1,4],[101,0,1,5],[100,0,0,0],[100,0,0,1],[100,0,0,2],[100,0,0,3],[100,0,0,4],[100,0,0,5]]},rm:{chp:1000,rep:0,bt:0,mp:[[100,0,1,0],[100,0,1,1],[100,0,1,2],[100,0,1,3],[100,0,1,4],[100,0,1,5],[101,0,0,0],[101,0,0,1],[101,0,0,2],[101,0,0,3],[101,0,0,4],[101,0,0,5]]}}</string>
<string name="test_string28">{al:[[180,0,7,0,0,1000],[109,0,5,0,0],[109,0,5,2,0],[109,0,5,4,0],[100,0,3,0,0],[100,0,3,1,0],[100,0,3,2,0],[100,0,3,3,0],[100,0,3,4,0],[100,0,3,5,0],[103,0,1,0,0],[103,0,1,1,0],[103,0,1,2,0],[103,0,1,3,0],[103,0,1,4,0],[103,0,1,5,0],[106,0,2,0,0],[106,0,2,1,0],[106,0,2,2,0],[106,0,2,3,0],[106,0,2,4,0],[106,0,2,5,0],[800,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[850],[950],[900,0],[1000,0,0]],v:4,s:-1575044211,rl:[[180,0,7,0,0,1000],[103,0,0,0,0],[103,0,0,1,0],[103,0,0,2,0],[103,0,0,3,0],[103,0,0,4,0],[103,0,0,5,0],[111,0,3,0,0],[111,0,3,1,0],[111,0,3,2,0],[111,0,3,3,0],[111,0,3,4,0],[111,0,3,5,0],[102,0,4,0,0],[102,0,4,1,0],[102,0,4,2,0],[102,0,4,3,0],[102,0,4,4,0],[102,0,4,5,0],[107,0,5,0,0],[107,0,5,1,0],[107,0,5,2,0],[107,0,5,3,0],[107,0,5,4,0],[107,0,5,5,0],[106,0,2,0,0],[106,0,2,1,0],[106,0,2,2,0],[106,0,2,3,0],[106,0,2,4,0],[106,0,2,5,0],[900],[1000,0,0]],m:[]}</string>
<string name="test_string29" formatted="false">category=temp%temp%foo</string>
</resources>