diff --git a/ArkUIKit/CoastingAxisEventNDK/.gitignore b/ArkUIKit/CoastingAxisEventNDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/.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/CoastingAxisEventNDK/AppScope/app.json5 b/ArkUIKit/CoastingAxisEventNDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a4df3eacd42f1b97583907421f857705f328655 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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.coastingaxiseventndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/element/string.json b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dfa5ba62951f8a8813f60edbaf595f5986a46947 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CoastingAxisEventNDK" + } + ] +} diff --git a/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/background.png b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/foreground.png b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/layered_image.json b/ArkUIKit/CoastingAxisEventNDK/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/README.md b/ArkUIKit/CoastingAxisEventNDK/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4f67f5ccaa89e39a5d87a6b686def7a3c56b4917 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/README.md @@ -0,0 +1,68 @@ +# CoastingAxisEventNDK + +## 介绍 + +本示例通过使用[ArkUI指南文档](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/reference)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接: + +1. [输入事件开发指导](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/capi-ui-input-event-h.md)。 + +本示例展示了如何注册监听和使用惯性滚动轴事件接口。通过惯性轴事件相关接口,在双指抛滑离开触控板时,让滚动类容器继续惯性滚动。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + +## 使用说明 +1. 安装编译生成的hap包,并打开应用; +2. 双指在触摸板上抛滑; + + +## 工程目录 + +``` +CoastingAxisEventNDK +entry/src/main/ets/ +└── pages + ├── common + │ └── icon.svg + └── Index.ets (应用主页面) +entry/src/main/ +├── cpp +│ ├── types +│ │ └── libentry +│ │ └── Index.d.ts (NDK函数对应的js映射) +│ ├── CMakeLists.txt (CMake脚本) +| ├── manager.cpp (创建文本实现CPP文件) +| ├── manager.h +│ └── napi_init.cpp (NDK函数) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API22版本SDK,版本号:6.0.2.53; + +3. 本示例已支持使DevEco Studio 5.0.5 Release (构建版本:5.0.13.220,构建 2025年7月22日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/CoastingAxisEventNDK > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/build-profile.json5 b/ArkUIKit/CoastingAxisEventNDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d0201328a158e954273d3b660d2df8c8d41006ea --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "compileSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/code-linter.json5 b/ArkUIKit/CoastingAxisEventNDK/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/code-linter.json5 @@ -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. + */ + +{ + "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/CoastingAxisEventNDK/entry/.gitignore b/ArkUIKit/CoastingAxisEventNDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/build-profile.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b6d841509d3d85babd136cde8d09281bbe392c71 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * 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/CoastingAxisEventNDK/entry/hvigorfile.ts b/ArkUIKit/CoastingAxisEventNDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/hvigorfile.ts @@ -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. + */ + +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/CoastingAxisEventNDK/entry/obfuscation-rules.txt b/ArkUIKit/CoastingAxisEventNDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/oh-package.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d993e5251fd56950970aa593aefef1b8d71e976 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/oh-package.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. + */ + +{ + "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/CoastingAxisEventNDK/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..86eda15caf5a47036e66bc4a3f1a0aa7c1b86b13 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CoastingAxisEventNDK) + +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) +target_link_libraries(entry PUBLIC libace_napi.z.so libace_ndk.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.cpp b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a58c5a1bcc6708953288a9cb47bdfc15593f529 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.cpp @@ -0,0 +1,219 @@ +/* + * 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 +#include + +#include "manager.h" + +namespace NativeXComponentSample { +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +static ArkUI_NativeNodeAPI_1* nativeModule_ = nullptr; +double g_px2vp = 0; + +const std::vector staticContacts = { + { "A", { Contact("Alice"), Contact("Alan"), Contact("Amy"), Contact("Andy"), Contact("Anna") } }, + { "B", + { Contact("Bob"), Contact("Betty"), Contact("Bruce"), Contact("Bella"), Contact("Brian"), Contact("Blake") } }, + { "C", { Contact("Charlie"), Contact("Cindy"), Contact("Chris"), Contact("Clara"), Contact("Carter") } }, + { "D", { Contact("David"), Contact("Diana"), Contact("Dan"), Contact("Daisy"), Contact("Duke"), Contact("Dora") } }, + { "E", { Contact("Emma"), Contact("Eric"), Contact("Eva"), Contact("Ethan"), Contact("Elise") } }, + { "F", + { Contact("Frank"), Contact("Fiona"), Contact("Felix"), Contact("Faith"), Contact("Flora"), Contact("Fred") } }, + { "G", { Contact("George"), Contact("Grace"), Contact("Gary"), Contact("Gina"), Contact("Gavin") } }, + { "H", + { Contact("Helen"), Contact("Henry"), Contact("Hank"), Contact("Hazel"), Contact("Hugo"), Contact("Holly") } }, + { "I", { Contact("Ivy"), Contact("Ian"), Contact("Iris"), Contact("Ivan"), Contact("Isla") } }, + { "J", { Contact("John"), Contact("Jane"), Contact("Jack"), Contact("Jill"), Contact("James"), Contact("Julia") } }, + { "K", { Contact("Kevin"), Contact("Kate"), Contact("Kyle"), Contact("Karen"), Contact("Karl") } }, + { "L", { Contact("Lucy"), Contact("Leo"), Contact("Lily"), Contact("Luke"), Contact("Liam"), Contact("Luna") } }, + { "M", { Contact("Mike"), Contact("Mary"), Contact("Mark"), Contact("Mia"), Contact("Max") } }, + { "N", { Contact("Nancy"), Contact("Nick"), Contact("Nora"), Contact("Noah"), Contact("Nina"), Contact("Nate") } }, + { "O", { Contact("Olivia"), Contact("Oscar"), Contact("Olive"), Contact("Owen"), Contact("Opal") } }, + { "P", { Contact("Peter"), Contact("Paula"), Contact("Paul"), Contact("Pam"), Contact("Phil"), Contact("Piper") } }, + { "Q", { Contact("Quinn"), Contact("Quentin"), Contact("Queen"), Contact("Quincy"), Contact("Quella") } }, + { "R", { Contact("Robert"), Contact("Rose"), Contact("Ryan"), Contact("Ruth"), Contact("Roy"), Contact("Rex") } }, + { "S", { Contact("Sarah"), Contact("Sam"), Contact("Steve"), Contact("Sue"), Contact("Sean") } }, + { "T", { Contact("Tom"), Contact("Tina"), Contact("Tim"), Contact("Tara"), Contact("Ted"), Contact("Troy") } }, + { "U", { Contact("Uma"), Contact("Ulysses"), Contact("Uriah"), Contact("Ulric"), Contact("Ula") } }, + { "V", + { Contact("Victor"), Contact("Vera"), Contact("Vince"), Contact("Violet"), Contact("Van"), Contact("Vicky") } }, + { "W", { Contact("William"), Contact("Wendy"), Contact("Wayne"), Contact("Willa"), Contact("Wade") } }, + { "X", { Contact("Xander"), Contact("Xena"), Contact("Xavier"), Contact("Xia"), Contact("Xerxes") } }, + { "Y", + { Contact("Yvonne"), Contact("Yves"), Contact("Yael"), Contact("Yuri"), Contact("Yolanda"), Contact("Yan") } }, + { "Z", { Contact("Zoe"), Contact("Zack"), Contact("Zara"), Contact("Zane"), Contact("Zelda") } } +}; + +NodeManager& NodeManager::GetInstance() +{ + static NodeManager instance; + return instance; +} + +void NodeManager::SetXComponent(OH_NativeXComponent* xComponent) +{ + xComponent_ = xComponent; +} + +void NodeManager::CreateNativeNode(double px2vp) +{ + if (!xComponent_ || px2vp == 0) { + return; + } + g_px2vp = px2vp; + nativeModule_ = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + if (nativeModule_ == nullptr) { + return; + } + // 创建一个Column容器组件 + ArkUI_NodeHandle column = nativeModule_->createNode(ARKUI_NODE_COLUMN); + // 创建List + ArkUI_NodeHandle listNode = CreateList(); + nativeModule_->addChild(column, listNode); + // 为List注册惯性轴事件监听 + RegisterCoastingAxisEvent(listNode); + OH_NativeXComponent_AttachNativeRootNode(xComponent_, column); +} + +ArkUI_NodeHandle NodeManager::CreateList() +{ + ArkUI_NodeHandle listNode = nativeModule_->createNode(ARKUI_NODE_LIST); + ArkUI_NumberValue value[] = { { .i32 = ARKUI_STICKY_STYLE_HEADER } }; + ArkUI_AttributeItem item = { value, 1 }; + nativeModule_->setAttribute(listNode, NODE_LIST_STICKY, &item); + for (const auto& group : staticContacts) { + auto groupNode = nativeModule_->createNode(ARKUI_NODE_LIST_ITEM_GROUP); + ArkUI_AttributeItem Item = { .object = CreateHeader(group.title) }; + nativeModule_->setAttribute(groupNode, NODE_LIST_ITEM_GROUP_SET_HEADER, &Item); + for (const auto& contact : group.contacts) { + auto listItem = CreateListItem(contact); + nativeModule_->addChild(groupNode, listItem); + } + nativeModule_->addChild(listNode, groupNode); + } + + return listNode; +} + +ArkUI_NodeHandle NodeManager::CreateListItem(const Contact& contact) +{ + auto listItem = nativeModule_->createNode(ARKUI_NODE_LIST_ITEM); + auto row = nativeModule_->createNode(ARKUI_NODE_ROW); + auto image = CreateListImage(contact.icon); + auto text = CreateListText(contact.name); + + ArkUI_NumberValue paddingValue[] = { { .f32 = 12 } }; + ArkUI_AttributeItem padding = { paddingValue, 1 }; + nativeModule_->setAttribute(row, NODE_PADDING, &padding); + + ArkUI_NumberValue alignValue[] = { { .i32 = ARKUI_VERTICAL_ALIGNMENT_CENTER } }; + ArkUI_AttributeItem align = { alignValue, 1 }; + nativeModule_->setAttribute(row, NODE_ROW_ALIGN_ITEMS, &align); + nativeModule_->addChild(row, image); + nativeModule_->addChild(row, text); + nativeModule_->addChild(listItem, row); + + return listItem; +} + +ArkUI_NodeHandle NodeManager::CreateListImage(std::string icon) +{ + auto image = nativeModule_->createNode(ARKUI_NODE_IMAGE); + ArkUI_AttributeItem item = { .string = icon.c_str() }; + nativeModule_->setAttribute(image, NODE_IMAGE_SRC, &item); + ArkUI_NumberValue value[] = { { .f32 = 40 } }; + ArkUI_AttributeItem height = { value, 1 }; + ArkUI_AttributeItem width = { value, 1 }; + nativeModule_->setAttribute(image, NODE_HEIGHT, &height); + nativeModule_->setAttribute(image, NODE_WIDTH, &width); + ArkUI_NumberValue radiusValue[] = { { .f32 = 20 } }; + ArkUI_AttributeItem radius = { radiusValue, 1 }; + nativeModule_->setAttribute(image, NODE_BORDER_RADIUS, &radius); + ArkUI_NumberValue marginValue[] = { { .f32 = 0 }, { .f32 = 17 }, { .f32 = 0 }, { .f32 = 0 } }; + ArkUI_AttributeItem margin = { marginValue, 4 }; + nativeModule_->setAttribute(image, NODE_MARGIN, &margin); + return image; +} + +ArkUI_NodeHandle NodeManager::CreateListText(std::string text) +{ + auto textNode = nativeModule_->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem str = { nullptr, 0, text.c_str() }; + nativeModule_->setAttribute(textNode, NODE_TEXT_CONTENT, &str); + ArkUI_NumberValue fontSizeValue[] = { { .f32 = 18 } }; + ArkUI_AttributeItem fontSize = { fontSizeValue, 1 }; + nativeModule_->setAttribute(textNode, NODE_FONT_SIZE, &fontSize); + return textNode; +} + +ArkUI_NodeHandle NodeManager::CreateHeader(const std::string& text) +{ + auto textNode = nativeModule_->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem str = { nullptr, 0, text.c_str() }; + nativeModule_->setAttribute(textNode, NODE_TEXT_CONTENT, &str); + + ArkUI_NumberValue fontSizeValue[] = { { .f32 = 20 } }; + ArkUI_AttributeItem fontSize = { fontSizeValue, 1 }; + nativeModule_->setAttribute(textNode, NODE_FONT_SIZE, &fontSize); + + ArkUI_NumberValue widthValue[] = { { .f32 = 100 } }; + ArkUI_AttributeItem width = { widthValue, 1 }; + nativeModule_->setAttribute(textNode, NODE_WIDTH_PERCENT, &width); + + ArkUI_NumberValue colorValue[] = { { .u32 = 0xfff1f3f5 } }; + ArkUI_AttributeItem color = { colorValue, 1 }; + nativeModule_->setAttribute(textNode, NODE_BACKGROUND_COLOR, &color); + + ArkUI_NumberValue paddingValue[] = { { .f32 = 5 } }; + ArkUI_AttributeItem padding = { paddingValue, 1 }; + nativeModule_->setAttribute(textNode, NODE_PADDING, &padding); + return textNode; +} + +void NodeManager::RegisterCoastingAxisEvent(ArkUI_NodeHandle node) +{ + nativeModule_->registerNodeEvent(node, NODE_ON_COASTING_AXIS_EVENT, 0, nullptr); + nativeModule_->registerNodeEvent(node, NODE_ON_AXIS, 0, nullptr); + nativeModule_->addNodeEventReceiver(node, [](ArkUI_NodeEvent* event) { + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + switch (eventType) { + case NODE_ON_COASTING_AXIS_EVENT: { + auto uiInputEvent = OH_ArkUI_NodeEvent_GetInputEvent(event); + auto handler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + auto coastingAxisEvent = OH_ArkUI_UIInputEvent_GetCoastingAxisEvent(uiInputEvent); + auto time = OH_ArkUI_CoastingAxisEvent_GetEventTime(coastingAxisEvent); + auto phase = OH_ArkUI_CoastingAxisEvent_GetPhase(coastingAxisEvent); + auto deltaX = OH_ArkUI_CoastingAxisEvent_GetDeltaX(coastingAxisEvent); + auto deltaY = OH_ArkUI_CoastingAxisEvent_GetDeltaY(coastingAxisEvent); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "NODE_ON_COASTING_AXIS_EVENT", + "phase=%{public}d, deltaX=%{public}f, deltaY=%{public}f, " + "time=%{public}ld", + phase, deltaX, deltaY, time); + ArkUI_NumberValue scrollOffset[] = { { .f32 = static_cast(deltaX * g_px2vp) }, + { .f32 = static_cast(deltaY * g_px2vp) } }; + ArkUI_AttributeItem scrollOffsetItem = { scrollOffset, + sizeof(scrollOffset) / sizeof(ArkUI_NumberValue) }; + nativeModule_->setAttribute(handler, NODE_SCROLL_BY, &scrollOffsetItem); + break; + } + default: { + break; + } + } + }); +} +} // namespace NativeXComponentSample diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.h b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.h new file mode 100644 index 0000000000000000000000000000000000000000..ccf13c9aaa4b4984d302bb5be783189dcc110a53 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/manager.h @@ -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. + */ + +#ifndef COASTING_AXIS_EVENT_MANAGER_H +#define COASTING_AXIS_EVENT_MANAGER_H + +#include +#include +#include + +namespace NativeXComponentSample { +struct Contact { + explicit Contact(std::string name) : name(name){}; + std::string name = ""; + std::string icon = "/pages/common/icon.svg"; +}; + +struct ContactsGroup { + std::string title = ""; + std::vector contacts = {}; +}; + +class NodeManager { +public: + ~NodeManager() = default; + static NodeManager &GetInstance(); + void SetXComponent(OH_NativeXComponent *xComponent); + void CreateNativeNode(double density); + +private: + NodeManager() = default; + ArkUI_NodeHandle CreateList(); + ArkUI_NodeHandle CreateListItem(const Contact &contact); + ArkUI_NodeHandle CreateHeader(const std::string &text); + ArkUI_NodeHandle CreateListText(std::string text); + ArkUI_NodeHandle CreateListImage(std::string icon); + void RegisterCoastingAxisEvent(ArkUI_NodeHandle node); + OH_NativeXComponent *xComponent_; +}; +} // namespace NativeXComponentSample + +#endif // COASTING_AXIS_EVENT_MANAGER_H diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e966ca45a2771cb85528824e788f6e6a50fa7b40 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,80 @@ +/* + * 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 + +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 argv[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[0], &valueType); + if (valueType != napi_number) { + return nullptr; + } + double px2vp; + napi_get_value_double(env, argv[0], &px2vp); + NativeXComponentSample::NodeManager::GetInstance().CreateNativeNode(px2vp); + return nullptr; +} + +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 } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + auto xComponent = GetXComponent(env, exports); + if (xComponent) { + NativeXComponentSample::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/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a7a9b11e7271de2a9361933a08f51189b8872757 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,16 @@ +/* + * 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: (px2vp: number) => void; \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..846e4c7e13ead48abe6019bd40f3a13bf8f9c083 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -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. + */ + +{ + "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/CoastingAxisEventNDK/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..03de9ddeb4315b230a1965f1c50fd9f5e2024ef5 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,59 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/main/ets/pages/Index.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..008c4b8d578de923fbac5bba3938413093d3d445 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/pages/Index.ets @@ -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. + */ + +import nativeNode from 'libentry.so'; + +@Entry +@Component +struct Index { + build() { + Row() { + Column() { + XComponent({ + id: "coastingAxisEvent", + type: XComponentType.NODE, + libraryname: "entry" + }).onAppear(()=> { + nativeNode.createNativeNode(this.getUIContext().px2vp(1)) + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/pages/common/icon.svg b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/pages/common/icon.svg new file mode 100644 index 0000000000000000000000000000000000000000..6329960c7aa012ff007c80af8d6e9b694ba85fd0 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/ets/pages/common/icon.svg @@ -0,0 +1,54 @@ + + + + + error + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/module.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..776ce01475229d674487a2830790c4c87b777379 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/main/resources/base/element/color.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/src/main/resources/base/element/float.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/element/string.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/src/main/resources/base/media/background.png b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/dark/element/color.json b/ArkUIKit/CoastingAxisEventNDK/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/entry/src/mock/Libentry.mock.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..eebf1ed910f6a8f2a9e7e565aa71b179b7b8b537 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,22 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/mock/mock-config.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7d2ba82b796a2850ced0a277d261d7d7355416 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/mock/mock-config.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. + */ + +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c16bc08c6fb53175fcdc9d628a4d6a9b34bef4c --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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'; +import IndexTest from './index.test'; + +export default function testsuite() { + abilityTest(); + IndexTest(); +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/index.test.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9bc0b9cf0c5de77a0464d48950c8e76316d8535 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/ets/test/index.test.ets @@ -0,0 +1,60 @@ +/* + * 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, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON, MatchPattern } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function IndexTest() { + + describe('IndexTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + let driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * @tc.number UiTest_001 + * @tc.name testCoastingAxisEvent + * @tc.desc 测试惯性滚动轴事件基本用法 + */ + it('testCoastingAxisEvent', 0, async (done: Function) => { + console.info('uitest: testCoastingAxisEvent begin'); + let driver = Driver.create(); + let user = await driver.findComponent(ON.text('Alice', MatchPattern.CONTAINS)); + expect(user === null).assertFalse(); + await driver.fling({x: 500, y: 500}, {x: 200, y: 200}, 20, 4000); + user = await driver.findComponent(ON.text('Alice', MatchPattern.CONTAINS)); + expect(user === null).assertTrue(); + await driver.delayMs(1000); + console.info('uitest: testTapGesture end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/module.json5 b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9983b2ba4e55e31a172f0328c82c9a75bfa00ded --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * 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/CoastingAxisEventNDK/entry/src/test/List.test.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/test/List.test.ets @@ -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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/entry/src/test/LocalUnit.test.ets b/ArkUIKit/CoastingAxisEventNDK/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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/CoastingAxisEventNDK/hvigor/hvigor-config.json5 b/ArkUIKit/CoastingAxisEventNDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70879912169503ff02665211233887556b8f4ae8 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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/CoastingAxisEventNDK/hvigorfile.ts b/ArkUIKit/CoastingAxisEventNDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/hvigorfile.ts @@ -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. + */ + +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/CoastingAxisEventNDK/oh-package.json5 b/ArkUIKit/CoastingAxisEventNDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bb713889dcf243763a520796f6a8bd779efa08b6 --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/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. + */ + +{ + "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/CoastingAxisEventNDK/ohosTest.md b/ArkUIKit/CoastingAxisEventNDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c560f98c8f647f0442319f996ea16f600e92445b --- /dev/null +++ b/ArkUIKit/CoastingAxisEventNDK/ohosTest.md @@ -0,0 +1,7 @@ +# NdkGestureSetting 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | -------------- |---------------------------------------|----------| :------- | -------- | +| 测试惯性滚动轴事件基本用法 | 在有触控板的设备上正常运行 | 鼠标放到应用上,双指在触控板上快速抛滑 | 应用列表可以在双指离开触控板后有惯性滚动效果 | 是 | Pass | \ No newline at end of file diff --git a/ArkUIKit/CoastingAxisEventNDK/screenshots/coasting_axis_event.png b/ArkUIKit/CoastingAxisEventNDK/screenshots/coasting_axis_event.png new file mode 100644 index 0000000000000000000000000000000000000000..99db5ad3279be55b6de886e56d5a16d819b0499e Binary files /dev/null and b/ArkUIKit/CoastingAxisEventNDK/screenshots/coasting_axis_event.png differ