app/src/main/java/io/github/kranex/rota/RotaActivity.java
/* when the touch screen is touched... */
when the touch screen is touched
when the touch screen is touched
public boolean onTouch(View v, MotionEvent event) {
            int maskedAction = event.getActionMasked();
            int pointerIndex = event.getActionIndex();
            int pointerId = event.getPointerId(pointerIndex);
            switch (maskedAction) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_POINTER_DOWN: {
                    if(event.getX(pointerIndex) < getWindow().getDecorView().getWidth()/2
                            && !joystickView.leftJoy.isVisible()){
                        joystickView.leftJoy.setVisible(true); 
                        joystickView.leftJoy.setOriginXY( 
                                event.getX(pointerIndex),
                                event.getY(pointerIndex));
                        joystickView.leftJoy.setXY(
                                event.getX(pointerIndex), 
                                event.getY(pointerIndex));
                        leftID = pointerId;
                    }
                    if(event.getX(pointerIndex) > getWindow().getDecorView().getWidth()/2
                            && !joystickView.rightJoy.isVisible()){
                        joystickView.rightJoy.setVisible(true);
                        joystickView.rightJoy.setOriginXY(
                                event.getX(pointerIndex),
                                event.getY(pointerIndex));
                        joystickView.rightJoy.setXY(
                                event.getX(pointerIndex),
                                event.getY(pointerIndex));
                        rightID = pointerId;
                    }
                    break;
                }
                case MotionEvent.ACTION_MOVE: {
                    if(leftID >= 0) {
                        joystickView.leftJoy.setXY(event.getX(
                                event.findPointerIndex(leftID)),
                                event.getY(event.findPointerIndex(leftID)));
                    }
                    if(rightID >= 0) {
                        joystickView.rightJoy.setXY(
                                event.getX(event.findPointerIndex(rightID)),
                                event.getY(event.findPointerIndex(rightID)));
                    }
                    break;
                }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_UP:
                case MotionEvent.ACTION_CANCEL: {
                    if(leftID >= 0 && leftID == pointerId) {
                        joystickView.leftJoy.setVisible(false);
                        leftID = -1;
                    }
                    else if(rightID >= 0 && rightID == pointerId) {
                        joystickView.rightJoy.setVisible(false);
                        rightID = -1;
                    }
                    break;
                }
            }
            joystickView.invalidate(); 
            return true;
        }
public boolean onTouch ( View v , MotionEvent event ) { int maskedAction = event . getActionMasked ( ) ; int pointerIndex = event . getActionIndex ( ) ; int pointerId = event . getPointerId ( pointerIndex ) ; switch ( maskedAction ) { case MotionEvent . ACTION_DOWN : case MotionEvent . ACTION_POINTER_DOWN : { if ( event . getX ( pointerIndex ) < getWindow ( ) . getDecorView ( ) . getWidth ( ) / 2 && ! joystickView . leftJoy . isVisible ( ) ) { joystickView . leftJoy . setVisible ( true ) ; joystickView . leftJoy . setOriginXY ( event . getX ( pointerIndex ) , event . getY ( pointerIndex ) ) ; joystickView . leftJoy . setXY ( event . getX ( pointerIndex ) , event . getY ( pointerIndex ) ) ; leftID = pointerId ; } if ( event . getX ( pointerIndex ) > getWindow ( ) . getDecorView ( ) . getWidth ( ) / 2 && ! joystickView . rightJoy . isVisible ( ) ) { joystickView . rightJoy . setVisible ( true ) ; joystickView . rightJoy . setOriginXY ( event . getX ( pointerIndex ) , event . getY ( pointerIndex ) ) ; joystickView . rightJoy . setXY ( event . getX ( pointerIndex ) , event . getY ( pointerIndex ) ) ; rightID = pointerId ; } break ; } case MotionEvent . ACTION_MOVE : { if ( leftID >= 0 ) { joystickView . leftJoy . setXY ( event . getX ( event . findPointerIndex ( leftID ) ) , event . getY ( event . findPointerIndex ( leftID ) ) ) ; } if ( rightID >= 0 ) { joystickView . rightJoy . setXY ( event . getX ( event . findPointerIndex ( rightID ) ) , event . getY ( event . findPointerIndex ( rightID ) ) ) ; } break ; } case MotionEvent . ACTION_UP : case MotionEvent . ACTION_POINTER_UP : case MotionEvent . ACTION_CANCEL : { if ( leftID >= 0 && leftID == pointerId ) { joystickView . leftJoy . setVisible ( false ) ; leftID = - 1 ; } else if ( rightID >= 0 && rightID == pointerId ) { joystickView . rightJoy . setVisible ( false ) ; rightID = - 1 ; } break ; } } joystickView . invalidate ( ) ; return true ; }
when the touch screen is touched...
when the touch screen is touched ...
// apparently I need a maskedAction over an Action. // Get the index and id of the pointer associated with the action. // switch through all possible actions. // ACTION_DOWN and ACTION_POINTER_DOWN, both occur when a finger is placed on the // Screen. POINTER_DOWN is called when the second or third or ... is placed. // if the touch occurs on the left and a joystick doesn't already exist. // show the left joystick. // set the center of the joystick. // set the hat of the joystick. // if the touch occurs on the right, and a joystick doesn't already exist. // action move is called when ANY current finger is moved. // if it was the finger associated with the left joystick. // update the location of the left joy hat. // if it was the finger associated with the right joystick. // update the location of the right joy hat. // ACTION_UP and ACTION_POINTER_UP are called when a finger is removed from // the screen. CANCEL is when a finger is canceled however that happens. // if there is a left joy and if the finger removed was the one associated // with it. // hide the left joy. // remove the left ID. // otherwise if there's a right joy and the finger removed was the one // associated with it. // hide the right joy. // remove the right ID. // redraw the joysticks.