[Android Q&A, Help & Troubleshooting] hugo.assis.j:
I'm starting to build an app that needs 2D drawing on Android Studio and even after some search I still have some troubles understanding some things. My intention is to draw Balls as objects, so that I can specify its radius and locations to draw. That ball should be a filled circle.

So here are my questions:

1. How to create the ball class in the most organized way? (Its constructors, methods, and stuff like that)​

1. Where to call that class to create balls?(what should I do on the onCreate() method? My coding should go in my MainActivity class?)​

1. How to draw them by a timer?(create a ball with a random radius and position and draw it on screen)​

1. Where to draw them? (container)​

I saw a lot of things using canvas, the mysterious onDraw() method and I didn't get much of it.

I didn't understand how to control when to draw it.

I used this code for leaning and kinda control the drawing of objects , but It seems too messy and dont feel right.

Its a sensor controlled ball.

Bubbleview.java

public class BubbleView extends View
{
private int diametro;
private int x;
private int y;
private int Xt;
private int Yt;
private ShapeDrawable bubble;
private ShapeDrawable rect;
private boolean isTouch = false;
private int width;
private int height;
private WindowManager wm;
private Display display;
private Point size;
private Point centroBola;
private Point centroRet;
//private Color Retcor;
//private Color Bolacor;

public BubbleView(Context context)
{
super(context);

/*--Instancias--*/
bubble = new ShapeDrawable(new OvalShape());
rect = new ShapeDrawable(new RectShape());
size = new Point();
//Retcor = new Color();
//Bolacor = new Color();

createBubble();
}
private void createBubble()
{
wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
display = wm.getDefaultDisplay();
display.getSize(size);

width = (size.x);
height = (size.y);

x = width/2;
y = height/2;

//centroBola.set(x+(diametro/2),y-(diametro/2));
diametro = 100;

bubble.setBounds(x-diametro,y-diametro, x + diametro, y + diametro);
rect.setBounds(0, 10, size.x-1,80);

bubble.getPaint().setColor(0xff74AC23);
//rect.getPaint().setColor(0xff74AC23);//0xffEE4400
}

protected void move(float f, float g)
{
if (isTouch)
{
x = Xt;
y = Yt;
}
else
{
if (bubble.getBounds().right > width)
{
x=width-diametro-1;
y = (int) (y + g);
}
if (bubble.getBounds().left < 0)
{
x = 0;
y = (int) (y + g);
}
if (bubble.getBounds().top < 0)
{
x = (int) (x - f);
y = 1;
}
if (bubble.getBounds().bottom > height) {
x = (int) (x - f);
y = height - diametro -1;
}

x = (int) (x - f);
y = (int) (y + g);

}

//rect.setBounds(x+40, y+40, x + diametro, y + diametro);
bubble.setBounds(x,y,x +diametro,y+diametro);

}

@Override
public boolean onTouchEvent(MotionEvent event)
{
Xt = (int) event.getX();
Yt = (int) event.getY();

int evento = event.getAction();

switch (evento)
{
case MotionEvent.ACTION_DOWN:
bubble.setBounds(0, 0, Xt + diametro,Yt+ diametro);
//rect.setBounds(Xt, Yt, Xt + diametro,Yt+ diametro);
//coords.setText("X: " + X + ", Y: " + Y);
isTouch = true;
break;

case MotionEvent.ACTION_MOVE:
//coords.setText("X: " + X + ", Y: " + Y);
break;

case MotionEvent.ACTION_UP:
//Toast.makeText(this, "Saiu da tela em: X: " + X + ", Y: " + Y, Toast.LENGTH_SHORT);
isTouch = false;
break;
}
return true;
}

protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//rect.draw(canvas);

bubble.draw(canvas);
}
}

So I tried to build my app using this as a reference, but no success.

Wich way should the code becomes more intuitive?

thx in advance