Successfully reported this slideshow.
Your SlideShare is downloading. ×

Groovy on Android

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
New adventures in 3D
New adventures in 3D
Loading in …3
×

Check these out next

1 of 53 Ad

Groovy on Android

Download to read offline

Presentation during Codemotion 2014 about using Groovy for Android development.

Presentation during Codemotion 2014 about using Groovy for Android development.

Advertisement
Advertisement

More Related Content

Similar to Groovy on Android (20)

Advertisement

Recently uploaded (20)

Advertisement

Groovy on Android

  1. 1. 1 Android and Groovy
  2. 2. 2 Mario Garcia Software Engineer Happily Working for @marioggar
  3. 3. 3 Let me tell you a story...
  4. 4. 4 Long Long time ago.... There was a back-end developer ...
  5. 5. 5 Long Long time ago.... He used to code using Groovy
  6. 6. 6 Long Long time ago.... But not all was happiness... At the beginning Groovy couldn't Work on Android
  7. 7. 7 But finally that day came.... During the GR8Conf...
  8. 8. 8 Cedric Champeau core developer Yes now you can!!! Released Groovy 2.4 :grooid Thanks Cedric!!!!
  9. 9. 9
  10. 10. 10 He took his mobile and.... Every seemed to be awesome but then ...
  11. 11. 11 Light became darkness because....
  12. 12. 12 Darkest hour No background on Android development Activity Fragment Layouts Adapters UIThread Bla bla... Bla bla... Bla bla...
  13. 13. 13 Darkest hour Almost no docs about Groovy on Android Cedric Champeau Blog http://melix.github.io/blog/ Github https://github.com/melix
  14. 14. 14 Create the first project.... Tools, tools everywhere ...
  15. 15. 15 Two paths %
  16. 16. 16 The Gradle Path Grab some of Cedric's projects Add what you need and build it Import to AS
  17. 17. 17 Gradle Hey is Groovy!! Less verbose than Maven Is code not XML Polyglot Same build tool for different languages At some point it should set you free from any IDE
  18. 18. 18 Gradle Plugins
  19. 19. 19 Gradle Android SDKs version
  20. 20. 20 Gradle Dependencies
  21. 21. 21 Android Studio Import your Gradle app
  22. 22. 22 Android Studio Project structure
  23. 23. 23 Java Path (Android Studio) Ask AS to create a Java project Add Cedric plugin Keep working
  24. 24. 24 Android Studio Or create a new Android/Gradle project
  25. 25. 25 He swore he would never... How can avoid repeating the whole process again ?
  26. 26. 26 Wish list Basic working Groovy skeleton Basic helpful dependencies to make my life less miserable Add Asciidoctor :) Add whatever you want...
  27. 27. 27 Lazybones What's lazybones A simple project creation tool that uses packaged project templates. Created by: Peter Leedbrook https://github.com/pledbrook/lazybones
  28. 28. 28 Lazybones With lazy bones he could: Basic working Groovy skeleton... DONE Basic dependencies to make my life less miserable... Add Asciidoctor... Add whatever you want... DONE DONE
  29. 29. 29 SHOW ME THE CODE How Groovy can help you ?
  30. 30. 30 Groovy by default At the beginning everything looked like Java:
  31. 31. 31 Groovy by default But even then if you looked a little bit closer... Some Groovy basic AST transformations saved precious lines Get rid of accessors
  32. 32. 32 Groovy by default Bean construction: Using map constructor:
  33. 33. 33 Groovy collections and more... Collections were more fun Filtering and mapping (find/collect)
  34. 34. 34 Closures Turn functional interfaces to functions (I): Whenever you have to implement an interface with just one method you can use a closure
  35. 35. 35 Closures Turn functional interfaces to functions (II): Whenever you have to implement an interface with just one method you can use a closure
  36. 36. 36 Closures - Fn Currying and MethodClosure: Plain Java methods can become high order functions
  37. 37. 37 Closures Functional Interface coertion:
  38. 38. 38 Traits Traits: Sometimes you have to extend different clases but still want to share some common behavior. (Activities/ListActivity) There are red lines because Android Studio doesn't recognize Traits...yet
  39. 39. 39 AST Transformations ASTs: Anytime you fill there is boilerplate code there is work for an AST to do You can create your own @ASTTest @AnnotationCollector @AutoClone @AutoExternalize @Canonical @ConditionalInterrupt @EqualsAndHashcode @Field @Immutable @IndexedProperty @InheritConstructors @Memoized @Sortable @TailRecursive @ThreadInterrupt @Trait @ToString @TupleConstructor @TypeChecked @Log @Log4j Still a few more
  40. 40. 40 SwissKnife A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and AndroidAnnotations
  41. 41. 41 SwissKnife Injecting Views. Forget about findViewById
  42. 42. 42 SwissKnife @OnBackground and @UIThread @OnBackground Creates an async task @UIThread It gets a handler instance to run the body in the UI thread
  43. 43. 43 SwissKnife @OnBackground and @UIThread
  44. 44. 44 SwissKnife @OnClick, @OnItemSelected... There are several other annotations for annotating methods you want to be triggered when an event occurs
  45. 45. 45 Grooid-tools A DSL for generating views with Groovy https://github.com/karfunkel/grooid-tools For example create a TextView s
  46. 46. 46 What about performance ? Faster, cleaner, cheaper...
  47. 47. 47 Performance Before blaming the language you may want to check if the problem is elsewhere ;)
  48. 48. 48 Performance @CompileStatic: It optimizes bytecode applying static check compilation Sorry, I don't have benchmarks on Android In the JDK we're doing well with InvokeDynamic On Android is advisable to use it...what please don't freak out !
  49. 49. 49 Performance http://open.blogs.nytimes.com/2014/08/?_r=0
  50. 50. 50 What's next ? The future
  51. 51. 51 Android Wear Stay tuned at http://melix.github.io/blog/
  52. 52. 52 Who knows ? Groovy Groovy everywhere
  53. 53. 53 Thank you … Q & A

×