• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Custom Android Code Templates
 

Custom Android Code Templates

on

  • 9,089 views

 

Statistics

Views

Total Views
9,089
Views on SlideShare
9,010
Embed Views
79

Actions

Likes
10
Downloads
0
Comments
1

4 Embeds 79

https://twitter.com 67
http://eventifier.co 9
http://www.linkedin.com 2
https://twimg0-a.akamaihd.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • http://es.droidcon.com/wp-content/uploads/2012/12/Custom-Android-Code-Templates.pdf
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Custom Android Code Templates Custom Android Code Templates Presentation Transcript

    • Custom Android Code Templates Paul Murphy DROIDCON SPAIN 2012Friday 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 TemplateFriday 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 EMFFriday 7 December 12
    • Code Generation Process recipe.xml.ftl UI Parameters FreeMarker MyActivity.java MyActivity.java.ftlFriday 7 December 12
    • Code Generation Process recipe.xml.ftl UI Parameters FreeMarker output directory root (source directory)Friday 7 December 12
    • Default ADT TemplatesFriday 7 December 12
    • Default ADT Templates Template Types: 1. Android Application Templates 2. Android Activity Templates 3. Android Object TemplatesFriday 7 December 12
    • Android Application TemplateFriday 7 December 12
    • Android Application TemplateFriday 7 December 12
    • Android Activity TemplateFriday 7 December 12
    • Android Activity TemplateFriday 7 December 12
    • Android Activity TemplateFriday 7 December 12
    • Android Activity Template Template ParametersFriday 7 December 12
    • Android Object TemplateFriday 7 December 12
    • Where are ADT Templates Located?Friday 7 December 12
    • <android-sdk>/tools/templatesFriday 7 December 12
    • Friday 7 December 12
    • Application TemplatesFriday 7 December 12
    • Friday 7 December 12
    • Activity TemplatesFriday 7 December 12
    • Friday 7 December 12
    • Android Object TemplatesFriday 7 December 12
    • Friday 7 December 12
    • Friday 7 December 12
    • Custom Android Code TemplateFriday 7 December 12
    • Tools and ConfigurationFriday 7 December 12
    • Tools and Config • Eclipse • FreeMarker IDE • Create a location mapping in Eclipse to <android-sdk>/tools/templates • ADT Plugin Preview ReleasesFriday 7 December 12
    • FreeMarker IDE Key Features: • Syntax Highlighting • Template Structure Outline • Developer: JBoss Tools Sub ProjectFriday 7 December 12
    • Friday 7 December 12
    • Install New Software..Friday 7 December 12
    • Add Site http://download.jboss.org/jbosstools/updates/development/junoFriday 7 December 12
    • Friday 7 December 12
    • Configuring Eclipse Workspace • Create New Eclipse Project • Set the Project Location to: <android-sdk>/tools/templatesFriday 7 December 12
    • Eclipse | New Project...Friday 7 December 12
    • New Project <android-sdk>/tools/templatesFriday 7 December 12
    • tools/templatesFriday 7 December 12
    • Configured EnvironmentFriday 7 December 12
    • Template Directory StructureFriday 7 December 12
    • Template Directory TemplateFriday 7 December 12
    • template.xml Template MetadataFriday 7 December 12
    • root Source DirectoryFriday 7 December 12
    • recipe.xml.ftl RecipeFriday 7 December 12
    • globals.xml.ftl Global VariablesFriday 7 December 12
    • root Source DirectoryFriday 7 December 12
    • app_package app_packageFriday 7 December 12
    • FreeMarker Template Files FreeMarker templateFriday 7 December 12
    • FreeMarker Template Files FreeMarker templatesFriday 7 December 12
    • Template FilesFriday 7 December 12
    • Template FilesFriday 7 December 12
    • template.xml Template MetadataFriday 7 December 12
    • template.xml Metadata UI Parameters Global Values Recipe to ExecuteFriday 7 December 12
    • template.xml Metadata UI Parameters Global Values globals.xml.ftl Recipe to Execute recipe.xml.ftlFriday 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 RecipeFriday 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 VariablesFriday 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 ExecutionFriday 7 December 12
    • FreeMarker Template LanguageFriday 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.orgFriday 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> OutputFriday 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.htmlFriday 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 TemplateFriday 7 December 12
    • ReviewFriday 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: @murphonicFriday 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.htmlFriday 7 December 12