Skip to content

Commit

Permalink
ability to remove the pointer from PointerSpeedometer.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastr committed Aug 26, 2017
1 parent 99acbfd commit 5cc9e41
Showing 1 changed file with 29 additions and 7 deletions.
Expand Up @@ -34,6 +34,8 @@ public class PointerSpeedometer extends Speedometer {
private int speedometerColor = 0xffeeeeee
, pointerColor = Color.WHITE;

private boolean withPointer = true;

public PointerSpeedometer(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -86,6 +88,7 @@ private void initAttributeSet(Context context, AttributeSet attrs) {
speedometerColor = a.getColor(R.styleable.PointerSpeedometer_sv_speedometerColor, speedometerColor);
pointerColor = a.getColor(R.styleable.PointerSpeedometer_sv_pointerColor, pointerColor);
circlePaint.setColor(a.getColor(R.styleable.PointerSpeedometer_sv_centerCircleColor, circlePaint.getColor()));
withPointer = a.getBoolean(R.styleable.PointerSpeedometer_sv_withPointer, withPointer);
a.recycle();
initAttributeValue();
}
Expand Down Expand Up @@ -119,13 +122,15 @@ protected void onDraw(Canvas canvas) {

canvas.drawArc(speedometerRect, getStartDegree(), getEndDegree()- getStartDegree(), false, speedometerPaint);

canvas.save();
canvas.rotate(90 + getDegree(), getSize() *.5f, getSize() *.5f);
canvas.drawCircle(getSize() *.5f, getSpeedometerWidth() *.5f + dpTOpx(8) + getPadding()
, getSpeedometerWidth() *.5f + dpTOpx(8), pointerBackPaint);
canvas.drawCircle(getSize() *.5f, getSpeedometerWidth() *.5f + dpTOpx(8) + getPadding()
, getSpeedometerWidth() *.5f + dpTOpx(1), pointerPaint);
canvas.restore();
if (withPointer) {
canvas.save();
canvas.rotate(90 + getDegree(), getSize() * .5f, getSize() * .5f);
canvas.drawCircle(getSize() * .5f, getSpeedometerWidth() * .5f + dpTOpx(8) + getPadding()
, getSpeedometerWidth() * .5f + dpTOpx(8), pointerBackPaint);
canvas.drawCircle(getSize() * .5f, getSpeedometerWidth() * .5f + dpTOpx(8) + getPadding()
, getSpeedometerWidth() * .5f + dpTOpx(1), pointerPaint);
canvas.restore();
}

drawSpeedUnitText(canvas);
drawIndicator(canvas);
Expand Down Expand Up @@ -223,6 +228,23 @@ public void setCenterCircleColor(int centerCircleColor) {
invalidate();
}

public boolean isWithPointer() {
return withPointer;
}

/**
* enable to draw circle pointer on speedometer arc.<br/>
* this will not make any change for the Indicator.
* @param withPointer true: draw the pointer,
* false: don't draw the pointer.
*/
public void setWithPointer(boolean withPointer) {
this.withPointer = withPointer;
if (!isAttachedToWindow())
return;
invalidate();
}

/**
* this Speedometer doesn't use this method.
* @return {@code Color.TRANSPARENT} always.
Expand Down

0 comments on commit 5cc9e41

Please sign in to comment.