当前位置:主页 > 查看内容

EasyClick 原生UI连载二十六

发布时间:2021-10-14 00:00| 位朋友查看

简介:原生UI连载目录 EasyClick 原生UI教程 原生UI连载二十六UI与脚本之间的交互 二 UI 参数设置效果图 main.xml 代码 ui.js代码 main.js代码 重要提示 EasyClick 原生UI教程 讲师Mr-老鬼QQ1156346325 EasyClick 原生UI教程电梯直达 EasyClick 原生UI教程总纲 原……

EasyClick 原生UI教程

讲师:Mr-老鬼,QQ:1156346325
EasyClick 原生UI教程电梯直达EasyClick 原生UI教程总纲

原生UI连载二十六UI与脚本之间的交互 二

了解下兄弟篇:原生UI连载六UI与脚本之间的交互 一

UI 参数设置效果图

在这里插入图片描述

main.xml 代码

<?xml version="1.0" encoding="UTF-8" ?><!--
  ~ Copyright(c) 2021,
  ~    文件名称:main.xml
  ~    创建时间:2021/4/25 下午9:50
  ~    作者:laogui
  -->

<ScrollView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:android="http://schemas.android.com/apk/res/android"
            xsi:noNamespaceSchemaLocation="layout.xsd"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
    <LinearLayout android:layout_height="match_parent"
                  android:layout_width="match_parent"
                  android:orientation="vertical"
                  android:padding="20dp">
        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="表单开始,设置tag属性,用于在代码里面获取对应的值" />


        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="姓名: " />

            <EditText android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:tag="name"
                      android:hint="请输入姓名" />

        </LinearLayout>

        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="年龄: " />

            <EditText android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:tag="age"
                      android:hint="请输入年龄" />

        </LinearLayout>


        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="性别: " />

            <Spinner android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:tag="sex"
                     android:text="男同学|女同学" />

        </LinearLayout>


        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="喜欢玩" />

            <EditText android:layout_width="100dp"
                      android:layout_height="wrap_content"
                      android:gravity="center_horizontal"
                      android:tag="a1"
                      android:hint="什么" />
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="" />
            <EditText android:layout_width="100dp"
                      android:gravity="center_horizontal"
                      android:layout_height="wrap_content"
                      android:tag="a2"
                      android:hint="什么" />
        </LinearLayout>


        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="爱        好: " />
            <LinearLayout android:layout_height="wrap_content"
                          android:orientation="vertical"
                          android:layout_width="match_parent">
                <CheckBox android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:tag="music"
                          android:text="听音乐" />
                <CheckBox android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:tag="sing"
                          android:text="唱歌" />
                <CheckBox android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:tag="dance"
                          android:text="跳舞" />
            </LinearLayout>

        </LinearLayout>


        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="所在年级: " />
            <RadioGroup android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_width="match_parent">
                <RadioButton android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:tag="one"
                             android:text="一年级" />
                <RadioButton android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:tag="two"
                             android:text="二年级" />
                <RadioButton android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:tag="three"
                             android:text="三年级" />
            </RadioGroup>

        </LinearLayout>
        <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:gravity="center_vertical"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:gravity="center_vertical"
                      android:text="备注: " />

            <EditText android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:tag="mark"
                      android:minHeight="100dp"
                      android:maxLines="1000"
                      android:hint="备注" />

        </LinearLayout>
        <Button android:layout_width="match_parent"
                android:layout_height="40dp"
                android:tag="saved"
                android:text="保存数据" />
    </LinearLayout>
</ScrollView>

ui.js代码

/*
 * Copyright(c) 2021,
 *    文件名称:ui.js
 *    创建时间:2021/4/25 下午9:50
 *    作者:laogui
 */

function main() {
    ui.layout("参数设置", "main.xml");
    ui.setEvent(ui.saved,"click",function (view){
        let saved = ui.saveAllConfig();// 保存所有数据 
        logd(saved);
    })
}
main();

点击按钮保存数据调试结果

[2021-04-25 22:02:05.265]【远程设备】预览成功...
[2021-04-25 22:02:05.597]【远程设备】解析UI layout/ui.js文件
[2021-04-25 22:02:05.938]【远程设备】执行UI成功
[2021-04-25 22:02:39.205]【远程设备】true // 数据返回保存成功

main.js代码


/*
 * Copyright(c) 2021,
 *    项目名称:619
 *    文件名称:main.js
 *    创建时间:2021/4/25 下午9:50
 *    作者:laogui
 */

function main() {
    //开始再这里编写代码了!!
    toast("Hello World");

    //如果自动化服务正常
    if (!autoServiceStart(3)) {
        logd("自动化服务启动失败,无法执行脚本")
        exit();
        return;
    }
    logd("开始执行脚本...")
    let name = readConfigString("name");//读取单个配置
    logd("姓名: " + name);
    logd("年龄: " + readConfigString("age"));
    logd("听音乐: " + readConfigString("music"));
    logd("是不是一年级: " + readConfigString("one"));
    logd("备注: " + readConfigString("mark"));
    logd(JSON.stringify(getConfigJSON()));// 获取所有配置
}

function autoServiceStart(time) {
    for (var i = 0; i < time; i++) {
        if (isServiceOk()) {
            return true;
        }
        var started = startEnv();
        logd("第" + (i + 1) + "次启动服务结果: " + started);
        if (isServiceOk()) {
            return true;
        }
    }
    return isServiceOk();
}

main();

运行工程调试结果

[2021-04-25 22:03:37.665]【远程设备】准备运行工程...
[2021-04-25 22:03:37.668]【远程设备】开始启动...
[2021-04-25 22:03:37.758]【远程设备】开始执行,请稍等
[2021-04-25 22:03:37.779]【远程设备】解析js/main.js文件
[2021-04-25 22:03:37.797]【远程设备】Toast消息: (js/main.js#12 )Hello World
[2021-04-25 22:03:47.58]【远程设备】第1次启动服务结果: true
[2021-04-25 22:03:47.76]【远程设备】开始执行脚本...
[2021-04-25 22:03:47.78]【远程设备】姓名: 张文
[2021-04-25 22:03:47.82]【远程设备】年龄: 18
[2021-04-25 22:03:47.86]【远程设备】{"name":"张文","age":"18","sex":"女同学","a1":"跳舞","a2":"看书","music":true,"sing":true,"dance":true,"one":false,"two":false,"three":true,"mark":"小姐姐","saved":"保存数据","jobTaskTag":""}
[2021-04-25 22:03:47.88]【远程设备】听音乐: true
[2021-04-25 22:03:47.90]【远程设备】备注: 小姐姐
[2021-04-25 22:03:47.91]【远程设备】是不是一年级: false

重要提示

注意XML文件里的tag属性 和ui.saved这种一定是对应的否则会报错!!!

我是Mr-老鬼、QQ1156346325 。交流QQ群:620028786,647082990
------------------------------------------------版权声明------------------------------------------------------
本文版权所有~Mr-老鬼 ~转载请注明原文地址
免责声明:本文所有的教程仅限交流学习使用不得用于违法用途,造成的法律后果本人不承担责任。

;原文链接:https://blog.csdn.net/qq_21460781/article/details/116139063
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐