use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class SeekBarProgressChangeHandler 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 seekBarViewParameterPosition = -1;
int progressParameterPosition = -1;
int fromUserParameterPosition = -1;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
seekBarViewParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
progressParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
fromUserParameterPosition = i;
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == seekBarViewParameterPosition) {
JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
textChangeCall.arg(seekBarViewParameter);
} else if (i == progressParameterPosition) {
JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
textChangeCall.arg(progressParameter);
} else if (i == fromUserParameterPosition) {
JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
textChangeCall.arg(fromUserParameter);
}
}
}
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class ViewByIdHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
TypeMirror uiFieldTypeMirror = param.asType();
JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.ID, true);
AbstractJClass viewClass = codeModelHelper.typeMirrorToJClass(uiFieldTypeMirror);
IJAssignmentTarget viewHolderTarget = null;
if (element.getKind() == ElementKind.FIELD) {
viewHolderTarget = fieldRef;
}
FoundViewHolder viewHolder = holder.getFoundViewHolder(idRef, viewClass, viewHolderTarget);
if (!viewHolder.getRef().equals(viewHolderTarget)) {
targetBlock.add(fieldRef.assign(viewHolder.getOrCastRef(viewClass)));
}
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class EComponentHolder method setPowerManagerRef.
private void setPowerManagerRef() {
JBlock methodBody = getInitBodyInjectionBlock();
JFieldRef serviceRef = getClasses().CONTEXT.staticRef("POWER_SERVICE");
powerManagerRef = getGeneratedClass().field(PRIVATE, getClasses().POWER_MANAGER, "powerManager" + generationSuffix());
methodBody.assign(powerManagerRef, cast(getClasses().POWER_MANAGER, getContextRef().invoke("getSystemService").arg(serviceRef)));
}
use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.
the class InjectHelper method processField.
private void processField(Element element, T holder) {
String fieldName = element.getSimpleName().toString();
JFieldRef fieldRef = JExpr._this().ref(fieldName);
handler.assignValue(createBlock(holder, false), fieldRef, holder, element, element);
}
use of com.helger.jcodemodel.JFieldRef 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