@Override public void unbind() { trySet(field, target, null); } }
private static @Nullable Unbinder parseBindBool(Object target, Field field, View source) { BindBool bindBool = field.getAnnotation(BindBool.class); if (bindBool == null) { return null; } validateMember(field); int id = bindBool.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == boolean.class) { value = resources.getBoolean(id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindInt(Object target, Field field, View source) { BindInt bindInt = field.getAnnotation(BindInt.class); if (bindInt == null) { return null; } validateMember(field); int id = bindInt.value(); Resources resources = source.getContext().getResources(); Class<?> fieldType = field.getType(); Object value; if (fieldType == int.class) { value = resources.getInteger(id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindBitmap(Object target, Field field, View source) { BindBitmap bindBitmap = field.getAnnotation(BindBitmap.class); if (bindBitmap == null) { return null; } validateMember(field); int id = bindBitmap.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == Bitmap.class) { value = BitmapFactory.decodeResource(resources, id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindString(Object target, Field field, View source) { BindString bindString = field.getAnnotation(BindString.class); if (bindString == null) { return null; } validateMember(field); int id = bindString.value(); Context context = source.getContext(); Class<?> fieldType = field.getType(); Object value; if (fieldType == String.class) { value = context.getString(id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable 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(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindAnim(Object target, Field field, View source) { BindAnim bindAnim = field.getAnnotation(BindAnim.class); if (bindAnim == null) { return null; } validateMember(field); int id = bindAnim.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == Animation.class) { value = resources.getAnimation(id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindFloat(Object target, Field field, View source) { BindFloat bindInt = field.getAnnotation(BindFloat.class); if (bindInt == null) { return null; } validateMember(field); int id = bindInt.value(); Context context = source.getContext(); Class<?> fieldType = field.getType(); Object value; if (fieldType == float.class) { value = Utils.getFloat(context, id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable 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(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindArray(Object target, Field field, View source) { BindArray bindArray = field.getAnnotation(BindArray.class); if (bindArray == null) { return null; } validateMember(field); int id = bindArray.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == TypedArray.class) { value = resources.obtainTypedArray(id); } else if (fieldType.isArray()) { Class<?> componentType = fieldType.getComponentType(); if (componentType == String.class) { value = resources.getStringArray(id); } else if (componentType == int.class) { value = resources.getIntArray(id); } else if (componentType == CharSequence.class) { value = resources.getTextArray(id); } else { throw new IllegalStateException(); // TODO } } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable 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(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static @Nullable Unbinder parseBindFont(Object target, Field field, View source) { BindFont bindFont = field.getAnnotation(BindFont.class); if (bindFont == null) { return null; } validateMember(field); int id = bindFont.value(); int style = bindFont.style(); Context context = source.getContext(); Class<?> fieldType = field.getType(); Object value; if (fieldType == Typeface.class) { Typeface font = ResourcesCompat.getFont(context, id); value = style != Typeface.NORMAL ? Typeface.create(font, style) : font; } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
trySet(field, target, value); return new FieldUnbinder(target, field);
private static @Nullable Unbinder parseBindView(Object target, Field field, View source) { BindView bindView = field.getAnnotation(BindView.class); if (bindView == null) { return null; } validateMember(field); int id = bindView.value(); boolean isRequired = isRequired(field); Class<?> viewClass = field.getType(); String who = "field '" + field.getName() + "'"; Object view; if (isRequired) { view = Utils.findRequiredViewAsType(source, id, who, viewClass); } else { view = Utils.findOptionalViewAsType(source, id, who, viewClass); } trySet(field, target, view); return new FieldUnbinder(target, field); }