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. Model Callbacks @Override protected void beforeSave() { updatedAt = System.currentTimeMillis();

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

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

    Supports Custom Converters - Supports Transactions
  4. Dependency Injection - Fast - No boilerplate - Minimum configuration

    - Support scopes and providers - Android system services in scope
  5. 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... } }
  6. 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); } }
  7. 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 ... }
  8. 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 }
  9. REST - Multipart request body and file upload - Support

    URL param and query param - Support JSON, XML - Header Manipulation
  10. 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); }
  11. 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> {
  12. 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!")); } }
  13. 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();
  14. 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));
  15. 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); }