From 8b08f66ae3d79787a124348530b6387eec24601c Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Fri, 1 Apr 2016 18:39:15 -0400 Subject: [PATCH] redraw whenever content changes --- .../android/library/TriangleLabelView.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/src/main/java/jp/shts/android/library/TriangleLabelView.java b/library/src/main/java/jp/shts/android/library/TriangleLabelView.java index cdfe7e1..b31fef5 100644 --- a/library/src/main/java/jp/shts/android/library/TriangleLabelView.java +++ b/library/src/main/java/jp/shts/android/library/TriangleLabelView.java @@ -165,6 +165,7 @@ public float getLabelTopPadding() { public void setLabelCenterPadding(float dp) { centerPadding = dp2px(dp); + relayout(); } public float getLabelCenterPadding() { @@ -173,6 +174,7 @@ public float getLabelCenterPadding() { public void setLabelBottomPadding(float dp) { bottomPadding = dp2px(dp); + relayout(); } public float getLabelBottomPadding() { @@ -182,11 +184,13 @@ public float getLabelBottomPadding() { public void setPrimaryText(String text) { primary.text = text; primary.resetStatus(); + relayout(); } public void setPrimaryText(@StringRes int textRes) { primary.text = getContext().getString(textRes); primary.resetStatus(); + relayout(); } public String getPrimaryText() { @@ -196,11 +200,13 @@ public String getPrimaryText() { public void setSecondaryText(String smallText) { secondary.text = smallText; secondary.resetStatus(); + relayout(); } public void setSecondaryText(@StringRes int textRes) { secondary.text = getContext().getString(textRes); secondary.resetStatus(); + relayout(); } public String getSecondaryText() { @@ -211,32 +217,38 @@ public void setPrimaryTextColor(@ColorInt int color) { primary.color = color; primary.initPaint(); primary.resetStatus(); + relayout(); } public void setPrimaryTextColorResource(@ColorRes int colorResource) { primary.color = ContextCompat.getColor(getContext(), colorResource); primary.initPaint(); primary.resetStatus(); + relayout(); } public void setSecondaryTextColor(@ColorInt int color) { secondary.color = color; secondary.initPaint(); secondary.resetStatus(); + relayout(); } public void setSecondaryTextColorResource(@ColorRes int colorResource) { secondary.color = ContextCompat.getColor(getContext(), colorResource); secondary.initPaint(); secondary.resetStatus(); + relayout(); } public void setPrimaryTextSize(float sp) { primary.size = sp2px(sp); + relayout(); } public void setSecondaryTextSize(float sp) { secondary.size = sp2px(sp); + relayout(); } public float getPrimaryTextSize() { @@ -250,11 +262,13 @@ public float getSecondaryTextSize() { public void setTriangleBackgroundColor(@ColorInt int color) { backGroundColor = color; trianglePaint.setColor(backGroundColor); + relayout(); } public void setTriangleBackgroundColorResource(@ColorRes int colorResource) { backGroundColor = ContextCompat.getColor(getContext(), colorResource); trianglePaint.setColor(backGroundColor); + relayout(); } public int getTriangleBackGroundColor() { @@ -263,6 +277,7 @@ public int getTriangleBackGroundColor() { public void setCorner(Corner corner) { this.corner = corner; + relayout(); } public Corner getCorner() { @@ -339,4 +354,11 @@ public float sp2px(float spValue) { return spValue * scale; } + /** + * Should be called whenever what we're displaying could have changed. + */ + private void relayout() { + invalidate(); + requestLayout(); + } } \ No newline at end of file