net.sf.andromedaioc.annotation.processor.ResourceAnnotationProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of andromeda-ioc Show documentation
Show all versions of andromeda-ioc Show documentation
Inversion of Control Framework for Android
The newest version!
package net.sf.andromedaioc.annotation.processor;
import android.app.Activity;
import net.sf.andromedaioc.annotation.Resource;
import net.sf.andromedaioc.context.AndromedaContext;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Process Resource annotation
*
* @author Alexey Mitrov
*/
public class ResourceAnnotationProcessor implements AnnotationProcessor {
public void process(Object target, Activity activity, AnnotatedElement annotated, AndromedaContext andromedaContext) throws Exception {
Resource resource = annotated.getAnnotation(Resource.class);
int id = resource.id();
Object resourceValue = andromedaContext.getResourceProvider().getAndroidResource(id);
if(annotated instanceof Field) {
Field field = (Field) annotated;
field.setAccessible(true);
field.set(target, resourceValue);
} else if(annotated instanceof Method) {
Method method = (Method) annotated;
method.invoke(target, resourceValue);
}
}
public boolean canProcessService() {
return true;
}
}