I am currently working on an application that allows me to draw freely.
The current method I'm using is as follows:
currentLine is a list that stores the history of all points returned ACTION_MOVE.
public boolean onTouchEvent (MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
Point p = new Point(event.getX(),event.getY());
currentLine.addPoint(p);
invalidate();
break;
}
return true;
}
Then I take these points and draw them in the method of onDrawmy class.
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
c.drawColor(Color.BLUE);
Paint p = new Paint();
p.setStyle(Style.FILL);
p.setColor(COLOR.WHITE);
if(currentLine.size()>0){
for(int x = 0;x<currentLine.size();x++){
c.drawCircle(currentLine.get(x).getX(), currentLine.get(x).getY(), 3, p);
}
}
}
And this method works great, without lag or anything else.
In addition, he does not get enough points that he needs.
For example, if I need to quickly drag my finger across the screen, it can display only 15 points of the entire event.
How can I improve MotionEvent performance / speed? How can I get more points? Or is there something else I should do?
---- ---- EDIT
.
drawCircle drawLine.
:
if(points.size()>0){
for(int x = 0;x<points.size()-1;x++){
c.drawLine(points.get(x).getX(), points.get(x).getY(), points.get(x+1).getX(), points.get(x+1).getY(), p);
}
}
, .
, , , MotionEvents.