Added automatic 9-patch workaround.

This commit is contained in:
Ryszard Wiśniewski 2010-03-27 21:09:16 +01:00
parent dc1a645396
commit d35120da35
2 changed files with 32 additions and 4 deletions

View File

@ -199,10 +199,14 @@ public class Androlib {
File apkFile = File.createTempFile("APKTOOL", null);
apkFile.delete();
File ninePatch = new File(appDir, "9patch");
if (! ninePatch.exists()) {
ninePatch = null;
}
mAndRes.aaptPackage(
apkFile,
new File(appDir, "AndroidManifest.xml"),
new File(appDir, "res")
new File(appDir, "res"), ninePatch, null, false
);
new ExtFile(apkFile).getDirectory()

View File

@ -66,13 +66,12 @@ final public class AndrolibResources {
throw new AndrolibException(ex);
}
File out9PatchDir = new File(outDir, "9patch/res");
ExtMXSerializer xmlSerializer = getResXmlSerializer();
for (ResPackage pkg : resTable.listMainPackages()) {
attrDecoder.setCurrentPackage(pkg);
for (ResResource res : pkg.listFiles()) {
ResFileValue fileValue = (ResFileValue) res.getValue();
fileDecoder.decode(in, fileValue.getStrippedPath(),
out, res.getFilePath());
decodeFile(res, in, out, fileDecoder, out9PatchDir);
}
for (ResValuesFile valuesFile : pkg.listValuesFiles()) {
generateValuesFile(valuesFile, out, xmlSerializer);
@ -156,6 +155,31 @@ final public class AndrolibResources {
return serial;
}
private void decodeFile(ResResource res, Directory in, Directory out,
ResFileDecoder fileDecoder, File out9PatchDir)
throws AndrolibException {
ResFileValue fileValue = (ResFileValue) res.getValue();
String inName = fileValue.getStrippedPath();
String outName = res.getFilePath();
fileDecoder.decode(in, inName, out, outName);
if (inName.endsWith(".9.png")) {
File out9PatchFile = new File(
out9PatchDir, outName + ".png");
out9PatchFile.getParentFile().mkdirs();
try {
BrutIO.copyAndClose(in.getFileInput(inName),
new FileOutputStream(out9PatchFile));
} catch (IOException ex) {
throw new AndrolibException(ex);
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
}
private void generateValuesFile(ResValuesFile valuesFile, Directory out,
XmlSerializer serial) throws AndrolibException {
try {