MotionEvent multi-touch events mix and affect each other (see Demo video)

Application Purpose:

A simple application that draws a circle for each touch that is recognized on the screen and follows touch events. With the "high pressure reading" the getPressure (int pointerIndex)color of the circle will change and the radius will increase. In addition, a touch identifier with getPointerId (int pointerIndex)x- and y-coordinates and pressure is displayed next to the touch of a finger .

Following the snipplet code of the important part (please forgive me, this is not the most pleasant code;) I know)

protected void onDraw(Canvas canvas){

    //draw circle only when finger(s) is on screen and moves 
    if(iTouchAction == (MotionEvent.ACTION_MOVE)){
        int x,y;
        float pressure;

        //Draw circle for every touch
        for (int i = 0; i < touchEvent.getPointerCount(); i++){
            x = (int)touchEvent.getX(i);
            y = (int)touchEvent.getY(i);
            pressure = touchEvent.getPressure(i);

            //High pressure
            if (pressure > 0.25){
                canvas.drawCircle(x, y, z+30, pressureColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+"  | "+x+"/"+y, x+90, y-80, touchColor);
                canvas.drawText(""+pressure, x+90, y-55, pressureColor);
            }else{ //normal touch event 
                canvas.drawCircle(x, y, z, touchColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+" | "+x+"/"+y, x+60, y-50, touchColor);
                canvas.drawText(""+pressure, x+60, y-25, pressureColor);
            }
        }           
    }
}

Problem:

HTC Desire Android 2.1 - . . , , - , "" x y. . , getPressure (int pointerIndex) PointerID, .

, : http://www.youtube.com/watch?v=bFxjFexrclU

:

  • ?
  • Android 2.1 , ?
  • 1) 2)?

/ (, , ).

+3
2

, .

, Nexus One (, , , HTC Desire), . " " ACTION_POINTER_UP/DOWN Android 2.2, , , . X Y; (x0, y0) (x1, y1) (x0, y1) (x1, y0). , , "" , Android .

, . , , , PackageManager FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT. , , .

+3

- ? , android 1.x/2.x.

, Luke , pre-3.x.

, , Cheers.

+1

Source: https://habr.com/ru/post/1766329/


All Articles