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

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
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
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
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...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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