diff --git a/speedviewlib/build.gradle b/speedviewlib/build.gradle index 19101ed..7882b74 100644 --- a/speedviewlib/build.gradle +++ b/speedviewlib/build.gradle @@ -56,7 +56,7 @@ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) group = 'com.github.anastr' -version = '1.4.1' +version = '1.5.0' bintray { user = properties.getProperty("bintray.user") diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/AwesomeSpeedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/AwesomeSpeedometer.kt index 399f7e3..70aa3e9 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/AwesomeSpeedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/AwesomeSpeedometer.kt @@ -9,7 +9,7 @@ import com.github.anastr.speedviewlib.components.indicators.TriangleIndicator * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class AwesomeSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class AwesomeSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val markPath = Path() private val trianglesPath = Path() diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/DeluxeSpeedView.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/DeluxeSpeedView.kt index 9ade19a..f626f87 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/DeluxeSpeedView.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/DeluxeSpeedView.kt @@ -11,7 +11,7 @@ import com.github.anastr.speedviewlib.components.indicators.NormalSmallIndicator * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val markPath = Path() private val smallMarkPath = Path() @@ -51,8 +51,7 @@ class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: Attribu } /** - * change the color of the center circle (if exist), - * **this option is not available for all Speedometers**. + * change the color of the center circle. */ var centerCircleColor: Int get() = circlePaint.color @@ -62,6 +61,16 @@ class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: Attribu invalidate() } + /** + * change the width of the center circle. + */ + var centerCircleRadius = dpTOpx(20f) + set(centerCircleRadius) { + field = centerCircleRadius + if (isAttachedToWindow) + invalidate() + } + init { init() initAttributeSet(context, attrs) @@ -102,6 +111,7 @@ class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: Attribu speedBackgroundPaint.color = a.getColor(R.styleable.DeluxeSpeedView_sv_speedBackgroundColor, speedBackgroundPaint.color) withEffects = a.getBoolean(R.styleable.DeluxeSpeedView_sv_withEffects, withEffects) circlePaint.color = a.getColor(R.styleable.DeluxeSpeedView_sv_centerCircleColor, circlePaint.color) + centerCircleRadius = a.getDimension(R.styleable.SpeedView_sv_centerCircleRadius, centerCircleRadius) a.recycle() isWithEffects = withEffects initAttributeValue() @@ -132,7 +142,7 @@ class DeluxeSpeedView @JvmOverloads constructor(context: Context, attrs: Attribu drawSpeedUnitText(canvas) drawIndicator(canvas) - canvas.drawCircle(size * .5f, size * .5f, widthPa / 12f, circlePaint) + canvas.drawCircle(size * .5f, size * .5f, centerCircleRadius, circlePaint) drawNotes(canvas) } diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Gauge.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Gauge.kt index ff00713..429e1f6 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Gauge.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Gauge.kt @@ -498,14 +498,9 @@ abstract class Gauge constructor(context: Context, attrs: AttributeSet? = null, protected fun getSpeedText() = "%.${speedTextFormat}f".format(locale, currentSpeed) /** - * get Max speed as string to **Draw**. + * get tick as string to **Draw**. */ - protected fun getMaxSpeedText() = "%.${tickTextFormat}f".format(locale, maxSpeed) - - /** - * get Min speed as string to **Draw**. - */ - protected fun getMinSpeedText() = "%.${tickTextFormat}f".format(locale, minSpeed) + protected fun getTickText(tick: Float) = "%.${tickTextFormat}f".format(locale, tick) /** * get current speed as **percent**. diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageLinearGauge.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageLinearGauge.kt index 3662159..e135e75 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageLinearGauge.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageLinearGauge.kt @@ -9,7 +9,7 @@ import android.util.AttributeSet * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class ImageLinearGauge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearGauge(context, attrs, defStyleAttr) { +open class ImageLinearGauge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearGauge(context, attrs, defStyleAttr) { private var image: Drawable? = null diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageSpeedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageSpeedometer.kt index ab94d2a..a0ee72e 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageSpeedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ImageSpeedometer.kt @@ -12,50 +12,10 @@ import android.util.AttributeSet * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class ImageSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class ImageSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private var imageSpeedometer: Drawable? = null -// /** -// * this Speedometer doesn't use this method. -// * @param typeface nothing. -// */ -// override var textTypeface: Typeface? -// get() = super.textTypeface -// @Deprecated("") -// set(typeface) { -// } -// -// /** -// * this Speedometer doesn't use this method. -// * @return `0` always. -// */ -// /** -// * this Speedometer doesn't use this method. -// * @param textSize nothing. -// */ -// override var textSize: Float -// @Deprecated("") -// get() = 0f -// @Deprecated("") -// set(textSize) { -// } -// -// /** -// * this Speedometer doesn't use this method. -// * @return `0` always. -// */ -// /** -// * this Speedometer doesn't use this method. -// * @param textColor nothing. -// */ -// override var textColor: Int -// @Deprecated("") -// get() = 0 -// @Deprecated("") -// set(textColor) { -// } - init { initAttributeSet(context, attrs) } diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/PointerSpeedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/PointerSpeedometer.kt index 4afd4aa..98ad0b3 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/PointerSpeedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/PointerSpeedometer.kt @@ -9,7 +9,7 @@ import com.github.anastr.speedviewlib.components.indicators.SpindleIndicator * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val markPath = Path() private val speedometerPaint = Paint(Paint.ANTI_ALIAS_FLAG) @@ -25,8 +25,7 @@ class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: Attr private var withPointer = true /** - * change the color of the center circle (if exist), - * **this option is not available for all Speedometers**. + * change the color of the center circle. */ var centerCircleColor: Int get() = circlePaint.color @@ -36,6 +35,16 @@ class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: Attr invalidate() } + /** + * change the width of the center circle. + */ + var centerCircleRadius = dpTOpx(12f) + set(centerCircleRadius) { + field = centerCircleRadius + if (isAttachedToWindow) + invalidate() + } + /** * enable to draw circle pointer on speedometer arc. * @@ -95,6 +104,7 @@ class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: Attr speedometerColor = a.getColor(R.styleable.PointerSpeedometer_sv_speedometerColor, speedometerColor) pointerColor = a.getColor(R.styleable.PointerSpeedometer_sv_pointerColor, pointerColor) circlePaint.color = a.getColor(R.styleable.PointerSpeedometer_sv_centerCircleColor, circlePaint.color) + centerCircleRadius = a.getDimension(R.styleable.SpeedView_sv_centerCircleRadius, centerCircleRadius) withPointer = a.getBoolean(R.styleable.PointerSpeedometer_sv_withPointer, withPointer) a.recycle() initAttributeValue() @@ -140,9 +150,9 @@ class PointerSpeedometer @JvmOverloads constructor(context: Context, attrs: Attr val c = centerCircleColor circlePaint.color = Color.argb((Color.alpha(c) * .5f).toInt(), Color.red(c), Color.green(c), Color.blue(c)) - canvas.drawCircle(size * .5f, size * .5f, widthPa / 14f, circlePaint) + canvas.drawCircle(size * .5f, size * .5f, centerCircleRadius + dpTOpx(6f), circlePaint) circlePaint.color = c - canvas.drawCircle(size * .5f, size * .5f, widthPa / 22f, circlePaint) + canvas.drawCircle(size * .5f, size * .5f, centerCircleRadius, circlePaint) drawNotes(canvas) } diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ProgressiveGauge.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ProgressiveGauge.kt index 8f287bd..382c8c2 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ProgressiveGauge.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/ProgressiveGauge.kt @@ -9,7 +9,7 @@ import android.util.AttributeSet * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class ProgressiveGauge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearGauge(context, attrs, defStyleAttr) { +open class ProgressiveGauge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearGauge(context, attrs, defStyleAttr) { /** the shape */ private val path = Path() diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/RaySpeedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/RaySpeedometer.kt index 9e3db4b..81bec8a 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/RaySpeedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/RaySpeedometer.kt @@ -13,7 +13,7 @@ import com.github.anastr.speedviewlib.components.indicators.Indicator * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class RaySpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class RaySpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val markPath = Path() private val ray1Path = Path() diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/SpeedView.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/SpeedView.kt index 9a3fee0..c712553 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/SpeedView.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/SpeedView.kt @@ -12,7 +12,7 @@ import com.github.anastr.speedviewlib.components.indicators.NormalIndicator * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val markPath = Path() private val circlePaint = Paint(Paint.ANTI_ALIAS_FLAG) @@ -21,8 +21,7 @@ class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? private val speedometerRect = RectF() /** - * change the color of the center circle (if exist), - * **this option is not available for all Speedometers**. + * change the color of the center circle. */ var centerCircleColor: Int get() = circlePaint.color @@ -32,6 +31,16 @@ class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? invalidate() } + /** + * change the width of the center circle. + */ + var centerCircleRadius = dpTOpx(20f) + set(centerCircleRadius) { + field = centerCircleRadius + if (isAttachedToWindow) + invalidate() + } + init { init() initAttributeSet(context, attrs) @@ -57,6 +66,7 @@ class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? val a = context.theme.obtainStyledAttributes(attrs, R.styleable.SpeedView, 0, 0) circlePaint.color = a.getColor(R.styleable.SpeedView_sv_centerCircleColor, circlePaint.color) + centerCircleRadius = a.getDimension(R.styleable.SpeedView_sv_centerCircleRadius, centerCircleRadius) a.recycle() } @@ -77,7 +87,7 @@ class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? drawSpeedUnitText(canvas) drawIndicator(canvas) - canvas.drawCircle(size * .5f, size * .5f, widthPa / 12f, circlePaint) + canvas.drawCircle(size * .5f, size * .5f, centerCircleRadius, circlePaint) drawNotes(canvas) } diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Speedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Speedometer.kt index d859fff..f2e928b 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Speedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/Speedometer.kt @@ -580,10 +580,16 @@ abstract class Speedometer @JvmOverloads constructor(context: Context, attrs: At startDegree % 360 <= 270 -> Paint.Align.CENTER else -> Paint.Align.RIGHT } + var tickStart: CharSequence? = null + if (onPrintTickLabel != null) + tickStart = onPrintTickLabel!!.getTickLabel(0, getMinSpeed()) + + if (tickStart == null) + tickStart = getTickText(getMinSpeed()) c.save() c.rotate(startDegree + 90f, size * .5f, size * .5f) c.rotate(-(startDegree + 90f), sizePa * .5f - textPaint.textSize + padding, textPaint.textSize + padding) - c.drawText(getMinSpeedText(), sizePa * .5f - textPaint.textSize + padding, textPaint.textSize + padding, textPaint) + c.drawText(tickStart.toString(), sizePa * .5f - textPaint.textSize + padding, textPaint.textSize + padding, textPaint) c.restore() textPaint.textAlign = when { endDegree % 360 <= 90 -> Paint.Align.RIGHT @@ -591,10 +597,16 @@ abstract class Speedometer @JvmOverloads constructor(context: Context, attrs: At endDegree % 360 <= 270 -> Paint.Align.CENTER else -> Paint.Align.RIGHT } + var tickEnd: CharSequence? = null + if (onPrintTickLabel != null) + tickEnd = onPrintTickLabel!!.getTickLabel(1, getMaxSpeed()) + + if (tickEnd == null) + tickEnd = getTickText(getMaxSpeed()) c.save() c.rotate(endDegree + 90f, size * .5f, size * .5f) c.rotate(-(endDegree + 90f), sizePa * .5f + textPaint.textSize + padding.toFloat(), textPaint.textSize + padding) - c.drawText(getMaxSpeedText(), sizePa * .5f + textPaint.textSize + padding.toFloat(), textPaint.textSize + padding, textPaint) + c.drawText(tickEnd.toString(), sizePa * .5f + textPaint.textSize + padding.toFloat(), textPaint.textSize + padding, textPaint) c.restore() } @@ -620,13 +632,10 @@ abstract class Speedometer @JvmOverloads constructor(context: Context, attrs: At tick = onPrintTickLabel!!.getTickLabel(i, ticks[i]) if (tick == null) - tick = if (tickTextFormat == FLOAT_FORMAT.toInt()) - "%.1f".format(locale, ticks[i]) - else - "%d".format(locale, ticks[i].toInt()) + tick = getTickText(ticks[i]) c.translate(0f, initTickPadding + padding.toFloat() + tickPadding.toFloat()) - StaticLayout(tick, textPaint, size, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false) + StaticLayout(tick, textPaint, size, Layout.Alignment.ALIGN_CENTER, 1f, 0f, false) .draw(c) c.restore() diff --git a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/TubeSpeedometer.kt b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/TubeSpeedometer.kt index d609d20..17201fd 100644 --- a/speedviewlib/src/main/java/com/github/anastr/speedviewlib/TubeSpeedometer.kt +++ b/speedviewlib/src/main/java/com/github/anastr/speedviewlib/TubeSpeedometer.kt @@ -11,7 +11,7 @@ import android.util.AttributeSet * this Library build By Anas Altair * see it on [GitHub](https://github.com/anastr/SpeedView) */ -class TubeSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { +open class TubeSpeedometer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : Speedometer(context, attrs, defStyleAttr) { private val tubePaint = Paint(Paint.ANTI_ALIAS_FLAG) private val tubeBacPaint = Paint(Paint.ANTI_ALIAS_FLAG) diff --git a/speedviewlib/src/main/res/values/attrs.xml b/speedviewlib/src/main/res/values/attrs.xml index c4669f5..d442029 100644 --- a/speedviewlib/src/main/res/values/attrs.xml +++ b/speedviewlib/src/main/res/values/attrs.xml @@ -4,6 +4,7 @@ + @@ -110,10 +111,12 @@ + + @@ -133,6 +136,7 @@ +