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

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Recently uploaded (20)

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

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