Skip to content

Commit 347cb62

Browse files
committed
Implemented Changes for androidannotations#728
1 parent 015e780 commit 347cb62

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,19 @@ public void hasOneMotionEventOrTwoMotionEventViewParameters(ExecutableElement ex
166166
} else {
167167
VariableElement firstParameter = parameters.get(0);
168168
String firstParameterType = firstParameter.asType().toString();
169-
if (!firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) {
169+
if (parameters.size() == 1 && !firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) {
170170
valid.invalidate();
171-
annotationHelper.printAnnotationError(executableElement, "the first parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType);
172-
}
173-
if (parameters.size() == 2) {
171+
annotationHelper.printAnnotationError(executableElement, "the parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType);
172+
} else { // if (parameters.size() == 2)
174173
VariableElement secondParameter = parameters.get(1);
175174
String secondParameterType = secondParameter.asType().toString();
176-
if (!secondParameterType.equals(CanonicalNameConstants.VIEW)) {
175+
176+
boolean isViewAndMotion = firstParameterType.equals(CanonicalNameConstants.VIEW) && secondParameterType.equals(CanonicalNameConstants.MOTION_EVENT);
177+
boolean isMotionAndView = firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT) && secondParameterType.equals(CanonicalNameConstants.VIEW);
178+
179+
if (!isViewAndMotion && !isMotionAndView) {
177180
valid.invalidate();
178-
annotationHelper.printAnnotationError(executableElement, "the second parameter must be a " + CanonicalNameConstants.VIEW + ", not a " + secondParameterType);
181+
annotationHelper.printAnnotationError(executableElement, "the parameters must be a " + CanonicalNameConstants.VIEW + " and a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType + " and a " + secondParameterType);
179182
}
180183
}
181184
}

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.lang.model.type.TypeMirror;
2424

2525
import org.androidannotations.annotations.Touch;
26+
import org.androidannotations.helper.CanonicalNameConstants;
2627
import org.androidannotations.rclass.IRClass;
2728

2829
import com.sun.codemodel.JBlock;
@@ -65,10 +66,22 @@ protected void processParameters(JMethod listenerMethod, JInvocation call, List<
6566
JVar eventParam = listenerMethod.param(classes.MOTION_EVENT, "event");
6667
boolean hasItemParameter = parameters.size() == 2;
6768

68-
call.arg(eventParam);
69-
if (hasItemParameter) {
69+
VariableElement first = parameters.get(0);
70+
String firstType = first.asType().toString();
71+
if (firstType.equals(CanonicalNameConstants.MOTION_EVENT)) {
72+
call.arg(eventParam);
73+
} else { // if (first.equals(CanonicalNameConstants.VIEW))
7074
call.arg(viewParam);
7175
}
76+
if (hasItemParameter) {
77+
VariableElement second = parameters.get(1);
78+
String secondType = second.asType().toString();
79+
if (secondType.equals(CanonicalNameConstants.MOTION_EVENT)) {
80+
call.arg(eventParam);
81+
} else { // if (first.equals(CanonicalNameConstants.MOTION_EVENT))
82+
call.arg(viewParam);
83+
}
84+
}
7285
}
7386

7487
@Override

0 commit comments

Comments
 (0)