SlideShare a Scribd company logo
1 of 76
Custom Android
                       Code Templates
                           Paul Murphy
                           DROIDCON SPAIN 2012




Friday 7 December 12
Agenda
                       • What are Android Code Templates?
                       • Default ADT Templates
                       • Where are ADT Templates Located?
                       • Tools and Configuration in Eclipse
                       • Template Directory Structure
                       • Template Files
                       • FreeMarker Template Language
                       • Demo - Animation Template
Friday 7 December 12
What are Android
                       Code Templates?


Friday 7 December 12
What are Android Code
                Templates?
                       • A mechanism for generating boilerplate
                         Android code and assets from the input
                         of simple UI parameters.
                       • Intergrated with the Eclipse ADT Plugin
                       • Templates are written using
                         FreeMarker - a Java templating engine
                       • It is relatively lightweight - not a full
                         metadata driven code generation
                         solution like EMF
Friday 7 December 12
Code Generation Process



                                               recipe.xml.ftl




                       UI Parameters
                                             FreeMarker

                                                                MyActivity.java




                       MyActivity.java.ftl




Friday 7 December 12
Code Generation Process



                                          recipe.xml.ftl




                       UI Parameters
                                        FreeMarker
                                                           output directory




                         root
                   (source directory)




Friday 7 December 12
Default ADT
                       Templates


Friday 7 December 12
Default ADT Templates

                       Template Types:
                       1. Android Application Templates
                       2. Android Activity Templates
                       3. Android Object Templates




Friday 7 December 12
Android Application Template




Friday 7 December 12
Android Application Template




Friday 7 December 12
Android Activity Template




Friday 7 December 12
Android Activity Template




Friday 7 December 12
Android Activity Template




Friday 7 December 12
Android Activity Template




                                  Template Parameters



Friday 7 December 12
Android Object Template




Friday 7 December 12
Where are
                       ADT Templates
                         Located?

Friday 7 December 12
<android-sdk>/tools/templates




Friday 7 December 12
Friday 7 December 12
Application Templates



Friday 7 December 12
Friday 7 December 12
Activity Templates




Friday 7 December 12
Friday 7 December 12
Android Object
                         Templates




Friday 7 December 12
Friday 7 December 12
Friday 7 December 12
Custom Android
                       Code Template




Friday 7 December 12
Tools and
                       Configuration


Friday 7 December 12
Tools and Config

                       • Eclipse
                       • FreeMarker IDE
                       • Create a location mapping in Eclipse to
                         <android-sdk>/tools/templates
                       • ADT Plugin Preview Releases


Friday 7 December 12
FreeMarker IDE

                       Key Features:
                • Syntax Highlighting
                • Template Structure Outline

                • Developer:
                       JBoss Tools Sub Project



Friday 7 December 12
Friday 7 December 12
Install New Software..




Friday 7 December 12
Add Site




                       http://download.jboss.org/jbosstools/updates/development/juno




Friday 7 December 12
Friday 7 December 12
Configuring Eclipse Workspace

                       • Create New Eclipse Project
                       • Set the Project Location to:
                         <android-sdk>/tools/templates




Friday 7 December 12
Eclipse | New Project...




Friday 7 December 12
New Project




                       <android-sdk>/tools/templates



Friday 7 December 12
tools/templates




Friday 7 December 12
Configured Environment




Friday 7 December 12
Template Directory
                    Structure


Friday 7 December 12
Template Directory

                                  Template




Friday 7 December 12
template.xml


                             Template Metadata




Friday 7 December 12
root


                          Source Directory




Friday 7 December 12
recipe.xml.ftl



                                   Recipe




Friday 7 December 12
globals.xml.ftl



                               Global Variables




Friday 7 December 12
root


                          Source Directory




Friday 7 December 12
app_package




                              app_package




Friday 7 December 12
FreeMarker Template Files




                                   FreeMarker template




Friday 7 December 12
FreeMarker Template Files




                                   FreeMarker templates



Friday 7 December 12
Template Files



Friday 7 December 12
Template Files




Friday 7 December 12
template.xml


                             Template Metadata




Friday 7 December 12
template.xml



                           Metadata

                         UI Parameters

                         Global Values


                           Recipe to
                            Execute


Friday 7 December 12
template.xml



                           Metadata

                         UI Parameters

                         Global Values
                                         globals.xml.ftl




                           Recipe to
                            Execute

                                         recipe.xml.ftl


Friday 7 December 12
template.xml

                       <?xml version="1.0"?>

                       <template name="My Template"
                       	 	 	 description="description...">

                           <category value="UI Components"/>

                            <parameter
                       	   	 	 	 id="duration"
                                	 	 type="float"
                       	   	 	 	 name="Animation Duration"/>

                       	   <globals file="globals.xml.ftl" />

                       	   <execute file="recipe.xml.ftl" />

                       </template>




Friday 7 December 12
Category Element

                        <?xml version="1.0"?>

                        <template name="My Template"
                        	 	 	 description="description...">

                            <category value="UI Components"/>

                             <parameter
                        	   	 	 	 id="duration"
                                 	 	 type="float"
                        	   	 	 	 name="Animation Duration"/>

                        	   <globals file="globals.xml.ftl" />

                        	   <execute file="recipe.xml.ftl" />

                        </template>




Friday 7 December 12
Category Element

                       • Applications
                                        <template name="MyTemplate">
                                        	 <category value="Applications"/>
                                        	 ....
                                        </template>


                                        <template name="MyTemplate">

                       • Activities     	 <category value="Activities"/>
                                        	 ...
                                        </template>


                                        <template name="MyTemplate">


                       • UI Component   	 <category value="UI Component"/>
                                        	 ...
                                        </template>




Friday 7 December 12
recipe.xml.ftl



                                   Recipe




Friday 7 December 12
recipe.xml



                          <copy>

                        <instantiate>

                          <merge>




Friday 7 December 12
recipe.xml



                                 <copy>

                               <instantiate>
               root
                                               output directory
         (source directory)
                                 <merge>




Friday 7 December 12
recipe.xml.ftl
                       <?xml version="1.0"?>

                       <recipe>

                       	     <copy
                       	     	 from="res/anim/zoom.xml"
                       	     	 to="res/anim/zoom.xml" />

                       	     <instantiate
                       	     	 from="res/anim/zoom.xml.ftl"
                                 to="res/anim/${filename}.xml" />

                              <merge
                       	     	 from="AndroidManifest.xml.ftl" />

                              <open
                       	     file="res/anim/${filename}.xml"/>

                           </recipe>




Friday 7 December 12
globals.xml.ftl



                               Global Variables




Friday 7 December 12
recipe.xml.ftl

                       <?xml version="1.0"?>



                       <globals>
                       	   <#-- Animation Defaults -->
                           <global id="slow" value="500" />
                           <global id="fast" value="100" />
                       </globals>




Friday 7 December 12
Template Variable Dataflow




        UI Parameters           Global Values
                                                  globals.xml.ftl




                               Recipe Execution



Friday 7 December 12
FreeMarker
                  Template Language



Friday 7 December 12
FreeMarker Template Language
                       • It is a Java Template Language used
                         for over 10 years
                       • It is an example of a DSL for generating
                         text output of any kind
                       • It has a small subset of programming
                         language constructs
                       • Similar to: Velocity Template Language,
                         C Preprocessor, PHP, Django templates
                       • http://freemarker.org
Friday 7 December 12
Introduction to FreeMarker
                            Template                                    Data

               <manifest>
                 <activity name="{activityName}">        <global id="HomeActivity" value=
               <manifest>                                "HomeActivity"/>




                                            FreeMarker

                                                        Merge



                                   <manifest>
                                     <activity name="HomeActivity">
                                   <manifest>



                                                    Output



Friday 7 December 12
FreeMarker “Markup”

                       • Interpolations
                       ${duration}


                       • FTL Tags
                        <#if animationType == "zoom">

                        </#if>


                       • Comments
                       <#-- FreeMarker Comment -->




Friday 7 December 12
Interpolations



                 package ${packageName};

                 public class ${activityClass} extends Activity {
                 	 protected void onCreate(Bundle savedInstanceState) {
                 	 	 setContentView(R.layout.${layoutName});
                 	 }
                 }




Friday 7 December 12
Conditional Tags

                • If Statement:
                       <#if animationType == "zoom">

                       </#if>


                • Else Statement:
                       <#if animationType == "zoom">

                       <#else>

                       </#if>




Friday 7 December 12
http://freemarker.org/docs/index.html




Friday 7 December 12
Extra Template Functions
                       string slashedPackageName(string)
                       This function converts a full Java package name to its corresponding directory path.

                       For example, if the given argument is com.example.foo, the return value will be com/
                       example/foo.

                       <global id="srcOut" value="src/${slashedPackageName(packageName)}" />




                       string underscoreToCamelCase(string)
                       This function converts an underscore-delimited string, such as foo_bar, to its
                       corresponding camel-case string, such as FooBar.




                       string activityToLayout(string)

                       This function converts an activity class-like identifer string, such as FooActivity, to a
                       corresponding resource-friendly identifier string, such as activity_foo.




Friday 7 December 12
Demo
                       Animation Template




Friday 7 December 12
Review



Friday 7 December 12
Ideas for Custom ADT?

                       • Custom SDK Templates
                       • Rapid Development Templates
                       • Templates enabling easy access to an
                         organisations visual assets colour
                         schemes etc...
                       • Generating the boiler plate code
                         required for Content Providers etc...



Friday 7 December 12
Questions?
                        Twitter: @murphonic




Friday 7 December 12
References

                       • Official FreeMarker Docs:
                         http://freemarker.org/docs/index.html
                       • Roman Nurik Android Template Article:
                         https://dl.dropbox.com/u/231329/
                         android/templatedocs/index.html




Friday 7 December 12

More Related Content

Similar to Custom Android Code Templates

Understanding Webkit Rendering
Understanding Webkit RenderingUnderstanding Webkit Rendering
Understanding Webkit RenderingAriya Hidayat
 
Ruby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingRuby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingDigital Natives
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app developmentGaurav Lochan
 
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012kennethaliu
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesBenoit Bénézech
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 
Cloud4all Architecture Overview
Cloud4all Architecture OverviewCloud4all Architecture Overview
Cloud4all Architecture Overviewicchp2012
 
How to be an agile programmer.
How to be an agile programmer.How to be an agile programmer.
How to be an agile programmer.Tsuyoshi Ushio
 
Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Phase2
 
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...Jesse Cravens
 
Reverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android appsReverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android appsGaurav Lochan
 
Разработка приложений в Android studio
Разработка приложений в Android studioРазработка приложений в Android studio
Разработка приложений в Android studioDev2Dev
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBYnon Perek
 
Working With Social APIs - SoMeT12
Working With Social APIs - SoMeT12Working With Social APIs - SoMeT12
Working With Social APIs - SoMeT12Mario Vasquez
 
The state of drupal 8 - Drupalcamp Gent
The state of drupal 8  - Drupalcamp GentThe state of drupal 8  - Drupalcamp Gent
The state of drupal 8 - Drupalcamp Gentswentel
 

Similar to Custom Android Code Templates (20)

Understanding Webkit Rendering
Understanding Webkit RenderingUnderstanding Webkit Rendering
Understanding Webkit Rendering
 
Grails 2.0 Update
Grails 2.0 UpdateGrails 2.0 Update
Grails 2.0 Update
 
HTML5 and Sencha Touch
HTML5 and Sencha TouchHTML5 and Sencha Touch
HTML5 and Sencha Touch
 
Ruby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingRuby meetup 7_years_in_testing
Ruby meetup 7_years_in_testing
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app development
 
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
 
RailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practicesRailsAdmin - Overview and Best practices
RailsAdmin - Overview and Best practices
 
Backbone
BackboneBackbone
Backbone
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 
Cloud4all Architecture Overview
Cloud4all Architecture OverviewCloud4all Architecture Overview
Cloud4all Architecture Overview
 
How to be an agile programmer.
How to be an agile programmer.How to be an agile programmer.
How to be an agile programmer.
 
Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Build and Deploy Sites Using Features
Build and Deploy Sites Using Features
 
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
 
Reverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android appsReverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android apps
 
Разработка приложений в Android studio
Разработка приложений в Android studioРазработка приложений в Android studio
Разработка приложений в Android studio
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Working With Social APIs - SoMeT12
Working With Social APIs - SoMeT12Working With Social APIs - SoMeT12
Working With Social APIs - SoMeT12
 
07 PhoneGap
07 PhoneGap07 PhoneGap
07 PhoneGap
 
The state of drupal 8 - Drupalcamp Gent
The state of drupal 8  - Drupalcamp GentThe state of drupal 8  - Drupalcamp Gent
The state of drupal 8 - Drupalcamp Gent
 
Fork cli tool
Fork cli toolFork cli tool
Fork cli tool
 

Recently uploaded

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Recently uploaded (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Custom Android Code Templates

  • 1. Custom Android Code Templates Paul Murphy DROIDCON SPAIN 2012 Friday 7 December 12
  • 2. Agenda • What are Android Code Templates? • Default ADT Templates • Where are ADT Templates Located? • Tools and Configuration in Eclipse • Template Directory Structure • Template Files • FreeMarker Template Language • Demo - Animation Template Friday 7 December 12
  • 3. What are Android Code Templates? Friday 7 December 12
  • 4. What are Android Code Templates? • A mechanism for generating boilerplate Android code and assets from the input of simple UI parameters. • Intergrated with the Eclipse ADT Plugin • Templates are written using FreeMarker - a Java templating engine • It is relatively lightweight - not a full metadata driven code generation solution like EMF Friday 7 December 12
  • 5. Code Generation Process recipe.xml.ftl UI Parameters FreeMarker MyActivity.java MyActivity.java.ftl Friday 7 December 12
  • 6. Code Generation Process recipe.xml.ftl UI Parameters FreeMarker output directory root (source directory) Friday 7 December 12
  • 7. Default ADT Templates Friday 7 December 12
  • 8. Default ADT Templates Template Types: 1. Android Application Templates 2. Android Activity Templates 3. Android Object Templates Friday 7 December 12
  • 14. Android Activity Template Template Parameters Friday 7 December 12
  • 16. Where are ADT Templates Located? Friday 7 December 12
  • 23. Android Object Templates Friday 7 December 12
  • 26. Custom Android Code Template Friday 7 December 12
  • 27. Tools and Configuration Friday 7 December 12
  • 28. Tools and Config • Eclipse • FreeMarker IDE • Create a location mapping in Eclipse to <android-sdk>/tools/templates • ADT Plugin Preview Releases Friday 7 December 12
  • 29. FreeMarker IDE Key Features: • Syntax Highlighting • Template Structure Outline • Developer: JBoss Tools Sub Project Friday 7 December 12
  • 32. Add Site http://download.jboss.org/jbosstools/updates/development/juno Friday 7 December 12
  • 34. Configuring Eclipse Workspace • Create New Eclipse Project • Set the Project Location to: <android-sdk>/tools/templates Friday 7 December 12
  • 35. Eclipse | New Project... Friday 7 December 12
  • 36. New Project <android-sdk>/tools/templates Friday 7 December 12
  • 39. Template Directory Structure Friday 7 December 12
  • 40. Template Directory Template Friday 7 December 12
  • 41. template.xml Template Metadata Friday 7 December 12
  • 42. root Source Directory Friday 7 December 12
  • 43. recipe.xml.ftl Recipe Friday 7 December 12
  • 44. globals.xml.ftl Global Variables Friday 7 December 12
  • 45. root Source Directory Friday 7 December 12
  • 46. app_package app_package Friday 7 December 12
  • 47. FreeMarker Template Files FreeMarker template Friday 7 December 12
  • 48. FreeMarker Template Files FreeMarker templates Friday 7 December 12
  • 49. Template Files Friday 7 December 12
  • 50. Template Files Friday 7 December 12
  • 51. template.xml Template Metadata Friday 7 December 12
  • 52. template.xml Metadata UI Parameters Global Values Recipe to Execute Friday 7 December 12
  • 53. template.xml Metadata UI Parameters Global Values globals.xml.ftl Recipe to Execute recipe.xml.ftl Friday 7 December 12
  • 54. template.xml <?xml version="1.0"?> <template name="My Template" description="description..."> <category value="UI Components"/> <parameter id="duration" type="float" name="Animation Duration"/> <globals file="globals.xml.ftl" /> <execute file="recipe.xml.ftl" /> </template> Friday 7 December 12
  • 55. Category Element <?xml version="1.0"?> <template name="My Template" description="description..."> <category value="UI Components"/> <parameter id="duration" type="float" name="Animation Duration"/> <globals file="globals.xml.ftl" /> <execute file="recipe.xml.ftl" /> </template> Friday 7 December 12
  • 56. Category Element • Applications <template name="MyTemplate"> <category value="Applications"/> .... </template> <template name="MyTemplate"> • Activities <category value="Activities"/> ... </template> <template name="MyTemplate"> • UI Component <category value="UI Component"/> ... </template> Friday 7 December 12
  • 57. recipe.xml.ftl Recipe Friday 7 December 12
  • 58. recipe.xml <copy> <instantiate> <merge> Friday 7 December 12
  • 59. recipe.xml <copy> <instantiate> root output directory (source directory) <merge> Friday 7 December 12
  • 60. recipe.xml.ftl <?xml version="1.0"?> <recipe> <copy from="res/anim/zoom.xml" to="res/anim/zoom.xml" /> <instantiate from="res/anim/zoom.xml.ftl" to="res/anim/${filename}.xml" /> <merge from="AndroidManifest.xml.ftl" /> <open file="res/anim/${filename}.xml"/> </recipe> Friday 7 December 12
  • 61. globals.xml.ftl Global Variables Friday 7 December 12
  • 62. recipe.xml.ftl <?xml version="1.0"?> <globals> <#-- Animation Defaults --> <global id="slow" value="500" /> <global id="fast" value="100" /> </globals> Friday 7 December 12
  • 63. Template Variable Dataflow UI Parameters Global Values globals.xml.ftl Recipe Execution Friday 7 December 12
  • 64. FreeMarker Template Language Friday 7 December 12
  • 65. FreeMarker Template Language • It is a Java Template Language used for over 10 years • It is an example of a DSL for generating text output of any kind • It has a small subset of programming language constructs • Similar to: Velocity Template Language, C Preprocessor, PHP, Django templates • http://freemarker.org Friday 7 December 12
  • 66. Introduction to FreeMarker Template Data <manifest> <activity name="{activityName}"> <global id="HomeActivity" value= <manifest> "HomeActivity"/> FreeMarker Merge <manifest> <activity name="HomeActivity"> <manifest> Output Friday 7 December 12
  • 67. FreeMarker “Markup” • Interpolations ${duration} • FTL Tags <#if animationType == "zoom"> </#if> • Comments <#-- FreeMarker Comment --> Friday 7 December 12
  • 68. Interpolations package ${packageName}; public class ${activityClass} extends Activity { protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.${layoutName}); } } Friday 7 December 12
  • 69. Conditional Tags • If Statement: <#if animationType == "zoom"> </#if> • Else Statement: <#if animationType == "zoom"> <#else> </#if> Friday 7 December 12
  • 71. Extra Template Functions string slashedPackageName(string) This function converts a full Java package name to its corresponding directory path. For example, if the given argument is com.example.foo, the return value will be com/ example/foo. <global id="srcOut" value="src/${slashedPackageName(packageName)}" /> string underscoreToCamelCase(string) This function converts an underscore-delimited string, such as foo_bar, to its corresponding camel-case string, such as FooBar. string activityToLayout(string) This function converts an activity class-like identifer string, such as FooActivity, to a corresponding resource-friendly identifier string, such as activity_foo. Friday 7 December 12
  • 72. Demo Animation Template Friday 7 December 12
  • 74. Ideas for Custom ADT? • Custom SDK Templates • Rapid Development Templates • Templates enabling easy access to an organisations visual assets colour schemes etc... • Generating the boiler plate code required for Content Providers etc... Friday 7 December 12
  • 75. Questions? Twitter: @murphonic Friday 7 December 12
  • 76. References • Official FreeMarker Docs: http://freemarker.org/docs/index.html • Roman Nurik Android Template Article: https://dl.dropbox.com/u/231329/ android/templatedocs/index.html Friday 7 December 12