I achieved to put the ball in the middle by doing:
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (isFirstTime) {
drawPath = new Path();
drawPath.moveTo(w / 2, h / 2);
isFirstTime = false;
}
//...
}
And I start the pathdrawing in the middle by:
public void update (float gravityX, float gravityY) {
if(lastUpdateTime == 0) {
posX = getWidth() /2;
posY = getHeight() /2;
lastUpdateTime = System.currentTimeMillis();
this.invalidate();
}
//...
}
But to draw the path I'm still having some trouble. I achieved to draw something, but it draws 2 lines: 1st the ball track, and 2nd a direct line from the middle to the ball. This last line makes the surface between the 2 lines to be painted ass well, so I have to still see how to solve this.
For this, I have included this at the end of the update() method:
drawPath.lineTo(posX, posY);
drawCanvas.drawPath(drawPath, drawPaint);
this.invalidate();
And my onDraw() method looks like this:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
canvas.drawPath(drawPath, drawPaint);
canvas.drawCircle(posX, posY, radius, drawPaint);
}