This document discusses three Android annotation libraries: ButterKnife, Lombok, and Android Annotations. It provides examples of how each library can simplify finding and injecting views, generating getters and setters, and processing annotations for Android activities without requiring as much boilerplate code. Specific features covered include ButterKnife's injection of views to reduce findViewById calls, Lombok's automatic generation of getters and setters, and Android Annotations' processing of annotations for configuration and injection in Android classes.
12. Lombok - before
public class GetterSetterExample {
private int age = 10;
private String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
protected void setName(String name) {
this.name = name;
}
}
12 Yooii Studios
13. Lombok - after
public class GetterSetterExample {
@Getter @Setter private int age = 10;
@Setter(AccessLevel.PROTECTED) private String name;
}
13 Yooii Studios
16. Android Annotations - after
@NoTitle
@Fullscreen
@EActivity(R.layout.bookmarks)
public class BookmarksToClipboardActivity extends Activity {
BookmarkAdapter adapter;
@ViewById ListView bookmarkList;
@ViewById EditText search;
@App BookmarkApplication application;
@RestService BookmarkClient restClient;
@AnimationRes Animation fadeIn;
@SystemService ClipboardManager clipboardManager;
@AfterViews // instead of onCreate() (called after injecting)
void initBookmarkList() {
adapter = new BookmarkAdapter(this);
bookmarkList.setAdapter(adapter);
}
16 Yooii Studios
17. To be continued´
? Robolectric (2.2+) -Testing
- http://robolectric.org/
? Otto - Event handler using bus
- http://square.github.io/otto/
17 Yooii Studios