Git Product home page Git Product logo

virtualview_tools's Introduction

Attention. This project is not maintained any more !!!

VirtualView Tools

中文文档

This project is a tool library as a part of VirtualView library, used to compile XML files:

How-to

Run From CMD

Tools Introduction

Download the source code, the executable is located at folder TemplateWorkSpace. There are several files here:

File Introduction
config.properties configs of widget's ID and attribute's value type
templatelist.properties the file list of XML template
build output folder after compiling XML files
template the source code XML files
compiler.jar executable jar file exported from the total source code
buildTemplate.sh the command script to run compiler.jar
How to Run
  • Execute the follow command in Terminal: sh buildTemplate.sh
  • The artifacts is located at folder build
How to Configure config.properties
  • VIEW_ID_XXXX
    • Define the widget's id, User's custom widget's should start from 1000;
    • For example, VIEW_ID_FrameLayout=1 means the tag <FrameLayout> in XML will be compiled to number 1;
    • The property name in should start with VIEW_ID_;  - Widget's Id value from 1 t0 1000 are reserved for system, so custom widget's id should be assigned start 1001;
  • property=ValueType
    • Define the attribute's value type, which decide how to parse and compile original value into a compiled data in.
    • Currently supported defination is:
      • Normal type:String(Default, no need configuration)、FloatColorExprNumberIntBool
      • Special type: FlagTypeAlignLayoutWidthHeightTextStyleDataModeVisibility
      • Enum type: Enum<name:value,……>
        • Enum desp:
          • For example: flexDirection=Enum<row:0,row-reverse:1,column:2,column-reverse:3>
          • This means the attribute row will be converted into number 0, and row-reverse into number 1
How to Configure templatelist.properties
  • Format: xmlFileName=outFileName,Version[,platform]
    • xmlFileName; The file name need to be compiled under folder template, no need to add file extension here;
    • outFileName: The output file name after compiling;
    • Version: XML file's version;
    • platform: Optional, valid value are android and iphone. Used to describe which platform current XML is target to, the output artifacts will be stored at a separate folder;
How to Write XML
  • The same way as before, while no need to write Java code to process new attributes, the only thing need to do is add a ValueType defination in config.properties;
Artifacts after Compiling
  • File under folder out: the binary data serialized from template file, all the other three outputs are generated from this.
  • File under folder java: the binary data in form of Java byte array. May be copied to Android project to run.
  • File udner folder sign: the md5 of binary data;
  • File under folder txt: the binary data in form of HEX string.

Use as API

Except that use as a command tool to compile file, there is an another way to compile XML data from an IDE plugin, a client, a backend service or somewhere else. So it's possible to use JAVA API to compile data, the example code is as follow:

//Build a ViewCompilerApi instance
ViewCompilerApi viewCompiler = new ViewCompilerApi();
//init a ConfigLoader to load config.properties.
viewCompiler.setConfigLoader(new LocalConfigLoader());
//read XML data from file or somewhere else
FileInputStream fis = new FileInputStream(rootDir);
//Parameters are XML data's InputStream, template name, template version
byte[] result = viewCompiler.compile(fis, "icon", 13);

Contributing

Before you open an issue or create a pull request, please read Contributing Guide first.

LICENSE

VirtualView tools is available under the MIT license.

virtualview_tools's People

Contributors

alibaba-oss avatar harrisonxi avatar isaced avatar jadyli avatar longerian avatar mikeafc avatar mingjunli avatar pmwy avatar rysle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

virtualview_tools's Issues

textStyle=“normal”报错

官方文档描述,
NText的textStyle属性可以赋值enum(normal/bold/italic/strike/underline),
VText的textStyle属性可以赋值enum(norma/bold/italic/strike)。
在使用textStyle=“normal”时报错:VALUE ERROR:key=textStyle value=normal。
需要修改TextBaseParser和TextStyleValueParser,在其中添加对normal的判断:
if (!TextUtils.equals("normal", str)) {
Log.e(TAG, "invalidate value:" + str);
ret = false;
break;
}

VSCode

What plug-ins does vscode need to install???

组件工具支持一份模板输出两个平台的模板

背景

有的属性两端需求不一样,比如对于背景色,为了提升性能,Android需要尽量少,iOS为了需要补充。为了防止多份模板,需要支持一份文件,两次输出。

方案

  1. 增加命名控件:android, iphone
  2. 带android的输出到Android,带iphone的输出到iphone目录,否则只输出一份共用的。

Could not find method install() for arguments [compilerJcenterInstall_4o5rl0y8sor0ptjem42w3hkhz$_run_closure1@14fe0f6c] on project ':virtual-compiler' of type org.gradle.api.Project.

Hi, 各位大佬,我使用 TemplateWorkSpace 目录下的 buildTemplate.sh 脚本,去生成模板输出时,功能完全正常。在 win 和 macOS 下都能正常工作。但是我看到 buildTemplate.sh 文件里使用了 compiler.jar 这个文件,所以,为了学习源码的设计思路,我想用这个工程重新编译,生成一个 compiler.jar 文件。
于是我尝试了在工程根目录和各子工程目录下使用 gradle tasks 查看任务,尝试使用 gradle gerenateJar 生成最终的 jar,或 gradle jar,gradle build,gradle assemble 等命令,均会提示像标题这样的错误。我注意到相关的代码可能对最终结果没什么影响,于是注释掉相关的代码,然后重新执行 gradle generateJar 命令,但是得到的 jar 文件全称为:compiler-1.0-SNAPSHOT-capsure.jar, 而且和 TempalteWorkSpace 里的 compiler.jar 并不一样,缺少了 junit 相关的 classes。而且,在替换 compiler.jar 之后,使用 buildTemplate.sh 脚本,无法正确生成 build 目录。
请问各位大佬,有谁知道如何编译这个工程吗?

XML 中无法输入多行文本

    <VText
            layoutWidth="50"
            layoutHeight="50"
            background="#0000FF"
            textSize="12"
            layoutGravity="v_center|h_center"
            gravity="h_center"
            lines="2"
            text="1\nheight = 100" />

类似以上 XML 无法生效,文本 text 的值为 "1",转义符及后续内容被截断。

尝试使用 &#x0020; 也无效。

NText的text一旦有"<>"这两个特殊字符,会导致编译结果不完整

比如正常的模板,text写"aa"

<?xml version="1.0" encoding="utf-8"?>
<VHLayout
        orientation="V"
        layoutWidth="300"
        layoutHeight="300"
        background="#999999">
	<NText
	    text="aa"
	    layoutWidth="wrap_content"
	    layoutHeight="wrap_content"/>
</VHLayout>

编译后的结果大小:159bytes,显示正常

把text改成"<>",感觉就好像截断了一样,编译后只有115bytes,并且不能正常显示

dalao能教教怎么使用吗

macOS
=========================TemplateWorkSpace =========================
$ sh buildTemplate.sh

java.io.FileNotFoundException: /virtualview_tools-master/compiler-tools/TemplateWorkSpace/templatelist.properties (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:220)
at java.base/java.io.FileInputStream.(FileInputStream.java:158)
at com.libra.virtualview.tool.CompilerResourceConfig.(CompilerResourceConfig.java:55)
at com.libra.virtualview.tool.VirtualViewCompileTool.compileInProject(VirtualViewCompileTool.java:71)
at com.libra.virtualview.tool.VirtualViewCompileTool.main(VirtualViewCompileTool.java:44)
templatelist.properties path error!
templatelist.properties path error!

========================= RealtimePreview=========================
$ ./run.sh

############# Begin Scripts #############
############# Copy All .xml files #############
############# Prebuild : templatelist.properties #############
############# Build: out files #############
java.io.FileNotFoundException:/virtualview_tools-master/compiler-tools/RealtimePreview/templatelist.properties (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:220)
at java.base/java.io.FileInputStream.(FileInputStream.java:158)
at com.libra.virtualview.tool.CompilerResourceConfig.(CompilerResourceConfig.java:55)
at com.libra.virtualview.tool.VirtualViewCompileTool.compileInProject(VirtualViewCompileTool.java:71)
at com.libra.virtualview.tool.VirtualViewCompileTool.main(VirtualViewCompileTool.java:44)
templatelist.properties path error!
templatelist.properties path error!
############# Build: data.json #############
模版 .out 未找到 : HelloWorld.xml
############# Run HTTP Server #############
Start HTTP Server : http://192.168.0.113:7788
############# Move .out files #############
############# Clean #############
############# Dir #############
templates: ["HelloWorld"]
############# Watch dog #############

编译后为什么显示不完全呢?

vvtest.xml如下:

<NImage
        layoutWidth="48rp"
        layoutHeight="48rp"
        layoutMarginLeft="34rp"
        layoutGravity="left|v_center"
        src="${imgUrl}"
        scaleType="center_crop"
/>
<NText
        layoutWidth="wrap_content"
        layoutHeight="wrap_content"
        layoutMarginLeft="94rp"
        text="${title}"
        layoutGravity="left|v_center"
        textSize="28rp"
        textColor="#555555"
/>
<NText
        layoutWidth="wrap_content"
        layoutHeight="wrap_content"
        layoutMarginRight="50rp"
        layoutGravity="right|v_center"
        textSize="28rp"
        text="${subtitle}"
        textColor="${subtitleColor}"/>
<NImage
        layoutWidth="14rp"
        layoutHeight="30rp"
        layoutMarginRight="28rp"
        layoutGravity="right|v_center"
        src="${arrowImgUrl}"
        scaleType="center_crop"
/>

<NLine
        layoutWidth="680rp"
        layoutHeight="1rp"
        orientation="H"
        layoutGravity="h_center|bottom"
        src="${lineImgUrl}"
        color="#999999"
/>

data.json如下:
[
{
"type": "container-scroll",
"style": {
"pageWidth": 300,
"hGap": 50,
"pageHeight": 100
},
"items": [
{
"imgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"arrowImgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"title": "标题1",
"subtitle": "subtitle1",
"type": "vvtest"
},
{
"imgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"arrowImgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"title": "标题2",
"subtitle": "subtitle2",
"type": "vvtest"
},
{
"imgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"arrowImgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"title": "标题3",
"subtitle": "subtitle3",
"type": "vvtest"
},
{
"imgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"arrowImgUrl": "https://gju2.alicdn.com/tps/i1/3316585763/O1CN01s5zdWd1sRV1Z56icV_!!0-item_pic.jpg_460x460Q90.jpg",
"title": "标题4",
"subtitle": "subtitle4",
"type": "vvtest"
}
]
}
]

最终效果就是只显示了 下面的指示器,上面的布局没有显示

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.