Skip to content

Contributing

Anas Altair edited this page Sep 28, 2017 · 8 revisions

if you want to contribute to this library, Please take look at these rules.

before you start, you have to know what you want to do:

Fix Bugs

report abut the bug with explain and Screenshots if it possible, and we will discuss about it to solve it as fast as possible.

improve the Library

add some methods, classes, interfaces..... anywhere, please Post a description of each new method and variable, use simple english language to explain.

Create New Speedometer

keep these in your mind when you want to create new Speedometer

  • extends Speedometer class.
  • implement abstract methods.
  • Override onSizeChanged(int w, int h, int oldW, int oldH) method.
  • Override onDraw(Canvas canvas) method.
  • add default Gauge values in defaultValues() method by call super for each, like so:
   super.setBackgroundCircleColor(Color.TRANSPARENT);
  • add default Speedometer values in defaultSpeedometerValues() method by call super for each, like so:
   super.setSpeedometerColor(Color.RED);
   super.setSpeedometerWidth(dpTOpx(40f));
  • call updateBackgroundBitmap(); at end of onSizeChanged method.
  • call drawSpeedUnitText(canvas); inside onDraw method.
  • call drawIndicator(canvas); inside onDraw method.
  • call drawNotes(canvas); at end of onDraw method.
  • add this lines at first of updateBackgroundBitmap method:
   Canvas c = createBackgroundBitmapCanvas();
   // draw on c canvas all drawing that doesn't change when speed update.

so, your CustomSpeedometer class must be like this:

/**
 * this Library build By Anas Altair, and this Speedometer added by YOUR_NAME.
 * see it on <a href="https://github.com/anastr/SpeedView">GitHub</a>
 */
public class CustomSpeedometer extends Speedometer {

    // add your Variables Here.

    public CustomSpeedometer(Context context) {
        this(context, null);
    }

    public CustomSpeedometer(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomSpeedometer(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void defaultValues() {
        // add default Gauge's values by call super.method like
        // super.setBackgroundCircleColor(Color.TRANSPARENT);
    }

    @Override
    protected void defaultSpeedometerValues() {
        // add default Speedometer's values by call super.method like
        // super.setStartEndDegree(135, 135 + 320);

        // by default there is No Indicator, add indicator by:
        // super.setIndicator(new TriangleIndicator(getContext())
        //        .setIndicatorWidth(dpTOpx(25f))
        //        .setIndicatorColor(0xff00e6e6));
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldW, int oldH) {
        super.onSizeChanged(w, h, oldW, oldH);

        // update your speedometer here if it depend on size.

        // don't remove this line, and don't move up.
        updateBackgroundBitmap();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // backgroundBitmap is Already painted.

        // you can draw what do you want here.

        // you must call this method to draw speed-unit Text.
        // this method must call before drawIndicator(canvas) method.
        drawSpeedUnitText(canvas);
        // you must call this method to draw the indicator.
        // put it wherever you want inside this method.
        drawIndicator(canvas);

        // you can draw what do you want here.

        // don't remove this line, and don't move up.
        drawNotes(canvas);
    }

    @Override
    protected void updateBackgroundBitmap() {
        // don't remove these lines.
        Canvas c = createBackgroundBitmapCanvas();

       // you can use this to draw min and max speed Text
       // at the default position.
       drawDefMinMaxSpeedPosition(c);
    }

    // add your custom methods here.
}

these methods/varibles can help you in your custom Speedometer:

method/varible description
getSpeedText() get correct speed as string to Draw.
getUnit() get unit string to Draw.
getSize() return width of SpeedometerRect.
getSizePa() return width of SpeedometerRect without padding.
getWidthPa() return View width without padding.
getHeightPa() return View height without padding.
isSpeedometerTextRightToLeft() if true you should draw unit string to the left of speed Text.
getPadding() use just this method to get padding.
getDegree() return correct degree of indicator.
getStartDegree() start degree where indicator and speedometer start.
getEndDegree() the end of speedometer, where indicator and speedometer must stop.
getLowSpeedOffset() return [0f, 1f], where LowSpeedSection must stop between startDegree and endDegree what is this?.
getMediumSpeedOffset() return [0f, 1f], where MediumSpeedSection must stop between startDegree and endDegree what is this?.
drawDefMinMaxSpeedPosition (canvas) use this method in updateBackgroundBitmap() method if you want to draw Min and Max speed text in default position.
unitTextPaint you must use this paint to draw unit text.

and also : getSpeedometerWidth(), getMarkColor(), getIndicatorColor(), getCenterCircleColor(), getLowSpeedColor(), getMediumSpeedColor(), getHighSpeedColor(), getTextColor(), getBackgroundCircleColor(), getIndicatorWidth().