Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Groovy android

2.873 visualizaciones

Publicado el

See how Groovy can help you in your Android development. From language basics to advanced features such as ASTs or Extension Modules. Also there's room for talking about testing and reactive programming.

Publicado en: Tecnología
  • Sé el primero en comentar

Groovy android

  1. 1. Android Apps with Groovy
  2. 2. About me ● Mario Garcia – Software engineer at Kaleidos https://github.com/mariogarcia @marioggar
  3. 3. Before I begin... ● Thanks to Tuenti ● Disclaimer – I'm not an Android developer – Questions welcomed :)
  4. 4. What is this talk about ? ● Summary – Android is NOT ONLY Java – Your first Grooid app – Groovy features – Useful libraries – Reactive – Testing – Q & A
  5. 5. Android is NOT ONLY Java ● Why not Groovy ? – Why not… ? – Chose your poison:
  6. 6. Create your first Android/Groovy app
  7. 7. Create your first Groovy app ● The Android Studio wizard – Meant for Java – If you go this way, then: ● Create a Java app through the wizard ● Add Groovy/Gradle plugin ● Add needed basic dependencies ● …
  8. 8. Create your first Groovy app ● A better way: – Create a basic skeleton with Lazybones – Import as Gradle project to Android Studio – Profit!
  9. 9. Create your first Groovy app ● Lazybones – A simple project creation tool – Templates – Really easy to use and extend
  10. 10. Create your first Groovy app ● Grooid templates – Lazybones templates for creating: ● Android app, Android lib ● Coming soon: Google Glass app
  11. 11. Create your first Groovy app ● Gradle – Android Reference build tool – Convention over Configuration – Still thinking of Maven ? check this out: ● https://gradle.org/maven_vs_gradle/
  12. 12. Create your first Groovy app ● Android Studio – Reference IDE based on Intellij IDEA – Really helpful specially for UI – Integrates perfectly with Gradle projects
  13. 13. Create your first Groovy app ● Demo
  14. 14. Groovy features out-of-the-box
  15. 15. Groovy features ● Domain classes ● Get rid of accessors ● No need to override constructors ● More AST to do pumbling staf – @AutoExternalize – @Canonical – @Immutable – @InheritConstructors – …. many more
  16. 16. Groovy features ● Beans
  17. 17. Groovy features ● Constructors
  18. 18. Groovy features ● GDK – Groovy extensions to the JDK ● Groovy collections (collect/inject/find) ● Safe methods to deal with JDK Classes – e.g: take(int) : use it instead of substring
  19. 19. Groovy features ● NPE and Exceptions – NPE ● ? operator ● * operator ● Elvis :? – Exceptions ● Go functional || Reactive – FNZ: Try<T>, Maybe<T> – RxJava/RxAndroid: onError()
  20. 20. Groovy features ● Safe operators
  21. 21. Groovy Features ● FNZ
  22. 22. Groovy features ● Closures ● No need to create inner classes anymore ● Wherever there is a Functional Interface you can use a Closure ● Also useful when creating DSLs
  23. 23. Groovy features ● Closures
  24. 24. Groovy features ● Closures (cont)
  25. 25. Groovy features ● DSLs
  26. 26. Groovy features ● Traits – Have you ever wanted to share some functionality between an Activity and a ListActivity ? ● Another way to share functionality among class hierarchies ● Used as if it were an interface ● IDE friendly
  27. 27. Groovy features Provides waiting spinner Provides easier call to Toast.makeXXX ● Traits
  28. 28. Groovy advanced Features
  29. 29. Advanced features ● Extension Modules – Add new functionality to existing code – Easy to use and program ● Just classes with static methods ● Android Studio recognizes Extension Modules out-of- the-box
  30. 30. Advanced features Busted! ● Extension modules
  31. 31. Advanced features ● Custom ASTs – Add new functionality to existing code ● During compilation time ● Extremely powerful ● No need for an annotation-processor ● Harder to code than Extension Modules
  32. 32. Advanced features ● Show a dialog
  33. 33. Advanced features
  34. 34. Advanced features
  35. 35. Advanced features ● Swissknife – Makes easier to deal with view injection and threading nightmare. ● Based on AndroidAnnotations and ButterKnife ● Collection of: ASTs, DSLs, Extension Modules
  36. 36. Reactive Programming
  37. 37. Reactive Programming ● RxAndroid + Groovy – Less verbose than using Java: ● Closures and Functional Interface coertion ● Composable Closures ● Method Reference
  38. 38. Code
  39. 39. Testing And Quality
  40. 40. Testing ● Spock – A better way of testing ● DSL to describe your tests in a fluent way ● Compatible with JUnit
  41. 41. Testing ● AndroidSpock – Create integration tests ● Under src/androidTest/groovy ● Helpers to inject and initialize activities in your tests ● Deploys and run tests in the device
  42. 42. Testing ● Robospock – Create unit tests ● Based on roboelectric 3.0 ● no DEXing or deployment time is wasted to execute your unit tests.
  43. 43. Other tools ● Quality code – Codenarc ● Static analysis for Groovy ● Highly Configurable ● Completely integrated with Gradle
  44. 44. References ● Links ● Android Studio – https://developer.android.com/sdk/index.html ● Lazybones – https://github.com/pledbrook/lazybones ● Grooid templates – https://github.com/mariogarcia/grooid-templates ● Swissknife – https://github.com/Arasthel/SwissKnife ● AndroidRx – https://github.com/ReactiveX/RxAndroid
  45. 45. References ● Links ● Spock – http://spockframework.github.io/spock/docs/1.0/index.html ● Android Spock – https://github.com/pieces029/android-spock ● Robo Spock – http://robospock.org/ ● Gradle – https://gradle.org/ ● Groovy Lang – http://www.groovy-lang.org/
  46. 46. References ● Links ● Codenarc – http://codenarc.sourceforge.net/ ● FNZ – http://mariogarcia.github.io/fnz/
  47. 47. Q & A
  48. 48. Common question ● Size of Groovy :grooid ?
  49. 49. Thanks!!

×