### Initializing and Using OCR with Different Engines (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/ocr-api.md This example demonstrates how to initialize and use various OCR engines (Tesseract, OCR-Lite, PaddleOCR) within a loop to perform OCR on an image. It shows the setup of OCR parameters, error handling during initialization, reading a bitmap, performing OCR, processing results, and releasing resources. It highlights the use of `ocr.newOcr()`, `tocr.initOcr()`, `tocr.ocrBitmap()`, and `tocr.releaseAll()`. ```javascript function main() { let tess = {"type": "tess", "path": "d:/tesseract-ocr/tessdata", "baseDir": "d:\\tesseract-ocr"} let ocrLite = { "type": "ocrLite", "baseDir": "c:/ec/OcrLiteNcnn", "single": 0, "cpuType": "win-lib-cpu-x64" } // 入使用paddleocr,就自己改下参数即可 let paddleOcr = { "type": "paddleOcr", "ocrType": "ONNX_PPOCR_V3" } let tocr = ocr.newOcr() let inited = tocr.initOcr(ocrLite) logd("初始化结果 -" + inited); if (!inited) { loge("error : " + tocr.getErrorMsg()); return; } for (var ix = 0; ix < 20; ix++) { //读取一个bitmap let bitmap = image.readBitmap("D:/Screenshot_20210127_152932_com.huawei.android.lau.jpg"); if (!bitmap) { loge("读取图片失败"); continue; } console.time("1") logd("start---ocr"); // 对图片进行识别 let result = tocr.ocrBitmap(bitmap, 30 * 1000, {"matMode": 1}); logd(result) if (result) { logd("ocr结果-》 " + JSON.stringify(result)); for (var i = 0; i < result.length; i++) { var value = result[i]; logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height); } } else { logw("未识别到结果"); } logd("耗时: " + console.timeEnd(1) + " ms") image.recycle(bitmap) sleep(1000); logd("ix = " + ix) } //释放所有资源 // paddleOcr会关闭ocr程序,如果不考虑关闭 不用调用这个函数 tocr.releaseAll(); } main(); ``` -------------------------------- ### Full PaddleOcrOnline Usage Example - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ocr-api.md A comprehensive example demonstrating the initialization and usage of `paddleOcrOnline` OCR in EasyClick for versions 9.17+. It includes environment setup, screen capture permission request, OCR object creation (`ocr.newOcr`), initialization with specific parameters (`paddleOcrOnline.initOcr`), performing OCR on a captured image (`ocrImage`), processing results, and resource cleanup (`releaseAll`) in a `setStopCallback`. ```javascript let paddleOcrOnline = null //脚本停止回调 setStopCallback(function () { //释放所有资源,一般不需要调用,或者放到setStopCallback中 logi("释放paddleOcrOnline对象") paddleOcrOnline && paddleOcrOnline.releaseAll() }) //初始化自动化环境 function initEnv() { if (!startEnv()) { loge("自动化启动失败,结束脚本") exit() } if (!image.requestScreenCapture(10000, 0)) { loge("申请截图权限失败,检查是否开启后台弹出,悬浮框等权限") exit() } //申请完权限至少等1s(垃圾设备多加点)再截图,否则会截不到图 sleep(1000) } //初始化所有ocr对象及环境 function initAllOcr() { // paddleOcrOnline,参数参考上方解释,不需要的参数可以不填 let paddleOcrOnlineMap = { "serverUrl": "10.0.0.112", "type": "paddleOcrOnline", "ocrType": "ONNX_PPOCR_V3" } //创建ocr对象,仅脚本开头一次即可 paddleOcrOnline = ocr.newOcr() //初始化ocr,仅脚本开头一次即可 if (!paddleOcrOnline.initOcr(paddleOcrOnlineMap)) { loge("OCR初始化失败 : " + paddleOcrOnline.getErrorMsg()) exit() } } // ocr识别 function ocrFunc() { // 截图 let img = image.captureFullScreenEx() if (!img) { loge("截图失败") return } logi("===================paddleOcrOnline识别======================") // 用paddleOcrOnline进行识别 let result = paddleOcrOnline.ocrImage(img, 20 * 1000, {}) if (result) { logd("ocr结果-> " + JSON.stringify(result)) for (let i = 0; i < result.length; i++) { let value = result[i] logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height) } } else { logw("未识别到结果") } //回收图片 image.recycle(img) } function main() { //初始化环境 initEnv() //初始化所有ocr对象及环境 initAllOcr() //多次识别 ocrFunc() ocrFunc() ocrFunc() } main() ``` -------------------------------- ### Installing Development Tools (Shell) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/testflow_ios.txt This command initiates the installation process for development tools required by the EasyClick project. It is intended to be run directly in a shell or command-line environment. ```Shell installdevtools ``` -------------------------------- ### Starting Screen Stream Capture (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/image-api.md Initializes a faster image stream screenshot mode, compatible with EC HarmonyNext 1.0.0+. Returns `true` if the stream starts successfully, `false` otherwise. Requires environment to be started (`startEnv()`). ```javascript function main() { logd("isServiceOk " + isServiceOk()); startEnv() logd("isServiceOk " + isServiceOk()); let cap = image.startScreenStream() logd("截图: " + cap) } main(); ``` -------------------------------- ### Opening Android Activity - JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md Opens another Android activity using a map of parameters, such as action, uri, pkg, className, and flag. This example shows opening an APK installation interface and a custom URI. ```javascript function main() { //打开安装包界面 var m = { "action": "android.intent.action.VIEW", "uri": "file:///sdcard/a.apk", "type": "application/vnd.android.package-archive" }; var x = ui.openActivity(m); ui.logd("x " + x); var map = { "uri": "xx://xx/live/6701887916223941379" }; ui.openActivity(map); } main(); ``` -------------------------------- ### EC System Configuration Parameters - JSON Example Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/global.md This JSON snippet provides an example structure for setting various EC system parameters. It defines settings such as running mode, auto-start service, and the visibility of log and control float windows. ```JSON { "running_mode": "无障碍", "auto_start_service": "是", "log_float_window": "否", "ctrl_float_window": "否" } ``` -------------------------------- ### OCR Lite Usage Example (EasyClick JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/ocr-api.md This comprehensive JavaScript example demonstrates how to initialize and use the `ocrLite` module for image recognition. It shows configuring `ocrLite` with `baseDir` and `cpuType`, handling initialization success/failure, reading a bitmap, performing OCR using `ocr.ocrBitmap()`, iterating through results, and releasing resources. It also highlights the prerequisite of enabling OpenCV in the EasyClick control panel for versions 2.8.0+. ```JavaScript function main() { //2.8.0+中控,要在中控设置页开启opencv功能,并重启中控 let ocrLite = { "type": "ocrLite", "baseDir": "c:/ec/OcrLiteNcnn", "cpuType": "win-lib-cpu-x64" } let inited = ocr.initOcr(ocrLite) logd("初始化结果 -" + inited); if (!inited) { loge("error : " + ocr.getErrorMsg()); return; } for (var ix = 0; ix < 20; ix++) { //读取一个bitmap let bitmap = image.readBitmap("D:/Screenshot_20210127_152932_com.huawei.android.lau.jpg"); if (!bitmap) { loge("读取图片失败"); continue; } console.time("1") logd("start---ocr"); // 对图片进行识别 let result = ocr.ocrBitmap(bitmap, 20 * 1000, {}); logd(result) if (result) { logd("ocr结果-》 " + JSON.stringify(result)); for (var i = 0; i < result.length; i++) { var value = result[i]; logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height); } } else { logw("未识别到结果"); } logd("耗时: " + console.timeEnd(1) + " ms") image.recycle(bitmap) sleep(1000); logd("ix = " + ix) } //释放所有资源 ocr.releaseAll(); } main(); ``` -------------------------------- ### Starting Automation Environment - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/global.md Initiates and starts the automation service environment. This function returns true on successful startup of the environment, and false if the startup fails. ```JavaScript function main() { var result = startEnv(); } main(); ``` -------------------------------- ### Starting EasyClick Script from H5 JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iostjdocs/zh-cn/funcs/ui/ui-js-inter.md This JavaScript snippet shows how to programmatically start an EasyClick script from an H5 page. It utilizes `window.ec.start` with an asynchronous callback. A `resp` value of `true` indicates that the script started successfully. ```JavaScript // H5中调用,不是脚本 // 异步回调 window.ec.start(function (resp) { // resp = true 代表正常 }); ``` -------------------------------- ### Starting Automation Environment - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iostjdocs/zh-cn/funcs/global/global.md Attempts to start the automation service environment. Note that this function's implementation may vary, and its actual operation should be verified through logs. It returns a boolean (`true` or `false`). ```javascript function main() { var result = startEnv(); } main(); ``` -------------------------------- ### Starting EasyClick iOS Bridge in Foreground (Linux) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/advance/deploy.md This command starts the EasyClick iOS bridge program (`ios-bridge`) in the foreground on a Linux system. Running it directly allows the user to view real-time logs and output directly in the terminal, which is useful for debugging or monitoring. ```Shell /home/bridge/ios-bridge ``` -------------------------------- ### Installing JavaScript Obfuscator and Class Validator (Shell) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/advance/jsobfuscator.md This snippet provides shell commands to globally install `javascript-obfuscator` and `class-validator` using npm. `javascript-obfuscator` is crucial for code obfuscation, while `class-validator` might be a related dependency. These commands are intended to be run in a command prompt or PowerShell environment. ```shell npm install -g javascript-obfuscator npm install -g class-validator ``` -------------------------------- ### Setting Wallpaper Service - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/global.md Activates the wallpaper service, applicable for EasyClick version 6.1.0 and above. The function returns true if the service starts successfully, and false if it fails to start. ```JavaScript function main() { var result = setWallpaperService(); } main(); ``` -------------------------------- ### Capturing Full Screen Image (JPG) with EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/image-api.md This function captures the current screen as a JPG `Image` object. The example demonstrates a loop to repeatedly capture, log, and recycle the image, emphasizing the critical need to call `image.recycle()` to free up system resources after use. It relies on `startEnv()` for environment setup and `isServiceOk()` for service status checks. ```JavaScript function main() { logd("isServiceOk " + isServiceOk()); startEnv() logd("isServiceOk " + isServiceOk()); for (let i = 0; i < 10; i++) { let cap = image.captureFullScreen() logd("截图数据: " + cap) sleep(1000) //图片要回收 image.recycle(cap) } } main(); ``` -------------------------------- ### Installing JavaScript Obfuscator and Class Validator via npm Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/advance/jsobfuscator.md This snippet provides the shell commands required to globally install `javascript-obfuscator` and `class-validator` using npm. These packages are essential prerequisites for enabling code obfuscation and validation functionalities within EasyClick projects. ```shell npm install -g javascript-obfuscator npm install -g class-validator ``` -------------------------------- ### Advanced UI Interaction and Event Handling (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md This comprehensive JavaScript snippet demonstrates various advanced UI interactions in EasyClick. It covers displaying toasts, loading multiple layouts, logging UI results, and handling events for different UI components like Switch, EditText, Spinner, RadioButton, and CheckBox. It also shows how to save configurations, open system settings, start scripts, and manage environment setup asynchronously. ```JavaScript /** * 该文件由EasyClick开发工具自动创建 */ function main() { ui.toast("我是ui的Toast函数"); var set = ui.layout("参数设置", "main.xml"); ui.layout("其他说明", "main2.xml"); ui.logd("设置UI结果: " + set); //Switch 开关按钮的用法 var auto_env = ui.getViewValue(ui.auto_env); ui.logd("tag为 auto_env 的值: " + auto_env); //开关按钮的事件 ui.setEvent(ui.auto_env, "checkedChange", function (view, isChecked) { ui.logd("tag为 auto_env isChecked " + isChecked); if (isChecked) { startAutoEnv(); } }); if (ui.isServiceOk()) { ui.auto_env.setChecked(true); } else { ui.auto_env.setChecked(false); } //EditText 编辑框的用法 var name = ui.getViewValue(ui.name); ui.logd("tag为name的值: " + name); ui.name.setText("我是name的值"); //Spinner 下拉选择框用法 var sex = ui.getViewValue(ui.sex); ui.logd("tag为 sex 的值: " + sex); //下拉选择框的事件 ui.setEvent(ui.sex, "itemSelected", function (position, value) { ui.logd("tag为 sex itemSelected " + value); }); //RadioButton 单选框用法 var three = ui.getViewValue(ui.three); ui.logd("tag为 three 的值: " + three); //单选框的事件 ui.setEvent(ui.three, "checkedChange", function (view, isChecked) { ui.logd("tag为 three isChecked " + isChecked); }); //CheckBox 复选框用法 var dance = ui.getViewValue(ui.dance); ui.logd("tag为 dance 的值: " + dance); //复选框的事件 ui.setEvent(ui.dance, "checkedChange", function (view, isChecked) { ui.logd("tag为 dance isChecked " + isChecked); }); //saveAllBtn 保存参数事件 ui.setEvent(ui.saveAllBtn, "click", function (view) { var s = ui.saveAllConfig(); ui.logd("保存所有参数结果 " + s) }); //系统设置按钮 ui.setEvent(ui.systemSetting, "click", function (view) { ui.openECSystemSetting(); }); //启动脚本按钮 ui.setEvent(ui.startBtn, "click", function (view) { ui.start(); }); //启动环境按钮 ui.setEvent(ui.envBtn, "click", function (view) { //异步启动环境,如果成功了就设置auto_env 按钮的状态 startAutoEnv(); }); //获取所有的UI参数 ui.logd("获取所有的UI参数:" + ui.getConfigJSON()); //设置值的用法,这里先注释掉 // ui.setViewValue(ui.name, "我是设置的"); // ui.setViewValue(ui.auto_env, false); // ui.setViewValue(ui.sex, "男生|女生"); // ui.setViewValue(ui.three, true); // ui.setViewValue(ui.dance, false) //内存临时存储变量和数据 ui.putShareData("nameVar", ui.name); ui.putShareData("value", "我是value"); } function startAutoEnv() { ui.startEnvAsync(function (r) { ui.logd("启动环境结果: " + r); ui.auto_env.setChecked(r); }); } main(); ``` -------------------------------- ### Starting EasyClick Script (ADB - v5.8.0+, Shell) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/question/question-answer.md This ADB command starts an EasyClick script (.iec file) located on the device's SD card. It targets the specific service and action for EasyClick versions 5.8.0 and above, using a fixed package name. ```Shell adb shell am startservice -a TESTCASE.EXEC.START.ACTION -n com.gibb.easyclick/com.gibb.abtest.testcase.service.MainService --es path /sdcard/a.iec ``` -------------------------------- ### Installing JavaScript Obfuscator and Class Validator via npm (Shell) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iostjdocs/zh-cn/advance/jsobfuscator.md This snippet provides shell commands to globally install `javascript-obfuscator` and `class-validator` using npm. These packages are essential prerequisites for enabling code obfuscation and validation within the EasyClick development environment. ```Shell npm install -g javascript-obfuscator npm install -g class-validator ``` -------------------------------- ### Getting Installed App List with device.applist (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/device-api.md This function retrieves a list of all applications currently installed on the device. It returns the list as a JSON string. ```JavaScript function main() { var applistx = device.applist(); logd(applistx); } main(); ``` -------------------------------- ### Starting EasyClick iOS Bridge in Background (Linux) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/advance/deploy.md This command starts the EasyClick iOS bridge program (`ios-bridge`) in the background on a Linux system. Using `nohup` ensures the process continues to run even after the user logs out or closes the terminal, and `&` detaches it from the current shell. ```Shell nohup /home/bridge/ios-bridge & ``` -------------------------------- ### Example System Configuration Parameters - JSON Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md Illustrates the structure and available parameters for setting EasyClick system configurations. Parameters include running_mode, auto_start_service, log_float_window, ctrl_float_window, and service_start_run_script, each with specific boolean or string values. ```json { "running_mode": "无障碍", "auto_start_service": "是", "volume_start_tc": "否", "log_float_window": "否", "ctrl_float_window": "否", "service_start_run_script": "否" } ``` -------------------------------- ### Getting Installed App List with device.applist (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/device-api.md Retrieves a comma-separated string of package names for all applications installed on the current device. The function returns a string that can be split to iterate through individual app package names. ```JavaScript function main() { let applist = device.applist(); if (applist) { let applist_arr = applist.split(",") for (let i = 0; i < applist_arr.length; i++) { logd(applist_arr[i]) } } } main(); ``` -------------------------------- ### Getting Image Height (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/image-api.md This function retrieves the height of a given image object. It takes an image object as input and returns its height as an integer. The example demonstrates capturing a full-screen image, getting its height, and recycling the image. ```JavaScript function main() { let req = startEnv(); if (!req) { logd("申请权限失败"); return; } //申请完权限至少等1s(垃圾设备多加点)再截图,否则会截不到图 sleep(1000) let aimage = image.captureFullScreen(); if (aimage != null) { let h = image.getHeight(aimage); logd("h " + h); //图片要回收 image.recycle(aimage) } } main(); ``` -------------------------------- ### Starting Image Stream Capture (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/image-api.md This function initializes a faster image stream screenshot mode. It returns a boolean indicating whether the stream was successfully started, enabling subsequent capture operations from the stream. This method is generally quicker than other screenshot approaches. ```javascript function main() { logd("isServiceOk " + isServiceOk()); startEnv() logd("isServiceOk " + isServiceOk()); let cap = image.startScreenStream() logd("截图: " + cap) } main(); ``` -------------------------------- ### Getting Image Width (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/image-api.md This function retrieves the width of a given image object. It takes an image object as input and returns its width as an integer. The example demonstrates capturing a full-screen image, getting its width, and recycling the image. ```JavaScript function main() { let req = startEnv(); if (!req) { logd("申请权限失败"); return; } //申请完权限至少等1s(垃圾设备多加点)再截图,否则会截不到图 sleep(1000) let aimage = image.captureFullScreen(); if (aimage != null) { let w = image.getWidth(aimage); logd("w " + w); //图片要回收 image.recycle(aimage) } } main(); ``` -------------------------------- ### Initializing and Using OCR with ocrMut Module (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iostjdocs/zh-cn/funcs/ocr-api.md This JavaScript example demonstrates the complete workflow for using the `ocrMut` module. It shows how to create a new OCR instance, initialize it with different configurations (e.g., `ocrLite`, `appleVision`, `paddleOcrOnline`), capture a full-screen image, perform OCR on the image, process the results, and finally release the OCR resources. It also includes error handling for initialization failures. ```javascript function main() { logd("开始执行脚本...") // 初始化一个实例 let ocrtest = ocrMut.newOcr(); let vision = {"type": "appleVision", "level": "accurate", "languages": "zh-Hans,en-US"} //paddleOcr参数 let paddleOcrOnline = { "type": "paddleOcrOnline", "ocrType": "ONNX_PPOCR_V3", "serverUrl": "192.168.2.13:9022", "limit": 12, "checkImage": "1", "padding": 200 } let ocrLite = {"type": "ocrLite"} let inited = ocrtest.initOcr(ocrLite) if (!inited) { loge("inited ocr error : " + ocrtest.getErrorMsg()) return } else { logd("ocr inited ok") } for (let i = 0; i < 3; i++) { let img = image.captureFullScreen() let ocrResult = ocrtest.ocrImage(img, 20000, null) logd("ocrResult " + JSON.stringify(ocrResult)); if (ocrResult) { logd("ocr结果-》 " + JSON.stringify(ocrResult)); for (var j = 0; j < ocrResult.length; j++) { var value = ocrResult[j]; logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height); } } else { logw("未识别到结果"); } image.recycle(img) sleep(2000) } //脚本运行完成了释放即可 不需要每次用完都释放 ocrtest.releaseAll() } main(); ``` -------------------------------- ### Getting Installed App Version Code (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/utils-api.md This snippet shows how to retrieve the integer version code of an installed application using `utils.getAppVersionCode`. It takes the application's package name as a parameter and returns the version code as an integer. ```javascript function main() { var versionCode = utils.getAppVersionCode("com.xx"); } main(); ``` -------------------------------- ### Getting Installed App Version Name (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/utils-api.md This snippet demonstrates how to retrieve the string version name of an installed application using `utils.getAppVersionName`. It takes the application's package name as a parameter and returns the version name (e.g., "1.0.0") as a string. ```javascript function main() { var r = utils.getAppVersionName("com.xx"); } main(); ``` -------------------------------- ### Starting Automation Environment (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/global/global.md Initializes the automation service environment, including automatic coordinate system correction to prevent drift. Returns true on successful startup, false otherwise. ```JavaScript function main() { var result = startEnv(); } main(); ``` -------------------------------- ### Getting Android OS Version in EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/device-api.md Retrieves the Android operating system version of the phone, for example, '6.0'. The function returns the OS version as a string. ```javascript function main() { var osVersion = device.getOSVersion(); toast(osVersion); } main(); ``` -------------------------------- ### Getting Android SDK Version in EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/device-api.md Retrieves the Android SDK version number of the phone, for example, 23. The function returns the SDK version as a string. ```javascript function main() { var sdkInt = device.getSdkInt(); toast(sdkInt); } main(); ``` -------------------------------- ### Initializing OpenCV Library - JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/image-api.md This function initializes the OpenCV library, which is a prerequisite for certain image recognition operations. The first initialization might take longer as it involves copying library files, but subsequent calls will be faster. It returns `true` on successful initialization and `false` otherwise. The example demonstrates calling `startEnv()` to request permissions, then `image.initOpenCV()` to initialize the library, and logs the result. ```JavaScript function main() { let req = startEnv(); if (!req) { logd("申请权限失败"); return; } sleep(1000) let d = image.initOpenCV(); logd(d) } main(); ``` -------------------------------- ### Getting Screen Dimensions with device.getScreenSize (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/device-api.md Retrieves the screen dimensions (width and height) of the device. The function returns a string formatted as 'width,height', for example, '750,1334'. ```JavaScript function main() { var width = device.getScreenSize(); logd(width); } main(); ``` -------------------------------- ### Getting Single Pixel Color from Bitmap (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/image-api.md This function retrieves the color value of a single pixel at specified (x, y) coordinates from a `Bitmap` object. It takes the bitmap, x-coordinate, and y-coordinate as input, returning an integer color value. The example demonstrates capturing a full-screen image, converting it to a bitmap, getting a pixel's color, and recycling the bitmap. ```JavaScript function main() { let req = startEnv(); if (!req) { logd("申请权限失败"); return; } logd("申请截图结果... " + request) ///申请完权限至少等1s(垃圾设备多加点)再截图,否则会截不到图 sleep(1000) let bitmap = image.captureFullScreen("jpg", 800, 800, 100, 100, 100); let color = image.getPixelBitmap(image.imageToBitmap(bitmap), 100, 100); //图片要回收 image.recycle(bitmap) } main(); ``` -------------------------------- ### Full OCR Example with Tesseract, OCRLite, and PaddleOCR (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/ocr-api.md A comprehensive JavaScript example demonstrating the initialization of Tesseract, OCRLite, and PaddleOCR, followed by a loop that reads an image, performs OCR using `ocrBitmap`, logs the results, and releases resources. It showcases error handling, performance logging, and iterating through recognized text and its bounding box information. ```JavaScript function main() { let tess = {"type": "tess", "path": "d:/tesseract-ocr/tessdata", "baseDir": "d:\\tesseract-ocr"} // ocrlite let ocrLite = { "type": "ocrLite", "baseDir": "c:/ec/OcrLiteNcnn", "single": 0, "cpuType": "win-lib-cpu-x64" } // 入使用paddleocr,就自己改下参数即可 let paddleOcr = { "type": "paddleOcr", "ocrType": "ONNX_PPOCR_V3" } let tocr = ocr.newOcr() let inited = tocr.initOcr(ocrLite) logd("初始化结果 -" + inited); if (!inited) { loge("error : " + tocr.getErrorMsg()); return; } for (var ix = 0; ix < 20; ix++) { //读取一个bitmap let bitmap = image.readBitmap("D:/Screenshot_20210127_152932_com.huawei.android.lau.jpg"); if (!bitmap) { loge("读取图片失败"); continue; } console.time("1") logd("start---ocr"); // 对图片进行识别 let result = tocr.ocrBitmap(bitmap, 30 * 1000, {"matMode": 1}); logd(result) if (result) { logd("ocr结果-》 " + JSON.stringify(result)); for (var i = 0; i < result.length; i++) { var value = result[i]; logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height); } } else { logw("未识别到结果"); } logd("耗时: " + console.timeEnd(1) + " ms") image.recycle(bitmap) sleep(1000); logd("ix = " + ix) } //释放所有资源 // paddleOcr会关闭ocr程序,如果不考虑关闭 不用调用这个函数 tocr.releaseAll(); } main(); ``` -------------------------------- ### Getting EasyClick IPA Version (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/global/global.md This snippet shows how to obtain the IPA version number, which is suitable for EC iOS USB version 6.6.0 and above. The `ipaVersion()` function returns a string, for example, '6.6.0'. ```JavaScript function main() { logd(ipaVersion()) } main(); ``` -------------------------------- ### Initializing OCR Instance (EasyClick JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/ocr-api.md This snippet demonstrates how to create a new OCR instance using `ocr.newOcr()`. This is the first step before performing any OCR operations. The `releaseAll()` method is shown for proper resource management. This functionality is compatible with EasyClick iOS 6.23.0 and above. ```JavaScript function main() { let o = ocr.newOcr(); // 这里做初始化和识别 o.releaseAll() } ``` -------------------------------- ### Initializing and Performing OCR with Apple Vision in EasyClick (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/ocr-agent-api.md This JavaScript example demonstrates how to initialize the EasyClick OCR module using `ocrAgent.initOcr` with the `appleVision` type, specifying language preferences. It then shows how to capture a full-screen image using `imageAgent.captureFullScreen` and perform OCR on it using `ocrAgent.ocrImage`. The results, including text labels, confidence, and bounding box coordinates, are logged. The snippet also includes error handling and proper resource release with `ocrAgent.releaseAll`. ```JavaScript function main() { let appleVision = { "type": "appleVision" } let inited = ocrAgent.initOcr(appleVision) logd("初始化结果 -" + inited); if (!inited) { loge("error : " + ocrAgent.getErrorMsg()); return; } for (var ix = 0; ix < 20; ix++) { //读取一个bitmap let img = imageAgent.captureFullScreen(); if (!img) { loge("读取图片失败"); continue; } console.time("1") logd("start---ocr"); // 对图片进行识别 let result = ocrAgent.ocrImage(img, 20 * 1000, {}); logd(result) if (result) { logd("ocr结果-》 " + JSON.stringify(result)); for (var i = 0; i < result.length; i++) { var value = result[i]; logd("文字 : " + value.label + " x: " + value.x + " y: " + value.y + " width: " + value.width + " height: " + value.height); } } else { logw("未识别到结果"); } logd("耗时: " + console.timeEnd(1) + " ms") imageAgent.recycle(img) sleep(1000); logd("ix = " + ix) } //释放所有资源 ocrAgent.releaseAll(); } main(); ``` -------------------------------- ### Getting UI Handler Object - JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md Retrieves the current Handler object, which can be used to post delayed tasks to the UI thread. This example demonstrates showing a log window and then closing it after a delay using postDelayed. ```javascript function main() { //展示浮窗 ui.showLogWindow(); ui.logd("显示消息") //3秒后在UI线程消失掉 ui.getHandler().postDelayed(function () { ui.closeLogWindow(); }, 3000); } main(); ``` -------------------------------- ### Initializing UI Layout in EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iostjdocs/zh-cn/funcs/ui/ui-js-inter.md This JavaScript snippet defines the `main` function which is the entry point for an EasyClick UI script. It uses `ui.layout` to display an HTML file (`index.html`) as the main UI. This is a fundamental step for setting up the H5 interface in an EasyClick project. ```JavaScript function main() { ui.layout("index", "index.html"); } main(); ``` -------------------------------- ### Retrieving All Sibling Nodes (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/selector-node.md This example shows how to get an array of all sibling `NodeInfo` objects of a selected node. It first selects a `ViewGroup` node and, if found, calls `siblings()` to retrieve all its siblings, then iterates and logs each sibling. ```JavaScript function main() { //选择 节点 clz=android.widget.ViewGroup 所有节点 var node = clz("android.widget.ViewGroup").getOneNodeInfo(10000); if (node) { var x = node.siblings(); //这玩意是个数组 for (let i = 0; i < x.length; i++) { logd(x[i]) } } else { toast("无节点"); } } main(); ``` -------------------------------- ### Initializing UI with Toast (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md This snippet demonstrates a basic JavaScript function `main` that uses `ui.toast` to display a message on the UI. It's intended to be placed in `ui.js` within the project's `layout` folder, serving as an entry point for simple UI control. ```JavaScript function main() { ui.toast("我是JS控制的UI"); } main(); ``` -------------------------------- ### Setting Integer Parameters with jdbc.psqlSetInt in JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/jdbcmysql-api.md This example shows how to use `jdbc.psqlSetInt` to bind an integer value to a parameter in a prepared statement. It includes the complete flow of JDBC operations, from connection setup to executing queries and updates, highlighting the use of integer parameters. ```JavaScript function main() { //mysql 的地址 ip:端口/数据库名 let mysqlUrl = "jdbc:mysql://192.168.0.3:3306/test?characterEncoding=utf8&autoReconnect=true" let inited = jdbc.init("com.mysql.cj.jdbc.Driver", mysqlUrl, "root", "root123456"); logd("inited " + inited); let conn = jdbc.connect() logd("connect " + conn); if (!conn) { logd(jdbc.getLastError()); exit() } //查询语句 let q = "select * from table1 where id=? or uname=?" //创建一个查询 let qur = jdbc.createPreparedStatement(q) if (qur) { //设置第一个索引的参数 jdbc.psqlSetInt(1, 1) //设置第二个索引参数 jdbc.psqlSetString(2, 'test') } //预处理查询 let data = jdbc.psqlQuery() logd(data); //关闭预处理语句 jdbc.psqlClose() //插入数据 q = "insert table1(`uname`,`ucontent`,`create_time`)values(?,?,?);" qur = jdbc.createPreparedStatement(q) if (qur) { //设置第一个索引的参数 jdbc.psqlSetString(1, "我是名称") //设置第二个索引参数 jdbc.psqlSetString(2, '我是内容') //设置时间戳 jdbc.psqlSetTimestamp(3, "yyyy-MM-dd hh:mm:ss", "2020-10-02 12:02:11") } rowcount = jdbc.psqlExecuteUpdate(); logi("插入语句执行影响行数 -" + rowcount); if (rowcount <= 0) { loge("插入错误: " + jdbc.getLastError()) } jdbc.connectionClose() } main(); ``` -------------------------------- ### Retrieving Automation Start Message (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/global/global.md Fetches the message related to the automation environment's startup. This function returns a string containing the startup message. ```JavaScript function main() { var result = getStartEnvMsg(); logd(result) } main(); ``` -------------------------------- ### Getting Current Activity Object - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/ui/ui-js-inter.md This function retrieves the current Android Activity object associated with the UI. It returns an Activity object or null. The example demonstrates obtaining the Activity, logging it, and then using it to set a new TextView as the content view, showcasing JavaScript-Java interaction. ```javascript function main() { var activity = ui.getActivity(); ui.logd("activity " + activity); //android context对象也是自带的 importPackage(android.widget); importPackage(android.graphics); //直接使用java对象 var tv = new android.widget.TextView(context); tv.setText("我是js和java交互的文本对象"); tv.setTextColor(Color.parseColor("#888888")) activity.setContentView(tv); } ``` -------------------------------- ### Loading JAR/APK Files with loadDex (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/global/global.md This snippet illustrates how to load a DEX file (typically a JAR or APK) using the `loadDex()` function. The `path` parameter can be a file name (which will be searched in the plugin directory) or a full file path. It returns `true` on successful loading and `false` otherwise. After loading, classes within the DEX file can be instantiated. ```JavaScript function main() { //类似这样会先从IEC文件的插件目录查找 //loadDex("ocr.apk"); //下面这个是 loadDex("D:/a.jar"); // a.apk中存在com.A这个这个类,可以直接使用 var obj = new com.A(); } main(); ``` -------------------------------- ### Getting Pixel Color Value in EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/image-api.md Retrieves the color value of a specific pixel from an image. Requires the image object and the x, y coordinates of the pixel. Returns an integer representing the color value. The example demonstrates screen capture and image recycling. ```javascript function main() { let request = image.requestScreenCapture(10000, 0); if (!request) { request = image.requestScreenCapture(10000, 0); } logd("申请截图结果... " + request) //申请完权限至少等1s(垃圾设备多加点)再截图,否则会截不到图 sleep(1000) let imageX = image.captureFullScreen(); let r = image.pixel(imageX, 100, 100); toast("result " + r); //图片要回收 image.recycle(imageX) } main(); ``` -------------------------------- ### Getting Last Node Event Time with lastNodeEventTime in JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/global-shortcut.md Retrieves the timestamp (in milliseconds) of the most recent node event. Available from EC 5.14.0+. This function can be used to determine if the node service is active and responsive. The example demonstrates continuous logging of the event time. ```JavaScript function main() { startEnv(); logd("开始监听"); while (true) { let d = lastNodeEventTime(); logd("time-" + d); sleep(1000) } } main(); ``` -------------------------------- ### Setting Agent Program Configuration - EasyClick JavaScript Source: https://github.com/yimudi003/easyclick-docs/blob/main/iosdocs/zh-cn/funcs/global/global-shortcut.md Sets the configuration for the agent program. The `ext` parameter is a map containing settings like `screenStreamQuality` (1-100 for screen projection quality) and `screenStreamFramerate` (10-60 for screen projection frame rate). Properties not to be set can be omitted from the map. Returns `true` on success, `false` on failure. ```JavaScript function main() { // 如果不想设置某个属性,可以不在map填写 var result = setAgentSetting({"screenStreamQuality": 60, "screenStreamFramerate": 20}); logd(result); } main(); ``` -------------------------------- ### Executing Asynchronously with thread.execAsync (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/hmdocs/zh-cn/funcs/thread-api.md This function executes a `runnable` function asynchronously by placing it into a thread pool for management. It returns a thread ID (`tid`) which can be used to monitor or cancel the thread. The example demonstrates starting an asynchronous loop, checking for cancellation, and then explicitly cancelling the thread after a delay. ```javascript function main() { var tid = thread.execAsync(function () { while (true) { logd("我是异步执行的代码"); sleep(1000); if (thread.isCancelled(tid)) { break; } } }); logd("tid " + tid); //5s后取消线程 sleep(5000); logd("取消线程 " + tid); thread.cancelThread(tid); sleep(5000); logd("结束 "); } main(); ``` -------------------------------- ### Retrieving a Specific Child Node by Index (JavaScript) Source: https://github.com/yimudi003/easyclick-docs/blob/main/docs/zh-cn/funcs/global/selector-node.md This example shows how to get a single child `NodeInfo` object from a parent node using its zero-based `index`. It first selects a `ViewGroup` node and, if found, retrieves its child at index 0, logging the result. ```JavaScript function main() { //选择 节点 clz=android.widget.ViewGroup 所有节点 var node = clz("android.widget.ViewGroup").getOneNodeInfo(10000); if (node) { var x = node.child(0); logd(x); } else { toast("无节点"); } } main(); ```