xref: /aosp_15_r20/sdk/templates/docs/index.html (revision 1789df15502f1991eff51ff970dce5df8404dd56)
1*1789df15SXin Li<!DOCTYPE html>
2*1789df15SXin Li<html>
3*1789df15SXin Li<!--
4*1789df15SXin Li  Copyright 2012 The Android Open Source Project
5*1789df15SXin Li
6*1789df15SXin Li  Licensed under the Apache License, Version 2.0 (the "License");
7*1789df15SXin Li  you may not use this file except in compliance with the License.
8*1789df15SXin Li  You may obtain a copy of the License at
9*1789df15SXin Li
10*1789df15SXin Li      http://www.apache.org/licenses/LICENSE-2.0
11*1789df15SXin Li
12*1789df15SXin Li  Unless required by applicable law or agreed to in writing, software
13*1789df15SXin Li  distributed under the License is distributed on an "AS IS" BASIS,
14*1789df15SXin Li  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15*1789df15SXin Li  See the License for the specific language governing permissions and
16*1789df15SXin Li  limitations under the License.
17*1789df15SXin Li  -->
18*1789df15SXin Li<head>
19*1789df15SXin Li  <meta charset="utf-8">
20*1789df15SXin Li  <title>Android IDE Template Format</title>
21*1789df15SXin Li  <link rel="stylesheet" href="cssreset-min.css">
22*1789df15SXin Li  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold;Inconsolata" title="roboto">
23*1789df15SXin Li  <link rel="stylesheet" href="prettify.css">
24*1789df15SXin Li  <link rel="stylesheet" href="default.css">
25*1789df15SXin Li  <script src="jquery-1.8.0.min.js"></script>
26*1789df15SXin Li  <script src="prettify.js"></script>
27*1789df15SXin Li  <script src="default.js"></script>
28*1789df15SXin Li</head>
29*1789df15SXin Li<body>
30*1789df15SXin Li
31*1789df15SXin Li<nav>
32*1789df15SXin Li
33*1789df15SXin Li</nav>
34*1789df15SXin Li
35*1789df15SXin Li<div id="page-content">
36*1789df15SXin Li
37*1789df15SXin Li<h1>Android IDE Template Format</h1>
38*1789df15SXin Li<br>
39*1789df15SXin Li<dl style="margin:0">
40*1789df15SXin Li  <dt>Format Version</dt>
41*1789df15SXin Li  <dd style="margin:0">4</dd>
42*1789df15SXin Li
43*1789df15SXin Li  <dt>Last Updated</dt>
44*1789df15SXin Li  <dd style="margin:0">1/30/2014</dd>
45*1789df15SXin Li</dl>
46*1789df15SXin Li
47*1789df15SXin Li
48*1789df15SXin Li
49*1789df15SXin Li
50*1789df15SXin Li
51*1789df15SXin Li<h2>Overview</h2>
52*1789df15SXin Li
53*1789df15SXin Li<p>This document describes the format and syntax for Android code templates. These templates provide starting points for entire projects (e.g. <code>NewAndroidApplication</code>) or application components such as activities (e.g. <code>BlankActivity</code>).</p>
54*1789df15SXin Li
55*1789df15SXin Li<p>Although these templates were originally introduced in the <a href="http://developer.android.com/tools/sdk/eclipse-adt.html">ADT Plugin</a> for Eclipse, the template format is designed for use by any IDE or command-line tool.</p>
56*1789df15SXin Li
57*1789df15SXin Li<p>Templates are customizable. Each template exposes several options (called parameters) that allow developers to customize the generated code. The most common workflow for <em>using</em> a template is as follows:</p>
58*1789df15SXin Li
59*1789df15SXin Li<ol>
60*1789df15SXin Li  <li>Choose a template.</li>
61*1789df15SXin Li  <li>Populate template options (parameters).</li>
62*1789df15SXin Li  <li>Preview and then execute the additions/changes to your project.</li>
63*1789df15SXin Li</ol>
64*1789df15SXin Li
65*1789df15SXin Li<h3>FreeMarker</h3>
66*1789df15SXin Li
67*1789df15SXin Li<p>Templates make heavy use of <a href="http://freemarker.sourceforge.net/">FreeMarker</a>, a Java templating engine used to enable things like control flows and variable substitutions inside files. It's similar to PHP, Django templates, etc. For those more acquainted with C/C++, think of it as a <a href="http://en.wikipedia.org/wiki/C_preprocessor">preprocessor</a> language (i.e. <code>#ifdef</code>).</p>
68*1789df15SXin Li
69*1789df15SXin Li<p>By convention, any file in the template directory structure that is to be processed by FreeMarker should have the <code>.ftl</code> file extension. So if one of your source files is <code>MyActivity.java</code>, and it contains FreeMarker instructions, it should be named something like <code>MyActivity.java.ftl</code>.</p>
70*1789df15SXin Li
71*1789df15SXin Li<p>For more documentation on FreeMarker, see the <a href="http://freemarker.sourceforge.net/docs/index.html">docs</a>. In particular, the <a href="http://freemarker.sourceforge.net/docs/ref_builtins_string.html">reference on string operations</a>.</p>
72*1789df15SXin Li
73*1789df15SXin Li<p>An example, templated version of an Android manifest, normally named <code>AndroidManifest.xml.ftl</code> is shown below.</p>
74*1789df15SXin Li
75*1789df15SXin Li<pre class="prettyprint lang-xml">
76*1789df15SXin Li&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"&gt;
77*1789df15SXin Li    &lt;application&gt;
78*1789df15SXin Li        &lt;activity android:name="<strong>${packageName}.${activityClass}</strong>"
79*1789df15SXin Li            android:parentActivityName="<strong>${parentActivityClass}</strong>"
80*1789df15SXin Li            android:label="@string/title_<strong>${activityToLayout(activityClass)}</strong>">
81*1789df15SXin Li            <strong>&lt;#if parentActivityClass != ""&gt;</strong>
82*1789df15SXin Li            &lt;meta-data android:name="android.support.PARENT_ACTIVITY"
83*1789df15SXin Li                android:value="<strong>${parentActivityClass}</strong>" /&gt;
84*1789df15SXin Li            <strong>&lt;/#if&gt;</strong>
85*1789df15SXin Li            <strong>&lt;#if isLauncher&gt;</strong>
86*1789df15SXin Li            &lt;intent-filter&gt;
87*1789df15SXin Li                &lt;action android:name="android.intent.action.MAIN" /&gt;
88*1789df15SXin Li                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
89*1789df15SXin Li            &lt;/intent-filter&gt;
90*1789df15SXin Li            <strong>&lt;/#if&gt;</strong>
91*1789df15SXin Li        &lt;/activity&gt;
92*1789df15SXin Li    &lt;/application&gt;
93*1789df15SXin Li&lt;/manifest&gt;
94*1789df15SXin Li</pre>
95*1789df15SXin Li
96*1789df15SXin Li<p>In this example excerpt from the <code>BlankActivity</code> template:</p>
97*1789df15SXin Li
98*1789df15SXin Li<ul>
99*1789df15SXin Li  <li>The expression <code>${activityClass}</code> is bound to the value of the 'Activity Class' template parameter.</li>
100*1789df15SXin Li  <li>The expression <code>${activityToLayout(activityClass)}</code> uses the <code>activityToLayout</code> method built into the template engine to convert an activity class such as <code>MyFooActivity</code> to <code>activity_my_foo</code>.</li>
101*1789df15SXin Li  <li>The <code>isLauncher</code> boolean variable and <code>parentActivityClass</code> string variables are bound to the values of the 'Launcher Activity' and 'Hierarchical Parent' template parameter, respectively.</li>
102*1789df15SXin Li</ul>
103*1789df15SXin Li
104*1789df15SXin Li
105*1789df15SXin Li
106*1789df15SXin Li
107*1789df15SXin Li
108*1789df15SXin Li<h2>Directory Structure</h2>
109*1789df15SXin Li
110*1789df15SXin Li<p>A template is a directory containing a number of XML and FreeMarker files. The only two mandatory files are <code>template.xml</code> and <code>recipe.xml.ftl</code>. Template source files (PNG files, templated Java and XML files, etc.) belong in a <code>root/</code> subdirectory. An example directory structure for a template is below:</p>
111*1789df15SXin Li
112*1789df15SXin Li<ul>
113*1789df15SXin Li  <li><strong>MyTemplate/</strong> <span class="dim">&mdash; Root directory</span><ul>
114*1789df15SXin Li    <li><a href="#toc_templatexml">template.xml</a> <span class="dim">&mdash; Metadata (description, parameters, etc.)</span></li>
115*1789df15SXin Li    <li><a href="#toc_recipexmlftl">recipe.xml.ftl</a> <span class="dim">&mdash; Instructions/script (files to copy, etc.)</span></li>
116*1789df15SXin Li    <li><a href="#toc_globalsxmlftl">globals.xml.ftl </a><span class="dim">&mdash; Optional global variables</span></li>
117*1789df15SXin Li    <li>template.png <span class="dim">&mdash; Default template thumbnail</span></li>
118*1789df15SXin Li    <li>template_foo.png <span class="dim">&mdash; Thumbnail when option 'foo' is selected</span></li>
119*1789df15SXin Li    <li>template_bar.png</li>
120*1789df15SXin Li    <li><strong><a href="#toc_root">root/</a></strong> <span class="dim">&mdash; Source files (which get processed/copied/merged with the output project)</span><ul>
121*1789df15SXin Li      <li>AndroidManifest.xml.ftl</li>
122*1789df15SXin Li      <li><strong>res/</strong> <ul>
123*1789df15SXin Li        <li>&hellip;</li>
124*1789df15SXin Li      </ul></li>
125*1789df15SXin Li      <li><strong>src/</strong> <ul>
126*1789df15SXin Li        <li><strong>app_package/</strong> <ul>
127*1789df15SXin Li          <li>MyActivity.java.ftl</li>
128*1789df15SXin Li        </ul></li>
129*1789df15SXin Li      </ul></li>
130*1789df15SXin Li    </ul></li>
131*1789df15SXin Li  </ul>
132*1789df15SXin Li</li>
133*1789df15SXin Li</ul>
134*1789df15SXin Li<br>
135*1789df15SXin Li
136*1789df15SXin Li<p>More on the role of each of these files is discussed in the sections below.</p>
137*1789df15SXin Li
138*1789df15SXin Li<h3>template.xml</h3>
139*1789df15SXin Li
140*1789df15SXin Li<p>Each template directory must contain a <code>template.xml</code> file. This XML file contains metadata about the template, including the name, description, category and user-visible parameters that the IDE will present as options to the user. The XML file also indicates the name of the <a href="#toc_recipexmlftl">recipe XML file</a> (which gets processed by FreeMarker), and the <a href="#toc_globalsxmlftl">global variables XML file</a> if there are global variables besides the template parameter values that should be visible to all FreeMarker-processed files (<code>.ftl</code> files).</p>
141*1789df15SXin Li
142*1789df15SXin Li<p>An example <code>template.xml</code> is shown below.</p>
143*1789df15SXin Li
144*1789df15SXin Li<pre class="prettyprint lang-xml">
145*1789df15SXin Li&lt;!-- A template for a blank activity. Use template format
146*1789df15SXin Li     version 4, as described in this document. -->
147*1789df15SXin Li&lt;template
148*1789df15SXin Li    format="4"
149*1789df15SXin Li    revision="2"
150*1789df15SXin Li    minApi="7"
151*1789df15SXin Li    minBuildApi="16"
152*1789df15SXin Li    name="Blank Activity"
153*1789df15SXin Li    description="Creates a new blank activity, with navigation."&gt;
154*1789df15SXin Li
155*1789df15SXin Li    &lt;!-- A string parameter; the value is available to FreeMarker
156*1789df15SXin Li         processed files (.ftl files) as ${activityName}. -->
157*1789df15SXin Li    &lt;parameter
158*1789df15SXin Li        id="activityClass"
159*1789df15SXin Li        name="Activity Name"
160*1789df15SXin Li        type="string"
161*1789df15SXin Li        constraints="class|unique|nonempty"
162*1789df15SXin Li        suggest="${layoutToActivity(layoutName)}"
163*1789df15SXin Li        default="MainActivity"
164*1789df15SXin Li        help="The name of the activity class to create." /&gt;
165*1789df15SXin Li
166*1789df15SXin Li    &lt;parameter
167*1789df15SXin Li        id="layoutName"
168*1789df15SXin Li        name="Layout Name"
169*1789df15SXin Li        type="string"
170*1789df15SXin Li        constraints="layout|unique|nonempty"
171*1789df15SXin Li        suggest="${activityToLayout(activityClass)}"
172*1789df15SXin Li        default="activity_main"
173*1789df15SXin Li        help="The name of the layout to create for the activity" /&gt;
174*1789df15SXin Li
175*1789df15SXin Li    &lt;parameter
176*1789df15SXin Li        id="navType"
177*1789df15SXin Li        name="Navigation Type"
178*1789df15SXin Li        type="enum"
179*1789df15SXin Li        default="none"
180*1789df15SXin Li        help="The type of navigation to use for the activity"&gt;
181*1789df15SXin Li        &lt;option id="none"&gt;None&lt;/option&gt;
182*1789df15SXin Li        &lt;option id="tabs" minApi="11"&gt;Tabs&lt;/option&gt;
183*1789df15SXin Li        &lt;option id="pager" minApi="11"&gt;Swipe Views&lt;/option&gt;
184*1789df15SXin Li        &lt;option id="dropdown" minApi="11"&gt;Dropdown&lt;/option&gt;
185*1789df15SXin Li    &lt;/parameter&gt;
186*1789df15SXin Li
187*1789df15SXin Li    &lt;parameter
188*1789df15SXin Li        id="fragmentName"
189*1789df15SXin Li        name="Fragment Name"
190*1789df15SXin Li        type="string"
191*1789df15SXin Li        constraints="class|unique|nonempty"
192*1789df15SXin Li        default="MainFragment"
193*1789df15SXin Li        visibility="navType != 'none'"
194*1789df15SXin Li        help="The name of the fragment class to create" /&gt;
195*1789df15SXin Li
196*1789df15SXin Li    &lt;!-- 512x512 PNG thumbnails. --&gt;
197*1789df15SXin Li    &lt;thumbs&gt;
198*1789df15SXin Li        &lt;!-- Default thumbnail. --&gt;
199*1789df15SXin Li        &lt;thumb&gt;template_default.png&lt;/thumb&gt;
200*1789df15SXin Li        &lt;!-- Attributes act as selectors based on chosen parameters. --&gt;
201*1789df15SXin Li        &lt;thumb navType="tabs"&gt;template_tabs.png&lt;/thumb&gt;
202*1789df15SXin Li        &lt;thumb navType="dropdown"&gt;template_dropdown.png&lt;/thumb&gt;
203*1789df15SXin Li    &lt;/thumbs&gt;
204*1789df15SXin Li
205*1789df15SXin Li    &lt;!-- Optional global variables. --&gt;
206*1789df15SXin Li    &lt;globals file="globals.xml.ftl" /&gt;
207*1789df15SXin Li
208*1789df15SXin Li    &lt;!-- Required recipe (script) to run when instantiating
209*1789df15SXin Li         the template. --&gt;
210*1789df15SXin Li    &lt;execute file="recipe.xml.ftl" /&gt;
211*1789df15SXin Li&lt;/template&gt;
212*1789df15SXin Li</pre>
213*1789df15SXin Li
214*1789df15SXin Li<p>Below is a listing of supported tags in <code>template.xml</code>.</p>
215*1789df15SXin Li
216*1789df15SXin Li<h4 class="includetoc">&lt;template&gt;</h4>
217*1789df15SXin Li
218*1789df15SXin Li<p>The template root element.</p>
219*1789df15SXin Li
220*1789df15SXin Li<dl>
221*1789df15SXin Li  <dt><code>format</code></dt>
222*1789df15SXin Li  <dd>The template format version that this template adheres to. Should be <code>4</code>.</dd>
223*1789df15SXin Li
224*1789df15SXin Li  <dt><code>revision</code></dt>
225*1789df15SXin Li  <dd>Optional. The version of this template (which you can increment when updating the template), as an integer.</dd>
226*1789df15SXin Li
227*1789df15SXin Li  <dt><code>name</code></dt>
228*1789df15SXin Li  <dd>The template's display name.</dd>
229*1789df15SXin Li
230*1789df15SXin Li  <dt><code>description</code></dt>
231*1789df15SXin Li  <dd>The template's description.</dd>
232*1789df15SXin Li
233*1789df15SXin Li  <dt><code>minApi</code></dt>
234*1789df15SXin Li  <dd>Optional. The minimum API level required for this template. The IDE will ensure that the target project has a <code>minSdkVersion</code> no lower than this value before instantiating the template.</dd>
235*1789df15SXin Li
236*1789df15SXin Li  <dt><code>minBuildApi</code></dt>
237*1789df15SXin Li  <dd>Optional. The minimum build target (expressed as an API level) required for this template. The IDE will ensure that the target project is targeting an API level greater than or equal to this value before instantiating the template. This ensures that the template can safely use newer APIs (optionally guarded by runtime API level checks) without introducing compile-time errors into the target project.</dd>
238*1789df15SXin Li</dl>
239*1789df15SXin Li
240*1789df15SXin Li<div class="deprecated">
241*1789df15SXin Li<h4 class="includetoc">&lt;dependency&gt;</h4>
242*1789df15SXin Li
243*1789df15SXin Li<p>This tag is deprecated for use in <code>template.xml</code>. Use <a href="#toc_recipe_dependency"><code>&lt;dependency&gt;</code></a> in <code>recipe.xml.ftl</code> instead.</p>
244*1789df15SXin Li
245*1789df15SXin Li<p>Indicates that the template requires that a given library be present in the target project. If not present, the IDE will add the dependency to the project.</p>
246*1789df15SXin Li
247*1789df15SXin Li<dl>
248*1789df15SXin Li  <dt><code>name</code></dt>
249*1789df15SXin Li  <dd>The name of the library. Currently accepted values are:<ul>
250*1789df15SXin Li    <li><code>android-support-v4</code></li>
251*1789df15SXin Li    <li><code>android-support-v13</code></li>
252*1789df15SXin Li  </ul></dd>
253*1789df15SXin Li
254*1789df15SXin Li  <dt><code>revision</code></dt>
255*1789df15SXin Li  <dd>The minimum revision of the library required by this template.</dd>
256*1789df15SXin Li</dl>
257*1789df15SXin Li</div>
258*1789df15SXin Li
259*1789df15SXin Li<div class="deprecated">
260*1789df15SXin Li<h4 class="includetoc">&lt;category&gt;</h4>
261*1789df15SXin Li
262*1789df15SXin Li<p>The template type. This element is optional.</p>
263*1789df15SXin Li
264*1789df15SXin Li<dl>
265*1789df15SXin Li  <dt><code>value</code></dt>
266*1789df15SXin Li  <dd>The template type. Should be one of the following values: <ul>
267*1789df15SXin Li    <li><code>Applications</code></li>
268*1789df15SXin Li    <li><code>Activities</code></li>
269*1789df15SXin Li    <li><code>UI Components</code></li>
270*1789df15SXin Li  </ul></dd>
271*1789df15SXin Li</dl>
272*1789df15SXin Li</div>
273*1789df15SXin Li
274*1789df15SXin Li<h4 class="includetoc">&lt;parameter&gt;</h4>
275*1789df15SXin Li
276*1789df15SXin Li<p>Defines a user-customizable template parameter.</p>
277*1789df15SXin Li
278*1789df15SXin Li<dl>
279*1789df15SXin Li  <dt><code>id</code></dt>
280*1789df15SXin Li  <dd>The identifier representing this variable, made available as a global variable in FreeMarker files. If the identifier is <code>foo</code>, the parameter value will be available in FreeMarker files as <code>${foo}</code>.</dd>
281*1789df15SXin Li
282*1789df15SXin Li  <dt><code>name</code></dt>
283*1789df15SXin Li  <dd>The display name of the template parameter.</dd>
284*1789df15SXin Li
285*1789df15SXin Li  <dt><code>type</code></dt>
286*1789df15SXin Li  <dd>The data type of the parameter. Either <code>string</code>, <code>boolean</code>, <code>enum</code>, or <code>separator</code>.</dd>
287*1789df15SXin Li
288*1789df15SXin Li  <dt><code>constraints</code></dt>
289*1789df15SXin Li  <dd>Optional. Constraints to impose on the parameter's value. Constraints can be combined using <code>|</code>. Valid constraint types are: <ul>
290*1789df15SXin Li    <li><code>nonempty</code> &mdash; the value must not be empty</li>
291*1789df15SXin Li    <li><code>apilevel</code> &mdash; the value should represent a numeric API level</li>
292*1789df15SXin Li    <li><code>package</code> &mdash; the value should represent a valid Java package name</li>
293*1789df15SXin Li    <li><code>app_package</code> &mdash; the value should represent a valid Android app package name</li>
294*1789df15SXin Li    <li><code>module</code> &mdash; the value should represent a valid Module name</li>
295*1789df15SXin Li    <li><code>class</code> &mdash; the value should represent a valid Java class name</li>
296*1789df15SXin Li    <li><code>activity</code> &mdash; the value should represent a fully-qualified activity class name</li>
297*1789df15SXin Li    <li><code>layout</code> &mdash; the value should represent a valid layout resource name</li>
298*1789df15SXin Li    <li><code>drawable</code> &mdash; the value should represent a valid drawable resource name</li>
299*1789df15SXin Li    <li><code>string</code> &mdash; the value should represent a valid string resource name</li>
300*1789df15SXin Li    <li><code>id</code> &mdash; the value should represent a valid id resource name</li>
301*1789df15SXin Li    <li><code>unique</code> &mdash; the value must be unique; this constraint only makes sense when other constraints are specified, such as <code>layout</code>, which would mean that the value should not represent an existing layout resource name</li>
302*1789df15SXin Li    <li><code>exists</code> &mdash; the value must already exist; this constraint only makes sense when other constraints are specified, such as <code>layout</code>, which would mean that the value should represent an existing layout resource name</li>
303*1789df15SXin Li  </ul></dd>
304*1789df15SXin Li
305*1789df15SXin Li  <dt><code>suggest</code></dt>
306*1789df15SXin Li  <dd>Optional. A FreeMarker expression representing the auto-suggested parameter value (a 'dynamic default'). When the user modifies other parameter values, and if this parameter's value has not been changed from its default, then the value changes to the result of this expression. This may seem to be circular since parameters can <code>suggest</code> against each other's values, but these expressions are only updated for non-edited values, so this approach lets the user edit either parameter value, and the other will automatically be updated to a reasonable default.</dd>
307*1789df15SXin Li
308*1789df15SXin Li  <dt><code>default</code></dt>
309*1789df15SXin Li  <dd>Optional. The default value for this parameter.</dd>
310*1789df15SXin Li
311*1789df15SXin Li  <dt><code>visibility</code></dt>
312*1789df15SXin Li  <dd>Optional. A FreeMarker expression that determines whether this parameter should be visible. The expression should evaluate to a boolean value (i.e. true or false).</dd>
313*1789df15SXin Li
314*1789df15SXin Li  <dt><code>help</code></dt>
315*1789df15SXin Li  <dd>Optional. The help string to display to the user for this parameter.</dd>
316*1789df15SXin Li
317*1789df15SXin Li</dl>
318*1789df15SXin Li
319*1789df15SXin Li<h4 class="includetoc">&lt;option&gt;</h4>
320*1789df15SXin Li
321*1789df15SXin Li<p>For parameters of type <code>enum</code>, represents a choice for the value.</p>
322*1789df15SXin Li
323*1789df15SXin Li<dl>
324*1789df15SXin Li  <dt><code>id</code></dt>
325*1789df15SXin Li  <dd>The parameter value to set if this option is chosen.</dd>
326*1789df15SXin Li
327*1789df15SXin Li  <dt><code>minApi</code></dt>
328*1789df15SXin Li  <dd>Optional. The minimum API level required if this option is chosen. The IDE will ensure that the target project has a <code>minSdkVersion</code> no lower than this value before instantiating the template.</dd>
329*1789df15SXin Li
330*1789df15SXin Li  <dt><code>[text]</code></dt>
331*1789df15SXin Li  <dd>The text content of this element represents the display value of the choice.</dd>
332*1789df15SXin Li</dl>
333*1789df15SXin Li
334*1789df15SXin Li<h4 class="includetoc">&lt;thumb&gt;</h4>
335*1789df15SXin Li
336*1789df15SXin Li<p>Represents a thumbnail for the template. <code>&lt;thumb&gt;</code> elements should be contained inside a <code>&lt;thumbs&gt;</code> element. The text contents of this element represent the path to the thumbnail. If this element has any attributes, they will be treated as selectors for parameter values. For example, if there are two thumbnails:</p>
337*1789df15SXin Li
338*1789df15SXin Li<pre class="prettyprint lang-xml">
339*1789df15SXin Li&lt;thumbs&gt;
340*1789df15SXin Li  &lt;thumb&gt;template.png&lt;/thumb&gt;
341*1789df15SXin Li  &lt;thumb navType="tabs"&gt;template_tabs.png&lt;/thumb&gt;
342*1789df15SXin Li&lt;/thumbs&gt;
343*1789df15SXin Li</pre>
344*1789df15SXin Li
345*1789df15SXin Li<p>The template 'preview' thumbnail will show <code>template_tabs.png</code> if the value of the <code>navType</code> template parameter is <code>tabs</code> and <code>template.png</code> otherwise.</p>
346*1789df15SXin Li
347*1789df15SXin Li<h4 class="includetoc">&lt;icons&gt;</h4>
348*1789df15SXin Li
349*1789df15SXin Li<p>States that the template would like the Asset Studio icon creation tool of the given type to run, and save the output icons with the given name.</p>
350*1789df15SXin Li
351*1789df15SXin Li<dl>
352*1789df15SXin Li  <dt><code>type</code></dt>
353*1789df15SXin Li  <dd>The type of icon wizard to create. Valid values are <code>notification</code>, <code>actionbar</code>, <code>launcher</code>.</dd>
354*1789df15SXin Li
355*1789df15SXin Li  <dt><code>name</code></dt>
356*1789df15SXin Li  <dd>The base icon name to output, e.g. <code>ic_stat_my_notification</code>.</dd>
357*1789df15SXin Li</dl>
358*1789df15SXin Li
359*1789df15SXin Li<h3>globals.xml.ftl</h3>
360*1789df15SXin Li
361*1789df15SXin Li<p>The optional globals XML file contains global variable definitions, for use in all FreeMarker processing jobs for this template.</p>
362*1789df15SXin Li
363*1789df15SXin Li<p>An example <code>globals.xml.ftl</code> is shown below.</p>
364*1789df15SXin Li
365*1789df15SXin Li<pre class="prettyprint lang-xml">
366*1789df15SXin Li&lt;globals&gt;
367*1789df15SXin Li    &lt;global id="srcOut"
368*1789df15SXin Li            value="src/${slashedPackageName(packageName)}" /&gt;
369*1789df15SXin Li    &lt;global id="activityNameLower"
370*1789df15SXin Li            value="${activityName?lower_case}" /&gt;
371*1789df15SXin Li    &lt;global id="activityClass"
372*1789df15SXin Li            value="${activityName}Activity" /&gt;
373*1789df15SXin Li&lt;/globals&gt;
374*1789df15SXin Li</pre>
375*1789df15SXin Li
376*1789df15SXin Li<h3>recipe.xml.ftl</h3>
377*1789df15SXin Li
378*1789df15SXin Li<p>The recipe XML file contains the individual instructions that should be executed when generating code from this template. For example, you can copy certain files or directories (the copy instruction), optionally running the source files through FreeMarker (the instantiate instruction), and ask the IDE to open a file after the code has been generated (the open instruction).</p>
379*1789df15SXin Li
380*1789df15SXin Li<p class="note"><strong>Note:</strong> The name of the recipe file is up to you, and is defined in <code>template.xml</code>. By convention, however, it's best to call it <code>recipe.xml.ftl</code>.</p>
381*1789df15SXin Li
382*1789df15SXin Li<p class="note"><strong>Note:</strong> The global variables in <code>globals.xml.ftl</code> are available for use in <code>recipe.xml.ftl</code>.</p>
383*1789df15SXin Li
384*1789df15SXin Li<p>An example <code>recipe.xml.ftl</code> is shown below.</p>
385*1789df15SXin Li
386*1789df15SXin Li<pre class="prettyprint lang-xml">
387*1789df15SXin Li&lt;recipe&gt;
388*1789df15SXin Li    &lt;#if appCompat?has_content&gt;
389*1789df15SXin Li    &lt;dependency mavenUrl="com.android.support:appcompat-v7:+"/&gt;
390*1789df15SXin Li    &lt;/#if&gt;
391*1789df15SXin Li
392*1789df15SXin Li    &lt;!-- runs FreeMarker, then copies from
393*1789df15SXin Li         [template-directory]/root/ to [output-directory],
394*1789df15SXin Li         automatically creating directories as needed. --&gt;
395*1789df15SXin Li    &lt;merge from="AndroidManifest.xml.ftl"
396*1789df15SXin Li             to="${escapeXmlAttribute(manifestDir)}/AndroidManifest.xml" /&gt;
397*1789df15SXin Li
398*1789df15SXin Li    &lt;!-- simply copy file, don't run FreeMarker --&gt;
399*1789df15SXin Li    &lt;copy from="res/drawable-mdpi"
400*1789df15SXin Li            to="${escapeXmlAttribute(resDir)}/res/drawable-mdpi" /&gt;
401*1789df15SXin Li    &lt;copy from="res/drawable-hdpi"
402*1789df15SXin Li            to="${escapeXmlAttribute(resDir)}/res/drawable-hdpi" /&gt;
403*1789df15SXin Li    &lt;copy from="res/drawable-xhdpi"
404*1789df15SXin Li            to="${escapeXmlAttribute(resDir)}/res/drawable-xhdpi" /&gt;
405*1789df15SXin Li    &lt;copy from="res/drawable-xxhdpi"
406*1789df15SXin Li            to="${escapeXmlAttribute(resDir)}/res/drawable-xxhdpi" /&gt;
407*1789df15SXin Li    &lt;copy from="res/menu/main.xml"
408*1789df15SXin Li            to="${escapeXmlAttribute(resDir)}/res/menu/${activityNameLower}.xml" /&gt;
409*1789df15SXin Li
410*1789df15SXin Li    &lt;!-- run FreeMarker and then merge with existing files --&gt;
411*1789df15SXin Li    &lt;merge from="res/values/dimens.xml"
412*1789df15SXin Li             to="${escapeXmlAttribute(resDir)}/res/values/dimens.xml" /&gt;
413*1789df15SXin Li    &lt;merge from="res/values-large/dimens.xml"
414*1789df15SXin Li             to="${escapeXmlAttribute(resDir)}/res/values-large/dimens.xml" /&gt;
415*1789df15SXin Li    &lt;merge from="res/values/styles.xml"
416*1789df15SXin Li             to="${escapeXmlAttribute(resDir)}/res/values/styles.xml" /&gt;
417*1789df15SXin Li    &lt;merge from="res/values/strings.xml.ftl"
418*1789df15SXin Li             to="${escapeXmlAttribute(resDir)}/res/values/strings.xml" /&gt;
419*1789df15SXin Li
420*1789df15SXin Li    &lt;!-- Decide which layout to add --&gt;
421*1789df15SXin Li    &lt;#if navType?contains("pager")&gt;
422*1789df15SXin Li        &lt;instantiate
423*1789df15SXin Li            from="${escapeXmlAttribute(resDir)}/res/layout/activity_pager.xml.ftl"
424*1789df15SXin Li              to="${escapeXmlAttribute(resDir)}/res/layout/activity_${activityNameLower}.xml" /&gt;
425*1789df15SXin Li    &lt;#elseif navType == "tabs" || navType == "dropdown"&gt;
426*1789df15SXin Li        &lt;copy from="${escapeXmlAttribute(resDir)}/res/layout/activity_fragment_container.xml"
427*1789df15SXin Li                to="${escapeXmlAttribute(resDir)}/res/layout/activity_${activityNameLower}.xml" /&gt;
428*1789df15SXin Li    &lt;#else&gt;
429*1789df15SXin Li        &lt;copy from="${escapeXmlAttribute(resDir)}/res/layout/activity_simple.xml"
430*1789df15SXin Li                to="${escapeXmlAttribute(resDir)}/res/layout/activity_${activityNameLower}.xml" /&gt;
431*1789df15SXin Li    &lt;/#if&gt;
432*1789df15SXin Li
433*1789df15SXin Li    &lt;!-- Decide which activity code to add --&gt;
434*1789df15SXin Li    &lt;#if navType == "none"&gt;
435*1789df15SXin Li        &lt;instantiate from="src/app_package/SimpleActivity.java.ftl"
436*1789df15SXin Li                       to="${escapeXmlAttribute(srcOut)}/${activityClass}.java" /&gt;
437*1789df15SXin Li    &lt;#elseif navType == "pager"&gt;
438*1789df15SXin Li        &lt;instantiate from="src/app_package/PagerActivity.java.ftl"
439*1789df15SXin Li                       to="${escapeXmlAttribute(srcOut)}/${activityClass}.java" /&gt;
440*1789df15SXin Li    &lt;#elseif navType == "tabs"&gt;
441*1789df15SXin Li        &lt;instantiate from="src/app_package/TabsActivity.java.ftl"
442*1789df15SXin Li                       to="${escapeXmlAttribute(srcOut)}/${activityClass}.java" /&gt;
443*1789df15SXin Li    &lt;#elseif navType == "dropdown"&gt;
444*1789df15SXin Li        &lt;instantiate from="src/app_package/DropdownActivity.java.ftl"
445*1789df15SXin Li                       to="${escapeXmlAttribute(srcOut)}/${activityClass}.java" /&gt;
446*1789df15SXin Li    &lt;/#if&gt;
447*1789df15SXin Li
448*1789df15SXin Li    &lt;!-- open the layout file and Java class when done --&gt;
449*1789df15SXin Li    &lt;open file="${escapeXmlAttribute(resDir)}/res/layout/${activityNameLower}.xml" /&gt;
450*1789df15SXin Li    &lt;open file="${escapeXmlAttribute(srcOut)}/${activityClass}.java" /&gt;
451*1789df15SXin Li&lt;/recipe&gt;
452*1789df15SXin Li</pre>
453*1789df15SXin Li
454*1789df15SXin Li<p>The instructions below are supported:</p>
455*1789df15SXin Li
456*1789df15SXin Li<h4 class="includetoc" data-tocid="recipe_dependency">&lt;dependency&gt;</h4>
457*1789df15SXin Li
458*1789df15SXin Li<p>Indicates that the template requires that a given library be present in the target project. If not present, the IDE will add the dependency to the project.</p>
459*1789df15SXin Li
460*1789df15SXin Li<dl>
461*1789df15SXin Li  <dt><code>mavenUrl</code></dt>
462*1789df15SXin Li  <dd>The maven coordinates of the library. For example,
463*1789df15SXin Li    <code>com.android.support:appcompat-v7:+</code></dd>
464*1789df15SXin Li</dl>
465*1789df15SXin Li
466*1789df15SXin Li<h4 class="includetoc">&lt;copy&gt;</h4>
467*1789df15SXin Li
468*1789df15SXin Li<p>The only required argument is <code>from</code> which specifies the location of the source files to copy under the <code>root/</code> directory. All necessary ancestor directories are automatically created if needed.</p>
469*1789df15SXin Li
470*1789df15SXin Li<p>The default destination location is the same path under the output directory root (i.e. the location of the destination project). If the optional <code>to</code> argument is provided, this specifies the output directory. Note that if the from path ends with <code>.ftl</code>, it will automatically be stripped. For example <code>&lt;instantiate from="res/values/strings.xml.ftl" /&gt;</code> is adequate; this will create a file named <code>strings.xml</code>, not <code>strings.xml.ftl</code>.</p>
471*1789df15SXin Li
472*1789df15SXin Li<p>This argument works recursively, so if <code>from</code> is a directory, that directory is recursively copied.</p>
473*1789df15SXin Li
474*1789df15SXin Li<h4 class="includetoc">&lt;instantiate&gt;</h4>
475*1789df15SXin Li
476*1789df15SXin Li<p>Same as <code>&lt;copy&gt;</code>, but each source file is first run through FreeMarker.</p>
477*1789df15SXin Li
478*1789df15SXin Li<h4 class="includetoc">&lt;merge&gt;</h4>
479*1789df15SXin Li
480*1789df15SXin Li<p>This instruction will run the source file through FreeMarker and then merge the contents of the output into an existing file in the project, or create a new file. The most common use case for this is to add components to the <code>AndroidManifest.xml</code> file of the destination project, or to merge resources such as strings into an existing <code>strings.xml</code> file.</p>
481*1789df15SXin Li
482*1789df15SXin Li<h4 class="includetoc">&lt;open&gt;</h4>
483*1789df15SXin Li
484*1789df15SXin Li<p>Instruct the IDE to open the file created by the specified <code>file</code> argument after code generation is complete.</p>
485*1789df15SXin Li
486*1789df15SXin Li<h4 class="includetoc">&lt;mkdir&gt;</h4>
487*1789df15SXin Li
488*1789df15SXin Li<p>Ensures the directory provided in the <code>at</code> argument exists.</p>
489*1789df15SXin Li
490*1789df15SXin Li<h3>root/</h3>
491*1789df15SXin Li
492*1789df15SXin Li<p>The actual template files (resources, Java sources, Android Manifest changes) should be placed in the <code>root/</code> directory, in a directory structure that roughly resembles what the output directory structure should look like.</p>
493*1789df15SXin Li
494*1789df15SXin Li<p>One difference is that instead of placing source files in <code>src/com/google/...</code> you can just use a naming convention like <code>src/app_package/</code> to indicate that files under this directory will be placed in the destination project's source file package root.</p>
495*1789df15SXin Li
496*1789df15SXin Li
497*1789df15SXin Li
498*1789df15SXin Li
499*1789df15SXin Li<h2>Built-in Template Functions</h2>
500*1789df15SXin Li
501*1789df15SXin Li<p>Several functions are available to FreeMarker expressions and files beyond the standard set of built-in FreeMarker functions. These are listed below.</p>
502*1789df15SXin Li
503*1789df15SXin Li<h3 data-toctitle="activityToLayout">string <em>activityToLayout</em>(string)</h3>
504*1789df15SXin Li
505*1789df15SXin Li<p>This function converts an activity class-like identifer string, such as <code>FooActivity</code>, to a corresponding resource-friendly identifier string, such as <code>activity_foo</code>.</p>
506*1789df15SXin Li
507*1789df15SXin Li<h4>Arguments</h4>
508*1789df15SXin Li<dl>
509*1789df15SXin Li  <dt><code>activityClass</code></dt>
510*1789df15SXin Li  <dd>The activity class name, e.g. <code>FooActivity</code> to reformat.</dd>
511*1789df15SXin Li</dl>
512*1789df15SXin Li
513*1789df15SXin Li<h4>See also</h4>
514*1789df15SXin Li<p><a href="#toc_layouttoactivity"><code>layoutToActivity</code></a></p>
515*1789df15SXin Li
516*1789df15SXin Li<h3 data-toctitle="camelCaseToUnderscore">string <em>camelCaseToUnderscore</em>(string)</h3>
517*1789df15SXin Li
518*1789df15SXin Li<p>This function converts a camel-case identifer string, such as <code>FooBar</code>, to its corresponding underscore-separated identifier string, such as <code>foo_bar</code>.</p>
519*1789df15SXin Li
520*1789df15SXin Li<h4>Arguments</h4>
521*1789df15SXin Li<dl>
522*1789df15SXin Li  <dt><code>camelStr</code></dt>
523*1789df15SXin Li  <dd>The camel-case string, e.g. <code>FooBar</code> to convert to an underscore-delimited string.</dd>
524*1789df15SXin Li</dl>
525*1789df15SXin Li
526*1789df15SXin Li<h4>See also</h4>
527*1789df15SXin Li<p><a href="#toc_underscoretocamelcase"><code>underscoreToCamelCase</code></a></p>
528*1789df15SXin Li
529*1789df15SXin Li<h3 data-toctitle="escapePropertyValue">string <em>escapePropertyValue</em>(string)</h3>
530*1789df15SXin Li
531*1789df15SXin Li<p>This function escapes a string, such as <code>foo=bar</code> such that it is suitable to be inserted in a Java <code>.properties</code> file as a property value, such as <code>foo\=bar</code>.</p>
532*1789df15SXin Li
533*1789df15SXin Li<h4>Arguments</h4>
534*1789df15SXin Li<dl>
535*1789df15SXin Li  <dt><code>str</code></dt>
536*1789df15SXin Li  <dd>The string, e.g. <code>foo=bar</code> to escape to a proper property value.</dd>
537*1789df15SXin Li</dl>
538*1789df15SXin Li
539*1789df15SXin Li<h3 data-toctitle="escapeXmlAttribute">string <em>escapeXmlAttribute</em>(string)</h3>
540*1789df15SXin Li
541*1789df15SXin Li<p>This function escapes a string, such as <code>Android's</code> such that it can be used as an XML attribute value: <code>Android&amp;apos;s</code>. In particular, it will escape ', ", &lt; and &amp;.</p>
542*1789df15SXin Li
543*1789df15SXin Li<h4>Arguments</h4>
544*1789df15SXin Li<dl>
545*1789df15SXin Li  <dt><code>str</code></dt>
546*1789df15SXin Li  <dd>The string to be escaped.</dd>
547*1789df15SXin Li</dl>
548*1789df15SXin Li
549*1789df15SXin Li<h4>See also</h4>
550*1789df15SXin Li<p><a href="#toc_escapexmltext"><code>escapeXmlText</code></a></p>
551*1789df15SXin Li<p><a href="#toc_escapexmlstring"><code>escapeXmlString</code></a></p>
552*1789df15SXin Li
553*1789df15SXin Li<h3 data-toctitle="escapeXmlText">string <em>escapeXmlText</em>(string)</h3>
554*1789df15SXin Li
555*1789df15SXin Li<p>This function escapes a string, such as <code>A &amp; B's</code> such that it can be used as XML text. This means it will escape &lt; and &gt;, but unlike <a href="#toc_escapexmlattribute"><code>escapeXmlAttribute</code></a> it will <b>not</b> escape ' and ". In the preceeding example, it will escape the string to <code>A &amp;amp; B\s</code>. Note that if you plan to use the XML text as the value for a &lt;string&gt; resource value, you should consider using <a href="#toc_escapexmlstring"><code>escapeXmlString</code></a> instead, since it performs additional escapes necessary for string resources.</p>
556*1789df15SXin Li
557*1789df15SXin Li<h4>Arguments</h4>
558*1789df15SXin Li<dl>
559*1789df15SXin Li  <dt><code>str</code></dt>
560*1789df15SXin Li  <dd>The string to escape to proper XML text.</dd>
561*1789df15SXin Li</dl>
562*1789df15SXin Li
563*1789df15SXin Li<h4>See also</h4>
564*1789df15SXin Li<p><a href="#toc_escapexmlattribute"><code>escapeXmlAttribute</code></a></p>
565*1789df15SXin Li<p><a href="#toc_escapexmlstring"><code>escapeXmlString</code></a></p>
566*1789df15SXin Li
567*1789df15SXin Li<h3 data-toctitle="escapeXmlString">string <em>escapeXmlString</em>(string)</h3>
568*1789df15SXin Li
569*1789df15SXin Li<p>This function escapes a string, such as <code>A &amp; B's</code> such that it is suitable to be inserted in a string resource file as XML text, such as <code>A &amp;amp; B\s</code>. In addition to escaping XML characters like &lt; and &amp;, it also performs additional Android specific escapes, such as escaping apostrophes with a backslash, and so on.</p>
570*1789df15SXin Li
571*1789df15SXin Li<h4>Arguments</h4>
572*1789df15SXin Li<dl>
573*1789df15SXin Li  <dt><code>str</code></dt>
574*1789df15SXin Li  <dd>The string, e.g. <code>Activity's Title</code> to escape to a proper resource XML value.</dd>
575*1789df15SXin Li</dl>
576*1789df15SXin Li
577*1789df15SXin Li<h4>See also</h4>
578*1789df15SXin Li<p><a href="#toc_escapexmlattribute"><code>escapeXmlAttribute</code></a></p>
579*1789df15SXin Li<p><a href="#toc_escapexmltext"><code>escapeXmlText</code></a></p>
580*1789df15SXin Li
581*1789df15SXin Li<h3 data-toctitle="extractLetters">string <em>extractLetters</em>(string)</h3>
582*1789df15SXin Li
583*1789df15SXin Li<p>This function extracts all the letters from a string, effectively removing any punctuation and whitespace characters.</p>
584*1789df15SXin Li
585*1789df15SXin Li<h4>Arguments</h4>
586*1789df15SXin Li<dl>
587*1789df15SXin Li  <dt><code>str</code></dt>
588*1789df15SXin Li  <dd>The string to extract letters from</dd>
589*1789df15SXin Li</dl>
590*1789df15SXin Li
591*1789df15SXin Li<h3 data-toctitle="classToResource">string <em>classToResource</em>(string)</h3>
592*1789df15SXin Li
593*1789df15SXin Li<p>This function converts an Android class name, such as <code>FooActivity</code> or <code>FooFragment</code>, to a corresponding resource-friendly identifier string, such as <code>foo</code>, stripping the 'Activity' or 'Fragment' suffix. Currently stripped suffixes are listed below.</p>
594*1789df15SXin Li
595*1789df15SXin Li<ul>
596*1789df15SXin Li  <li>Activity</li>
597*1789df15SXin Li  <li>Fragment</li>
598*1789df15SXin Li  <li>Provider</li>
599*1789df15SXin Li  <li>Service</li>
600*1789df15SXin Li</ul>
601*1789df15SXin Li
602*1789df15SXin Li<h4>Arguments</h4>
603*1789df15SXin Li<dl>
604*1789df15SXin Li  <dt><code>className</code></dt>
605*1789df15SXin Li  <dd>The class name, e.g. <code>FooActivity</code> to reformat as an underscore-delimited string with suffixes removed.</dd>
606*1789df15SXin Li</dl>
607*1789df15SXin Li
608*1789df15SXin Li<h4>See also</h4>
609*1789df15SXin Li<p><a href="#toc_activitytolayout"><code>activityToLayout</code></a></p>
610*1789df15SXin Li
611*1789df15SXin Li<h3 data-toctitle="layoutToActivity">string <em>layoutToActivity</em>(string)</h3>
612*1789df15SXin Li
613*1789df15SXin Li<p>This function converts a resource-friendly identifer string, such as <code>activity_foo</code>, to a corresponding Java class-friendly identifier string, such as <code>FooActivity</code>.</p>
614*1789df15SXin Li
615*1789df15SXin Li<h4>Arguments</h4>
616*1789df15SXin Li<dl>
617*1789df15SXin Li  <dt><code>resourceName</code></dt>
618*1789df15SXin Li  <dd>The resource name, e.g. <code>activity_foo</code> to reformat.</dd>
619*1789df15SXin Li</dl>
620*1789df15SXin Li
621*1789df15SXin Li<h4>See also</h4>
622*1789df15SXin Li<p><a href="#toc_activitytolayout"><code>activityToLayout</code></a></p>
623*1789df15SXin Li
624*1789df15SXin Li<h3 data-toctitle="slashedPackageName">string <em>slashedPackageName</em>(string)</h3>
625*1789df15SXin Li
626*1789df15SXin Li<p>This function converts a full Java package name to its corresponding directory path. For example, if the given argument is <code>com.example.foo</code>, the return value will be <code>com/example/foo</code>.</p>
627*1789df15SXin Li
628*1789df15SXin Li<h4>Arguments</h4>
629*1789df15SXin Li<dl>
630*1789df15SXin Li  <dt><code>packageName</code></dt>
631*1789df15SXin Li  <dd>The package name to reformat, e.g. <code>com.example.foo</code>.</dd>
632*1789df15SXin Li</dl>
633*1789df15SXin Li
634*1789df15SXin Li<h3 data-toctitle="underscoreToCamelCase">string <em>underscoreToCamelCase</em>(string)</h3>
635*1789df15SXin Li
636*1789df15SXin Li<p>This function converts an underscore-delimited string, such as <code>foo_bar</code>, to its corresponding camel-case string, such as <code>FooBar</code>.</p>
637*1789df15SXin Li
638*1789df15SXin Li<h4>Arguments</h4>
639*1789df15SXin Li<dl>
640*1789df15SXin Li  <dt><code>underStr</code></dt>
641*1789df15SXin Li  <dd>The underscore-delimited string, e.g. <code>foo_bar</code> to convert to a camel-case string.</dd>
642*1789df15SXin Li</dl>
643*1789df15SXin Li
644*1789df15SXin Li<h4>See also</h4>
645*1789df15SXin Li<p><a href="#toc_camelcasetounderscore"><code>camelCaseToUnderscore</code></a></p>
646*1789df15SXin Li
647*1789df15SXin Li
648*1789df15SXin Li
649*1789df15SXin Li<h2>Built-in Template Parameters</h2>
650*1789df15SXin Li
651*1789df15SXin Li<p>Several parameters are available to FreeMarker expressions and files beyond <a href="#toc_parameter">those defined by the template</a>. These are listed below.</p>
652*1789df15SXin Li
653*1789df15SXin Li<h3>packageName</h3>
654*1789df15SXin Li
655*1789df15SXin Li<p>The Java-style Android package name for the project, e.g. <code>com.example.foo</code></p>
656*1789df15SXin Li
657*1789df15SXin Li<h3>applicationPackage</h3>
658*1789df15SXin Li
659*1789df15SXin Li<p>Will be the application package (i.e. the package name declared in the app manifest) if the target package for this template is not the application package. Otherwise, this parameter will be empty.</p>
660*1789df15SXin Li
661*1789df15SXin Li<h3>isNewProject</h3>
662*1789df15SXin Li
663*1789df15SXin Li<p>A boolean indicating whether or not this template is being instantiated as part of a New Project flow.</p>
664*1789df15SXin Li
665*1789df15SXin Li<h3>minApi</h3>
666*1789df15SXin Li
667*1789df15SXin Li<p>The minimum API level the project supports. Note that this value could be a string so consider using <a href="#toc_minapilevel"><code>minApiLevel</code></a> instead.</p>
668*1789df15SXin Li
669*1789df15SXin Li<h3>minApiLevel</h3>
670*1789df15SXin Li
671*1789df15SXin Li<p>The minimum API level the project supports, guaranteed to be a number. This is generally used to guard the generation of code based on the project's API level, for example:</p>
672*1789df15SXin Li
673*1789df15SXin Li<pre>
674*1789df15SXin Liint drawableResourceId = android.R.layout.simple_list_item_<strong>&lt;#if minApiLevel gte 11&gt;</strong>activated_<strong>&lt;/#if&gt;</strong>_1;
675*1789df15SXin Li</pre>
676*1789df15SXin Li
677*1789df15SXin Li<h3>buildApi</h3>
678*1789df15SXin Li
679*1789df15SXin Li<p>The API level that the project is building against, guaranteed to be a number. This is generally used to guard the generation of code based on what version of the Android SDK the project is being built against, for example:</p>
680*1789df15SXin Li
681*1789df15SXin Li<pre>
682*1789df15SXin Li&lt;TextView android:layout_width="wrap_content"
683*1789df15SXin Li    android:layout_height="<strong>&lt;#if buildApi gte 8&gt;</strong>match_parent<strong>&lt;#else&gt;</strong>fill_parent<strong>&lt;/#if&gt;</strong>" /&gt;
684*1789df15SXin Li</pre>
685*1789df15SXin Li
686*1789df15SXin Li<h3>manifestDir</h3>
687*1789df15SXin Li
688*1789df15SXin Li<p>The target output directory for the <code>AndroidManifest.xml</code> file. This varies depending on the project's directory structure (Gradle-style or Ant-style).</p>
689*1789df15SXin Li
690*1789df15SXin Li<h3>srcDir</h3>
691*1789df15SXin Li
692*1789df15SXin Li<p>The target Java source root directory for the project. This varies depending on the project's directory structure (Gradle-style or Ant-style). It's common to concatenate the package name:</p>
693*1789df15SXin Li
694*1789df15SXin Li<pre>
695*1789df15SXin Li${srcDir}/${slashedPackageName(packageName)}
696*1789df15SXin Li</pre>
697*1789df15SXin Li
698*1789df15SXin Li<h4>See also</h4>
699*1789df15SXin Li<p><a href="#toc_slashedpackagename"><code>slashedPackageName</code></a></p>
700*1789df15SXin Li
701*1789df15SXin Li<h3>resDir</h3>
702*1789df15SXin Li
703*1789df15SXin Li<p>The target resource directory root (<code>res/</code> folder) for the project. This varies depending on the project's directory structure (Gradle-style or Ant-style).</p>
704*1789df15SXin Li
705*1789df15SXin Li
706*1789df15SXin Li
707*1789df15SXin Li
708*1789df15SXin Li
709*1789df15SXin Li<h2>Notes for Template Authors</h2>
710*1789df15SXin Li
711*1789df15SXin Li<h3>Tools metadata</h3>
712*1789df15SXin Li
713*1789df15SXin Li<p>When creating activity layouts, make sure to include the activity name in the root view in the layout as part of the <code>tools</code> namespace, as shown in the following example:</p>
714*1789df15SXin Li
715*1789df15SXin Li<pre class="prettyprint lang-xml">
716*1789df15SXin Li&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
717*1789df15SXin Li    <strong>xmlns:tools="http://schemas.android.com/tools"</strong>
718*1789df15SXin Li    android:layout_width="match_parent"
719*1789df15SXin Li    android:layout_height="match_parent"
720*1789df15SXin Li    android:gravity="center"
721*1789df15SXin Li    android:text="@string/hello_world"
722*1789df15SXin Li    android:padding="@dimen/padding_medium"
723*1789df15SXin Li    <strong>tools:context=".${activityClass}"</strong> /&gt;
724*1789df15SXin Li</pre>
725*1789df15SXin Li
726*1789df15SXin Li<p>As of ADT 20 we use this attribute in layouts to maintain a mapping to the active activity to use for a layout. (Yes, there can be more than one, but this attribute is showing the activity context you want to edit the layout as. For example, it will be used to look up a theme registration (which is per-activity rather than per-layout) in the manifest file, and we will use this for other features in the future&mdash;for example to preview the action bar, which also requires us to know the activity context.</p>
727*1789df15SXin Li
728*1789df15SXin Li</div>
729*1789df15SXin Li
730*1789df15SXin Li</body>
731*1789df15SXin Li</html>
732