use of org.androidannotations.holder.PageChangeHolder in project androidannotations by androidannotations.
the class PageScrolledHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int positionParameterPosition = -1;
int positionOffsetParameterPosition = -1;
int positionOffsetPixelsParameterPosition = -1;
int viewPagerParameterPosition = -1;
int numberOfIntParameters = 0;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
if (numberOfIntParameters == 0 && positionOffsetParameterPosition == -1) {
positionParameterPosition = i;
} else {
positionOffsetPixelsParameterPosition = i;
}
numberOfIntParameters++;
} else if (parameterType.getKind() == TypeKind.FLOAT || CanonicalNameConstants.FLOAT.equals(parameterType.toString())) {
positionOffsetParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageScrolledBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation pageScrollCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == positionParameterPosition) {
JVar positionParam = pageChangeHolder.getPageScrolledPositionParam();
pageScrollCall.arg(positionParam);
} else if (i == positionOffsetParameterPosition) {
JVar pageScrolledPositionOffsetParam = pageChangeHolder.getPageScrolledPositionOffsetParam();
pageScrollCall.arg(pageScrolledPositionOffsetParam);
} else if (i == positionOffsetPixelsParameterPosition) {
JVar pageScrolledPositionOffsetPixelsParam = pageChangeHolder.getPageScrolledPositionOffsetPixelsParam();
pageScrollCall.arg(pageScrolledPositionOffsetPixelsParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
pageScrollCall.arg(viewParameter);
}
}
}
}
use of org.androidannotations.holder.PageChangeHolder in project androidannotations by androidannotations.
the class PageScrollStateChangedHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int stateParameterPosition = -1;
int viewPagerParameterPosition = -1;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
stateParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageScrollStateChangedBody();
IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = methodBody.invoke(thisRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == stateParameterPosition) {
JVar stateParam = pageChangeHolder.getPageScrollStateChangedStateParam();
methodCall.arg(stateParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
methodCall.arg(viewParameter);
}
}
}
}
use of org.androidannotations.holder.PageChangeHolder in project androidannotations by androidannotations.
the class PageSelectedHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int positionParameterPosition = -1;
int viewPagerParameterPosition = -1;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
positionParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageSelectedBody();
IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = methodBody.invoke(thisRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == positionParameterPosition) {
JVar stateParam = pageChangeHolder.getPageSelectedPositionParam();
methodCall.arg(stateParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
methodCall.arg(viewParameter);
}
}
}
}
Aggregations