use of org.androidannotations.holder.HasOnActivityResult 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