LayoutLib: fix Capabilities and getDimensionPixelSize

Commented out a Capability that is not in ADT 10.

BridgeTypedArray.getDimensionPixelSize shouldn't call
getDimension since most of the code is duplicated, and
it prevents use from properly detecting malformed attribute
values.

Change-Id: I005b17061590dc0668729af16e896fad815f1973
This commit is contained in:
Xavier Ducrohet
2011-03-08 11:50:21 -08:00
parent 6f2fb57064
commit adaa12cd9e
3 changed files with 23 additions and 12 deletions

View File

@@ -393,7 +393,7 @@ public final class Path_Delegate {
for (int i = 0 ; i < 3 ; i++) {
if (radii[i * 2] != radii[(i + 1) * 2] || radii[i * 2 + 1] != radii[(i + 1) * 2 + 1]) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
"Different corner size is not support in Path.addRoundRect.",
"Different corner sizes are not supported in Path.addRoundRect.",
null, null /*data*/);
break;
}

View File

@@ -192,7 +192,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
Capability.UNBOUND_RENDERING,
Capability.CUSTOM_BACKGROUND_COLOR,
Capability.RENDER,
Capability.LAYOUT_ONLY,
//Capability.LAYOUT_ONLY, // disable to run on ADT 10.0 which doesn't include this.
Capability.EMBEDDED_LAYOUT,
Capability.VIEW_MANIPULATION,
Capability.PLAY_ANIMATION,

View File

@@ -488,18 +488,29 @@ public final class BridgeTypedArray extends TypedArray {
return defValue;
}
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; // 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*/);
if (ResourceHelper.stringToFloat(s, mValue)) {
float f = mValue.getDimension(mBridgeResources.mMetrics);
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;
}
if (f == 0) return 0;
if (f < 1) return 1;
return (int)(f+0.5f);
}
// looks like we were unable to resolve the dimension value
Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
String.format(
"\"%1$s\" in attribute \"%2$s\" is not a valid format.",
s, mNames[index]), null /*data*/);
return defValue;
}