From d35120da357b2ae7f323fbde330375c91d177678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Sat, 27 Mar 2010 21:09:16 +0100 Subject: [PATCH] Added automatic 9-patch workaround. --- src/brut/androlib/Androlib.java | 6 +++- src/brut/androlib/res/AndrolibResources.java | 30 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/brut/androlib/Androlib.java b/src/brut/androlib/Androlib.java index 574fadcf..07181536 100644 --- a/src/brut/androlib/Androlib.java +++ b/src/brut/androlib/Androlib.java @@ -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() diff --git a/src/brut/androlib/res/AndrolibResources.java b/src/brut/androlib/res/AndrolibResources.java index d1a0a57d..102f1147 100644 --- a/src/brut/androlib/res/AndrolibResources.java +++ b/src/brut/androlib/res/AndrolibResources.java @@ -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 {