-
<template>
中的name
属性,对应新建Activity
时显示的名字 -
<category>
对应New的类别为Activity 上面parameter标签中部分属性如下: -
id :唯一标识,最终通过该属性的值,获取用户输入值(文本框内容,是否选中)
-
name:界面上的类似label的提示语
-
type : 输入值类型
-
constraints:填写值的约束
-
suggest:建议值,比如填写ActivityName的时候,会给出一个布局文件的建议值。
-
default:默认值
-
help:底部显示的提升语 对应的android studio操作的图形化界面(上面代码有删减)
<?xml version="1.0"?>
<#include “…/common/common_globals.xml.ftl” />
globals存储的是一些全局变量
<?xml version="1.0"?>
<#import “root://activities/common/kotlin_macros.ftl” as kt>
<#include “…/common/recipe_manifest.xml.ftl” />
<@kt.addAllKotlinDependencies />
<#if generateLayout>
<#include “…/common/recipe_simple.xml.ftl” />
</#if>
<instantiate from=“root/src/app_package/SimpleActivity.${ktOrJavaExt}.ftl”
to="
e
s
c
a
p
e
X
m
l
A
t
t
r
i
b
u
t
e
(
s
r
c
O
u
t
)
/
{escapeXmlAttribute(srcOut)}/
escapeXmlAttribute(srcOut)/{activityClas
s}.${ktOrJavaExt}" />
常用标签及其含义:
-
copy :从root中copy文件到我们的目标目录,比如我们的模板Activity需要使用一些图标,那么可能就需要使用copy标签将这些图标拷贝到我们的项目对应文件夹。
-
merge : 合并的意思,比如将我们使用到的strings.xml合并到我们的项目的stirngs.xml中
-
instantiate : 和copy类似,但是可以看到上例试将ftl->java文件的,也就是说中间会通过一个步骤,将ftl中的变量都换成对应的值,那么完整的流程是
ftl->freemarker process -> java
。 -
open:在代码生成后,打开指定的文件,比如我们新建一个Activity后,默认就会将该Activity打开。
freemaker简单语法:
//当价格为0时,就会打印出 “Pythons are free today!”:
<#if animals.python.price != 0>
Pythons are not free today!
</#if>
<#if >
<#elseif >
<#else >
</#if >
<#if animals.python.price < animals.elephant.price>
Pythons are cheaper than elephants today.
<#elseif animals.elephant.price < animals.python.price>
Elephants are cheaper than pythons today.
<#else>
Elephants and pythons cost the same today.
</#if>
使用 include
指令, 我们可以在模板中插入其他文件的内容。
============================================================
一.template
<?xml version="1.0"?><template
format=“5”
revision=“5”
name=“自定义列表的 Activity”
minApi=“9”
minBuildApi=“14”
description=“创建一个新的列表”>
<parameter
id=“activityClass”
name=“Activity Name”
type=“string”
constraints=“class|unique|nonempty”
suggest="${layoutToActivity(layoutName)}"
default=“MainActivity”
help=“The name of the activity class to create” />
<parameter
id=“isLauncher”
name=“Launcher Activity”
type=“boolean”
default=“false”
help=“If true, this activity will have a CATEGORY_LAUNCHER intent filter, making it visible in the launcher” />
<parameter
id=“generateLayout”
name=“Generate Layout File”
type=“boolean”
default=“true”
help=“If true, a layout file will be generated” />
<parameter
id=“layoutName”
name=“Layout Name”
type=“string”
constraints=“layout|unique|nonempty”
suggest="${activityToLayout(activityClass)}"
default=“activity_main”
visibility=“generateLayout”
help=“The name of the layout to create for the activity” />
<parameter
id=“generateAdapter”
name=“是否自动创建adapter”
type=“boolean”
default=“true”
help=“If true, a adapter file will be generated” />
<parameter
id=“adapterName”
name=“adapter Name”
type=“string”
constraints=“class|unique|nonempty”
suggest="${underscoreToCamelCase(classToResource(activityClass))}Adapter"
default=“MainAdapter”
visibility=“generateAdapter”
help=“The name of the adapter to create for the activity” />
<parameter
id=“generateItemLayout”
name=“是否自动创建item”
type=“boolean”
default=“true”
help=“If true, a item layout file will be generated” />
<parameter
id=“itemLayoutName”
name=“item 的 Layout Name”
type=“string”
constraints=“layout|unique|nonempty”
suggest=“item_${classToResource(activityClass)}”
default=“item_main”
visibility=“generateItemLayout”
help=“The name of the layout to create for the activity” />
<parameter
id=“backwardsCompatibility”
name=“Backwards Compatibility (AppCompat)”
type=“boolean”
default=“true”
help=“If false, this activity base class will be Activity instead of AppCompatActivity” />
_${classToResource(activityClass)}"
default=“item_main”
visibility=“generateItemLayout”
help=“The name of the layout to create for the activity” />
<parameter
id=“backwardsCompatibility”
name=“Backwards Compatibility (AppCompat)”
type=“boolean”
default=“true”
help=“If false, this activity base class will be Activity instead of AppCompatActivity” />