Skip to content

Commit

Permalink
all speedometers are open, add sv_centerCircleRadius attribute, defau…
Browse files Browse the repository at this point in the history
…lt tick in custom now.

Signed-off-by: Anas Altair <[email protected]>
  • Loading branch information
anastr committed Dec 28, 2019
1 parent b643b94 commit 0cb4e01
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 74 deletions.
2 changes: 1 addition & 1 deletion speedviewlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
}

Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,21 +580,33 @@ 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
endDegree % 360 <= 180 -> Paint.Align.LEFT
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()
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions speedviewlib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<attr name="sv_speedometerColor" format="color"/>
<attr name="sv_speedometerBackColor" format="color"/>
<attr name="sv_centerCircleColor" format="color" />
<attr name="sv_centerCircleRadius" format="dimension" />

<attr name="sv_speedBackgroundColor" format="color" />
<attr name="sv_withEffects" format="boolean" />
Expand Down Expand Up @@ -110,10 +111,12 @@

<declare-styleable name="SpeedView" parent="Speedometer">
<attr name="sv_centerCircleColor" />
<attr name="sv_centerCircleRadius" />
</declare-styleable>

<declare-styleable name="DeluxeSpeedView" parent="Speedometer">
<attr name="sv_centerCircleColor" />
<attr name="sv_centerCircleRadius" />
<attr name="sv_speedBackgroundColor" />
<attr name="sv_withEffects" />
</declare-styleable>
Expand All @@ -133,6 +136,7 @@

<declare-styleable name="PointerSpeedometer" parent="Speedometer">
<attr name="sv_centerCircleColor" />
<attr name="sv_centerCircleRadius" />
<attr name="sv_speedometerColor" />
<attr name="sv_pointerColor" format="color"/>
<attr name="sv_withPointer" format="boolean"/>
Expand Down

0 comments on commit 0cb4e01

Please sign in to comment.