Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Choosing Right!

Choosing Right!

How an Android library can fix your needs.

Alexey Buzdin

February 19, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. Choosing Right! How an Android library can fix your needs

  2. Alexey Buzdin

  3. ORMs - Fast

  4. ORMs - Fast - Supports Cursor

  5. Cursor new FlowCursorList<>(true, TestModel.class, Condition.column(TestModel$Table.NAME) .like("pasta%")); on getItem -> move

    Cursor
  6. ORMs - Fast - Supports Cursor - Supports Migration

  7. ORMs - Fast - Supports Cursor - Supports Migration -

    Supports Query Syntax
  8. Query Syntax new Select().from(Item.class) .orderBy(“RANDOM()") .executeSingle();

  9. ORMs Bonus points - Model Callbacks

  10. Model Callbacks @Override protected void beforeSave() { updatedAt = System.currentTimeMillis();

    } @Override protected void afterDelete() { // clean up some things? }
  11. ORMs Bonus points - Supports Relations - Model Callbacks

  12. ORMs Bonus points - Supports Relations - Model Callbacks -

    Supports Custom Converters - Supports Transactions
  13. ORMs Bonus points - Supports Relations - Model Callbacks -

    Supports Custom Converters - Supports Transactions
  14. DBFlow https://github.com/Raizlabs/DBFlow ActiveAndroid ORMLite Ollie https://github.com/pardom/ActiveAndroid https://github.com/pardom/Ollie https://github.com/j256/ormlite-android https://github.com/emilsjolander/sprinkles Sprinkles

  15. Images - Image transformations - ImageView recycling - Automatic memory

    and disk caching
  16. Images https://github.com/loopj/android-smart-image-view https://github.com/square/picasso

  17. Dependency Injection - Fast - No boilerplate - Minimum configuration

    - Support scopes and providers - Android system services in scope
  18. Dependency Injection https://github.com/google/dagger https://github.com/roboguice/roboguice https://github.com/square/dagger RoboGuice 3.0 Dagger Dagger 2.0

  19. RoboGuice Defaults https://github.com/roboguice/roboguice/blob/master/ roboguice/src/main/java/roboguice/config/ DefaultRoboModule.java

  20. Dagger

  21. Dagger 2.0

  22. Resource Injection - View injection - Resource injection - Listeners

    injection
  23. InjectViews 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... } }
  24. InjectView Holder static class ViewHolder { @InjectView(R.id.title) TextView name; @InjectView(R.id.job_title)

    TextView jobTitle; public ViewHolder(View view) { ButterKnife.inject(this, view); } }
  25. Listeners @OnClick(R.id.submit) public void submit(View view) { // TODO submit

    data to server... } @OnItemSelected(R.id.list_view) void onItemSelected(int position) { // TODO ... }
  26. Inject Resource public class MyActivity extends RoboActivity { @InjectResource(R.anim.my_animation) Animation

    myAnimation; @InjectResource(R.string.app_name) String appName; // the rest of your code }
  27. Resource Injection RoboGuice 3.0 https://github.com/roboguice/roboguice ButterKnife https://github.com/JakeWharton/butterknife AndroidAnnotations https://github.com/excilys/androidannotations

  28. REST - Multipart request body and file upload - Support

    URL param and query param - Support JSON, XML - Header Manipulation
  29. REST https://github.com/square/retrofit Retrofit AndroidAnnotations https://github.com/excilys/androidannotations

  30. AndroidAnnotations @Rest("http://www.bookmarks.com") public interface BookmarkClient { @Get("/bookmarks/{userId}?search={search}") Bookmarks getBookmarks(String search,

    String userId); } ……. @RestService BookmarkClient restClient; …….
  31. Retrofit RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("https://api.github.com") .build(); GitHubService service

    = restAdapter.create(GitHubService.class); public interface GitHubService { @GET("/users/{user}/repos") List<Repo> listRepos(@Path("user") String user); }
  32. HTTP http://loopj.com/android-async-http/ Android Async Http https://github.com/square/okhttp OK-Http

  33. Tests https://github.com/square/assertj-android https://github.com/robolectric/robolectric https://github.com/RobotiumTech/robotium https://code.google.com/p/android-test-kit/wiki/Espresso AssertJ Robolectric Espresso Robotium

  34. Robotium public void testPreferenceIsSaved() throws Exception { Solo solo =

    new Solo(getInstrumentation(), getActivity()); solo.clickOnText("txt"); solo.clearEditText(2); solo.enterText(2, "robotium"); solo.clickOnButton("Save"); solo.goBack(); solo.clickOnText("Edit File Extensions"); assertTrue(solo.searchText(“application/robotium")); } } public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> {
  35. Robolectric @RunWith(RobolectricTestRunner.class) public class MyActivityTest { @Test public void clickingButton_shouldChangeResultsViewText()

    throws Exception { Activity activity = Robolectric.buildActivity(MyActivity.class).create().get(); Button pressMeButton = (Button) activity.findViewById(R.id.press_me_button); TextView results = (TextView) activity.findViewById(R.id.results_text_view); pressMeButton.performClick(); String resultsText = results.getText().toString(); assertThat(resultsText, equalTo("Testing Android Rocks!")); } }
  36. AssertJ assertThat(layout).isVisible() .isVertical() .hasChildCount(4) .hasShowDividers(SHOW_DIVIDERS_MIDDLE); assertThat(view).isGone();

  37. Validation https://github.com/inmite/android-validation-komensky https://github.com/ragunathjawahar/android-saripaar Android Validation Komensky Android Saripaar

  38. Android Saripaar @NotEmpty @Email private EditText emailEditText; @Password(min = 6,

    scheme = Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS) private EditText passwordEditText; @ConfirmPassword private EditText confirmPasswordEditText; @Checked(message = "You must agree to the terms.") private CheckBox iAgreeCheckBox; new Validator(this).validate();
  39. Android Validation Komensky @NotEmpty(messageId = R.string.validation_name) @MinLength(value = 3, messageId

    = R.string.validation_name_length, order = 2) private EditText mNameEditText; FormValidator.validate(this, new SimpleErrorPopupCallback(this));
  40. Misc Pidcat https://github.com/square/otto Otto https://github.com/JakeWharton/pidcat https://github.com/avast/android-butterknife-zelezny Android Butterknife Zelezny

  41. Pidcat

  42. Android Butterknife Zelezny

  43. Otto Bus bus = new Bus(); bus.post(new AnswerAvailableEvent(42)); @Subscribe public

    void answerAvailable(AnswerAvailableEvent event) { // TODO: React to the event somehow! } bus.register(this); @Produce public AnswerAvailableEvent produceAnswer() { // Assuming 'lastAnswer' exists. return new AnswerAvailableEvent(this.lastAnswer); }