SlideShare a Scribd company logo
1 of 53
Download to read offline
1 
Android and Groovy
2 
Mario Garcia 
Software Engineer 
Happily Working for 
@marioggar
3 
Let me tell you a story...
4 
Long Long time ago.... 
There was a back-end developer ...
5 
Long Long time ago.... 
He used to code using Groovy
6 
Long Long time ago.... 
But not all was happiness... 
At the beginning Groovy couldn't 
Work on Android
7 
But finally that day came.... 
During the GR8Conf...
8 
Cedric Champeau 
core developer 
Yes now you can!!! 
Released Groovy 2.4 :grooid 
Thanks 
Cedric!!!!
9
10 
He took his mobile and.... 
Every seemed to be awesome 
but then ...
11 
Light became darkness because....
12 
Darkest hour 
No background on Android development 
Activity 
Fragment 
Layouts 
Adapters 
UIThread 
Bla bla... 
Bla bla... 
Bla bla...
13 
Darkest hour 
Almost no docs about Groovy on Android 
Cedric Champeau 
Blog http://melix.github.io/blog/ 
Github https://github.com/melix
14 
Create the first project.... 
Tools, tools everywhere 
...
15 
Two paths 
%
16 
The Gradle Path 
Grab some of Cedric's projects 
Add what you need and build it 
Import to AS
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 
Gradle 
Plugins
19 
Gradle 
Android SDKs version
20 
Gradle 
Dependencies
21 
Android Studio 
Import your Gradle app
22 
Android Studio 
Project structure
23 
Java Path (Android Studio) 
Ask AS to create a Java project 
Add Cedric plugin 
Keep working
24 
Android Studio 
Or create a new Android/Gradle project
25 
He swore he would never... 
How can avoid repeating 
the whole process again ?
26 
Wish list 
Basic working Groovy skeleton 
Basic helpful dependencies to make my life less miserable 
Add Asciidoctor :) 
Add whatever you want...
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 
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 
SHOW ME THE CODE 
How Groovy can help you ?
30 
Groovy by default 
At the beginning everything looked like Java:
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 
Groovy by default 
Bean construction: 
Using map constructor:
33 
Groovy collections and more... 
Collections were more fun 
Filtering and mapping (find/collect)
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 
Closures 
Turn functional interfaces to functions (II): 
Whenever you have to implement an interface with just one method you can 
use a closure
36 
Closures - Fn 
Currying and MethodClosure: 
Plain Java methods can become high order functions
37 
Closures 
Functional Interface coertion:
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 
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 
SwissKnife 
A multi-purpose Groovy library containing view injection and threading for 
Android using annotations. It's based on both ButterKnife and 
AndroidAnnotations
41 
SwissKnife 
Injecting Views. Forget about findViewById
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 
SwissKnife 
@OnBackground and @UIThread
44 
SwissKnife 
@OnClick, @OnItemSelected... 
There are several other annotations for annotating methods you want to be 
triggered when an event occurs
45 
Grooid-tools 
A DSL for generating views with Groovy 
https://github.com/karfunkel/grooid-tools 
For example create a TextView 
s
46 
What about performance ? 
Faster, cleaner, cheaper...
47 
Performance 
Before blaming the language you may want to check if the 
problem is elsewhere ;)
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 
Performance 
http://open.blogs.nytimes.com/2014/08/?_r=0
50 
What's next ? 
The future
51 
Android Wear 
Stay tuned at 
http://melix.github.io/blog/
52 
Who knows ? 
Groovy Groovy everywhere
53 
Thank you … 
Q & A

More Related Content

Similar to Groovy on Android

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1benDesigning
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...Ambassador Labs
 
Making Security Invisible
Making Security InvisibleMaking Security Invisible
Making Security InvisibleJ On The Beach
 
I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...Neil Crosby
 
Show you mine
Show you mineShow you mine
Show you mineviemonde
 
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / ConspectKo Turk
 
JVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsJVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsKo Turk
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptDarren Adkinson
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedWojciech Koszek
 
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Horgix
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0André Moreira
 
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodonePrototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodoneCodemotion
 
App inventor presentation
App inventor presentationApp inventor presentation
App inventor presentationAndrew Kamau
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)YangJerng Hwa
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Openstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkOpenstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkAndrew Shafer
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 

Similar to Groovy on Android (20)

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
 
Making Security Invisible
Making Security InvisibleMaking Security Invisible
Making Security Invisible
 
I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...
 
Show you mine
Show you mineShow you mine
Show you mine
 
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
 
JVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsJVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEs
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScript
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learned
 
SWT - Technical Deep Dive
SWT - Technical Deep DiveSWT - Technical Deep Dive
SWT - Technical Deep Dive
 
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0
 
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodonePrototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
 
App inventor presentation
App inventor presentationApp inventor presentation
App inventor presentation
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Openstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkOpenstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud Framework
 
Groovy android
Groovy androidGroovy android
Groovy android
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 

More from Mario García

Blockchain 101 (spanish)
Blockchain 101 (spanish)Blockchain 101 (spanish)
Blockchain 101 (spanish)Mario García
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Mario García
 
Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Mario García
 
Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Mario García
 
Macro macro, burrito burrit
Macro macro, burrito burritMacro macro, burrito burrit
Macro macro, burrito burritMario García
 
Creating ASTTs The painful truth
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truthMario García
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyMario García
 
Test Motherfucker...Test
Test Motherfucker...TestTest Motherfucker...Test
Test Motherfucker...TestMario García
 
Programación concurrente con GPars
Programación concurrente con GParsProgramación concurrente con GPars
Programación concurrente con GParsMario García
 
Greach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonGreach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonMario García
 

More from Mario García (15)

Blockchain 101 (spanish)
Blockchain 101 (spanish)Blockchain 101 (spanish)
Blockchain 101 (spanish)
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)
 
Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)
 
GraphQL & Ratpack
GraphQL & RatpackGraphQL & Ratpack
GraphQL & Ratpack
 
GraphQL y Groovy
GraphQL y GroovyGraphQL y Groovy
GraphQL y Groovy
 
Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)
 
GraphQL and Groovy
GraphQL and GroovyGraphQL and Groovy
GraphQL and Groovy
 
Macro macro, burrito burrit
Macro macro, burrito burritMacro macro, burrito burrit
Macro macro, burrito burrit
 
Creating ASTTs The painful truth
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truth
 
Gpars Workshop 2014
Gpars Workshop 2014Gpars Workshop 2014
Gpars Workshop 2014
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Test Motherfucker...Test
Test Motherfucker...TestTest Motherfucker...Test
Test Motherfucker...Test
 
Programación concurrente con GPars
Programación concurrente con GParsProgramación concurrente con GPars
Programación concurrente con GPars
 
Gradle vs Maven
Gradle vs MavenGradle vs Maven
Gradle vs Maven
 
Greach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonGreach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con Griffon
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Groovy on Android

  • 1. 1 Android and Groovy
  • 2. 2 Mario Garcia Software Engineer Happily Working for @marioggar
  • 3. 3 Let me tell you a story...
  • 4. 4 Long Long time ago.... There was a back-end developer ...
  • 5. 5 Long Long time ago.... He used to code using Groovy
  • 6. 6 Long Long time ago.... But not all was happiness... At the beginning Groovy couldn't Work on Android
  • 7. 7 But finally that day came.... During the GR8Conf...
  • 8. 8 Cedric Champeau core developer Yes now you can!!! Released Groovy 2.4 :grooid Thanks Cedric!!!!
  • 9. 9
  • 10. 10 He took his mobile and.... Every seemed to be awesome but then ...
  • 11. 11 Light became darkness because....
  • 12. 12 Darkest hour No background on Android development Activity Fragment Layouts Adapters UIThread Bla bla... Bla bla... Bla bla...
  • 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 Create the first project.... Tools, tools everywhere ...
  • 16. 16 The Gradle Path Grab some of Cedric's projects Add what you need and build it Import to AS
  • 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
  • 19. 19 Gradle Android SDKs version
  • 21. 21 Android Studio Import your Gradle app
  • 22. 22 Android Studio Project structure
  • 23. 23 Java Path (Android Studio) Ask AS to create a Java project Add Cedric plugin Keep working
  • 24. 24 Android Studio Or create a new Android/Gradle project
  • 25. 25 He swore he would never... How can avoid repeating the whole process again ?
  • 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 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 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 SHOW ME THE CODE How Groovy can help you ?
  • 30. 30 Groovy by default At the beginning everything looked like Java:
  • 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 Groovy by default Bean construction: Using map constructor:
  • 33. 33 Groovy collections and more... Collections were more fun Filtering and mapping (find/collect)
  • 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 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 Closures - Fn Currying and MethodClosure: Plain Java methods can become high order functions
  • 37. 37 Closures Functional Interface coertion:
  • 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 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 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 SwissKnife Injecting Views. Forget about findViewById
  • 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
  • 44. 44 SwissKnife @OnClick, @OnItemSelected... There are several other annotations for annotating methods you want to be triggered when an event occurs
  • 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 What about performance ? Faster, cleaner, cheaper...
  • 47. 47 Performance Before blaming the language you may want to check if the problem is elsewhere ;)
  • 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 !
  • 50. 50 What's next ? The future
  • 51. 51 Android Wear Stay tuned at http://melix.github.io/blog/
  • 52. 52 Who knows ? Groovy Groovy everywhere
  • 53. 53 Thank you … Q & A