Skip to content

Instantly share code, notes, and snippets.

View ChaitanyaPramod's full-sized avatar

Chaitanya Pramod ChaitanyaPramod

View GitHub Profile
Bindings Listeners
BindAnim OnCheckedChanged
BindArray OnClick
BindBitmap OnEditorAction
BindBool OnFocusChange
BindColor OnItemClick
BindDimen OnItemLongClick
BindDrawable OnItemSelected
BindFloat OnLongClick
BindFont OnPageChange
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) {
@ChaitanyaPramod
ChaitanyaPramod / Annotations
Last active March 26, 2018 04:52
Demystifying Butterknife snippets
BindAnim
BindArray
BindBitmap
BindBool
BindColor
BindDimen
BindDrawable
BindFloat
BindFont
BindInt
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);
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
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);
}
...
}
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");
...
public class MainActivity_ViewBinding implements Unbinder {
private MainActivity target;
@UiThread
public MainActivity_ViewBinding(MainActivity target) {
this(target, target.getWindow().getDecorView());
}
@UiThread
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 / index.html
Created July 3, 2013 10:01
Gist to test the bug due to which node-webkit 0.6.1 doesn't show tooltip popup with the content of the `title` attribute
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Title test</title>
<style>
#block {
background-color: lightblue;
height: 200px;
width: 200px;