package io.github.controlwear.virtual.joystick.android;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

public class JoystickView extends View {


    private int mButtonColor;
    private int mBorderColor;


    /*
    CONSTRUCTORS
     */


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


    public JoystickView(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.JoystickView,
                0, 0
        );

        try {
            mButtonColor = styledAttributes.getColor(R.styleable.JoystickView_buttonColor, Color.BLACK);
            mBorderColor = styledAttributes.getColor(R.styleable.JoystickView_borderColor, Color.BLACK);
        } finally {
            styledAttributes.recycle();
        }
    }


    public JoystickView(Context context) {
        super(context);
    }


    /*
    SETTERS
     */


    public void setButtonColor(int newColor){
        mButtonColor=newColor;
    }


    public void setBorderColor(int newColor){
        mBorderColor=newColor;
    }
}
@@ -147,20 +147,83 @@
 aphics.C
-olor
+anvas;%0Aimport android.graphics.Color;%0Aimport android.graphics.Paint
 ;%0Aimport
@@ -336,54 +336,519 @@
 ate 
-int mButtonColor;%0A    private int mBorderColor
+static final int DEFAULT_SIZE = 200;%0A    private static final double RATIO_SIZE_BUTTON = 0.25;%0A    private static final double RATIO_SIZE_BORDER = 0.75;%0A%0A    // DRAWING%0A    private int mButtonColor;%0A    private int mBorderColor;%0A    private Paint mPaintCircleButton;%0A    private Paint mPaintCircleBorder;%0A%0A    // COORDINATE%0A    private int mPosX = 0;%0A    private int mPosY = 0;%0A    private int mCenterX = 0;%0A    private int mCenterY = 0;%0A%0A    // SIZE%0A    private int mBorderRadius;%0A    private int mButtonRadius
 ;%0A%0A%0A
@@ -1582,16 +1582,39 @@
        %7D
+%0A%0A        setupPaint();
 %0A    %7D%0A%0A
@@ -1685,24 +1685,2026 @@
 t);%0A    %7D%0A%0A%0A
+    protected void setupPaint() %7B%0A        mPaintCircleButton = new Paint();%0A        mPaintCircleButton.setAntiAlias(true);%0A        mPaintCircleButton.setColor(mButtonColor);%0A        mPaintCircleButton.setStyle(Paint.Style.FILL);%0A%0A        mPaintCircleBorder = new Paint();%0A        mPaintCircleBorder.setAntiAlias(true);%0A        mPaintCircleBorder.setColor(mBorderColor);%0A        mPaintCircleBorder.setStyle(Paint.Style.STROKE);%0A        mPaintCircleBorder.setStrokeWidth(3);%0A    %7D%0A%0A%0A    @Override%0A    protected void onDraw(Canvas canvas) %7B%0A        // Draw the circle border%0A        canvas.drawCircle(mCenterX, mCenterY, mBorderRadius, mPaintCircleBorder);%0A%0A        // Draw the circle button%0A        canvas.drawCircle(mPosX, mPosY, mButtonRadius, mPaintCircleButton);%0A    %7D%0A%0A%0A    @Override%0A    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) %7B%0A        super.onSizeChanged(xNew, yNew, xOld, yOld);%0A%0A        // get the center of view to position circle%0A        mCenterX = mPosX = getWidth() / 2;%0A        mCenterY = mPosY = getWidth() / 2;%0A%0A        // radius based on smallest size : height OR width%0A        int d = Math.min(xNew, yNew);%0A        mButtonRadius = (int) (d / 2 * RATIO_SIZE_BUTTON);%0A        mBorderRadius = (int) (d / 2 * RATIO_SIZE_BORDER);%0A    %7D%0A%0A%0A    @Override%0A    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) %7B%0A        // setting the measured values to resize the view to a certain width and height%0A        int d = Math.min(measure(widthMeasureSpec), measure(heightMeasureSpec));%0A        setMeasuredDimension(d, d);%0A    %7D%0A%0A%0A    private int measure(int measureSpec) %7B%0A        if (MeasureSpec.getMode(measureSpec) == MeasureSpec.UNSPECIFIED) %7B%0A            // if no bounds are specified return a default size (200)%0A            return DEFAULT_SIZE;%0A        %7D else %7B%0A            // As you want to fill the available space%0A            // always return the full available bounds.%0A            return MeasureSpec.getSize(measureSpec);%0A        %7D%0A    %7D%0A%0A%0A
     /*%0A    S

Add some drawing (with size and paint setup)