use of com.helger.jcodemodel.IJExpression 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.IJExpression in project androidannotations by androidannotations.
the class SharedPrefHandler method generateFieldMethodAndEditorFieldMethod.
private void generateFieldMethodAndEditorFieldMethod(Element element, SharedPrefHolder sharedPrefHolder) {
for (ExecutableElement method : getValidMethods(element)) {
IJExpression keyExpression = generateFieldMethod(sharedPrefHolder, method);
sharedPrefHolder.createEditorFieldMethods(method, keyExpression);
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class ReceiverHandler method registerAndUnregisterReceiver.
private void registerAndUnregisterReceiver(HasReceiverRegistration holder, Receiver.RegisterAt registerAt, JFieldVar intentFilterField, JFieldVar receiverField, boolean local) {
JBlock registerBlock = null;
JBlock unregisterBlock = null;
if (holder instanceof HasActivityLifecycleMethods) {
HasActivityLifecycleMethods activityLifecycleMethods = (HasActivityLifecycleMethods) holder;
switch(registerAt) {
case OnCreateOnDestroy:
registerBlock = activityLifecycleMethods.getOnCreateAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnDestroyBeforeSuperBlock();
break;
case OnStartOnStop:
registerBlock = activityLifecycleMethods.getOnStartAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnStopBeforeSuperBlock();
break;
case OnResumeOnPause:
registerBlock = activityLifecycleMethods.getOnResumeAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnPauseBeforeSuperBlock();
break;
}
if (holder instanceof EFragmentHolder && registerAt == Receiver.RegisterAt.OnAttachOnDetach) {
EFragmentHolder fragmentHolder = (EFragmentHolder) holder;
registerBlock = fragmentHolder.getOnAttachAfterSuperBlock();
unregisterBlock = fragmentHolder.getOnDetachBeforeSuperBlock();
}
} else {
registerBlock = holder.getStartLifecycleAfterSuperBlock();
unregisterBlock = holder.getEndLifecycleBeforeSuperBlock();
}
IJExpression broadcastManager;
if (local) {
if (getProcessingEnvironment().getElementUtils().getTypeElement(CanonicalNameConstants.LOCAL_BROADCAST_MANAGER) == null) {
broadcastManager = getClasses().ANDROIDX_LOCAL_BROADCAST_MANAGER.staticInvoke("getInstance").arg(holder.getContextRef());
} else {
broadcastManager = getClasses().LOCAL_BROADCAST_MANAGER.staticInvoke("getInstance").arg(holder.getContextRef());
}
} else {
broadcastManager = holder.getContextRef();
}
registerBlock.invoke(broadcastManager, "registerReceiver").arg(receiverField).arg(intentFilterField);
unregisterBlock.invoke(broadcastManager, "unregisterReceiver").arg(receiverField);
}
use of com.helger.jcodemodel.IJExpression 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.IJExpression 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);
}
Aggregations