Merge pull request #67 from NativeScript/issue-65

Fix: java.lang.NumberFormatException when applying clip-path with per…
This commit is contained in:
Rossen Hristov
2016-11-02 17:04:55 +02:00
committed by GitHub

View File

@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
*/ */
public class BorderDrawable extends ColorDrawable { public class BorderDrawable extends ColorDrawable {
private float density; private float density;
private String id;
private int borderTopColor; private int borderTopColor;
private int borderRightColor; private int borderRightColor;
@@ -177,6 +178,12 @@ public class BorderDrawable extends ColorDrawable {
this.density = density; this.density = density;
} }
public BorderDrawable(float density, String id){
super();
this.density = density;
this.id = id;
}
// For backwards compatibility // For backwards compatibility
public void refresh(float borderWidth, public void refresh(float borderWidth,
int borderColor, int borderColor,
@@ -273,6 +280,10 @@ public class BorderDrawable extends ColorDrawable {
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
Rect bounds = this.getBounds(); Rect bounds = this.getBounds();
if (bounds.width() <= 0 || bounds.height() <= 0) {
// When the view is off-screen the bounds might be empty and we don't have anything to draw.
return;
}
float topBackoffAntialias = calculateBackoffAntialias(this.borderTopColor, this.borderTopWidth, this.density); float topBackoffAntialias = calculateBackoffAntialias(this.borderTopColor, this.borderTopWidth, this.density);
float rightBackoffAntialias = calculateBackoffAntialias(this.borderRightColor, this.borderRightWidth, this.density); float rightBackoffAntialias = calculateBackoffAntialias(this.borderRightColor, this.borderRightWidth, this.density);
@@ -689,7 +700,7 @@ public class BorderDrawable extends ColorDrawable {
if (source.contains("px")) { if (source.contains("px")) {
result = Float.parseFloat(source.replace("px", "")); result = Float.parseFloat(source.replace("px", ""));
} }
else if (source.contains("%") && total > 0) { else if (source.contains("%")) {
result = (Float.parseFloat(source.replace("%", "")) / 100) * (total / density); result = (Float.parseFloat(source.replace("%", "")) / 100) * (total / density);
} else { } else {
result = Float.parseFloat(source); result = Float.parseFloat(source);
@@ -697,6 +708,36 @@ public class BorderDrawable extends ColorDrawable {
return result * density; return result * density;
} }
public String toDebugString() {
return
getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + "; " +
"id: " + this.id + "; " +
"borderTopColor: " + this.borderTopColor + "; " +
"borderRightColor: " + this.borderRightColor + "; " +
"borderBottomColor: " + this.borderBottomColor + "; " +
"borderLeftColor: " + this.borderLeftColor + "; " +
"borderTopWidth: " + this.borderTopWidth + "; " +
"borderRightWidth: " + this.borderRightWidth + "; " +
"borderBottomWidth: " + this.borderBottomWidth + "; " +
"borderLeftWidth: " + this.borderLeftWidth + "; " +
"borderTopLeftRadius: " + this.borderTopLeftRadius + "; " +
"borderTopRightRadius: " + this.borderTopRightRadius + "; " +
"borderBottomRightRadius: " + this.borderBottomRightRadius + "; " +
"borderBottomLeftRadius: " + this.borderBottomLeftRadius + "; " +
"clipPath: " + this.clipPath + "; " +
"backgroundColor: " + this.backgroundColor + "; " +
"backgroundImage: " + this.backgroundImage + "; " +
"backgroundRepeat: " + this.backgroundRepeat + "; " +
"backgroundPosition: " + this.backgroundPosition + "; " +
"backgroundSize: " + this.backgroundSize + "; "
;
}
private class BackgroundDrawParams { private class BackgroundDrawParams {
private boolean repeatX = true; private boolean repeatX = true;
private boolean repeatY = true; private boolean repeatY = true;