use of org.androidannotations.holder.TextWatcherHolder in project androidannotations by androidannotations.
the class AfterTextChangeHandler 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 editableParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.EDITABLE.equals(parameterType.toString())) {
editableParameterPosition = i;
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getAfterTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == editableParameterPosition) {
JVar afterTextChangeEditableParam = textWatcherHolder.getAfterTextChangedEditableParam();
textChangeCall.arg(afterTextChangeEditableParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of org.androidannotations.holder.TextWatcherHolder in project androidannotations by androidannotations.
the class TextChangeHandler 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 startParameterPosition = -1;
int countParameterPosition = -1;
int beforeParameterPosition = -1;
int charSequenceParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
String parameterName = parameter.toString();
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.CHAR_SEQUENCE.equals(parameterType.toString())) {
charSequenceParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
if ("start".equals(parameterName)) {
startParameterPosition = i;
} else if ("count".equals(parameterName)) {
countParameterPosition = i;
} else if ("before".equals(parameterName)) {
beforeParameterPosition = i;
}
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getOnTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == startParameterPosition) {
JVar startParameter = textWatcherHolder.getOnTextChangedStartParam();
textChangeCall.arg(startParameter);
} else if (i == countParameterPosition) {
JVar countParameter = textWatcherHolder.getOnTextChangedCountParam();
textChangeCall.arg(countParameter);
} else if (i == beforeParameterPosition) {
JVar beforeParameter = textWatcherHolder.getOnTextChangedBeforeParam();
textChangeCall.arg(beforeParameter);
} else if (i == charSequenceParameterPosition) {
JVar charSequenceParam = textWatcherHolder.getOnTextChangedCharSequenceParam();
textChangeCall.arg(charSequenceParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of org.androidannotations.holder.TextWatcherHolder in project androidannotations by androidannotations.
the class BeforeTextChangeHandler 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 startParameterPosition = -1;
int countParameterPosition = -1;
int afterParameterPosition = -1;
int charSequenceParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
String parameterName = parameter.toString();
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.CHAR_SEQUENCE.equals(parameterType.toString())) {
charSequenceParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
if ("start".equals(parameterName)) {
startParameterPosition = i;
} else if ("count".equals(parameterName)) {
countParameterPosition = i;
} else if ("after".equals(parameterName)) {
afterParameterPosition = i;
}
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getBeforeTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == startParameterPosition) {
JVar startParameter = textWatcherHolder.getBeforeTextChangedStartParam();
textChangeCall.arg(startParameter);
} else if (i == countParameterPosition) {
JVar countParameter = textWatcherHolder.getBeforeTextChangedCountParam();
textChangeCall.arg(countParameter);
} else if (i == afterParameterPosition) {
JVar afterParameter = textWatcherHolder.getBeforeTextChangedAfterParam();
textChangeCall.arg(afterParameter);
} else if (i == charSequenceParameterPosition) {
JVar charSequenceParam = textWatcherHolder.getBeforeTextChangedCharSequenceParam();
textChangeCall.arg(charSequenceParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
Aggregations