Skip to content

Contributing

Anas Altair edited this page Dec 25, 2016 · 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 values in defaultValues() method by call super for each, like so:
   super.setBackgroundCircleColor(Color.TRANSPARENT);
  • add default indicator at end of defaultValues() method (default indicator is NoIndicator).
  • call updateBackgroundBitmap(); at end of onSizeChanged method.
  • call drawIndicator(canvas); inside onDraw method.
  • call drawNotes(canvas); at end of onDraw method.
  • add these lines at first of updateBackgroundBitmap method:
   if (getWidth() == 0 || getHeight() == 0)
       return null;
   backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(backgroundBitmap);
   c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

and return backgroundBitmap;.

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 values by call super.method like
        // super.setBackgroundCircleColor(Color.TRANSPARENT);

        // this is default Indicator, change it to what you want,
        // you can remove this line, but don't move it up.
        setIndicator(Indicator.Indicators.NormalIndicator);
    }

    @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);
        // don't need to draw backgroundBitmap.

        // you must call this method to draw the indicator.
        // put it wherever you want inside this method.
        drawIndicator(canvas);

        // draw what do you want.

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

    @Override
    protected Bitmap updateBackgroundBitmap() {
        // don't remove these lines.
        if (getWidth() == 0 || getHeight() == 0)
            return null;
        backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(backgroundBitmap);
        c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

        // backgroundBitmap used to contain all drawing that doesn't change with speed change.
        // draw them in c Canvas here.

        return backgroundBitmap;
    }

    // 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.
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?.
drawDefaultMinAndMaxSpeedPosition (canvas) use this method in updateBackgroundBitmap() method if you want to draw Min and Max speed text in default position.
speedTextPaint you must use this paint to draw speed text.
unitTextPaint you must use this paint to draw unit text.

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