際際滷

際際滷Share a Scribd company logo
Android Opensources
Wooseong Kim (???)
1 Yooii Studios
1. ButterKnife
2. Lombok
3.Android Annotations
Yooii Studios2
ButterKnife?
3 Yooii Studios
? http://jakewharton.github.io/butterknife/
? using Annotation Processing
? No more ?ndViewById in Activity, View,
ListAdapter etc.
? Simplify click listeners
ButterKnife
4 Yooii Studios
ButterKnife - before / at activity
class ExampleActivity extends Activity {
TextView title;
TextView subtitle;
TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
title = (TextView) ?ndViewById(R.id.title);
subtitle = (TextView) ?ndViewById(R.id.subtitle);
footer = (TextView) ?ndViewById(R.id.footer);
//TODO Use views...
}
}
5 Yooii Studios
ButterKnife - after / at activity
class ExampleActivity extends Activity {
@InjectView(R.id.title)TextView title;
@InjectView(R.id.subtitle)TextView subtitle;
@InjectView(R.id.footer)TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.inject(this);
//TODO Use "injected" views...
}
}
6 Yooii Studios
ButterKnife - after / at view
public class FancyFragment extends Fragment {
@InjectView(R.id.button1) Button button1;
@InjectView(R.id.button2) Button button2;
@OverrideView onCreateView(LayoutIn?ater in?ater,ViewGroup container, Bundle
savedInstanceState) {
View view = in?ater.in?ate(R.layout.fancy_fragment, container, false);
ButterKnife.inject(this, view);
//TODO Use "injected" views...
return view;
}
}
7 Yooii Studios
ButterKnife - after / at list adapter
public class MyAdapter extends BaseAdapter {
@Override publicView getView(int position,View view,ViewGroup parent) {
ViewHolder holder;
view = in?ater.in?ate(R.layout.whatever, parent, false);
holder = new ViewHolder(view);
holder.name.setText("John Doe");
// etc...
return convertView;
static classViewHolder {
@InjectView(R.id.title)TextView name;
@InjectView(R.id.job_title)TextView jobTitle;
publicViewHolder(View view) {
ButterKnife.inject(this, view);
}
}
}
8 Yooii Studios
ButterKnife - onClick
@OnClick({ R.id.door1, R.id.door2, R.id.door3 })
public void pickDoor(DoorView door) {
if (door.hasPrizeBehind()) {
Toast.makeText(this, "You win!", LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Try again", LENGTH_SHORT).show();
}
}
9 Yooii Studios
Lombok ?
10 Yooii Studios
? http://projectlombok.org/
? No more Getter / Setter!
Lombok
11 Yooii Studios
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
Lombok - after
public class GetterSetterExample {
@Getter @Setter private int age = 10;
@Setter(AccessLevel.PROTECTED) private String name;
}
13 Yooii Studios
Android
Annotations ?
14 Yooii Studios
Android Annotations - before
public class BookmarksToClipboardActivity extends Activity {
BookmarkAdapter adapter;
ListView bookmarkList;
EditText search;
BookmarkApplication application;
Animation fadeIn;
ClipboardManager clipboardManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN);
setContentView(R.layout.bookmarks);
bookmarkList = (ListView) ?ndViewById(R.id.bookmarkList);
search = (EditText) ?ndViewById(R.id.search);
application = (BookmarkApplication) getApplication();
fadeIn = AnimationUtils.loadAnimation(this, anim.fade_in);
clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
View updateBookmarksButton1 = ?ndViewById(R.id.updateBookmarksButton1);
updateBookmarksButton1.setOnClickListener(new OnClickListener() {
15 Yooii Studios
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
To be continued´
? Robolectric (2.2+) -Testing
- http://robolectric.org/
? Otto - Event handler using bus
- http://square.github.io/otto/
17 Yooii Studios
Thank you!
18 Yooii Studios

More Related Content

Android Opensources - ButterKnife, Lombok

  • 1. Android Opensources Wooseong Kim (???) 1 Yooii Studios
  • 2. 1. ButterKnife 2. Lombok 3.Android Annotations Yooii Studios2
  • 4. ? http://jakewharton.github.io/butterknife/ ? using Annotation Processing ? No more ?ndViewById in Activity, View, ListAdapter etc. ? Simplify click listeners ButterKnife 4 Yooii Studios
  • 5. ButterKnife - before / at activity class ExampleActivity extends Activity { TextView title; TextView subtitle; TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); title = (TextView) ?ndViewById(R.id.title); subtitle = (TextView) ?ndViewById(R.id.subtitle); footer = (TextView) ?ndViewById(R.id.footer); //TODO Use views... } } 5 Yooii Studios
  • 6. ButterKnife - after / at activity class ExampleActivity extends Activity { @InjectView(R.id.title)TextView title; @InjectView(R.id.subtitle)TextView subtitle; @InjectView(R.id.footer)TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.inject(this); //TODO Use "injected" views... } } 6 Yooii Studios
  • 7. ButterKnife - after / at view public class FancyFragment extends Fragment { @InjectView(R.id.button1) Button button1; @InjectView(R.id.button2) Button button2; @OverrideView onCreateView(LayoutIn?ater in?ater,ViewGroup container, Bundle savedInstanceState) { View view = in?ater.in?ate(R.layout.fancy_fragment, container, false); ButterKnife.inject(this, view); //TODO Use "injected" views... return view; } } 7 Yooii Studios
  • 8. ButterKnife - after / at list adapter public class MyAdapter extends BaseAdapter { @Override publicView getView(int position,View view,ViewGroup parent) { ViewHolder holder; view = in?ater.in?ate(R.layout.whatever, parent, false); holder = new ViewHolder(view); holder.name.setText("John Doe"); // etc... return convertView; static classViewHolder { @InjectView(R.id.title)TextView name; @InjectView(R.id.job_title)TextView jobTitle; publicViewHolder(View view) { ButterKnife.inject(this, view); } } } 8 Yooii Studios
  • 9. ButterKnife - onClick @OnClick({ R.id.door1, R.id.door2, R.id.door3 }) public void pickDoor(DoorView door) { if (door.hasPrizeBehind()) { Toast.makeText(this, "You win!", LENGTH_SHORT).show(); } else { Toast.makeText(this, "Try again", LENGTH_SHORT).show(); } } 9 Yooii Studios
  • 10. Lombok ? 10 Yooii Studios
  • 11. ? http://projectlombok.org/ ? No more Getter / Setter! Lombok 11 Yooii Studios
  • 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
  • 15. Android Annotations - before public class BookmarksToClipboardActivity extends Activity { BookmarkAdapter adapter; ListView bookmarkList; EditText search; BookmarkApplication application; Animation fadeIn; ClipboardManager clipboardManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN); setContentView(R.layout.bookmarks); bookmarkList = (ListView) ?ndViewById(R.id.bookmarkList); search = (EditText) ?ndViewById(R.id.search); application = (BookmarkApplication) getApplication(); fadeIn = AnimationUtils.loadAnimation(this, anim.fade_in); clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); View updateBookmarksButton1 = ?ndViewById(R.id.updateBookmarksButton1); updateBookmarksButton1.setOnClickListener(new OnClickListener() { 15 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