diff --git a/ArkUIKit/NativeNodeSample/.gitignore b/ArkUIKit/NativeNodeSample/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/NativeNodeSample/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/AppScope/app.json5 b/ArkUIKit/NativeNodeSample/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c6907772e67d9a0d30ef45cc03574fc28cab6bbf --- /dev/null +++ b/ArkUIKit/NativeNodeSample/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.example.nativenodesample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/NativeNodeSample/AppScope/resources/base/element/string.json b/ArkUIKit/NativeNodeSample/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..f6fca8ec8cc62fae2ac637de6e4699aee074425f --- /dev/null +++ b/ArkUIKit/NativeNodeSample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NativeNodeSample" + } + ] +} diff --git a/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/background.png b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/foreground.png b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/layered_image.json b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/NativeNodeSample/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/README_zh.md b/ArkUIKit/NativeNodeSample/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..f6ea209a500279ed5a3c2043f10926748a9561e6 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/README_zh.md @@ -0,0 +1,79 @@ +# ArkUI使用NODE IMAGE指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例, +展示在工程中,帮助开发者更好的理解并合理使用ArkUI提供的组件以及组件属性。通过该工程可以创建IMAGE组件并可以设置、获取、重置组件对应 +节点属性,对已创建的IMAGE组件进行销毁操作。该工程中代码详细描述可参考[显示图片 (Image)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.0-Release/zh-cn/application-dev/ui/arkts-graphics-display.md)。 + +### 效果预览 + +| 首页 | 设置图像内容顺时针旋转90度显示 | +|------------------------------------|---------------------------------| +| ![](screenshots/device/image1.png) |![](screenshots/device/result.png) | + +### 使用说明 + +1. 在主界面,可以点击“选择节点类型”,创建需要的组件。 + +2. 选择组件对应的“选择节点属性”菜单列。 + +3. 通过文本输入,设置属性值。 + +4. 点击“设置属性值”,查看效果。 + +5. 点击“获取属性值”,查看已设置的属性值。 + +6. 点击“重置”,清除设置的属性。 + +7. 点击“清理”,移除创建的组件节点。 + +### 工程目录 +``` +entry/src/main/cpp +|---CMakeLists.txt // 编译脚本 +|---napi_init.cpp // 实现创建、设置、获取、重置组件属性 +|---manager.cpp // 管理组件节点 +|---types + |---Index.d.ts // napi对外接口定义 +entry/src/main/ets/ +|---entryability +|---pages +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---index.test.ets // 示例代码测试代码 +``` + +### 具体实现 + +1. 在[Index.ets](entry%2Fsrc%2Fmain%2Fets%2Fpages%2FIndex.ets)文件中,通过点击按钮创建IMAGE组件节点,并通过文本输入框设置、获取、重置属性值。 +2. 在[Index.d.ts](entry%2Fsrc%2Fmain%2Fcpp%2Ftypes%2Flibentry%2FIndex.d.ts)文件中,定义napi对外接口。 +3. 在[napi_init.cpp](entry%2Fsrc%2Fmain%2Fcpp%2Fnapi_init.cpp)文件中,实现Index.d.ts中对外的接口。 +4. 在[manager.cpp](entry%2Fsrc%2Fmain%2Fcpp%2Fmanager.cpp)文件中,通过调用ArkUI的接口实现创建、设置、获取、重置组件属性。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例支持标准系统上运行, 支持设备:RK3568等。 + +2.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.47,镜像版本号:OpenHarmony_5.0.2.57。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUIDocSample/NativeNodeSample > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/build-profile.json5 b/ArkUIKit/NativeNodeSample/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..af763a9779f07bd26b856c39093dbdabc3f40b83 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ], + "signingConfigs": [ + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/code-linter.json5 b/ArkUIKit/NativeNodeSample/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/code-linter.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/.gitignore b/ArkUIKit/NativeNodeSample/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/build-profile.json5 b/ArkUIKit/NativeNodeSample/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..1f28520fc48e32a1440b8c3ed958205edb0f123e --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["armeabi-v7a","arm64-v8a","x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/hvigorfile.ts b/ArkUIKit/NativeNodeSample/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/obfuscation-rules.txt b/ArkUIKit/NativeNodeSample/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/oh-package.json5 b/ArkUIKit/NativeNodeSample/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..75d2e499a804dc9c4875b133326ee877cc980c65 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..6637f827201cbd8534df105d2ce9d5e5ab5c4319 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,23 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NativeNodeSample) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp manager.cpp) + +#add_subdirectory(nativeNodeDemo1) + +find_library( + libace-lib + ace_ndk.z +) + +target_link_libraries(entry PUBLIC ${libace-lib} libace_napi.z.so libnative_drawing.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.cpp b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.cpp new file mode 100755 index 0000000000000000000000000000000000000000..17d4861f77cc717e5c1ad6a2bf2284991a609db2 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.cpp @@ -0,0 +1,492 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "manager.h" + +#include +#include +#include +#include +#include + +namespace NativeNode::Manager { + +constexpr uint32_t MATRIX_ARRAY_SIZE = 16; +NodeManager& NodeManager::GetInstance() +{ + static NodeManager instance; + return instance; +} + +ArkUI_NativeNodeAPI_1* NodeManager::GetNodeApi() +{ + static ArkUI_NativeNodeAPI_1* nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + return nodeApi; +} + +void NodeManager::SetXComponent(OH_NativeXComponent* xComponent) +{ + xComponent_ = xComponent; +} + +struct AttributeScope { + ArkUI_NodeType nodeType; + ArkUI_NodeAttributeType begin; + ArkUI_NodeAttributeType end; +}; + +AttributeScope attributeArray[] = { + { ARKUI_NODE_TIME_PICKER, NODE_TIME_PICKER_SELECTED, NODE_TIME_PICKER_ENABLE_CASCADE }, + { ARKUI_NODE_TEXT_PICKER, NODE_TEXT_PICKER_OPTION_RANGE }, + { ARKUI_NODE_CALENDAR_PICKER, NODE_CALENDAR_PICKER_HINT_RADIUS, NODE_CALENDAR_PICKER_MARK_TODAY }, + { ARKUI_NODE_IMAGE_ANIMATOR, NODE_IMAGE_ANIMATOR_IMAGES, NODE_IMAGE_ANIMATOR_ITERATION }, + { ARKUI_NODE_IMAGE, NODE_IMAGE_SRC, NODE_IMAGE_ORIENTATION }, +}; + +static ArkUI_NumberValue timePickerValue1[] = { { .i32 = 1 } }; +static ArkUI_NumberValue textPickerValue1[] = { { .i32 = ARKUI_TEXTPICKER_RANGETYPE_SINGLE } }; +static ArkUI_NumberValue textPickerValue2[] = { { .i32 = 0 } }; +static ArkUI_NumberValue textPickerValue3[] = { { .f32 = 10.0 } }; +static ArkUI_NumberValue hdrBrightness[] = { { .f32 = 1.0 } }; +static ArkUI_NumberValue orientation[] = { { .i32 = ARKUI_ORIENTATION_DOWN } }; +static ArkUI_NumberValue copyOption[] = { { .i32 = ARKUI_COPY_OPTIONS_IN_APP } }; +static ArkUI_NumberValue imageMatrix[MATRIX_ARRAY_SIZE] = { { .f32 = 5.0f }, { .f32 = 0.0f }, { .f32 = 0.0f }, + { .f32 = 0.0f }, { .f32 = 0.0f }, { .f32 = 1.0f }, { .f32 = 0.0f }, { .f32 = 0.0f }, { .f32 = 0.0f }, + { .f32 = 0.0f }, { .f32 = 1.0f }, { .f32 = 0.0f }, { .f32 = 0.0f }, { .f32 = 400.0f }, + { .f32 = 0.0f }, { .f32 = 1.0f } }; +static ArkUI_NumberValue dynamicRangeMode[] = { { .i32 = 1 } }; +static ArkUI_NumberValue enableAnalyzer[] = { { .i32 = 1 } }; +static ArkUI_NumberValue matchDirection[] = { { .i32 = 1 } }; +static ArkUI_NumberValue sourceSize[] = { { .i32 = -100 }, { .i32 = 100 } }; +static ArkUI_NumberValue calendarPickerValue1[] = { { .f32 = 10.0f } }; +static ArkUI_NumberValue calendarPickerValue2[] = { { .u32 = 2025 }, { .u32 = 1 }, { .u32 = 1 } }; +static ArkUI_NumberValue calendarPickerValue3[] = { { .i32 = ARKUI_CALENDAR_ALIGNMENT_START }, { .f32 = 10.0f }, + { .f32 = 10.0f } }; +static ArkUI_NumberValue calendarPickerValue4[] = { { .u32 = 0xFFFF0000 }, { .f32 = 10.0f }, + { .i32 = ARKUI_FONT_WEIGHT_NORMAL } }; + +static std::map attributeValueMap = { + // ARKUI_NODE_TIME_PICKER + { NODE_TIME_PICKER_SELECTED, { timePickerValue1, 1, "11-59", nullptr } }, + { NODE_TIME_PICKER_USE_MILITARY_TIME, { timePickerValue1, 1, "11-59", nullptr } }, + { NODE_TIME_PICKER_DISAPPEAR_TEXT_STYLE, { timePickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TIME_PICKER_TEXT_STYLE, { timePickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TIME_PICKER_SELECTED_TEXT_STYLE, { timePickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TIME_PICKER_START, { timePickerValue1, 1, "00:00:00", nullptr } }, + { NODE_TIME_PICKER_END, { timePickerValue1, 1, "23:59:59", nullptr } }, + { NODE_TIME_PICKER_ENABLE_CASCADE, { timePickerValue1, 1, nullptr, nullptr } }, + // ARKUI_NODE_TEXT_PICKER + { NODE_TEXT_PICKER_OPTION_RANGE, { textPickerValue1, 1, "1;2;3", nullptr } }, + { NODE_TEXT_PICKER_OPTION_SELECTED, { textPickerValue2, 1, nullptr, nullptr } }, + { NODE_TEXT_PICKER_OPTION_VALUE, { textPickerValue1, 1, "1;2;3", nullptr } }, + { NODE_TEXT_PICKER_DISAPPEAR_TEXT_STYLE, { textPickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TEXT_PICKER_TEXT_STYLE, { textPickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TEXT_PICKER_SELECTED_TEXT_STYLE, { textPickerValue1, 1, "#ff182431;14;normal;Arial;normal", nullptr } }, + { NODE_TEXT_PICKER_SELECTED_INDEX, { textPickerValue2, 1, nullptr, nullptr } }, + { NODE_TEXT_PICKER_CAN_LOOP, { textPickerValue2, 1, nullptr, nullptr } }, + { NODE_TEXT_PICKER_DEFAULT_PICKER_ITEM_HEIGHT, { textPickerValue3, 1, nullptr, nullptr } }, + { NODE_TEXT_PICKER_ENABLE_HAPTIC_FEEDBACK, { textPickerValue1, 1, nullptr, nullptr } }, + // ARKUI_NODE_CALENDAR_PICKER + { NODE_CALENDAR_PICKER_HINT_RADIUS, { calendarPickerValue1, 1, nullptr, nullptr } }, + { NODE_CALENDAR_PICKER_SELECTED_DATE, { calendarPickerValue2, 3, nullptr, nullptr } }, + { NODE_CALENDAR_PICKER_EDGE_ALIGNMENT, { calendarPickerValue3, 3, nullptr, nullptr } }, + { NODE_CALENDAR_PICKER_TEXT_STYLE, { calendarPickerValue4, 3, nullptr, nullptr } }, + { NODE_CALENDAR_PICKER_START, { timePickerValue1, 1, "2025-1-1", nullptr } }, + { NODE_CALENDAR_PICKER_END, { timePickerValue1, 1, "2025-1-1", nullptr } }, + // ARKUI_NODE_IMAGE_ANIMATOR + { NODE_IMAGE_ANIMATOR_IMAGES, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_STATE, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_DURATION, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_REVERSE, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_FIXED_SIZE, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_FILL_MODE, { timePickerValue1, 1, nullptr, nullptr } }, + { NODE_IMAGE_ANIMATOR_ITERATION, { timePickerValue1, 1, nullptr, nullptr } }, + // ARKUI_NODE_IMAGE attributes type and value map + { NODE_IMAGE_HDR_BRIGHTNESS, { hdrBrightness, 1, nullptr, nullptr } }, + { NODE_IMAGE_ORIENTATION, { orientation, 1, nullptr, nullptr } }, + { NODE_IMAGE_IMAGE_MATRIX, { imageMatrix, MATRIX_ARRAY_SIZE, nullptr, nullptr } }, + { NODE_IMAGE_COPY_OPTION, { copyOption, 1, nullptr, nullptr } }, + { NODE_IMAGE_DYNAMIC_RANGE_MODE, { dynamicRangeMode, 1, nullptr, nullptr } }, + { NODE_IMAGE_ENABLE_ANALYZER, { enableAnalyzer, 1, nullptr, nullptr } }, + { NODE_IMAGE_MATCH_TEXT_DIRECTION, { matchDirection, 1, nullptr, nullptr } }, + { NODE_IMAGE_SOURCE_SIZE, { sourceSize, 2, nullptr, nullptr } }, +}; + +int32_t NodeManager::AddNativeNode(ArkUI_NodeHandle newNode, int32_t nodeType) +{ + if (newNode == nullptr) { + return -1; + } + + std::lock_guard lock(mutex_); + int32_t id = nodeId_++; + nativeNodeMap_[id] = { newNode, nodeType }; + return id; +} + +NodeRecord NodeManager::GetNativeNode(int32_t id) +{ + std::lock_guard lock(mutex_); + auto it = nativeNodeMap_.find(id); + if (it != nativeNodeMap_.end()) { + return it->second; + } + return { nullptr, -1 }; +} + +void NodeManager::RemoveNativeNode(int32_t id) +{ + std::lock_guard lock(mutex_); + auto it = nativeNodeMap_.find(id); + if (it != nativeNodeMap_.end()) { + nativeNodeMap_.erase(it); + } +} + +int32_t NodeManager::CreateNativeNode(int32_t nodeType) +{ + if (!xComponent_) { + return -1; + } + ArkUI_NativeNodeAPI_1* nodeApi = GetNodeApi(); + if (nodeApi == nullptr) { + return -1; + } + bool isValid = false; + for (int i = 0; i < sizeof(attributeArray) / sizeof(AttributeScope); i++) { + if (attributeArray[i].nodeType == nodeType) { + isValid = true; + break; + } + } + if (!isValid) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----CreateNativeNode, isValid is false"); + return -1; + } + + ArkUI_NodeHandle newNode = nodeApi->createNode((ArkUI_NodeType)nodeType); + if (nodeType == ARKUI_NODE_IMAGE) { + ArkUI_AttributeItem srcItem = {}; + srcItem.string = "resource://base/media/startIcon2.png"; + nodeApi->setAttribute(newNode, NODE_IMAGE_SRC, &srcItem); // create image node and set src attribute + ArkUI_NumberValue valueWidth[] = { { .f32 = 200 } }; + ArkUI_AttributeItem itemWidth = { valueWidth, sizeof(valueWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(newNode, NODE_WIDTH, &itemWidth); + ArkUI_NumberValue valueHeight[] = { { .f32 = 400 } }; + ArkUI_AttributeItem itemHeight = { valueHeight, sizeof(valueHeight) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(newNode, NODE_HEIGHT, &itemHeight); + } + + int32_t newNodeId = AddNativeNode(newNode, nodeType); + BindEventByType(newNode, nodeType, BIND_EVENT); + OH_NativeXComponent_AttachNativeRootNode(xComponent_, newNode); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----CreateNativeNode, nodeType:%{public}d, nodeId:%{public}d", + nodeType, newNodeId); + return newNodeId; +} + +void NodeManager::RemoveOldNode(int32_t nodeId) +{ + if (!xComponent_) { + return; + } + ArkUI_NodeHandle oldNode = GetNativeNode(nodeId).nodeHandle; + int32_t nodeType = GetNativeNode(nodeId).nodeType; + OH_NativeXComponent_DetachNativeRootNode(xComponent_, oldNode); + BindEventByType(oldNode, nodeType, UNBIND_EVENT); + RemoveNativeNode(nodeId); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----RemoveOldNode, nodeId:%{public}d", nodeId); +} + +bool NodeManager::IsValidAttributeType(int32_t nodeType, int32_t attributeType) +{ + bool isValid = false; + for (int i = 0; i < sizeof(attributeArray) / sizeof(AttributeScope); i++) { + if (attributeArray[i].nodeType == nodeType) { + if (attributeArray[i].begin <= attributeType && attributeType <= attributeArray[i].end) { + isValid = true; + } + break; + } + } + if (!isValid) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----IsValidAttributeType, isValid is false"); + } + return isValid; +} + +int32_t NodeManager::SetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType, int32_t value) +{ + int32_t ret = 0; + if (!IsValidAttributeType(nodeType, attributeType)) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + ArkUI_NativeNodeAPI_1* nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle node = GetNativeNode(nodeId).nodeHandle; + if (nodeApi == nullptr || node == nullptr) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + + ArkUI_NumberValue itemValue[] = { { .i32 = value } }; + ArkUI_AttributeItem attributeItem = { itemValue, sizeof(itemValue) / sizeof(ArkUI_NumberValue) }; + // when set NODE_IMAGE_ENABLE_ANALYZER, need set NODE_IMAGE_DRAGGABLE to 0, can only be pasted + if (attributeType == NODE_IMAGE_ENABLE_ANALYZER) { + ArkUI_NumberValue valueEnable[] = { { .i32 = 0 } }; + ArkUI_AttributeItem itemValue = { valueEnable, sizeof(valueEnable) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_IMAGE_DRAGGABLE, &itemValue); + } + // set NODE_IMAGE_COPY_OPTION, attribute value is ARKUI_COPY_OPTIONS_LOCAL_DEVICE + if (attributeType == NODE_IMAGE_COPY_OPTION) { + int32_t copyValue = ArkUI_CopyOptions::ARKUI_COPY_OPTIONS_LOCAL_DEVICE; + ArkUI_NumberValue value[] = { { .i32 = copyValue } }; + ArkUI_AttributeItem valueCopyItem = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_IMAGE_COPY_OPTION, &valueCopyItem); + } + // set other attribute type + ret = nodeApi->setAttribute(node, (ArkUI_NodeAttributeType)attributeType, &attributeItem); + + if (attributeType == NODE_IMAGE_ORIENTATION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE orientation SetNativeNodeAttribute, type:%{public}d, ret:%{public}d, item_value:%{public}d", + attributeType, ret, attributeItem.value[0].i32); + } else if (attributeType == NODE_IMAGE_ENABLE_ANALYZER) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE enable analyzer SetNativeNodeAttribute, type:%{public}d, ret:%{public}d, item_value:%{public}d", + attributeType, ret, attributeItem.value[0].i32); + } else if (attributeType == NODE_IMAGE_MATCH_TEXT_DIRECTION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE match direction SetNativeNodeAttribute, type:%{public}d, ret:%{public}d, item_value:%{public}d", + attributeType, ret, attributeItem.value[0].i32); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE default SetNativeNodeAttribute, type:%{public}d, ret:%{public}d, item_value:%{public}d", + attributeType, ret, attributeItem.value[0].i32); + } + return ret; +} +// When the user inputs multiple values, attribute setting +int32_t NodeManager::SetNativeNodeAttribute( + int32_t nodeId, int32_t nodeType, int32_t attributeType, const std::vector& value) +{ + int32_t ret = -1; + if (!IsValidAttributeType(nodeType, attributeType)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "NODE_IMAGE IsValidAttributeType"); + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + ArkUI_NativeNodeAPI_1* nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle node = GetNativeNode(nodeId).nodeHandle; + if (nodeApi == nullptr || node == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "NODE_IMAGE nodeApi or node is nullptr"); + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + // The following attributes do not support input with more than 2 parameters + if (value.size() <= 0 || (value.size() >= 2 && (attributeType == NODE_IMAGE_COPY_OPTION || + attributeType == NODE_IMAGE_ENABLE_ANALYZER || attributeType == NODE_IMAGE_ORIENTATION))) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + // The following NODE_IMAGE_SOURCE_SIZE attributes do not support input with more than 3 parameters + if (value.size() >= 3 && attributeType == NODE_IMAGE_SOURCE_SIZE) { // 3 means three elements + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + + // set attribute type is NODE_IMAGE_IMAGE_MATRIX, must set NODE_IMAGE_OBJECT_FIT to ARKUI_OBJECT_FIT_NONE_MATRIX + if (attributeType == NODE_IMAGE_IMAGE_MATRIX) { + if (value.size() < MATRIX_ARRAY_SIZE) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + int32_t objectFitValue = ArkUI_ObjectFit::ARKUI_OBJECT_FIT_NONE_MATRIX; + ArkUI_NumberValue valueObject[] = { { .i32 = objectFitValue } }; + ArkUI_AttributeItem valueItem = { valueObject, sizeof(valueObject) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_IMAGE_OBJECT_FIT, &valueItem); + ArkUI_NumberValue valueMatrix[100] = {}; + for (int i = 0; i < value.size(); ++i) { + valueMatrix[i].f32 = value[i]; + } + ArkUI_AttributeItem valueItemMatrix = { valueMatrix, sizeof(valueMatrix) / sizeof(ArkUI_NumberValue) }; + ret = nodeApi->setAttribute(node, NODE_IMAGE_IMAGE_MATRIX, &valueItemMatrix); + } + // set attribute type is NODE_IMAGE_SOURCE_SIZE + if (attributeType == NODE_IMAGE_SOURCE_SIZE) { + ArkUI_NumberValue valueSourceSize[] = { { .i32 = static_cast(value[0]) }, + { .i32 = static_cast(value[1]) } }; + ArkUI_AttributeItem valueItemSourceSize = { valueSourceSize, + sizeof(valueSourceSize) / sizeof(ArkUI_NumberValue) }; + ret = nodeApi->setAttribute(node, (ArkUI_NodeAttributeType)attributeType, &valueItemSourceSize); + } + return ret; +} + +int32_t NodeManager::ResetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType) +{ + int32_t ret = -1; + if (!IsValidAttributeType(nodeType, attributeType)) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + ArkUI_NativeNodeAPI_1* nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle node = GetNativeNode(nodeId).nodeHandle; + if (nodeApi == nullptr || node == nullptr) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + // call reset interface with attribute type + ret = nodeApi->resetAttribute(node, (ArkUI_NodeAttributeType)attributeType); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE ResetNativeNodeAttribute, type:%{public}d, ret:%{public}d", attributeType, ret); + const ArkUI_AttributeItem* attributeItem = nodeApi->getAttribute(node, (ArkUI_NodeAttributeType)attributeType); + if (attributeType == NODE_IMAGE_ORIENTATION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE orientation GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", attributeType, + attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_IMAGE_MATRIX) { + for (int i = 0; i < MATRIX_ARRAY_SIZE; ++i) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE imageMatrix GetAttribute, type:%{public}d, size:%{public}d, value:%{public}f", + attributeType, attributeItem->size, attributeItem->value[i].f32); + } + } else if (attributeType == NODE_IMAGE_ENABLE_ANALYZER) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE enable analyzer GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_MATCH_TEXT_DIRECTION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE match direction GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_SOURCE_SIZE) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE sourceSize GetAttribute, type:%{public}d, size:%{public}d, value_0:%{public}d, " + "value_1:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32, attributeItem->value[1].i32); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE hdr brightness GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", attributeType, + attributeItem->size, attributeItem->value[0].i32); + } + return ret; +} + +const ArkUI_AttributeItem* NodeManager::GetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType) +{ + if (!IsValidAttributeType(nodeType, attributeType)) { + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle node = GetNativeNode(nodeId).nodeHandle; + if (nodeApi == nullptr || node == nullptr) { + return nullptr; + } + // call get attribute interface with attribute type + const ArkUI_AttributeItem* attributeItem = nodeApi->getAttribute(node, (ArkUI_NodeAttributeType)attributeType); + if (attributeType == NODE_IMAGE_ORIENTATION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE orientation GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", attributeType, + attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_IMAGE_MATRIX) { + for (int i = 0; i < MATRIX_ARRAY_SIZE; ++i) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE imageMatrix GetAttribute, type:%{public}d, size:%{public}d, value:%{public}f", + attributeType, attributeItem->size, attributeItem->value[i].f32); + } + } else if (attributeType == NODE_IMAGE_HDR_BRIGHTNESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE hdr brightness GetAttribute, type:%{public}d, size:%{public}d, value:%{public}f", attributeType, + attributeItem->size, attributeItem->value[0].f32); + } else if (attributeType == NODE_IMAGE_DYNAMIC_RANGE_MODE) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE dynamic rangeMode GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_ENABLE_ANALYZER) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE enable analyzer GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_MATCH_TEXT_DIRECTION) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE match direction GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32); + } else if (attributeType == NODE_IMAGE_SOURCE_SIZE) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE sourceSize GetAttribute, type:%{public}d, size:%{public}d, value_0:%{public}d, " + "value_1:%{public}d", + attributeType, attributeItem->size, attributeItem->value[0].i32, attributeItem->value[1].i32); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", + "NODE_IMAGE hdr brightness GetAttribute, type:%{public}d, size:%{public}d, value:%{public}d", attributeType, + attributeItem->size, attributeItem->value[0].i32); + } + return attributeItem; +} + +void NodeManager::BindEventByType(ArkUI_NodeHandle newNode, int32_t nodeType, EventOperation operation) +{ + switch (nodeType) { + case ARKUI_NODE_IMAGE: + BindEventFunc(newNode, NODE_IMAGE_ON_COMPLETE, NODE_IMAGE_ON_DOWNLOAD_PROGRESS, operation); + break; + case ARKUI_NODE_DATE_PICKER: + BindEventFunc( + newNode, NODE_DATE_PICKER_EVENT_ON_DATE_CHANGE, NODE_DATE_PICKER_EVENT_ON_DATE_CHANGE, operation); + break; + case ARKUI_NODE_TIME_PICKER: + BindEventFunc(newNode, NODE_TIME_PICKER_EVENT_ON_CHANGE, NODE_TIME_PICKER_EVENT_ON_CHANGE, operation); + break; + case ARKUI_NODE_TEXT_PICKER: + BindEventFunc(newNode, NODE_TEXT_PICKER_EVENT_ON_CHANGE, NODE_TEXT_PICKER_EVENT_ON_SCROLL_STOP, operation); + break; + case ARKUI_NODE_CALENDAR_PICKER: + BindEventFunc( + newNode, NODE_CALENDAR_PICKER_EVENT_ON_CHANGE, NODE_CALENDAR_PICKER_EVENT_ON_CHANGE, operation); + break; + case ARKUI_NODE_IMAGE_ANIMATOR: + BindEventFunc(newNode, NODE_IMAGE_ANIMATOR_EVENT_ON_START, NODE_IMAGE_ANIMATOR_EVENT_ON_FINISH, operation); + break; + default: + break; + } +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + int32_t eventTypeId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----OnEventReceive, eventTypeId:%{public}d", eventTypeId); +} + +void NodeManager::BindEventFunc(ArkUI_NodeHandle newNode, int32_t begin, int32_t end, EventOperation operation) +{ + ArkUI_NativeNodeAPI_1* nodeApi = GetNodeApi(); + if (nodeApi == nullptr) { + return; + } + if (operation == BIND_EVENT) { + // 注册事件 + nodeApi->registerNodeEventReceiver(&OnEventReceive); + int32_t ret = -1; + for (int32_t index = begin; index <= end; index++) { + ret = nodeApi->registerNodeEvent(newNode, (ArkUI_NodeEventType)index, index, nullptr); + if (ret != ARKUI_ERROR_CODE_NO_ERROR) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----BIND_EVENT fail, errorcode:%{public}d", ret); + break; + } + } + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----BIND_EVENT success"); + } else { + for (int32_t index = begin; index <= end; index++) { + nodeApi->unregisterNodeEvent(newNode, (ArkUI_NodeEventType)index); + } + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----UNBIND_EVENT finish"); + } +} +} // namespace NativeNode::Manager diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.h b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.h new file mode 100755 index 0000000000000000000000000000000000000000..f85844b21af66db520fd3ac5cefbbb2973528abb --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/manager.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CAPI_MANAGER_H +#define CAPI_MANAGER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NativeNode::Manager { +using EventCallback = std::function; + +// 指定对事件进行绑定还是解绑 +enum EventOperation { + BIND_EVENT, + UNBIND_EVENT, +}; + +struct NodeRecord { + ArkUI_NodeHandle nodeHandle; + int32_t nodeType; +}; + +class NodeManager { +public: + ~NodeManager() = default; + static NodeManager& GetInstance(); + static ArkUI_NativeNodeAPI_1* GetNodeApi(); + + void SetXComponent(OH_NativeXComponent* xComponent); + int32_t CreateNativeNode(int32_t nodeType); + void RemoveOldNode(int32_t nodeId); + int32_t SetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType, int32_t value); + int32_t SetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, + int32_t attributeType, const std::vector& values); + int32_t ResetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType); + const ArkUI_AttributeItem* GetNativeNodeAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType); +private: + NodeManager() = default; + int32_t AddNativeNode(ArkUI_NodeHandle newNode, int32_t nodeType); + NodeRecord GetNativeNode(int32_t id); + void RemoveNativeNode(int32_t id); + bool IsValidAttributeType(int32_t nodeType, int32_t attributeType); + void BindEventByType(ArkUI_NodeHandle newNode, int32_t nodeType, EventOperation operation); + void BindEventFunc(ArkUI_NodeHandle newNode, int32_t begin, int32_t end, EventOperation operation); + + OH_NativeXComponent* xComponent_; + std::unordered_map callbackMap_; + + std::map nativeNodeMap_; + std::mutex mutex_; + int32_t nodeId_ = 1; +}; +} + +#endif //CAPI_MANAGER_H diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/napi_init.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c41ce638df5e5eed925aa1fa55b7df4423c360fd --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "manager.h" +#include +#include +#include +#include +#include +#include +#include + +static OH_NativeXComponent* GetXComponent(napi_env env, napi_value exports) +{ + if ((env == nullptr) || (exports == nullptr)) { + return nullptr; + } + napi_value exportInstance = nullptr; + if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { + return nullptr; + } + OH_NativeXComponent* xComp = nullptr; + if (napi_unwrap(env, exportInstance, reinterpret_cast(&xComp)) != napi_ok) { + return nullptr; + } + return xComp; +} + +static napi_value CreateNativeNode(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t nodeType; + napi_get_value_int32(env, args[0], &nodeType); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----CreateNativeNode, input nodeType:%{public}d", nodeType); + if (nodeType < 0) { + napi_value result; + napi_create_int32(env, -1, &result); + return result; + } + + int32_t newNodeId = NativeNode::Manager::NodeManager::GetInstance().CreateNativeNode(nodeType); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "NativeNode", "-----CreateNativeNode, newNodeId:%{public}d", newNodeId); + if (newNodeId != -1) { + napi_value result; + napi_create_int32(env, newNodeId, &result); + return result; + } + return nullptr; +} + +static napi_value RemoveOldNode(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t nodeId; + napi_get_value_int32(env, args[0], &nodeId); + if (nodeId < 0) { + return nullptr; + } + + NativeNode::Manager::NodeManager::GetInstance().RemoveOldNode(nodeId); + return nullptr; +} + +static std::vector ParseFloatValues(const std::string& value) +{ + std::vector floatValues; + std::stringstream ss(value); + std::string item; + while (std::getline(ss, item, '/')) { + if (!item.empty()) { + try { + float floatValue = std::stof(item); + floatValues.push_back(floatValue); + } catch (const std::exception&) { + continue; + } + } + } + return floatValues; +} + +static int32_t HandleStringAttribute(int32_t nodeId, int32_t nodeType, int32_t attributeType, const std::string& value) +{ + size_t slashCount = std::count(value.begin(), value.end(), '/'); + if (slashCount > 0) { + std::vector floatValues = ParseFloatValues(value); + if (!floatValues.empty()) { + return NativeNode::Manager::NodeManager::GetInstance().SetNativeNodeAttribute( + nodeId, nodeType, attributeType, floatValues); + } + return -1; + } + + try { + int32_t intValue = std::stoi(value); + return NativeNode::Manager::NodeManager::GetInstance().SetNativeNodeAttribute( + nodeId, nodeType, attributeType, intValue); + } catch (const std::exception&) { + return -1; + } +} + +static napi_value SetNativeNodeAttribute(napi_env env, napi_callback_info info) +{ + size_t argc = 4; // 4 means four arguments are expected + napi_value args[4] = {nullptr}; // 4 means four arguments size + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + int32_t nodeId; + napi_get_value_int32(env, args[0], &nodeId); + int32_t nodeType; + napi_get_value_int32(env, args[1], &nodeType); + int32_t attributeType; + napi_get_value_int32(env, args[2], &attributeType); // 2 means the third argument + napi_valuetype valueType; + napi_typeof(env, args[3], &valueType); // 3 means the fourth argument + + int32_t ret = -1; + if (valueType != napi_string) { + napi_value result; + napi_create_int32(env, ret, &result); + return result; + } + + size_t valueLen; + napi_get_value_string_utf8(env, args[3], nullptr, 0, &valueLen); // 3 means the fourth argument + + std::string value(valueLen + 1, '\0'); + napi_get_value_string_utf8(env, args[3], &value[0], valueLen + 1, nullptr); // 3 means the fourth argument + + ret = HandleStringAttribute(nodeId, nodeType, attributeType, value); + + napi_value result; + napi_create_int32(env, ret, &result); + return result; +} + +static napi_value ResetNativeNodeAttribute(napi_env env, napi_callback_info info) +{ + size_t argc = 3; // 3 means 3 arguments are expected + napi_value args[3] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t nodeId; + napi_get_value_int32(env, args[0], &nodeId); + int32_t nodeType; + napi_get_value_int32(env, args[1], &nodeType); + int32_t attributeType; + napi_get_value_int32(env, args[2], &attributeType); // 2 means the third argument + + int32_t ret = NativeNode::Manager::NodeManager::GetInstance().ResetNativeNodeAttribute(nodeId, + nodeType, attributeType); + napi_value result; + napi_create_int32(env, ret, &result); + return result; +} + +static napi_value GetNativeNodeAttribute(napi_env env, napi_callback_info info) +{ + size_t argc = 3; // 3 means three arguments are expected + napi_value args[3] = {nullptr}; // 3 means three arguments are expected + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + int32_t nodeId = -1; + napi_get_value_int32(env, args[0], &nodeId); + int32_t nodeType = -1; + napi_get_value_int32(env, args[1], &nodeType); + int32_t attributeType = -1; + napi_get_value_int32(env, args[2], &attributeType); // 2 means the third argument + napi_value result; + if (nodeType < 0 || attributeType < 0) { + napi_create_int32(env, -1, &result); + return result; + } + const ArkUI_AttributeItem* item = NativeNode::Manager::NodeManager::GetInstance().GetNativeNodeAttribute(nodeId, + nodeType, attributeType); + if (item == nullptr) { + napi_create_int32(env, -1, &result); + return result; + } + std::stringstream ss; + bool hasValue = false; + if (item->size > 0) { + for (size_t i = 0; i < item->size; i++) { + if (hasValue) { + ss << "/"; + } + if (attributeType != NODE_IMAGE_IMAGE_MATRIX) { + ss << static_cast(item->value[i].i32); + } else { + ss << std::fixed << std::setprecision(6) << item->value[i].f32; // 6 means six decimal places + } + hasValue = true; + } + } + if (item->string != nullptr) { + if (hasValue) { + ss << "/"; + } + ss << item->string; + hasValue = true; + } + if (!hasValue) { + ss << "-1"; + } + std::string resultStr = ss.str(); + napi_create_string_utf8(env, resultStr.c_str(), resultStr.length(), &result); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "createNativeNode", nullptr, CreateNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "removeOldNode", nullptr, RemoveOldNode, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "setNativeNodeAttribute", nullptr, SetNativeNodeAttribute, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "resetNativeNodeAttribute", nullptr, ResetNativeNodeAttribute, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getNativeNodeAttribute", nullptr, GetNativeNodeAttribute, nullptr, nullptr, nullptr, napi_default, nullptr }, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + auto xComponent = GetXComponent(env, exports); + if (xComponent) { + NativeNode::Manager::NodeManager::GetInstance().SetXComponent(xComponent); + } + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..486675548e409ab648baf9e1841a7b9d713dc87f --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const createNativeNode: (nodeType: number) => number; +export const resetNativeNodeAttribute: (nodeId: number, nodeType: number, attributeType: number) => number; +export const removeOldNode: (nodeId: number) => void; +export const setNativeNodeAttribute: (nodeId: number, nodeType: number, attributeType: number, attributeValue: string) => number; +export const getNativeNodeAttribute: (nodeId: number, nodeType: number, attributeType: number) => string; \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c69ca2198f11d3288b2ac61227a583604b647c78 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/NativeNodeSample/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..44bcd860455af6a6737d6952e09d47807be58e45 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/NativeNodeSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..ced5661da1d94764d0ac8f5b902ae0683b942606 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/ets/pages/Index.ets b/ArkUIKit/NativeNodeSample/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..b12e96cd7d43a4bcde979fe259e7775067f9273f --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import testNapi from 'libentry.so'; +import node from '@ohos.arkui.node'; + +function isValidType(id: number) : boolean { + if (id !== -1) { // -1 means invalid type + return true; + } + return false; +} + +function getNodeType(type: string) : number { + let ret = -1; + switch (type) { + case 'TIME_PICKER': + ret = 14; + break; + case 'TEXT_PICKER': + ret = 15; + break; + case 'CALENDAR_PICKER': + ret = 16; + break; + case 'IMAGE_ANIMATOR': + ret = 19; + break; + case 'IMAGE': + ret = 4; + break; + default: + break; + } + return ret; +} + +const SUCC_TAG = '创建成功'; +const FAIL_TAG = '创建失败'; + +@Entry +@Component +struct Index { + @State nodeId: number = -1; + @State nodeStatus: string = FAIL_TAG; + @State curNodeType: string = '未设置'; + @State attributeType: string = '未设置'; + @State attributeTypeId: number = -1; + @State attributeValue: string = '-1'; + @State resultValue: string = '-1'; + @State curAttrStatus: number = -1; + + @Builder + SubMenuNodeType() { + Menu() { + MenuItem({ content: 'TIME_PICKER' }).width('50%').onChange(()=> { this.curNodeType = 'TIME_PICKER'}) + MenuItem({ content: 'TEXT_PICKER'}).width('50%').onChange(()=> { this.curNodeType = 'TEXT_PICKER' }) + MenuItem({ content: 'CALENDAR_PICKER'}).width('50%').onChange(()=> { this.curNodeType = 'CALENDAR_PICKER' }) + MenuItem({ content: 'IMAGE_ANIMATOR'}).width('50%').onChange(()=> { this.curNodeType = 'IMAGE_ANIMATOR' }) + MenuItem({ content: 'IMAGE'}).width('50%').onChange(()=> { this.curNodeType = 'IMAGE' }) + } + } + + @Builder + SubMenuAttributeType() { + Menu() { + MenuItem({ content: 'TIME_PICKER', builder: ():void=>this.SubMenu_TIME_PICKER() }).width('50%') + MenuItem({ content: 'TEXT_PICKER', builder: ():void=>this.SubMenu_TIME_PICKER() }).width('50%') + MenuItem({ content: 'CALENDAR_PICKER', builder: ():void=>this.SubMenu_TIME_PICKER() }).width('50%') + MenuItem({ content: 'IMAGE_ANIMATOR', builder: ():void=>this.SubMenu_TIME_PICKER() }).width('50%') + MenuItem({ content: 'IMAGE', builder: ():void=>this.SubMenu_IMAGE() }).width('50%') + } + } + // add image attributeType + @Builder + SubMenu_IMAGE() { + Menu() { + MenuItem({ content: 'SRC' }).width('50%').onChange(()=> { + this.attributeType = 'SRC' + this.attributeTypeId = 4000 + }) + MenuItem({ content: 'OBJECT_FIT' }).width('50%').onChange(()=> { + this.attributeType = 'OBJECT_FIT' + this.attributeTypeId = 4001 + }) + MenuItem({ content: 'INTERPOLATION' }).width('50%').onChange(()=> { + this.attributeType = 'INTERPOLATION' + this.attributeTypeId = 4002 + }) + MenuItem({ content: 'OBJECT_REPEAT' }).width('50%').onChange(()=> { + this.attributeType = 'OBJECT_REPEAT' + this.attributeTypeId = 4003 + }) + MenuItem({ content: 'COLOR_FILTER' }).width('50%').onChange(()=> { + this.attributeType = 'COLOR_FILTER' + this.attributeTypeId = 4004 + }) + MenuItem({ content: 'AUTO_RESIZE' }).width('50%').onChange(()=> { + this.attributeType = 'AUTO_RESIZE' + this.attributeTypeId = 4005 + }) + MenuItem({ content: 'ALT' }).width('50%').onChange(()=> { + this.attributeType = 'ALT' + this.attributeTypeId = 4006 + }) + MenuItem({ content: 'DRAGGABLE' }).width('50%').onChange(()=> { + this.attributeType = 'DRAGGABLE' + this.attributeTypeId = 4007 + }) + MenuItem({ content: 'RENDER_MODE' }).width('50%').onChange(()=> { + this.attributeType = 'RENDER_MODE' + this.attributeTypeId = 4008 + }) + MenuItem({ content: 'FIT_ORIGINAL_SIZE' }).width('50%').onChange(()=> { + this.attributeType = 'FIT_ORIGINAL_SIZE' + this.attributeTypeId = 4009 + }) + MenuItem({ content: 'FILL_COLOR' }).width('50%').onChange(()=> { + this.attributeType = 'FILL_COLOR' + this.attributeTypeId = 4010 + }) + MenuItem({ content: 'RESIZABLE' }).width('50%').onChange(()=> { + this.attributeType = 'RESIZABLE' + this.attributeTypeId = 4011 + }) + MenuItem({ content: 'SYNC_LOAD' }).width('50%').onChange(()=> { + this.attributeType = 'SYNC_LOAD' + this.attributeTypeId = 4012 + }) + MenuItem({ content: 'SOURCE_SIZE' }).width('50%').onChange(()=> { + this.attributeType = 'SOURCE_SIZE' + this.attributeTypeId = 4013 + }) + MenuItem({ content: 'IMAGE_MATRIX' }).width('50%').onChange(()=> { + this.attributeType = 'IMAGE_MATRIX' + this.attributeTypeId = 4014 + }) + MenuItem({ content: 'MATCH_TEXT_DIRECTION' }).width('50%').onChange(()=> { + this.attributeType = 'MATCH_TEXT_DIRECTION' + this.attributeTypeId = 4015 + }) + MenuItem({ content: 'COPY_OPTION' }).width('50%').onChange(()=> { + this.attributeType = 'COPY_OPTION' + this.attributeTypeId = 4016 + }) + MenuItem({ content: 'ENABLE_ANALYZER' }).width('50%').onChange(()=> { + this.attributeType = 'ENABLE_ANALYZER' + this.attributeTypeId = 4017 + }) + MenuItem({ content: 'DYNAMIC_RANGE_MODE' }).width('50%').onChange(()=> { + this.attributeType = 'DYNAMIC_RANGE_MODE' + this.attributeTypeId = 4018 + }) + MenuItem({ content: 'HDR_BRIGHTNESS' }).width('50%').onChange(()=> { + this.attributeType = 'HDR_BRIGHTNESS' + this.attributeTypeId = 4019 + }) + MenuItem({ content: 'ORIENTATION' }).width('50%').onChange(()=> { + this.attributeType = 'ORIENTATION' + this.attributeTypeId = 4020 + }) + } + } + @Builder + SubMenu_TIME_PICKER() { + Menu() { + MenuItem({ content: 'SELECTED' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED' + this.attributeTypeId = 14000 + }) + MenuItem({ content: 'USE_MILITARY_TIME' }).width('50%').onChange(()=> { + this.attributeType = 'USE_MILITARY_TIME' + this.attributeTypeId = 14001 + }) + MenuItem({ content: 'DISAPPEAR_TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'DISAPPEAR_TEXT_STYLE' + this.attributeTypeId = 14002 + }) + MenuItem({ content: 'TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'TEXT_STYLE' + this.attributeTypeId = 14003 + }) + MenuItem({ content: 'SELECTED_TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED_TEXT_STYLE' + this.attributeTypeId = 14004 + }) + MenuItem({ content: 'START' }).width('50%').onChange(()=> { + this.attributeType = 'START' + this.attributeTypeId = 14005 + }) + MenuItem({ content: 'END' }).width('50%').onChange(()=> { + this.attributeType = 'END' + this.attributeTypeId = 14006 + }) + MenuItem({ content: 'ENABLE_CASCADE' }).width('50%').onChange(()=> { + this.attributeType = 'ENABLE_CASCADE' + this.attributeTypeId = 14007 + }) + } + } + + @Builder + SubMenu_TEXT_PICKER() { + Menu() { + MenuItem({ content: 'OPTION_RANGE' }).width('50%').onChange(()=> { + this.attributeType = 'OPTION_RANGE' + this.attributeTypeId = 15000 + }) + MenuItem({ content: 'OPTION_SELECTED' }).width('50%').onChange(()=> { + this.attributeType = 'OPTION_SELECTED' + this.attributeTypeId = 15001 + }) + MenuItem({ content: 'OPTION_VALUE' }).width('50%').onChange(()=> { + this.attributeType = 'OPTION_VALUE' + this.attributeTypeId = 15002 + }) + MenuItem({ content: 'DISAPPEAR_TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'DISAPPEAR_TEXT_STYLE' + this.attributeTypeId = 15003 + }) + MenuItem({ content: 'TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'TEXT_STYLE' + this.attributeTypeId = 15004 + }) + MenuItem({ content: 'SELECTED_TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED_TEXT_STYLE' + this.attributeTypeId = 15005 + }) + MenuItem({ content: 'SELECTED_INDEX' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED_INDEX' + this.attributeTypeId = 15006 + }) + MenuItem({ content: 'CAN_LOOP' }).width('50%').onChange(()=> { + this.attributeType = 'CAN_LOOP' + this.attributeTypeId = 15007 + }) + MenuItem({ content: 'DEFAULT_PICKER_ITEM_HEIGHT' }).width('50%').onChange(()=> { + this.attributeType = 'DEFAULT_PICKER_ITEM_HEIGHT' + this.attributeTypeId = 15008 + }) + MenuItem({ content: 'COLUMN_WIDTHS' }).width('50%').onChange(()=> { + this.attributeType = 'COLUMN_WIDTHS' + this.attributeTypeId = 15009 + }) + MenuItem({ content: 'ENABLE_HAPTIC_FEEDBACK' }).width('50%').onChange(()=> { + this.attributeType = 'ENABLE_HAPTIC_FEEDBACK' + this.attributeTypeId = 15010 + }) + MenuItem({ content: 'SELECTED_BACKGROUND_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED_BACKGROUND_STYLE' + this.attributeTypeId = 15011 + }) + } + } + + @Builder + SubMenu_CALENDAR_PICKER() { + Menu() { + MenuItem({ content: 'HINT_RADIUS' }).width('50%').onChange(()=> { + this.attributeType = 'HINT_RADIUS' + this.attributeTypeId = 16000 + }) + MenuItem({ content: 'SELECTED_DATE' }).width('50%').onChange(()=> { + this.attributeType = 'SELECTED_DATE' + this.attributeTypeId = 16001 + }) + MenuItem({ content: 'EDGE_ALIGNMENT' }).width('50%').onChange(()=> { + this.attributeType = 'EDGE_ALIGNMENT' + this.attributeTypeId = 16002 + }) + MenuItem({ content: 'TEXT_STYLE' }).width('50%').onChange(()=> { + this.attributeType = 'TEXT_STYLE' + this.attributeTypeId = 16003 + }) + MenuItem({ content: 'START' }).width('50%').onChange(()=> { + this.attributeType = 'START' + this.attributeTypeId = 16004 + }) + MenuItem({ content: 'END' }).width('50%').onChange(()=> { + this.attributeType = 'END' + this.attributeTypeId = 16005 + }) + MenuItem({ content: 'DISABLED_DATE_RANGE' }).width('50%').onChange(()=> { + this.attributeType = 'DISABLED_DATE_RANGE' + this.attributeTypeId = 16006 + }) + MenuItem({ content: 'MARK_TODAY' }).width('50%').onChange(()=> { + this.attributeType = 'MARK_TODAY' + this.attributeTypeId = 16007 + }) + } + } + + @Builder + SubMenu_IMAGE_ANIMATOR() { + Menu() { + MenuItem({ content: 'IMAGES' }).width('50%').onChange(()=> { + this.attributeType = 'IMAGES' + this.attributeTypeId = 19000 + }) + MenuItem({ content: 'STATE' }).width('50%').onChange(()=> { + this.attributeType = 'STATE' + this.attributeTypeId = 19001 + }) + MenuItem({ content: 'DURATION' }).width('50%').onChange(()=> { + this.attributeType = 'DURATION' + this.attributeTypeId = 19002 + }) + MenuItem({ content: 'REVERSE' }).width('50%').onChange(()=> { + this.attributeType = 'REVERSE' + this.attributeTypeId = 19003 + }) + MenuItem({ content: 'FIXED_SIZE' }).width('50%').onChange(()=> { + this.attributeType = 'FIXED_SIZE' + this.attributeTypeId = 19004 + }) + MenuItem({ content: 'FILL_MODE' }).width('50%').onChange(()=> { + this.attributeType = 'FILL_MODE' + this.attributeTypeId = 19005 + }) + MenuItem({ content: 'ITERATION' }).width('50%').onChange(()=> { + this.attributeType = 'ITERATION' + this.attributeTypeId = 19006 + }) + } + } + + + build() { + Column() { + Text('native_node功能示例') + .fontSize(24) + .margin(10) + .fontWeight(FontWeight.Bold) + .height('10%') + Row() { + Column() { + Button('选择节点类型:') + .width('50%') + .margin({ left: 10 }) + .bindMenu(this.SubMenuNodeType) + Text(`当前类型: ${this.curNodeType}`) + .fontSize(14) + .margin(10) + Text(`当前状态: ${this.nodeStatus}`) + .fontSize(14) + .margin(10) + + Row() { + Button('创建') + .width('30%') + .margin(10) + .onClick(() => { + // 先将之前创建的节点清理 + testNapi.removeOldNode(this.nodeId); + this.nodeId = -1; + // 创建新节点 + this.nodeId = testNapi.createNativeNode(getNodeType(this.curNodeType)) + this.nodeStatus = (this.nodeId == -1) ? FAIL_TAG : SUCC_TAG; + }) + Button('重置') + .width('30%') + .margin(10) + .onClick(() => { + // 重置新节点 + this.nodeId = testNapi.resetNativeNodeAttribute(this.nodeId, getNodeType(this.curNodeType), + this.attributeTypeId) + this.nodeStatus = (this.nodeId == -1) ? FAIL_TAG : SUCC_TAG; + }) + Button('清理') + .width('30%') + .margin(10) + .onClick(() => { + testNapi.removeOldNode(this.nodeId); + this.nodeId = -1; + this.nodeStatus = FAIL_TAG; + }) + } + + } + .width('50%') + + Column() { + Button('选择节点属性:') + .width('50%') + .margin({ left: 10 }) + .bindMenu(this.SubMenuAttributeType) + Text(`当前属性类型: ${this.attributeType}`) + .fontSize(14) + .margin(10) + Text(`返回值: ${this.resultValue}`) + .fontSize(14) + .margin(5) + Text(`返回错误码: ${this.curAttrStatus}`) + .fontSize(14) + .margin(5) + // 添加用户输入框 + Row() { + Text('属性值:') + .alignSelf(ItemAlign.End) + .fontSize(14) + TextInput({ placeholder: '请输入属性值', text: this.attributeValue }) + .width('60%') + .height(40) + .onChange((value: string) => { + this.attributeValue = value; + }) + } + .width('100%') + .margin(20) + .justifyContent(FlexAlign.End) + + Button('设置属性值') + .margin(25) + .alignSelf(ItemAlign.End) + .onClick( + () => { + this.curAttrStatus = -1; + this.curAttrStatus = testNapi.setNativeNodeAttribute(this.nodeId, getNodeType(this.curNodeType), + this.attributeTypeId, this.attributeValue); + } + ) + Button('获取属性值') + .margin(20) + .alignSelf(ItemAlign.End) + .onClick( + () => { + this.resultValue = testNapi.getNativeNodeAttribute(this.nodeId, getNodeType(this.curNodeType), + this.attributeTypeId); + } + ) + } + .width('50%') + } + .height('30%') + + XComponent({ + id: "xComponent", + type: XComponentType.NODE, + libraryname: "entry" + }).onAppear(()=> { + }) + .width('60%') + .height('40%') + } + } +} diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/module.json5 b/ArkUIKit/NativeNodeSample/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..78a72362efdf4ef6d9c8400b25527133d926dd45 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/color.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/float.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/string.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/background.png b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..be4105a540f934fd33ca9d03a5a33407f40eca5d Binary files /dev/null and b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon2.png b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon2.png new file mode 100755 index 0000000000000000000000000000000000000000..24bd43eb05e4e5a8b35a3bc9651ec1abbef1ba68 Binary files /dev/null and b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/media/startIcon2.png differ diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkUIKit/NativeNodeSample/entry/src/main/resources/dark/element/color.json b/ArkUIKit/NativeNodeSample/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/mock/Libentry.mock.ets b/ArkUIKit/NativeNodeSample/entry/src/mock/Libentry.mock.ets new file mode 100755 index 0000000000000000000000000000000000000000..82fa70b5693ddab96d237d2d17d943d866b61465 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/mock/mock-config.json5 b/ArkUIKit/NativeNodeSample/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/mock/mock-config.json5 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7f30942b81554a399e89aa253c7089eca4f8d8d1 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/ohosTest/module.json5 b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..15985f07ded51de709b7c68483df86e9071ade0b --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/NativeNodeSample/entry/src/test/List.test.ets b/ArkUIKit/NativeNodeSample/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/entry/src/test/LocalUnit.test.ets b/ArkUIKit/NativeNodeSample/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/NativeNodeSample/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/hvigor/hvigor-config.json5 b/ArkUIKit/NativeNodeSample/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..70879912169503ff02665211233887556b8f4ae8 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/NativeNodeSample/hvigorfile.ts b/ArkUIKit/NativeNodeSample/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeSample/oh-package.json5 b/ArkUIKit/NativeNodeSample/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..463ba600e57f685bdc2b1d5a759cd939fe9f1762 --- /dev/null +++ b/ArkUIKit/NativeNodeSample/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/NativeNodeSample/ohosTest.md b/ArkUIKit/NativeNodeSample/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..94ba776ab3b8074712192f808f480ef035fa0ebd --- /dev/null +++ b/ArkUIKit/NativeNodeSample/ohosTest.md @@ -0,0 +1,7 @@ +# NativeNodeSample 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | -------------- | ----------------------- | ------------------------------------------------------------ | :------- | -------- | +| 示例代码验证 | 设备正常运行 | 输入a、b的值 | 符合预期 | 是 | Pass | diff --git a/ArkUIKit/NativeNodeSample/screenshots/device/image1.png b/ArkUIKit/NativeNodeSample/screenshots/device/image1.png new file mode 100755 index 0000000000000000000000000000000000000000..da5029f442c6c24db679a705ade4b45b87ca80e4 Binary files /dev/null and b/ArkUIKit/NativeNodeSample/screenshots/device/image1.png differ diff --git a/ArkUIKit/NativeNodeSample/screenshots/device/result.png b/ArkUIKit/NativeNodeSample/screenshots/device/result.png new file mode 100755 index 0000000000000000000000000000000000000000..d4faf361922cdc328a55b7c40ebcabcb593ad050 Binary files /dev/null and b/ArkUIKit/NativeNodeSample/screenshots/device/result.png differ