From 9c0833084374cd3d03e4c800a06d9e56b5233aea Mon Sep 17 00:00:00 2001 From: paroca72 Date: Fri, 31 May 2019 22:09:08 +0700 Subject: [PATCH] Changed labeler starting position --- app/app.iml | 1 + .../com/sccomponents/demo/MainActivity.java | 10 +++-- .../sccomponents/gauges/library/ScWriter.java | 38 +++++++++++++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/app.iml b/app/app.iml index 994ba14..dd56b0c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -149,5 +149,6 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/sccomponents/demo/MainActivity.java b/app/src/main/java/com/sccomponents/demo/MainActivity.java index 5d66bdb..21cdedf 100644 --- a/app/src/main/java/com/sccomponents/demo/MainActivity.java +++ b/app/src/main/java/com/sccomponents/demo/MainActivity.java @@ -39,10 +39,10 @@ protected void onCreate(Bundle savedInstanceState) { ScCopier base = gauge.getBase(); base.setColors(Color.parseColor("#ff0000")); - base.setWidths(60); + base.setWidths(100); ScCopier progress = gauge.getProgress(); - progress.setWidths(60); + progress.setWidths(100); progress.setColors(Color.parseColor("#00ff00")); ScNotches notches = gauge.getNotches(); @@ -55,8 +55,9 @@ protected void onCreate(Bundle savedInstanceState) { ScLabeler labeler = gauge.getLabeler(); labeler.setVisible(true); - //labeler.setBending(true); - labeler.setBackground(Color.parseColor("#ffff00")); + labeler.setBending(true); + labeler.setLetterSpacing(0.3f); + //labeler.setBackground(Color.parseColor("#ffff00")); labeler.getPainter().setTextSize(60); labeler.getPainter().setTextAlign(Paint.Align.RIGHT); labeler.setPosition(ScFeature.Positions.MIDDLE); @@ -64,6 +65,7 @@ protected void onCreate(Bundle savedInstanceState) { gauge.setAngleStart(0); gauge.setAngleSweep(270); gauge.setHighValue(10); + //gauge.setPadding(30, 30, 30, 30); } } diff --git a/library/src/main/java/com/sccomponents/gauges/library/ScWriter.java b/library/src/main/java/com/sccomponents/gauges/library/ScWriter.java index 9e33305..5192a02 100644 --- a/library/src/main/java/com/sccomponents/gauges/library/ScWriter.java +++ b/library/src/main/java/com/sccomponents/gauges/library/ScWriter.java @@ -30,6 +30,7 @@ public class ScWriter extends ScRepetitions { private int mBackground; private int mPadding; private float mInterline; + private float mLetterSpacing; private float[] mFirstPoint; private float[] mGenericPoint; @@ -55,6 +56,7 @@ public ScWriter() { this.mBackground = Color.TRANSPARENT; this.mPadding = 0; this.mInterline = 1.0f; + this.mLetterSpacing = 0.3f; this.mRepetitionInfo = new TokenInfo(); this.mFirstPoint = new float[2]; @@ -202,8 +204,8 @@ private int getTextWidth(String text) { * Passed the font size calculate the letters spacing * @return the letter spacing */ - private float getLetterSpacing() { - float letterSpacing = this.getPainter().getTextSize() / 3.0f; + private float getInternalLetterSpacing() { + float letterSpacing = this.getPainter().getTextSize() * this.mLetterSpacing; return letterSpacing < 1.0f ? 1.0f: letterSpacing; } @@ -224,7 +226,7 @@ private float getHorizontalOffset(String text) { // Correct for bending float width = this.getTextWidth(text); if (this.getBending() && text.length() > 1) - width += this.getLetterSpacing() * (text.length() - 2); + width += this.getInternalLetterSpacing() * (text.length() - 2); // Calculate the start position considering the painter text align switch (align) { @@ -299,7 +301,7 @@ private void drawTextOnPath(Canvas canvas, String token, float distance, // Holders float currentPos = distance; int textHeight = this.getTextBounds(token, 0, token.length()).height(); - float letterSpacing = this.getLetterSpacing(); + float letterSpacing = this.getInternalLetterSpacing(); // Get the last point info of the whole path float pathLength = this.getMeasure().getLength(); @@ -679,6 +681,34 @@ public void setInterline(float value) { } + /** + * Return the spacing value between the text letters. + * The value is expressed in ratio respect the font size. + * Note that this setting have effect only when bending is true. + * The default value is 0.3 + * @return the spacing value + */ + @SuppressWarnings("unused") + public float getLetterSpacing() { + return this.mLetterSpacing; + } + + /** + * Set the spacing value between the text letters. + * The value is expressed in ratio respect the font size. + * Note that this setting have effect only when bending is true. + * The default value is 0.3 + * @param value the spacing value + */ + @SuppressWarnings("unused") + public void setLetterSpacing(float value) { + if (this.mLetterSpacing != value) { + this.mLetterSpacing = value; + this.onPropertyChange("letterSpacing", value); + } + } + + // *************************************************************************************** // Public classes and methods