0

I've recently been trying to use multi touch for my app but haven't been able to find any help with my problem ill post the bit of my code im having trouble with. im using and old adk with a api level of 7 is multi touch available for androids running 2.1?

thanks

@Override
    public boolean onTouchEvent(MotionEvent event) {
            super.onTouchEvent(event);


            int action = event.getAction() & MotionEvent.ACTION_MASK;

            switch (action) {
            case MotionEvent.ACTION_DOWN: {
                float tx = event.getX();
                float ty = event.getY();
                if (tx > joystick.getWidth() - joystick.getWidth() && tx < (joystick.getWidth() / 3) && ty > getHeight() - joystick.getHeight()) {
                    left();
                    invalidate();
                }
                if (tx > (joystick.getWidth()/3)*2 && tx < (joystick.getWidth()) && ty > getHeight() - joystick.getHeight()) {
                    right();
                    invalidate();
                }
                if (tx > getWidth() - button.getWidth() - (button.getWidth() / 4)
                        && ty > getHeight() - button.getHeight()
                                - (button.getHeight() / 4)) {
                    jump();
                    invalidate();
                }else{jump_true = 0 ;
                jump_is = true;}
                    break;
            }
            case MotionEvent.ACTION_MOVE: {
                float txm = event.getX();
                float tym = event.getY();
                if (txm > joystick.getWidth() - joystick.getWidth() && txm < (joystick.getWidth() / 3) && tym > getHeight() - joystick.getHeight()) {
                    left();
                    right = false;
                    invalidate();
                }
                if (txm > getWidth() - button.getWidth() - (button.getWidth() / 4)
                        && tym > getHeight() - button.getHeight()
                                - (button.getHeight() / 4)) {
                    //jump();
                    //invalidate();
                }else{
                    //jump_true = 0 ;
                    //jump_is = true;
                }
                if (txm > (joystick.getWidth()/3)*2 && txm < (joystick.getWidth()) && tym > getHeight() - joystick.getHeight()) {
                    right();
                    left = false;
                    invalidate();
                }
                if (txm > getWidth() - button.getWidth() - (button.getWidth() / 4)
                        && tym > getHeight() - button.getHeight()
                                - (button.getHeight() / 4)) {
                    jump();
                    invalidate();
                }else{jump_true = 0 ;
                jump_is = true;}
                    break;
            }

            case MotionEvent.ACTION_POINTER_DOWN: {
                float txp = event.getX();
                float typ = event.getY();
                if (txp > getWidth() - button.getWidth() - (button.getWidth() / 4)
                        && typ > getHeight() - button.getHeight()
                                - (button.getHeight() / 4)) {
                    jump();
                    invalidate();
                }else{jump_true = 0 ;
                jump_is = true;}

                if (txp > joystick.getWidth() - joystick.getWidth() && txp < (joystick.getWidth() / 3) && typ > getHeight() - joystick.getHeight()) {
                    left();
                    right = false;
                    invalidate();
                }
                if (txp > getWidth() - button.getWidth() - (button.getWidth() / 4)
                        && typ > getHeight() - button.getHeight()
                                - (button.getHeight() / 4)) {
                    //jump();
                    //invalidate();
                }else{
                    //jump_true = 0 ;
                    //jump_is = true;
                }
                if (txp > (joystick.getWidth()/3)*2 && txp < (joystick.getWidth()) && typ > getHeight() - joystick.getHeight()) {
                    right();
                    left = false;
                    invalidate();
                }
            break;
            }
            case MotionEvent.ACTION_POINTER_UP: {
                touch_up();
                invalidate();
                    break;
            }
            case MotionEvent.ACTION_UP: {
                touch_up();
                invalidate();
                    break;
            }
            }

            return true;
    }


    private void touch_up() {
        left = false;
        right = false;
        jump_true = 0 ;
        jump_is = true;
    }

    private void left() {
        left = true;
    }
    private void right(){
        right = true;
    }
    private void jump() {
        jump_true=1;
        jump_done = false;
    }
  • Are you testing it on emulator or in a phone? If you're using a phone, be sure if hardware sopports multi touch. – Guedes Apr 09 '12 at 20:49
  • What do you mean by `not working`? Rather than dumping code and saying how it doesn't work please tell us what is wrong and what you have tried? – slayton Apr 09 '12 at 20:51
  • no my phone definitely supports multi-touch and by not working i mean it wont detect the second finger it only works with one finger –  Apr 09 '12 at 20:53

1 Answers1

0

Yes, multitouch is available for 2.0 and up. See http://androidandme.com/2009/10/news/android-2-0-does-indeed-feature-multitouch/.

Also, use logcat to ensure your motion events are being triggered.

lrAndroid
  • 2,834
  • 18
  • 27