Skip to content

Instantly share code, notes, and snippets.

View Annotations.csv
Bindings Listeners
BindAnim OnCheckedChanged
BindArray OnClick
BindBitmap OnEditorAction
BindBool OnFocusChange
BindColor OnItemClick
BindDimen OnItemLongClick
BindDrawable OnItemSelected
BindFloat OnLongClick
BindFont OnPageChange
View BindingSet-brewJava.java
JavaFile brewJava(int sdk, boolean debuggable) {
return JavaFile.builder(bindingClassName.packageName(), createType(sdk, debuggable))
.addFileComment("Generated code from Butter Knife. Do not modify!")
.build();
}
private TypeSpec createType(int sdk, boolean debuggable) {
TypeSpec.Builder result = TypeSpec.classBuilder(bindingClassName.simpleName())
.addModifiers(PUBLIC);
if (isFinal) {
View FinalRClassBuilder.java
public final class FinalRClassBuilder {
...
private static final String[] SUPPORTED_TYPES = {
"anim", "array", "attr", "bool", "color", "dimen", "drawable", "id", "integer", "layout", "menu", "plurals",
"string", "style", "styleable"
};
...
public static void brewJava(File rFile, File outputDir, String packageName, String className)
throws Exception {
CompilationUnit compilationUnit = JavaParser.parse(rFile);
View MyActivity.java
public class MyActivity extends Activity {
@BindView(R.id.my_text_view) TextView myTextView;
private Unbinder unbinder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// instead of reflection using
View Butterknife-createBinding.java
private static Unbinder createBinding(@NonNull Object target, @NonNull View source) {
Class<?> targetClass = target.getClass();
...
Constructor<? extends Unbinder> constructor = findBindingConstructorForClass(targetClass);
...
try {
return constructor.newInstance(target, source);
}
...
}
View ButterKnifeProcessor-parseListenerAnnotation.java
private void parseListenerAnnotation(Class<? extends Annotation> annotationClass, Element element,
Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames)
throws Exception {
...
ExecutableElement executableElement = (ExecutableElement) element;
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Assemble information on the method.
Annotation annotation = element.getAnnotation(annotationClass);
Method annotationValue = annotationClass.getDeclaredMethod("value");
View GeneratedViewBinding.java
...
public class MainActivity_ViewBinding implements Unbinder {
private MainActivity target;
@UiThread
public MainActivity_ViewBinding(MainActivity target) {
this(target, target.getWindow().getDecorView());
}
@UiThread
View ButterKnifeProcessor-parseBindView.java
private void parseBindView(Element element, Map<TypeElement, BindingSet.Builder> builderMap,
Set<TypeElement> erasedTargetNames) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
...
// Assemble information on the field.
int id = element.getAnnotation(BindView.class).value();
BindingSet.Builder builder = builderMap.get(enclosingElement);
QualifiedId qualifiedId = elementToQualifiedId(element, id);
if (builder != null) {
@ChaitanyaPramod
ChaitanyaPramod / Annotations
Last active Mar 26, 2018
Demystifying Butterknife snippets
View Annotations
BindAnim
BindArray
BindBitmap
BindBool
BindColor
BindDimen
BindDrawable
BindFloat
BindFont
BindInt
View ReParentViewGroup.java
package com.your.packagename.here;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import java.util.ArrayList;
You can’t perform that action at this time.