use of com.helger.jcodemodel.JVar 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.JVar in project androidannotations by androidannotations.
the class ServiceActionHandler method addActionInOnHandleIntent.
private void addActionInOnHandleIntent(EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) {
JMethod onHandleIntentMethod = holder.getOnHandleIntentMethod();
// If action match, call the method
JInvocation actionCondition = actionKeyField.invoke("equals").arg(holder.getOnHandleIntentIntentAction());
JBlock callActionBlock = holder.getOnHandleIntentBody()._if(actionCondition)._then();
JInvocation callActionInvocation = JExpr._super().invoke(methodName);
// For each method params, we get back value from extras and put it
// in super calls
List<? extends VariableElement> methodParameters = executableElement.getParameters();
if (methodParameters.size() > 0) {
// Extras
JVar intent = holder.getOnHandleIntentIntent();
JVar extras = callActionBlock.decl(getClasses().BUNDLE, "extras");
extras.init(intent.invoke("getExtras"));
callActionBlock = callActionBlock._if(extras.ne(_null()))._then();
// Extras params
for (VariableElement param : methodParameters) {
String paramName = param.getSimpleName().toString();
String extraParamName = paramName + "Extra";
JFieldVar paramVar = getStaticExtraField(holder, paramName);
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), param.asType());
IJExpression getExtraExpression = bundleHelper.getExpressionToRestoreFromBundle(extraParamClass, extras, paramVar, onHandleIntentMethod);
JVar extraField = callActionBlock.decl(extraParamClass, extraParamName, getExtraExpression);
callActionInvocation.arg(extraField);
}
}
callActionBlock.add(callActionInvocation);
callActionBlock._return();
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class OnActivityResultHandler method process.
@Override
public void process(Element element, HasOnActivityResult holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int requestCode = executableElement.getAnnotation(OnActivityResult.class).value();
JBlock onResultBlock = holder.getOnActivityResultCaseBlock(requestCode).blockSimple();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation onResultInvocation = JExpr.invoke(activityRef, methodName);
JVar intent = holder.getOnActivityResultDataParam();
JVar extras = null;
for (VariableElement parameter : parameters) {
TypeMirror parameterType = parameter.asType();
if (parameter.getAnnotation(OnActivityResult.Extra.class) != null) {
if (extras == null) {
extras = onResultBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(intent.ne(_null()).cand(intent.invoke("getExtras").ne(_null())), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
IJExpression extraParameter = extraHandler.getExtraValue(parameter, extras, onResultBlock, holder);
onResultInvocation.arg(extraParameter);
} else if (CanonicalNameConstants.INTENT.equals(parameterType.toString())) {
onResultInvocation.arg(intent);
} else if (//
parameterType.getKind().equals(TypeKind.INT) || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
onResultInvocation.arg(holder.getOnActivityResultResultCodeParam());
}
}
onResultBlock.add(onResultInvocation);
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ItemSelectHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation itemSelectedCall, List<? extends VariableElement> parameters) {
AbstractJClass narrowAdapterViewClass = getClasses().ADAPTER_VIEW.narrow(getCodeModel().wildcard());
JVar onItemClickParentParam = listenerMethod.param(narrowAdapterViewClass, "parent");
listenerMethod.param(getClasses().VIEW, "view");
JVar onItemClickPositionParam = listenerMethod.param(getCodeModel().INT, "position");
listenerMethod.param(getCodeModel().LONG, "id");
itemSelectedCall.arg(JExpr.TRUE);
boolean hasItemParameter = parameters.size() == 2;
boolean secondParameterIsInt = false;
String secondParameterQualifiedName = null;
if (hasItemParameter) {
VariableElement secondParameter = parameters.get(1);
TypeMirror secondParameterType = secondParameter.asType();
secondParameterQualifiedName = secondParameterType.toString();
secondParameterIsInt = secondParameterType.getKind() == TypeKind.INT;
}
if (hasItemParameter) {
if (secondParameterIsInt) {
itemSelectedCall.arg(onItemClickPositionParam);
} else {
itemSelectedCall.arg(JExpr.cast(getJClass(secondParameterQualifiedName), invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
}
}
onNothingSelectedMethod.param(narrowAdapterViewClass, "parent");
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation nothingSelectedCall = invoke(activityRef, getMethodName());
onNothingSelectedMethod.body().add(nothingSelectedCall);
nothingSelectedCall.arg(JExpr.FALSE);
if (hasItemParameter) {
if (secondParameterIsInt) {
nothingSelectedCall.arg(lit(-1));
} else {
nothingSelectedCall.arg(_null());
}
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ViewNotifierHelper method implementHasViewsInHolder.
private void implementHasViewsInHolder() {
holder.getGeneratedClass()._implements(HasViews.class);
JCodeModel codeModel = environment.getCodeModel();
JDirectClass genericType = codeModel.directClass("T");
JMethod findViewById = holder.getGeneratedClass().method(PUBLIC, genericType, "internalFindViewById");
findViewById.generify("T", environment.getClasses().VIEW);
findViewById.annotate(Override.class);
JVar idParam = findViewById.param(codeModel.INT, "id");
IJExpression findViewByIdExpression = holder.getFindViewByIdExpression(idParam);
findViewById.body()._return(JExpr.cast(genericType, findViewByIdExpression));
}
Aggregations