aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2013-02-28 09:51:31 -0800
committerSiva Velusamy <vsiva@google.com>2013-02-28 09:55:16 -0800
commit6c69b41c2bd49b8a1d403cad5cc9cece7ecfac9f (patch)
tree15c5d505e0515625949cd2fa89d1c66933a0c72a
parent272f2c36f2936b6000423742fd0bbba4f65f64cb (diff)
downloadsdk-6c69b41c2bd49b8a1d403cad5cc9cece7ecfac9f.zip
sdk-6c69b41c2bd49b8a1d403cad5cc9cece7ecfac9f.tar.gz
sdk-6c69b41c2bd49b8a1d403cad5cc9cece7ecfac9f.tar.bz2
Ignore layout bound markers during patch calculation
Change-Id: I0ae90c2867e2599a71ddf11f83352db4868deca2
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java9
-rw-r--r--draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java27
2 files changed, 33 insertions, 3 deletions
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java b/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
index 8b92655..9efcdda 100644
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
+++ b/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
@@ -172,15 +172,20 @@ public class PatchInfo {
private static P getPatches(int[] pixels) {
int lastIndex = 1;
- int lastPixel = pixels[1];
+ int lastPixel;
boolean first = true;
boolean startWithPatch = false;
List<Pair<Integer>> fixed = new ArrayList<Pair<Integer>>();
List<Pair<Integer>> patches = new ArrayList<Pair<Integer>>();
+ // ignore layout bound markers for the purpose of patch calculation
+ lastPixel = pixels[1] != PatchInfo.RED_TICK ? pixels[1] : 0;
+
for (int i = 1; i < pixels.length - 1; i++) {
- int pixel = pixels[i];
+ // ignore layout bound markers for the purpose of patch calculation
+ int pixel = pixels[i] != PatchInfo.RED_TICK ? pixels[i] : 0;
+
if (pixel != lastPixel) {
if (lastPixel == BLACK_TICK) {
if (first) startWithPatch = true;
diff --git a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java b/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
index 7ca4fdd..7350b82 100644
--- a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
+++ b/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
@@ -32,7 +32,13 @@ public class PatchInfoTest extends TestCase {
for (int row = 0; row < h; row++) {
for (int col = 0; col < w; col++) {
char c = data[row].charAt(col);
- image.setRGB(col, row, c == '*' ? PatchInfo.BLACK_TICK : 0);
+ int color = 0;
+ if (c == '*') {
+ color = PatchInfo.BLACK_TICK;
+ } else if (c == 'R') {
+ color = PatchInfo.RED_TICK;
+ }
+ image.setRGB(col, row, color);
}
}
return image;
@@ -101,4 +107,23 @@ public class PatchInfoTest extends TestCase {
assertEquals(2, pi.verticalPadding.first.intValue());
assertEquals(0, pi.verticalPadding.second.intValue());
}
+
+ // make sure that the presence of layout bound markers doesn't affect patch/padding info
+ public void testIgnoreLayoutBoundMarkers() {
+ BufferedImage image = createImage(new String[] {
+ "0RR3**6789",
+ "R........R",
+ "*.........",
+ "*........*",
+ "4........*",
+ "5***456R89",
+ });
+ PatchInfo pi = new PatchInfo(image);
+
+ assertFalse(pi.horizontalStartWithPatch);
+
+ assertEquals(1, pi.patches.size());
+ assertEquals(2, pi.verticalPatches.size());
+ assertEquals(2, pi.horizontalPatches.size());
+ }
}