I have created a path objects as shown below which draws a different shapes.Different buttons response to drawing different shapes on the canvas. I would like to shift the path objects that i have created in the canvas but I do not know how to.
I only know the method of implementing ontouchlistener on a bitmap and not on path objects.
my codes are as follows:
ArrayList<Path> paths = new ArrayList<Path>();
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
paintColor.setColor(Color.RED);
paintColor.setStrokeWidth(2);
paintColor.setStyle(Paint.Style.STROKE);
if (MainActivity.isRectangle) {
Path path = new Path();
path.moveTo(1, 1);
path.lineTo(90, 1);
path.lineTo(90, 60);
path.lineTo(1, 60);
path.close();
paths.add(path);
}
for (Path p : paths) {
canvas.drawPath(p, paintColor );
}
canvas.drawPath(path, paintColor);
invalidate();
}
//mainActivity
rectbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
isTriangle = false;
isRectangle = true;
isCircle= false;
isParallelogram = false;
isTapezium = false;
dv.invalidate();
}// onclick
});
onTouchEvent
@Override
public boolean onTouch(View v,MotionEvent event){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
//screen touch get x of the touch event
x = event.getX();
//screen touch get y of the touch event
y =event.getY();
for (Path p : paths) {
path.moveTo(x,y);
}
dv.invalidate();
break;
case MotionEvent.ACTION_UP:
//screen touch get x of the touch event
x = event.getX();
//screen touch get y of the touch event
y =event.getY();
break;
case MotionEvent.ACTION_MOVE:
//screen touch get x of the touch event
x = event.getX();
//screen touch get y of the touch event
y =event.getY();
break;
}
return true;
}
Please advice. Thank you.