From de52fcba8c55d7afa2e16f9667f09d29164f59b4 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Fri, 8 Jun 2012 12:28:33 -0500 Subject: [PATCH] Added 9patch fix from Charles, worked on com.htc.resources.apk bugs --- .../androlib/res/data/ResConfigFlags.java | 23 +++++++------- .../res/decoder/Res9patchStreamDecoder.java | 30 +++++++++++++++---- .../test/java/brut/androlib/TestUtils.java | 2 +- .../brut/apktool/testapp/apktool.yml | 2 +- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/ResConfigFlags.java b/apktool-lib/src/main/java/brut/androlib/res/data/ResConfigFlags.java index fa404dae..19160524 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/ResConfigFlags.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/ResConfigFlags.java @@ -16,7 +16,6 @@ package brut.androlib.res.data; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -83,27 +82,27 @@ public class ResConfigFlags { byte uiMode, short smallestScreenWidthDp, short screenWidthDp, short screenHeightDp, boolean isInvalid) { if (orientation < 0 || orientation > 3) { - LOGGER.log(Level.WARNING, "Invalid orientation value: {0}", orientation); + LOGGER.warning("Invalid orientation value: " + orientation); orientation = 0; isInvalid = true; } if (touchscreen < 0 || touchscreen > 3) { - LOGGER.log(Level.WARNING, "Invalid touchscreen value: {0}", touchscreen); + LOGGER.warning("Invalid touchscreen value: " + touchscreen); touchscreen = 0; isInvalid = true; } if (density < -1) { - LOGGER.log(Level.WARNING, "Invalid density value: {0}", density); + LOGGER.warning("Invalid density value: " + density); density = 0; isInvalid = true; } if (keyboard < 0 || keyboard > 3) { - LOGGER.log(Level.WARNING, "Invalid keyboard value: {0}", keyboard); + LOGGER.warning("Invalid keyboard value: " + keyboard); keyboard = 0; isInvalid = true; } if (navigation < 0 || navigation > 4) { - LOGGER.log(Level.WARNING, "Invalid navigation value: {0}", navigation); + LOGGER.warning("Invalid navigation value: " + navigation); navigation = 0; isInvalid = true; } @@ -197,6 +196,9 @@ public class ResConfigFlags { case UI_MODE_TYPE_DESK: ret.append("-desk"); break; + case UI_MODE_TYPE_TELEVISION: + ret.append("-television"); + break; } switch (uiMode & MASK_UI_MODE_NIGHT) { case UI_MODE_NIGHT_YES: @@ -212,8 +214,8 @@ public class ResConfigFlags { case DENSITY_LOW: ret.append("-ldpi"); break; - case DENSITY_TV: - ret.append("-tvdpi"); + case DENSITY_MEDIUM: + ret.append("-mdpi"); break; case DENSITY_HIGH: ret.append("-hdpi"); @@ -360,12 +362,11 @@ public class ResConfigFlags { public final static byte TOUCHSCREEN_STYLUS = 2; public final static byte TOUCHSCREEN_FINGER = 3; - public final static short DENSITY_DEFAULT = 160; + public final static short DENSITY_DEFAULT = 0; public final static short DENSITY_LOW = 120; public final static short DENSITY_MEDIUM = 160; public final static short DENSITY_HIGH = 240; public final static short DENSITY_XHIGH = 320; - public final static short DENSITY_TV = 213; public final static short DENSITY_NONE = -1; public final static byte KEYBOARD_ANY = 0; @@ -417,4 +418,4 @@ public class ResConfigFlags { private static final Logger LOGGER = Logger.getLogger(ResConfigFlags.class.getName()); -} +} \ No newline at end of file diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java index beff017d..6342fcc2 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java @@ -20,6 +20,8 @@ import brut.androlib.AndrolibException; import brut.androlib.err.CantFind9PatchChunk; import brut.util.ExtDataInput; import java.awt.image.BufferedImage; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; import java.io.*; import javax.imageio.ImageIO; import org.apache.commons.io.IOUtils; @@ -36,15 +38,31 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(), h = im.getHeight(); - BufferedImage im2 = new BufferedImage( - w + 2, h + 2, BufferedImage.TYPE_4BYTE_ABGR); - if (im.getType() == BufferedImage.TYPE_4BYTE_ABGR) { - im2.getRaster().setRect(1, 1, im.getRaster()); + BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_4BYTE_ABGR); + Raster src = im.getRaster(); + + NinePatch np = getNinePatch(data); + WritableRaster dst = im2.getRaster(); + int nbands = im.getSampleModel().getNumBands(); + int[] bands = new int[4]; + if (nbands == 2) { + bands[0] = bands[1] = bands[2] = 0; + bands[3] = 1; } else { - im2.getGraphics().drawImage(im, 1, 1, null); + bands[0] = 0; + bands[1] = 1; + bands[2] = 2; + bands[3] = 3; + } + int[] band = null; + for (int y = 0; y < h; y++) { + for (int bi = 0; bi < 4; bi++) { + band = src.getSamples(0, y, w, 1, bands[bi], band); + dst.setSamples(1, y + 1, w, 1, bi, band); + } } - NinePatch np = getNinePatch(data); + drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); diff --git a/apktool-lib/src/test/java/brut/androlib/TestUtils.java b/apktool-lib/src/test/java/brut/androlib/TestUtils.java index 53d59c87..d6efc275 100644 --- a/apktool-lib/src/test/java/brut/androlib/TestUtils.java +++ b/apktool-lib/src/test/java/brut/androlib/TestUtils.java @@ -1,4 +1,4 @@ -/** + /** * Copyright 2011 Ryszard Wiśniewski * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/apktool-lib/src/test/resources/brut/apktool/testapp/apktool.yml b/apktool-lib/src/test/resources/brut/apktool/testapp/apktool.yml index 555ac244..6e9af5f7 100644 --- a/apktool-lib/src/test/resources/brut/apktool/testapp/apktool.yml +++ b/apktool-lib/src/test/resources/brut/apktool/testapp/apktool.yml @@ -1,4 +1,4 @@ -version: 1.3.2 +version: 1.4.7 apkFileName: testapp.apk isFrameworkApk: false usesFramework: