butterknife.compiler.FieldDrawableBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of butterknife-compiler Show documentation
Show all versions of butterknife-compiler Show documentation
Field and method binding for Android views.
package butterknife.compiler;
import com.squareup.javapoet.CodeBlock;
import static butterknife.compiler.BindingSet.CONTEXT_COMPAT;
import static butterknife.compiler.BindingSet.UTILS;
final class FieldDrawableBinding implements ResourceBinding {
private final Id id;
private final String name;
private final Id tintAttributeId;
FieldDrawableBinding(Id id, String name, Id tintAttributeId) {
this.id = id;
this.name = name;
this.tintAttributeId = tintAttributeId;
}
@Override public Id id() {
return id;
}
@Override public boolean requiresResources(int sdk) {
return false;
}
@Override public CodeBlock render(int sdk) {
if (tintAttributeId.value != 0) {
return CodeBlock.of("target.$L = $T.getTintedDrawable(context, $L, $L)", name, UTILS, id.code,
tintAttributeId.code);
}
if (sdk >= 21) {
return CodeBlock.of("target.$L = context.getDrawable($L)", name, id.code);
}
return CodeBlock.of("target.$L = $T.getDrawable(context, $L)", name, CONTEXT_COMPAT, id.code);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy