Tuesday, 29 October 2013

Droidcon 2013: Ship Faster With Open Source from Square

Pierre-Yves Ricau, Square @piwai

Sample project: http://github.com/pyricau/shipfaster

  • look out for talk later at devoxx about how square got rid of fragments
  • debug panel in app, slides from right
    • lets you adjust the settings

dagger dependency injection

https://github.com/square/dagger

  • create object graph in application
  • injection happens in activity onCreate (prob. base class)
  • can switch between modules when create graph (e.g. using build settings)
  • resolves dependencies at compile time as it’s annotation based
    • don’t get errors at run time
    • doesn’t use reflection so faster
  • also generates dot files so can view dependency graph

otto

https://github.com/square/otto

  • (the bus driver in the Simpsons…)
  • broadcasts are not type safe and fragile
  • define event classes
  • the bus then calls the event methods for all subscribers
  • also provides an event logger
  • events are called synchronously

dagger & otto together

  • use a custom annotation with dagger bindings
  • can then add subscription/unsubscription easily

robolectric

http://robolectric.org/

  • main developer now at square…

retrofit REST client

https://github.com/square/retrofit

  • define an interface for API
  • methods take a callback method
  • callback will happen on UI thread
  • suggestion: use otto bus to fire events on return
  • create a RestAdapter and plug it in using dagger
  • has a log level to show you all headers
  • also works with protocol buffers
  • async by default, but can also do sync if you want to do multiple serialized calls from a background thread
  • can use underneath robospice

picasso

https://github.com/square/picasso

  • image loader from URLs
  • placeholder & error images
  • resize dimensions
  • don’t need to deal with http or caching at all!
  • has debug indicator corners on images:
    • green from memory
    • yellow from filesystem
    • red from network
  • can apply transforms to images
  • handles large images well
  • adjusts threads for downloading & encoding according to network status (wifi, 3G)
  • but may not respect cache expiry headers… (poss only when not used with OkHttp)

OkHttp

https://github.com/square/okhttp

  • Android has switched from Apache HttpClient to URLConnection
  • HttpClient no longer maintained in Android :-(
  • OkHttp now part of AOSP!
  • create a client and retrieve an HttpURLConnection
  • used by retrofit and picasso by default

more info available

No comments: