diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java index eadfe16e80..e0fddb6265 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java @@ -166,16 +166,20 @@ public void hasOneMotionEventOrTwoMotionEventViewParameters(ExecutableElement ex } else { VariableElement firstParameter = parameters.get(0); String firstParameterType = firstParameter.asType().toString(); - if (!firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) { + if (parameters.size() == 1 && !firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) { valid.invalidate(); - annotationHelper.printAnnotationError(executableElement, "the first parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType); + annotationHelper.printAnnotationError(executableElement, "the parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType); } if (parameters.size() == 2) { VariableElement secondParameter = parameters.get(1); String secondParameterType = secondParameter.asType().toString(); - if (!secondParameterType.equals(CanonicalNameConstants.VIEW)) { + + boolean isViewAndMotion = firstParameterType.equals(CanonicalNameConstants.VIEW) && secondParameterType.equals(CanonicalNameConstants.MOTION_EVENT); + boolean isMotionAndView = firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT) && secondParameterType.equals(CanonicalNameConstants.VIEW); + + if (!isViewAndMotion && !isMotionAndView) { valid.invalidate(); - annotationHelper.printAnnotationError(executableElement, "the second parameter must be a " + CanonicalNameConstants.VIEW + ", not a " + secondParameterType); + annotationHelper.printAnnotationError(executableElement, "the parameters must be a " + CanonicalNameConstants.VIEW + " and a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType + " and a " + secondParameterType); } } } diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java index 338944342d..b20921d891 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java @@ -23,6 +23,7 @@ import javax.lang.model.type.TypeMirror; import org.androidannotations.annotations.Touch; +import org.androidannotations.helper.CanonicalNameConstants; import org.androidannotations.rclass.IRClass; import com.sun.codemodel.JBlock; @@ -65,10 +66,22 @@ protected void processParameters(JMethod listenerMethod, JInvocation call, List< JVar eventParam = listenerMethod.param(classes.MOTION_EVENT, "event"); boolean hasItemParameter = parameters.size() == 2; - call.arg(eventParam); - if (hasItemParameter) { + VariableElement first = parameters.get(0); + String firstType = first.asType().toString(); + if (firstType.equals(CanonicalNameConstants.MOTION_EVENT)) { + call.arg(eventParam); + } else { call.arg(viewParam); } + if (hasItemParameter) { + VariableElement second = parameters.get(1); + String secondType = second.asType().toString(); + if (secondType.equals(CanonicalNameConstants.MOTION_EVENT)) { + call.arg(eventParam); + } else { + call.arg(viewParam); + } + } } @Override