Release 2.0.1Beta

This commit is contained in:
hyb1996
2017-03-19 16:21:07 +08:00
parent 85affed538
commit dd787236e7
110 changed files with 2428 additions and 4710 deletions

View File

@@ -3,11 +3,14 @@ package com.stardust.view;
import android.view.View;
import android.widget.CompoundButton;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by Stardust on 2017/1/30.
*
* 哈你说我为什么不用AA框架之前还不知道嘛所以现在用了。
*/
public class ViewBinder {
@@ -21,6 +24,7 @@ public class ViewBinder {
throw new RuntimeException("You must implement findViewById to use view binding", e);
}
Method[] methods = o.getClass().getDeclaredMethods();
bindId(o, findViewById);
for (Method method : methods) {
method.setAccessible(true);
bindClick(o, method, findViewById);
@@ -28,6 +32,20 @@ public class ViewBinder {
}
}
private static void bindId(Object o, Method findViewById) {
for (Field field : o.getClass().getDeclaredFields()) {
field.setAccessible(true);
ViewBinding.Id id = field.getAnnotation(ViewBinding.Id.class);
if (id == null || id.value() == 0)
continue;
try {
field.set(o, findViewById.invoke(o, id.value()));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
private static void bindCheck(final Object o, final Method method, Method findViewById) {
ViewBinding.Check annotation = method.getAnnotation(ViewBinding.Check.class);
if (annotation == null || annotation.value() == 0)

View File

@@ -32,4 +32,10 @@ public @interface ViewBinding {
@interface Check {
int value();
}
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface Id {
int value();
}
}