Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down