All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.andromedaioc.annotation.processor.ResourceAnnotationProcessor Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy