Bonjour
J'essaie de commencer à dessiner à partir du milieu de l'écran (le cercle), j'ai récupèré les coordonnées, X et Y du milieu de l'écran et j'ai fait une fonction booleen

Le problème est que lorsque je commence à dessiner n'importe où sur l'écran Normalement je ne pourrai pas dessiner, ce n'est pas le cas, en plus de sa mon premier trait est automatiquement connecté au point x = 0 et y = 0 ! il est ou le probleme ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 @Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                if (!canDraw ) {
                    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    Toast.makeText(getContext(), "Cliquez sur le cercle ", Toast.LENGTH_SHORT).show();
                    // Vibrate for 500 milliseconds
                    v.vibrate(500);
                } else if (canDraw && touchIsInsideCircle(x, y)) {
                    startTouch(x, y);
                    invalidate();
                    break;
                }
            case MotionEvent.ACTION_UP:
                if (!canDraw) {
                    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    Toast.makeText(getContext(), "Cliquez sur le cercle ", Toast.LENGTH_SHORT).show();
                    // Vibrate for 500 milliseconds
                    v.vibrate(500);
                } else if (canDraw ) {

                    upTouch();
                    invalidate();
                    break;
                }
            case MotionEvent.ACTION_MOVE:
                if (!canDraw) {
                    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    Toast.makeText(getContext(), "Cliquez sur le cercle ", Toast.LENGTH_SHORT).show();
                    // Vibrate for 500 milliseconds
                    v.vibrate(500);
                } else if (canDraw ) {
                    moveTouche(x, y);
                    invalidate();
                    break;
                }
        }
        return true;
    }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
private boolean touchIsInsideCircle(float x, float y) {

        return (x <750 && x > 690 && y <1200  && y >1000);

}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   private void startTouch (float x , float y){
        if ((canDraw) ){
path.moveTo(x,y);
        mX = x;
        mY = y ;
    }}
    public void moveTouche (float x,float y ) {
        if ((canDraw)) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if(dx >= Tolerance || dy >= Tolerance){
            path.quadTo(mX,mY,(x+mX)/2,(y+mY)/2);
            mX = x ;
            mY = y;

        }}
    }
    private void upTouch(){
        if ((canDraw)) {
        path.lineTo(mX,mY);
    }}