/*
软件作者:https://xuhss.com/oxox/pro
*/
"ui";
/**
*作者QQ: 1811588980
*完成时间: 2019年6月14日 下午11:36:58
*测试机型: vivo PD1813D
*Auto.js版本: 4.1.0 Alpha5
*Android版本: 8.1.0
*屏幕: 1080*2280
*API: 27
*备注: 录制字符笔画数据。
**/
ui.layout(
<vertical>
<horizontal w="*">
<input id="input" hint="请输入单个字符" layout_weight="1"/>
<button id="but" text="录笔画"/>
</horizontal>
<canvas layout_weight="1" id="canvas" />
<HorizontalScrollView w="*"h="50" bg="#dddddd">
<horizontal h="auto">
<button id="but_A" layout_weight="1" h="auto" text="退笔"/>
<button id="but_B" layout_weight="1" h="auto" text="清笔"/>
<button id="but_C" layout_weight="1" h="auto" text="退字"/>
<button id="but_D" layout_weight="1" h="auto" text="定字"/>
<button id="but_E" layout_weight="1" h="auto" text="保存至文件"/>
</horizontal>
</HorizontalScrollView>
</vertical>
);
var storage = storages.create("AJ笔画录制");
var currentTxt = storage.get("txt", "");
//已录制的字符数据。
var MainStrokeAry = storage.get("json", new Array); //↓↓↓↓
/*元素
{
txt:k,
stroke:[[x,y,x,y,x,y,………],………]
}
*/
//单个字符的笔画数据。
var strokeAry = new Array; //[[x,y,x,y,x,y,………],………]
//每笔的数据。
var strokePoints = new Array; //[x,y,x,y,x,y,………]
threads.start(function() {
//console.show();
});
var paint = new Paint;
paint.setTextAlign(Paint.Align.CENTER);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setARGB(255, 255, 0, 0);
var kg = false;
var jishi = 0;
//new android.graphics.RectF
ui.but.click(function() {
let t = String(ui.input.getText());
if (t && t.length == 1) {
currentTxt = t;
} else {
toastLog("你输入的不对" + t);
};
});
ui.but_A.click(function() {
strokeAry.pop();
});
ui.but_B.click(function() {
strokeAry = new Array;
});
ui.but_C.click(function() {
MainStrokeAry.pop();
});
ui.but_D.click(function() {
MainStrokeAry.push({
txt: currentTxt,
stroke: strokeAry
});
});
ui.but_E.click(function() {
threads.start(function() {
var p = dialogs.prompt("保存路径", storage.get("savePath", "/sdcard/脚本/LZ笔画数据.js"));
if (p) {
storage.put("savePath", p);
let json = {};
for (let obj of MainStrokeAry) {
json[obj.txt] = obj.stroke;
};
files.write(p, JSON.stringify(json));
//files.write(p, JSON.stringify(json,null,4));
toastLog("成功");
};
});
});
events.on("exit", function() {
storage.put("txt", currentTxt);
storage.put("json", MainStrokeAry);
//files.write(storage.get("savePath", "/sdcard/脚本/LZ动作.js"), );
});
ui.canvas.on("draw", (canvas) => {
canvas.drawARGB(255, 127, 127, 127);
var w = canvas.getWidth();
var h = canvas.getHeight();
var textSize = w;
paint.setTextSize(textSize);
var AX = w / 2;
var AY = h / 2;
paint.setStyle(Paint.Style.STROKE);
if (currentTxt) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
paint.setColor(colors.BLACK);
let rect = new android.graphics.RectF(0, (h - w) / 2, w, (h - w) / 2 + paint.getTextSize());
canvas.drawRect(rect, paint);
paint.setColor(colors.LTGRAY);
canvas.drawText(currentTxt, w / 2, (h - w) / 2 + paint.getTextSize(), paint);
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(4);
paint.setColor(colors.RED);
paint.setTextSize(50);
canvas.drawText("已录制成功" + MainStrokeAry.length + "个", w / 2, paint.getTextSize() * 1.365, paint);
canvas.drawLine(0, paint.getTextSize() * 1.365, w, paint.getTextSize() * 1.365, paint);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(colors.GREEN);
for (let points of strokeAry) {
for (let i = 0; i < points.length - 1; i += 2) {
let x = points[i] / 1000 * w,
y = points[i + 1] / 1000 * w + (h - w) / 2;
if (i == 0) {
canvas.drawCircle(x, y, 10, paint);
} else {
let x1 = points[i - 2] / 1000 * w,
y2 = points[i - 1] / 1000 * w + (h - w) / 2;
canvas.drawLine(x1, y2, x, y, paint);
canvas.drawCircle(x, y, 10, paint);
};
};
};
for (let i = 0; i < strokePoints.length - 1; i += 2) {
let x = strokePoints[i] / 1000 * w,
y = strokePoints[i + 1] / 1000 * w + (h - w) / 2;
if (i == 0) {
canvas.drawCircle(x, y, 10, paint);
} else {
let x1 = strokePoints[i - 2] / 1000 * w,
y2 = strokePoints[i - 1] / 1000 * w + (h - w) / 2;
canvas.drawLine(x1, y2, x, y, paint);
canvas.drawCircle(x, y, 10, paint);
};
};
} else {
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(5);
paint.setColor(colors.GREEN);
paint.setTextSize(60);
canvas.drawText("请输入一个字符按按钮即可录制", w / 2, h / 2 + paint.getTextSize() * 0.365, paint);
};
});
var RY;
var isMove = false;
function addPoint(X, Y) {
X = Math.floor(X);
Y = Math.floor(Y);
if (strokePoints.length >= 4) {
let x1 = strokePoints[strokePoints.length - 4];
let y1 = strokePoints[strokePoints.length - 3];
let x2 = strokePoints[strokePoints.length - 2];
let y2 = strokePoints[strokePoints.length - 1];
let FR1 = ydfx([x2 - x1, y2 - y1]);
let FR2 = ydfx([X - x2, Y - y2]);
if (Math.abs(FR2 - FR1) >= 18 && weiyi([x2 - x1, y2 - y1]) >= 100) {
strokePoints.push(X, Y);
} else {
strokePoints[strokePoints.length - 2] = X;
strokePoints[strokePoints.length - 1] = Y;
};
} else {
strokePoints.push(X, Y);
};
};
ui.canvas.setOnTouchListener(new android.view.View.OnTouchListener((view, event) => {
try {
var W = view.getWidth();
var H = view.getHeight();
var PC = event.getPointerCount();
switch (event.getActionMasked()) {
case event.ACTION_MOVE:
isMove = true;
for (let i = 0; i < PC; i++) {
let id = event.getPointerId(i);
let X = event.getX(i);
let Y = event.getY(i);
if (i == 0) {
addPoint(X / W * 1000, (Y - (H - W) / 2) / W * 1000);
};
};
break;
case event.ACTION_CANCEL:
//log("CANCEL");
kg = false;
strokePoints = new Array;
break;
case event.ACTION_OUTSIDE:
//log("OUTSIDE");
break;
default:
var I = Math.floor(event.getAction() / 256);
var ID = event.getPointerId(I);
var X = event.getX(I);
var Y = event.getY(I);
var RX = event.getRawX();
var RY = event.getRawY();
switch (event.getActionMasked()) {
case event.ACTION_DOWN:
//第一个手指按下。
[虚幻私塾】
- 粉丝: 335
- 资源: 1558
最新资源
- 基于SpringBoot+Vue的校园招聘管理系统(前端代码)
- C++期末大作业-2024-QT仓库商品管理系统,经过老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用
- DH-GSTN5600 剩余电流式电气火灾监控探测器 安装使用说明书
- 天津理工大学信息系统设计实验
- jsp ssm 学校录取查询系统 高校志愿填报录取 项目源码 web java【项目源码+数据库脚本+项目说明+软件工具】毕设
- jsp ssm 网上购物系统 在线购物 在线商城平台 项目源码 web java【项目源码+数据库脚本+项目说明+软件工具】毕设
- 29网课交单平台源码最新修复全开源版本
- jsp ssm 超市网上购物系统 超市管理 超市购物 项目源码 web java【项目源码+数据库脚本+项目说明+软件工具】毕
- 海湾火灾自动报警系统主要设备参数
- C++自制多功能游戏头文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈