Help developer extension

how make this extension on kodular

public class CustomView extends ImageView{
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context) {
super(context);
}
boolean drawGlow = false;
//this is the pixel coordinates of the screen
float glowX = 0;
float glowY = 0;
//this is the radius of the circle we are drawing
float radius = 20;
//this is the paint object which specifies the color and alpha level
//of the circle we draw
Paint paint = new Paint();
{
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setAlpha(50);
};

@Override
public void draw(Canvas canvas){
    super.draw(canvas);
    if(drawGlow)
        canvas.drawCircle(glowX, glowY, radius, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event){
    if(event.getAction() == MotionEvent.ACTION_DOWN){
        drawGlow = true;
    }else if(event.getAction() == MotionEvent.ACTION_UP)
        drawGlow = false;

    glowX = event.getX();
    glowY = event.getY();
    this.invalidate();
    return true;
}

}

1 Like

May I know where you got this code?

3 Likes

gordon iam confuse about draw technical if in view i can make extension. that i take from android studio code. please teach me how make draw extension or other sample draw

Seems like generated with GPT.

2 Likes

give me sample code make circle with draw on layout

1 Like

You can check Canvas component’s source code here.

1 Like

vknow360 please give me simple code in a view i want make drawa circle. cause if use view getview() become error. what should code use for draw for target a view

1 Like

Create a class extending View.
Override onDraw() method to get Canvas object.
Draw circle on this canvas with code.

Now add a method in your extension to get HVArrangement as container.
Cast ViewGroup to this arrangement.
Create a new instance of view class you created.
Add this instance as child to viewgroup.
That’s it.

1 Like

i dont understand … i want look simple sample code so i can learn with that.
in android studio

/**
*/
class   MyView extends View
{
    TextPaint   text_paint;
    Paint       paint;

    private void    InitView()
    {
        text_paint = new TextPaint( Paint.ANTI_ALIAS_FLAG );
        text_paint.setColor( Color.BLACK );
        paint = new Paint();
    }

    public MyView(Context context)
    {
        super(context);
        InitView();
    }

    public MyView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        InitView();
    }


    public MyView(Context context, AttributeSet attrs, int defaultStyle)
    {   
        super(context, attrs, defaultStyle);
        InitView();
    }


    @Override
    protected void  onDraw( Canvas canvas )
    {
        super.onDraw(canvas);
        //int   w, h;
        //w = canvas.getWidth();
        //h = canvas.getHeight();
        //paint.setColor( Color.WHITE );
        //canvas.drawRect(0, 0, w-1, h-1, paint );
        //canvas.drawText( "ciao", 100, 100, text_paint);
    }

};