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

3rd Party Android

3rd Party Android

Slides from my talk on Google IO extended event in May 2016 about introduction to various 3rd party libraries in Android

Kshitij Aggarwal

May 19, 2016
Tweet

More Decks by Kshitij Aggarwal

Other Decks in Programming

Transcript

  1. JWAP (Jake Wharton Assisted Programming) • ButterKnife • Retrofit/Volley •

    Timber • Picasso/Glide • OkHttp • Dagger • Realm • Stetho
  2. JWAP (Jake Wharton Assisted Programming) • ButterKnife • Retrofit/Volley •

    Timber • Picasso/Glide • OkHttp • Dagger • Realm • Stetho
  3. ButterKnife • http://jakewharton.github.io/butterknife/ @BindView(R.id.tv_total_items) TextView tvTotalItems; @BindView(R.id.pb_login) ProgressBar progressBar; @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); ButterKnife.bind(this); } @OnClick(R.id.nav_home) public void goToHome() { //Code to run on click of home }
  4. ButterKnife Pros • You write less code • Cached findViewById

    calls • No Need to write setOnClickListener • Group click handler listeners • Cleaner code overall • Loads of other convenience annotations Cons • Issue with RecyclerViews click handling • Major changes between versions • Runtime errors
  5. Retrofit • http://square.github.io/retrofit/ public interface GitHubService { @GET("users/{user}/repos") Call<List<Repo>> listRepos(@Path("user")

    String user); @GET("group/{id}/users") Call<List<User>> groupList(@Path("id") int groupId); } Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.github.com/") .build(); GitHubService service = retrofit.create(GitHubService.class); Call<List<Repo>> repos = service.listRepos("octocat");
  6. Retrofit Pros • You write less code • Everything is

    done for you • Pluggable infrastructure • Ability to add network interceptors (e.g. Stetho) • Bundle with OkHttp3, Okio, Moshi for a world class network architecture • Cleaner code overall • Loads of other convenience annotations Cons • None that I could find
  7. Timber • https://github.com/JakeWharton/timber Timber.plant(new Timber.DebugTree()); Timber.e(throwable, "No Session at app

    Launch"); Timber.d("Session Loaded " + sessionIdPojo); 05-18 11:44:22.909 3053-3053/com.android D/MyApplication: Session Loaded 44tslt6pf85tvsb59qefnd1ba2
  8. Timber Pros • You write less code • No need

    for TAG • Awesome way to log errors • Gives you control when and where logs will appear • Pluggable Infrastructure e.g. Crashlytics • Great Open Source project to learn from Cons • None that I could find
  9. Picasso Pros • You write less code • Auto request

    cancellation in list adapters • Auto managed memory • One of the best ways to handle images in the most optimised way • Disc & Memory caching Cons • None that I could find
  10. OkHttp • http://square.github.io/okhttp/ OkHttpClient client = new OkHttpClient(); String run(String

    url) throws IOException { Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string(); }
  11. OkHttp Pros • You write less code • Much simpler

    way to handle network requests • Supports the latest Web protocol standards like HTTP/2, SPDY etc • Updated outside the platform to get the latest version • Better handles exceptional cases • Asynchronous built in Cons • None that I could find
  12. Realm • http://realm.io public class Dog extends RealmObject { @Required

    // Name cannot be null private String name; private int age; } Dog dog = new Dog(); dog.setName("Rex"); dog.setAge(1); RealmConfiguration realmConfig = new RealmConfiguration.Builder(context).build(); Realm realm = Realm.getInstance(realmConfig); realm.beginTransaction(); realm.copyToRealm(dog); realm.commitTransaction(); final RealmResults<Dog> puppies = realm.where(Dog.class).lessThan("age", 2).findAll();
  13. Realm Pros • You write less code • No-SQL all

    the things • Ridiculously easy to read & write data • Much natural way of thinking about data storage • Faster than Ferrari Cons • Unstable API’s. Still under active development • Easy to forget about read/write state conflict
  14. Honorary Mentions • Joda Time (https://github.com/dlew/joda-time-android) • Event Bus (https://github.com/greenrobot/EventBus)

    • Dagger (http://square.github.io/dagger/) • Stetho (http://facebook.github.io/stetho/) • Glide (https://github.com/bumptech/glide) • Volley (https://developer.android.com/training/volley/request.html) • Moshi (https://github.com/square/moshi)