LayoutLib: Fix dimension parsing to handle negative value.

Also make TypedArray.getDimensionPixelSize properly
handle negative values (which are not allowed).

Change-Id: I960fc1c9e8ad97852d4a14e4f0f71a2c2034b4e7
This commit is contained in:
Xavier Ducrohet
2011-03-07 20:50:21 -08:00
parent c12b409351
commit 6f2fb57064
2 changed files with 10 additions and 14 deletions

View File

@@ -412,9 +412,7 @@ public final class BridgeTypedArray extends TypedArray {
return LayoutParams.MATCH_PARENT;
} else if (s.equals(BridgeConstants.WRAP_CONTENT)) {
return LayoutParams.WRAP_CONTENT;
}
if (RenderResources.REFERENCE_NULL.equals(s)) {
} else if (RenderResources.REFERENCE_NULL.equals(s)) {
return defValue;
}
@@ -486,23 +484,21 @@ public final class BridgeTypedArray extends TypedArray {
return LayoutParams.MATCH_PARENT;
} else if (s.equals(BridgeConstants.WRAP_CONTENT)) {
return LayoutParams.WRAP_CONTENT;
}
if (RenderResources.REFERENCE_NULL.equals(s)) {
} else if (RenderResources.REFERENCE_NULL.equals(s)) {
return defValue;
}
// FIXME huh?
float f = getDimension(index, defValue);
final int res = (int)(f+0.5f);
if (res != 0) return res;
if (f == 0) return 0;
if (f > 0) return 1;
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT,
"Can't convert to dimension: " + Integer.toString(index),
null, null /*data*/);
if (f > 0) return 1; // this is to support ]0;1[ range (since >=1 is handled 2 lines above)
if (f < 0) {
// negative values are not allowed in pixel dimensions
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
"Negative pixel dimension: " + s,
null, null /*data*/);
}
return defValue;
}

View File

@@ -377,7 +377,7 @@ public final class ResourceHelper {
}
// check the first character
if (buf[0] < '0' && buf[0] > '9' && buf[0] != '.') {
if (buf[0] < '0' && buf[0] > '9' && buf[0] != '.' && buf[0] != '-') {
return false;
}