use of androidx.annotation.Nullable in project butterknife by JakeWharton.
the class ButterKnife method parseBindDimen.
@Nullable
private static Unbinder parseBindDimen(Object target, Field field, View source) {
BindDimen bindDimen = field.getAnnotation(BindDimen.class);
if (bindDimen == null) {
return null;
}
validateMember(field);
int id = bindDimen.value();
Resources resources = source.getContext().getResources();
Class<?> fieldType = field.getType();
Object value;
if (fieldType == int.class) {
value = resources.getDimensionPixelSize(id);
} else if (fieldType == float.class) {
value = resources.getDimension(id);
} else {
throw new IllegalStateException("@BindDimen field type must be 'int' or 'float'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
}
trySet(field, target, value);
return Unbinder.EMPTY;
}
use of androidx.annotation.Nullable in project butterknife by JakeWharton.
the class ButterKnife method parseOnTouch.
@Nullable
private static Unbinder parseOnTouch(final Object target, final Method method, View source) {
OnTouch onTouch = method.getAnnotation(OnTouch.class);
if (onTouch == null) {
return null;
}
validateMember(method);
final boolean propagateReturn = validateReturnType(method, boolean.class);
final ArgumentTransformer argumentTransformer = createArgumentTransformer(method, ON_TOUCH_TYPES);
List<View> views = findViews(source, onTouch.value(), isRequired(method), method.getName(), View.class);
ViewCollections.set(views, ON_TOUCH, (v, event) -> {
Object returnValue = tryInvoke(method, target, argumentTransformer.transform(v, event));
// noinspection SimplifiableConditionalExpression
return propagateReturn ? (boolean) returnValue : true;
});
return new ListenerUnbinder<>(views, ON_TOUCH);
}
use of androidx.annotation.Nullable in project butterknife by JakeWharton.
the class ButterKnife method parseBindDrawable.
@Nullable
private static Unbinder parseBindDrawable(Object target, Field field, View source) {
BindDrawable bindDrawable = field.getAnnotation(BindDrawable.class);
if (bindDrawable == null) {
return null;
}
validateMember(field);
int id = bindDrawable.value();
int tint = bindDrawable.tint();
Context context = source.getContext();
Class<?> fieldType = field.getType();
Object value;
if (fieldType == Drawable.class) {
value = tint != Constants.NO_RES_ID ? Utils.getTintedDrawable(context, id, tint) : ContextCompat.getDrawable(context, id);
} else {
throw new IllegalStateException("@BindDrawable field type must be 'Drawable'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
}
trySet(field, target, value);
return Unbinder.EMPTY;
}
use of androidx.annotation.Nullable in project butterknife by JakeWharton.
the class ButterKnife method parseBindColor.
@Nullable
private static Unbinder parseBindColor(Object target, Field field, View source) {
BindColor bindColor = field.getAnnotation(BindColor.class);
if (bindColor == null) {
return null;
}
validateMember(field);
int id = bindColor.value();
Context context = source.getContext();
Object value;
Class<?> fieldType = field.getType();
if (fieldType == int.class) {
value = ContextCompat.getColor(context, id);
} else if (fieldType == ColorStateList.class) {
value = ContextCompat.getColorStateList(context, id);
} else {
throw new IllegalStateException("@BindColor field type must be 'int' or 'ColorStateList'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
}
trySet(field, target, value);
return Unbinder.EMPTY;
}
use of androidx.annotation.Nullable in project butterknife by JakeWharton.
the class ButterKnife method parseOnEditorAction.
@Nullable
private static Unbinder parseOnEditorAction(final Object target, final Method method, View source) {
OnEditorAction onEditorAction = method.getAnnotation(OnEditorAction.class);
if (onEditorAction == null) {
return null;
}
validateMember(method);
final boolean propagateReturn = validateReturnType(method, boolean.class);
final ArgumentTransformer argumentTransformer = createArgumentTransformer(method, ON_EDITOR_ACTION_TYPES);
List<TextView> views = findViews(source, onEditorAction.value(), isRequired(method), method.getName(), TextView.class);
ViewCollections.set(views, ON_EDITOR_ACTION, (v, actionId, event) -> {
Object value = tryInvoke(method, target, argumentTransformer.transform(v, actionId, event));
// noinspection SimplifiableConditionalExpression
return propagateReturn ? (boolean) value : true;
});
return new ListenerUnbinder<>(views, ON_EDITOR_ACTION);
}
Aggregations