mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #32 from NativeScript/optimization
Small optimisation.
This commit is contained in:
@@ -21,6 +21,17 @@ public class BorderDrawable extends ColorDrawable {
|
||||
private float density;
|
||||
private float borderWidth;
|
||||
private int borderColor;
|
||||
private float borderRadius;
|
||||
private String clipPath;
|
||||
private int backgroundColor;
|
||||
private Bitmap backgroundImage;
|
||||
private float backgroundImageWidth;
|
||||
private float backgroundImageHeight;
|
||||
private String backgroundRepeat;
|
||||
private String backgroundPosition;
|
||||
private CSSValue[] backgroundPositionParsedCSSValues;
|
||||
private String backgroundSize;
|
||||
private CSSValue[] backgroundSizeParsedCSSValues;
|
||||
|
||||
public float getBorderWidth() {
|
||||
return borderWidth;
|
||||
@@ -66,18 +77,6 @@ public class BorderDrawable extends ColorDrawable {
|
||||
return backgroundSize;
|
||||
}
|
||||
|
||||
private float borderRadius;
|
||||
private String clipPath;
|
||||
private int backgroundColor;
|
||||
private Bitmap backgroundImage;
|
||||
private float backgroundImageWidth;
|
||||
private float backgroundImageHeight;
|
||||
private String backgroundRepeat;
|
||||
private String backgroundPosition;
|
||||
private CSSValue[] backgroundPositionParsedCSSValues;
|
||||
private String backgroundSize;
|
||||
private CSSValue[] backgroundSizeParsedCSSValues;
|
||||
|
||||
public BorderDrawable(float density){
|
||||
super();
|
||||
this.density = density;
|
||||
@@ -96,74 +95,21 @@ public class BorderDrawable extends ColorDrawable {
|
||||
CSSValue[] backgroundPositionParsedCSSValues,
|
||||
String backgroundSize,
|
||||
CSSValue[] backgroundSizeParsedCSSValues){
|
||||
boolean dirty = false;
|
||||
|
||||
if (this.borderWidth != borderWidth){
|
||||
this.borderWidth = borderWidth;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.borderColor != borderColor){
|
||||
this.borderColor = borderColor;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.borderRadius != borderRadius){
|
||||
this.borderRadius = borderRadius;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
|
||||
if (!compare(this.clipPath, clipPath)){
|
||||
this.clipPath = clipPath;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.backgroundColor != backgroundColor){
|
||||
this.backgroundColor = backgroundColor;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.backgroundImage != backgroundImage){
|
||||
this.backgroundImage = backgroundImage;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.backgroundImageWidth != backgroundImageWidth){
|
||||
this.backgroundImageWidth = backgroundImageWidth;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (this.backgroundImageHeight != backgroundImageHeight){
|
||||
this.backgroundImageHeight = backgroundImageHeight;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (!compare(this.backgroundRepeat, backgroundRepeat)){
|
||||
this.backgroundRepeat = backgroundRepeat;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (!compare(this.backgroundPosition, backgroundPosition)){
|
||||
this.backgroundPosition = backgroundPosition;
|
||||
this.backgroundPositionParsedCSSValues = backgroundPositionParsedCSSValues;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (!compare(this.backgroundSize, backgroundSize)){
|
||||
this.backgroundSize = backgroundSize;
|
||||
this.backgroundSizeParsedCSSValues = backgroundSizeParsedCSSValues;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (dirty){
|
||||
this.invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean compare(String str1, String str2) {
|
||||
return (str1 == null ? str2 == null : str1.equals(str2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
@@ -281,6 +227,7 @@ public class BorderDrawable extends ColorDrawable {
|
||||
}
|
||||
|
||||
private static void drawClipPath(String clipPath, Canvas canvas, Paint paint, RectF bounds, float density) {
|
||||
// Sample string is polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
|
||||
String functionName = clipPath.substring(0, clipPath.indexOf("("));
|
||||
String value = clipPath.replace(functionName+"(", "").replace(")", "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user