// Retrieves the normalized coordinates (-1 to 1) for any given (x,y)
    // value reported by the Android MotionEvent.
    private boolean getNormalizedCoordinates(MotionEvent motionEvent) {
      InputDevice device = motionEvent.getDevice();
      if (device != null) {
        InputDevice.MotionRange range =
            device.getMotionRange(MotionEvent.AXIS_X, motionEvent.getSource());
        float x = range.getMax() + 1;
        range = motionEvent.getDevice().getMotionRange(MotionEvent.AXIS_Y, motionEvent.getSource());
        float y = range.getMax() + 1;
        this.x = (motionEvent.getX() / x * 2.0f - 1.0f);
        this.y = 1.0f - motionEvent.getY() / y * 2.0f;
        if (motionEvent.getAction() == MotionEvent.ACTION_SCROLL) {
          this.z = (motionEvent.getAxisValue(MotionEvent.AXIS_VSCROLL) > 0 ? -1 : 1);
        } else {
          this.z = 0;
        }

        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
          this.isActive = true;
        } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
          this.isActive = false;
        }
        return true;
      }
      return false;
    }
  @Override
  public void onJoystickChange(MotionEvent e) {
    InputDevice device = e.getDevice();

    int[] speeds =
        calculateMotorSpeed(e.getAxisValue(MotionEvent.AXIS_X), e.getAxisValue(MotionEvent.AXIS_Y));

    methodHandler.accelerateToMotorSpeed(MethodHandler.Motor.LEFT, speeds[0]);
    methodHandler.accelerateToMotorSpeed(MethodHandler.Motor.RIGHT, speeds[1]);
  }
  @Override
  public boolean onGenericMotionEvent(MotionEvent motionEvent) {
    // DebugInput.debugMotionEvent(motionEvent);

    int playerNum = OuyaController.getPlayerNumByDeviceId(motionEvent.getDeviceId());
    if (playerNum < 0) {
      Log.e(TAG, "Failed to find playerId for Controller=" + motionEvent.getDevice().getName());
      return true;
    }

    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_LS_X, motionEvent.getAxisValue(OuyaController.AXIS_LS_X));
    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_LS_Y, motionEvent.getAxisValue(OuyaController.AXIS_LS_Y));
    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_RS_X, motionEvent.getAxisValue(OuyaController.AXIS_RS_X));
    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_RS_Y, motionEvent.getAxisValue(OuyaController.AXIS_RS_Y));
    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_L2, motionEvent.getAxisValue(OuyaController.AXIS_L2));
    dispatchGenericMotionEventNative(
        playerNum, OuyaController.AXIS_R2, motionEvent.getAxisValue(OuyaController.AXIS_R2));
    return true;
  }