Efficiency Android MotionEvent ACTION_MOVE. How to increase productivity?

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);

    //Draw Background Color
    c.drawColor(Color.BLUE);

    //Setup Paint
    Paint p = new Paint();
    p.setStyle(Style.FILL);
    p.setColor(COLOR.WHITE);

    //iterate through points
    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.

+5
4

, .

android 3.0+, .

android:hardwareAccelerated="true"

<application> . .

, , . invalidate (Rect dirty) invalidate().

+7

, event.getHistoricalX/Y()

+7

Put a small stream of sleep in a movement event; which helped me solve the problem when a ton of traffic events jammed the listener.

Thread.sleep(100);
0
source

Invalidate (); bad for performance. Try to calculate rect constraints and call invalidate (bounds)

0
source

All Articles