public class DraweeViewAnnotation {
@MyAnno(name = "Hello word")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "DraweeViewAnnotation{" +
"name='" + name + '\'' +
'}';
}
}
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Target({ElementType.FIELD,ElementType.METHOD})
@interface MyAnno {
public String name() default "Hello";
}
DiskCacheConfig my_images = DiskCacheConfig.newBuilder(this)
.setBaseDirectoryName("images")
.setBaseDirectoryPath(Environment.getDataDirectory())
.build();
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
.setMainDiskCacheConfig(my_images)
.build();
case R.id.zhu:
Method[] methods = DraweeViewAnnotation.class.getMethods();
Field[] fields = DraweeViewAnnotation.class.getDeclaredFields();
for (Field field : fields) {
MyAnno myAnno = field.getAnnotation(MyAnno.class);
if (myAnno != null) {
Toast.makeText(MainActivity.this, "sayHello: " + myAnno.name(), Toast.LENGTH_SHORT).show();
}
}
for (Method method : methods) {
MyAnno annotation = method.getAnnotation(MyAnno.class);
if (annotation != null) {
Toast.makeText(MainActivity.this, "sayHello: " + annotation.name(), Toast.LENGTH_SHORT).show();
}
}
break;