diff --git a/function/ui_compare/capidemo/.gitignore b/function/ui_compare/capidemo/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..4a8074e50a1d6d61d58e3962faf9b1f27fb27a3f --- /dev/null +++ b/function/ui_compare/capidemo/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +build-profile.json5 \ No newline at end of file diff --git a/function/ui_compare/capidemo/AppScope/app.json5 b/function/ui_compare/capidemo/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5f0deb75205610a7000e46414d1557fa40810ec2 --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.openharmony.arkui_capi_demo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/element/string.json b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..fb020ee114b8acb97b8dd12741b8a36ef4d5a26d --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ArkUI_CAPI_Demo" + } + ] +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png differ diff --git a/function/ui_compare/capidemo/README.md b/function/ui_compare/capidemo/README.md new file mode 100755 index 0000000000000000000000000000000000000000..80a5141f789450de473ca5924a703b02c8652799 --- /dev/null +++ b/function/ui_compare/capidemo/README.md @@ -0,0 +1,3 @@ +# capidemo + +c api demo project \ No newline at end of file diff --git a/function/ui_compare/capidemo/build-profile.json5 b/function/ui_compare/capidemo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..25255c09b22c8ee5c92dd996d086837b3ccb6982 --- /dev/null +++ b/function/ui_compare/capidemo/build-profile.json5 @@ -0,0 +1,29 @@ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/code-linter.json5 b/function/ui_compare/capidemo/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..95fce531ca2df66e9e28ad1fb183730472234fc7 --- /dev/null +++ b/function/ui_compare/capidemo/code-linter.json5 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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": { + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/.gitignore b/function/ui_compare/capidemo/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..32abf8fd5e44623ebe60bf2adeee4a366372cc85 --- /dev/null +++ b/function/ui_compare/capidemo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/build-profile.json5 b/function/ui_compare/capidemo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b4ebac31a62c3558f1b1e4558eea73ed0ad99cf --- /dev/null +++ b/function/ui_compare/capidemo/entry/build-profile.json5 @@ -0,0 +1,20 @@ +{ + "apiType": 'stageMode', + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "armeabi-v7a", "x86_64"], + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/hvigorfile.ts b/function/ui_compare/capidemo/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..c57c77181d0d36beb49c897ff3fc1ad92f7eaa7c --- /dev/null +++ b/function/ui_compare/capidemo/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/function/ui_compare/capidemo/entry/oh-package.json5 b/function/ui_compare/capidemo/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..7d6ab2164afcb6febf05fd7f955b67cc3a807a3e --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "", + "devDependencies": { + "@types/libnativerender.so": "file:./src/main/cpp/types/libnativerender" + }, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..a09128ba4acf72041c16c0a4354389a5bcd533cb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,99 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(XComponent) + +# Automatically refresh source files +file(GLOB_RECURSE ALL_CPP_FILES ${PROJECT_SOURCE_DIR}/*.cpp) +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +add_definitions(-DOHOS_PLATFORM) + + +function(getAllCpp path parentDir exclude) + set(LOCAL_LIST) + file(GLOB ALL_DIR RELATIVE ${parentDir} ${parentDir}/*) + foreach(ITEM ${ALL_DIR}) + set(ITEM_DIR ${parentDir}/${ITEM}) + set(FIND_BOOL FALSE) + foreach(dir ${exclude}) + if("${dir}" STREQUAL "${ITEM}") + set(FIND_BOOL TRUE) + break() + endif() + endforeach() + if ("${FIND_BOOL}" STREQUAL "FALSE") + if(EXISTS ${ITEM_DIR}) + file(GLOB ALL_FILE ${ITEM_DIR}/*.cpp) + list(APPEND LOCAL_LIST ${ALL_FILE}) + endif() + endif () + endforeach() + set(path ${LOCAL_LIST} PARENT_SCOPE) +endfunction() + +set(path) +set(exclude "types") +set(CMAKE_CXX_STANDARD 17) +getAllCpp("${path}" ${PROJECT_SOURCE_DIR} "${exclude}") + +add_library(nativerender SHARED + napi_init.cpp + ${path} +) +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +find_library( + # Sets the name of the path variable. + libace-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_ndk.z +) + +find_library( + # Sets the name of the path variable. + libnapi-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_napi.z +) + +find_library( + # Sets the name of the path variable. + libuv-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + uv +) + +find_library( + # Sets the name of the path variable. + EGL-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + EGL +) + +find_library( + # Sets the name of the path variable. + GLES-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + GLESv3 +) + +target_include_directories(nativerender PUBLIC + ${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include + PUBLIC component +) + +target_link_libraries(nativerender PUBLIC + libnative_drawing.so ${EGL-lib} ${GLES-lib} ${hilog-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib}) +target_link_libraries(nativerender PUBLIC libhilog_ndk.z.so libpixelmap.so libudmf.so) + diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h new file mode 100755 index 0000000000000000000000000000000000000000..de2a5e8cf1eaf39cd4fe9a9d2385f377433719be --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMON_TEST_H +#define ARKUI_CAPI_DEMO_COMMON_TEST_H + +#include +#include + +namespace ArkUICApiDemo { + +#define PARAM_0 0 +#define PARAM_1 1 +#define PARAM_2 2 +#define PARAM_3 3 +#define PARAM_4 4 +#define PARAM_5 5 +#define PARAM_6 6 +#define PARAM_7 7 +#define PARAM_8 8 +#define PARAM_9 9 +#define PARAM_10 10 +#define PARAM_11 11 +#define PARAM_12 12 +#define PARAM_64 64 +#define DEFAULT_MARGIN 10 +#define SIZE_10 10 +#define SIZE_30 30 +#define SIZE_50 50 +#define SIZE_100 100 +#define SIZE_150 150 +#define SIZE_180 180 +#define SIZE_200 200 +#define SIZE_250 250 +#define SIZE_300 300 +#define SIZE_350 350 +#define SIZE_400 400 +#define SIZE_500 500 +#define SIZE_600 600 +#define SIZE_800 800 +#define SIZE_1000 1000 +#define SIZE_2000 2000 +#define SIZE_3000 3000 +#define DEFAULT_VALUE_TAG 7000 +#define ENUM_ABNORMAL_VALUE 500 +#define INVALID_PARAM 401 +#define COLOR_RED 0xFFFF0000 +#define COLOR_GREEN 0xFF00FF00 +#define COLOR_BLUE 0xFF0000FF +#define COLOR_YELLOW 0xFFFFFF00 +#define COLOR_PURPLE 0xFFFF11FF +#define COLOR_PINK 0xFFFFC0CB +#define COLOR_GRAY 0xFFDDDDDD +#define COLOR_TRANSPARENT 0x00000000 +#define COLOR_BLACK 0xFF000000 +#define COLOR_WHITE 0xFFFFFFFF +#define COLOR_LIGHT_BLUE 0xFF00FFFF +#define ON_CLICK_EVENT_ID 6001 +#define ON_FOCUS_EVENT_ID 6002 +#define ON_TOUCH_EVENT_ID 6003 +#define ON_AREA_CHANGE_EVENT_ID 6004 +#define ON_APPEAR_EVENT_ID 6005 +#define ON_BLUR_EVENT_ID 6006 +#define ON_CHANGE_EVENT_ID 6007 +#define ON_SUBMIT_EVENT_ID 6008 +#define ON_CUT_EVENT_ID 6009 +#define ON_PASTE_EVENT_ID 6010 +#define ON_MEASURE_EVENT_ID 6011 +#define ON_LAYOUT_EVENT_ID 6012 +#define ON_DRAW_EVENT_ID 6013 +#define ON_CUSTOM_EVENT_1_ID 9001 +#define ON_CUSTOM_EVENT_2_ID 9002 +#define ON_CUSTOM_EVENT_3_ID 9003 +#define ON_CUSTOM_EVENT_4_ID 9004 +#define ON_CUSTOM_EVENT_5_ID 9005 +#define ON_CUSTOM_EVENT_6_ID 9006 +#define PARAM_NEGATIVE_1 (-1) +#define PARAM_NEGATIVE_100 (-100) +#define PARAM_NEGATIVE_5 (-5) +#define PARAM_NEGATIVE_5 (-5) +/** + * Log print domain. + */ +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMON_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6fd8c36a04d4828db0d71f0bc954b57ed67de04d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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 "button_component.h" + +namespace ArkUICApiDemo { + +void ButtonComponent::SetLable(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BUTTON_LABEL, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h new file mode 100755 index 0000000000000000000000000000000000000000..a0fafb7c813a7d61a0a8e79984bb0ed39397a34e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H +#define ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ButtonComponent : public Component { +public: + ButtonComponent() : Component(ARKUI_NODE_BUTTON) {} + explicit ButtonComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetLable(const std::string& content); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h new file mode 100755 index 0000000000000000000000000000000000000000..56c93a34b2a7f605b3db0a9b1e6cb9be5092374c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H +#define ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ColumnComponent : public Component { +public: + ColumnComponent() : Component(ARKUI_NODE_COLUMN) {} + explicit ColumnComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f8aa4404841d08c18e1f15d9fdb2bb6cc6dd694f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2024 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 "component.h" + +#include +#include + +namespace ArkUICApiDemo { + +Component::Component(ArkUI_NodeType type) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = _nodeAPI->createNode(type); + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); +} + +Component::Component(ArkUI_NodeHandle handle) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = handle; + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); + + int32_t count = _nodeAPI->getTotalChildCount(_component); + for (int32_t i = 0; i < count; i++) { + auto temp = _nodeAPI->getChildAt(_component, i); + children_.emplace_back(std::make_shared(temp)); + } +} + +int32_t Component::setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item) +{ + return _nodeAPI->setAttribute(_component, attribute, item); +} + +const ArkUI_AttributeItem* Component::getAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->getAttribute(_component, attribute); +} + +int32_t Component::resetAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->resetAttribute(_component, attribute); +} + +void Component::SetWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH, &item); +} +void Component::SetPercentWidth(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH_PERCENT, &item); +} +void Component::SetHeight(float height) +{ + ArkUI_NumberValue value[] = { { .f32 = height } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT, &item); +} +void Component::SetPercentHeight(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT_PERCENT, &item); +} +void Component::SetBackgroundColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_COLOR, &item); +} +void Component::SetBackgroundImage(const std::string& backgroundImage) +{ + ArkUI_AttributeItem item = { nullptr, 0, backgroundImage.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE, &item); +} +void Component::SetBackgroundImageSizeWithStyle(int32_t imageSize) +{ + ArkUI_NumberValue value[] = { { .i32 = imageSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE_SIZE_WITH_STYLE, &item); +} +void Component::SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) +{ + ArkUI_NumberValue value[] = { { .f32 = topLeft }, { .f32 = topRight }, { .f32 = bottomLeft }, + { .f32 = bottomRight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_RADIUS, &item); +} + +void Component::SetPadding(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING, &item); +} + +void Component::SetPaddingPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING_PERCENT, &item); +} + +void Component::SetMargin(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} +void Component::SetMargin(float margin) +{ + ArkUI_NumberValue value[] = { { .f32 = margin }, { .f32 = margin }, { .f32 = margin }, { .f32 = margin } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} + +void Component::SetMarginPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN_PERCENT, &item); +} + +void Component::SetEnabled(int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ENABLED, &item); +} + +void Component::SetAlign(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGNMENT, &item); +} + +void Component::SetAlignRules(ArkUI_AlignmentRuleOption* option) +{ + ArkUI_AttributeItem item = { .object = option }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_RULES, &item); +} + +void Component::SetAlignSelf(int32_t value) +{ + ArkUI_NumberValue val[] = { { .i32 = value } }; + ArkUI_AttributeItem item = { val, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_SELF, &item); +} + +void Component::SetOpacity(float opacity) +{ + ArkUI_NumberValue value[] = { { .f32 = opacity } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_OPACITY, &item); +} + +void Component::SetBorderWidth(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderWidth(float borderWidth) +{ + ArkUI_NumberValue value[] = { { .f32 = borderWidth }, { .f32 = borderWidth }, { .f32 = borderWidth }, + { .f32 = borderWidth } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left) +{ + ArkUI_NumberValue value[] = { { .u32 = top }, { .u32 = right }, { .u32 = bottom }, { .u32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_COLOR, &item); +} + +void Component::SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left) +{ + ArkUI_NumberValue value[] = { { .i32 = top }, { .i32 = right }, { .i32 = bottom }, { .i32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_STYLE, &item); +} + +void Component::SetVisibility(int32_t visibility) +{ + ArkUI_NumberValue value[] = { { .i32 = visibility } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_VISIBILITY, &item); +} +void Component::SetId(const std::string& id) +{ + ArkUI_AttributeItem item = { nullptr, 0, id.c_str() }; + _nodeAPI->setAttribute(_component, NODE_ID, &item); +} +void Component::AddChild(const std::shared_ptr& child) +{ + children_.emplace_back(child); + OnAddChild(child); +} + +void Component::RemoveChild(const std::shared_ptr& child) +{ + children_.remove(child); + OnRemoveChild(child); +} + +void Component::RemoveAll() +{ + children_.clear(); + OnRemoveAll(); +} + +void Component::InsertChild(const std::shared_ptr& child, int32_t index) +{ + if (index >= children_.size()) { + AddChild(child); + } else { + auto iter = children_.begin(); + std::advance(iter, index); + children_.insert(iter, child); + OnInsertChild(child, index); + } +} + +std::shared_ptr Component::GetPreviousSibling() +{ + auto previousSibling = _nodeAPI->getPreviousSibling(_component); + return std::make_shared(previousSibling); +}; + +std::shared_ptr Component::GetNextSibling() +{ + auto nextSibling = _nodeAPI->getNextSibling(_component); + return std::make_shared(nextSibling); +}; + +void Component::NodeEventReceiver(ArkUI_NodeEvent* event) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // 获取事件发生的UI组件对象。 + auto nodeHandle = OH_ArkUI_NodeEvent_GetNodeHandle(event); + // 获取保持在UI组件对象中的自定义数据,返回封装类指针。 + auto* node = reinterpret_cast(nodeAPI->getUserData(nodeHandle)); + // 基于封装类实例对象处理事件。 + if (node) { + node->ProcessNodeEvent(event); + } +} +void Component::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void Component::ProcessNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "ProcessNodeEvent eventType=%{public}d", eventType); + switch (eventType) { + case NODE_ON_CLICK: { + if (onClick_) { + onClick_(); + } + break; + } + case NODE_TOUCH_EVENT: { + if (onTouch_) { + onTouch_(event); + } + break; + } + case NODE_EVENT_ON_DISAPPEAR: { + if (onDisappear_) { + onDisappear_(); + } + break; + } + case NODE_EVENT_ON_APPEAR: { + if (onAppear_) { + onAppear_(); + } + break; + } + case NODE_ON_HOVER: { + if (onHover_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_ON_HOVER"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + int32_t isHover = result->data[0].i32; + onHover_(static_cast(isHover)); + } + break; + } + case NODE_EVENT_ON_VISIBLE_AREA_CHANGE: { + if (onVisibleAreaChange_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_EVENT_ON_VISIBLE_AREA_CHANGE"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + bool visible = static_cast(result->data[0].i32); + float ratio = result->data[1].f32; + onVisibleAreaChange_(visible, ratio); + } + break; + } + case NODE_ON_MOUSE: { + if (onMouse_) { + onMouse_(event); + } + break; + } + case NODE_ON_TOUCH_INTERCEPT: { + if (onTouchIntercept_) { + onTouchIntercept_(event); + } + break; + } + case NODE_ON_FOCUS: { + if (onFocus_) { + onFocus_(); + } + break; + } + default: { + OnNodeEvent(event); + } + } +} + +void Component::RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray) +{ + ArkUI_NumberValue value[ratioArray.size()]; + + for (size_t i = 0; i < ratioArray.size(); i++) { + value[i].f32 = { ratioArray[i] }; + } + ArkUI_AttributeItem item = { value, static_cast(ratioArray.size()) }; + + onVisibleAreaChange_ = onVisibleAreaChange; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_VISIBLE_AREA_CHANGE, 0, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h new file mode 100755 index 0000000000000000000000000000000000000000..6ed0ab226f3d988f671acc6e649a7980e251a044 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMPONENT_H +#define ARKUI_CAPI_DEMO_COMPONENT_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class Component { +public: + explicit Component(ArkUI_NodeType type); + explicit Component(ArkUI_NodeHandle handle); + virtual ~Component() = default; + + int32_t setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item); + const ArkUI_AttributeItem* getAttribute(ArkUI_NodeAttributeType attribute); + int32_t resetAttribute(ArkUI_NodeAttributeType attribute); + + void SetWidth(float width); + void SetPercentWidth(float percent); + void SetHeight(float height); + void SetPercentHeight(float percent); + void SetBackgroundColor(uint32_t color); + void SetBackgroundImage(const std::string& backgroundImage); + void SetBackgroundImageSizeWithStyle(int32_t imageSize); + void SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight); + void SetPadding(float top, float right, float bottom, float left); + void SetPaddingPercent(float top, float right, float bottom, float left); + void SetMargin(float top, float right, float bottom, float left); + void SetMargin(float margin); + void SetMarginPercent(float top, float right, float bottom, float left); + void SetEnabled(int32_t enable); + void SetAlign(int32_t align); + void SetAlignRules(ArkUI_AlignmentRuleOption* option); + void SetAlignSelf(int32_t value); + void SetOpacity(float opacity); + void SetBorderWidth(float top, float right, float bottom, float left); + void SetBorderWidth(float borderWidth); + void SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left); + void SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left); + void SetVisibility(int32_t visibility); + virtual void SetFontSize(float fontSize); + void SetId(const std::string& id); + void AddChild(const std::shared_ptr& child); + void RemoveChild(const std::shared_ptr& child); + void RemoveAll(); + void InsertChild(const std::shared_ptr& child, int32_t index); + std::list> GetChildren() + { + return children_; + } + std::shared_ptr GetPreviousSibling(); + std::shared_ptr GetNextSibling(); + + ArkUI_NodeHandle GetComponent() + { + return _component; + } + // 处理通用事件。 + void RegisterOnClick(const std::function& onClick) + { + onClick_ = onClick; + _nodeAPI->registerNodeEvent(_component, NODE_ON_CLICK, 0, nullptr); + } + + void RegisterOnTouch(const std::function& onTouch) + { + onTouch_ = onTouch; + _nodeAPI->registerNodeEvent(_component, NODE_TOUCH_EVENT, 0, nullptr); + } + + void RegisterOnDisappear(const std::function& onDisappear) + { + onDisappear_ = onDisappear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_DISAPPEAR, 0, nullptr); + } + + void RegisterOnAppear(const std::function& onAppear) + { + onAppear_ = onAppear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_APPEAR, 0, nullptr); + } + void RegisterOnHover(const std::function& onHover) + { + onHover_ = onHover; + _nodeAPI->registerNodeEvent(_component, NODE_ON_HOVER, 0, nullptr); + } + void RegisterOnMouse(const std::function& onMouse) + { + onMouse_ = onMouse; + _nodeAPI->registerNodeEvent(_component, NODE_ON_MOUSE, 0, nullptr); + } + void RegisterOnTouchIntercept(const std::function& onTouchIntercept) + { + onTouchIntercept_ = onTouchIntercept; + _nodeAPI->registerNodeEvent(_component, NODE_ON_TOUCH_INTERCEPT, 0, nullptr); + } + void RegisterOnFocus(const std::function& onFocus) + { + onFocus_ = onFocus; + _nodeAPI->registerNodeEvent(_component, NODE_ON_FOCUS, 0, nullptr); + } + void RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray); + + static void NodeEventReceiver(ArkUI_NodeEvent* event); + void ProcessNodeEvent(ArkUI_NodeEvent* event); + virtual void OnNodeEvent(ArkUI_NodeEvent* event) {} + +protected: + // 组件树操作的实现类对接。 + void OnAddChild(const std::shared_ptr& child) + { + _nodeAPI->addChild(_component, child->GetComponent()); + } + void OnRemoveChild(const std::shared_ptr& child) + { + _nodeAPI->removeChild(_component, child->GetComponent()); + } + void OnRemoveAll() + { + _nodeAPI->removeAllChildren(_component); + } + void OnInsertChild(const std::shared_ptr& child, int32_t index) + { + _nodeAPI->insertChildAt(_component, child->GetComponent(), index); + } + +protected: + std::list> children_; + ArkUI_NodeHandle _component { nullptr }; + ArkUI_NativeNodeAPI_1* _nodeAPI { nullptr }; + +private: + std::function onClick_; + std::function onDisappear_; + std::function onAppear_; + std::function onTouch_; + std::function onHover_; + std::function onVisibleAreaChange_; + std::function onMouse_; + std::function onTouchIntercept_; + std::function onFocus_; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h new file mode 100755 index 0000000000000000000000000000000000000000..6c9e26da66515c89cee0b0e8615ce9034064c96a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H +#define ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { + +class FlowItemComponent : public Component { +public: + FlowItemComponent() : Component(ARKUI_NODE_FLOW_ITEM) {} + explicit FlowItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4fcbf0b516edaefc6917bae35546d3dbf6ea33fc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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 "grid_component.h" + +namespace ArkUICApiDemo { +void GridComponent::SetGridColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_TEMPLATE, &item); +} +void GridComponent::SetGridRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_TEMPLATE, &item); +} +void GridComponent::SetGridColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_GAP, &item); +} +void GridComponent::SetGridRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_GAP, &item); +} +void GridComponent::SetGridCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_CACHED_COUNT, &item); +} +void GridComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h new file mode 100755 index 0000000000000000000000000000000000000000..2fbf1b1d9a5d9508caf9d45f45cec15bec901ae0 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_GRID_COMPONENT_H +#define ARKUI_CAPI_DEMO_GRID_COMPONENT_H + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +class GridItemComponent : public Component { +public: + GridItemComponent() : Component(ARKUI_NODE_GRID_ITEM) {} + explicit GridItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; + +class GridComponent : public Component { +public: + GridComponent() : Component(ARKUI_NODE_GRID) {} + explicit GridComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_GRID_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetGridColumnsTemplate(const std::string& str); + void SetGridRowsTemplate(const std::string& str); + void SetGridColumnsGap(float val); + void SetGridRowsGap(float val); + void SetGridCachedCount(int32_t cachedCount); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + void ReleaseAdapter() + { + return _adapter.reset(); + } + +private: + std::shared_ptr> _adapter; +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_GRID_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..70c16d54887f77247eb45b3038c55803750aee14 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 "image_component.h" + +#include + +namespace ArkUICApiDemo { + +int32_t ImageComponent::SetImageSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetImageSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetObjectFit(const int32_t objectFit) +{ + ArkUI_NumberValue value[] = { { .i32 = objectFit } }; + ArkUI_AttributeItem item = { value, 1 }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_OBJECT_FIT, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h new file mode 100755 index 0000000000000000000000000000000000000000..e4803ad1df10e29ce76e299fd09a728a1b8ae68e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageComponent : public Component { +public: + ImageComponent() : Component(ARKUI_NODE_IMAGE) {} + explicit ImageComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSrc(const std::string& content); + int32_t SetImageSrc(ArkUI_DrawableDescriptor* descriptors); + int32_t SetObjectFit(const int32_t objectFit); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8eefc40e6b766c4971809bd94e5347c10f411e9d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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 "imageanimator_component.h" + +namespace ArkUICApiDemo { +void ImageAnimatorComponent::SetState(int32_t state) +{ + ArkUI_NumberValue value[] = { { .i32 = state } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_STATE, &item); +} + +void ImageAnimatorComponent::SetIteration(int32_t iteration) +{ + ArkUI_NumberValue value[] = { { .i32 = iteration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_ITERATION, &item); +} + +void ImageAnimatorComponent::SetImage(std::vector& vector) +{ + ArkUI_AttributeItem item = { .object = vector.data(), .size = static_cast(vector.size()) }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_IMAGES, &item); +} + +void ImageAnimatorComponent::SetFixedSize(int32_t fixedSize) +{ + ArkUI_NumberValue value[] = { { .i32 = fixedSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FIXED_SIZE, &item); +} + +void ImageAnimatorComponent::SetReverse(int32_t reverse) +{ + ArkUI_NumberValue value[] = { { .i32 = reverse } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_REVERSE, &item); +} + +void ImageAnimatorComponent::SetFillMode(int32_t mode) +{ + ArkUI_NumberValue value[] = { { .i32 = mode } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FILL_MODE, &item); +} + +void ImageAnimatorComponent::SetDuration(int32_t duration) +{ + ArkUI_NumberValue value[] = { { .i32 = duration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_DURATION, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h new file mode 100755 index 0000000000000000000000000000000000000000..cf18cd881bacd1973721a4fc2e75f1ee21b320d4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageAnimatorComponent : public Component { +public: + ImageAnimatorComponent() : Component(ARKUI_NODE_IMAGE_ANIMATOR) {} + explicit ImageAnimatorComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetState(int32_t state); + void SetIteration(int32_t iteration); + void SetImage(std::vector& vector); + void SetFixedSize(int32_t fixedSize); + void SetReverse(int32_t reverse); + void SetFillMode(int32_t mode); + void SetDuration(int32_t duration); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..7a74ee781b6ac2cc3920b400ba060db64bd91dab --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 "imagespan_component.h" + +namespace ArkUICApiDemo { + +int32_t ImageSpanComponent::SetImageSpanSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +int32_t ImageSpanComponent::SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h new file mode 100755 index 0000000000000000000000000000000000000000..4305f550ed28a49b58e5cb7af627e0e7576f4999 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageSpanComponent : public Component { +public: + ImageSpanComponent() : Component(ARKUI_NODE_IMAGE_SPAN) {} + explicit ImageSpanComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSpanSrc(const std::string& content); + int32_t SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4fd01b55a127caec7e81cfbb1d9afdb6b529965d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2024 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 "list_component.h" + +namespace ArkUICApiDemo { + +void ListItemSwipeActionOption::SetStart(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetStart(_option, item); +} + +void ListItemSwipeActionOption::SetEnd(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEnd(_option, item); +} + +void ListItemSwipeActionOption::SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEdgeEffect(_option, edgeEffect); +} + +int32_t ListItemSwipeActionOption::GetEdgeEffect() +{ + return OH_ArkUI_ListItemSwipeActionOption_GetEdgeEffect(_option); +} + +void ListItemSwipeActionOption::SetOnOffsetChange(OnOffsetChangeCallback callback) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChange(_option, callback); +} + +void ListItemSwipeActionOption::SetOnOffsetChangWithUserData( + OnOffsetChangeWithUserDataCallback callback, void* userData) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChangeWithUserData(_option, userData, callback); +} + +int32_t ListChildrenMainSizeOption::SetDefaultMainSize(float defaultMainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_SetDefaultMainSize(_option, defaultMainSize); +} + +float ListChildrenMainSizeOption::GetDefaultMainSize() +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetDefaultMainSize(_option); +} + +void ListChildrenMainSizeOption::Resize(int32_t totalSize) +{ + OH_ArkUI_ListChildrenMainSizeOption_Resize(_option, totalSize); +} + +int32_t ListChildrenMainSizeOption::Splice(int32_t index, int32_t deleteCount, int32_t addCount) +{ + return OH_ArkUI_ListChildrenMainSizeOption_Splice(_option, index, deleteCount, addCount); +} + +int32_t ListChildrenMainSizeOption::UpdateSize(int32_t index, float mainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_UpdateSize(_option, index, mainSize); +} + +float ListChildrenMainSizeOption::GetMainSize(int32_t index) +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetMainSize(_option, index); +} + +void ListItemComponent::SetListItemSwiperAction(ListItemSwipeActionOption* option) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_SWIPE_ACTION, &item); +} + +void ListComponent::SetListDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIRECTION, &item); +} + +void ListComponent::SetListSticky(int32_t stickyStyle) +{ + ArkUI_NumberValue value[] = { { .i32 = stickyStyle } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_STICKY, &item); +} + +void ListComponent::SetListSpace(float space) +{ + ArkUI_NumberValue value[] = { { .f32 = space } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_SPACE, &item); +} + +void ListComponent::SetListCachedCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_CACHED_COUNT, &item); +} + +void ListComponent::SetListScrollToIndex(const std::vector& data) +{ + ArkUI_AttributeItem item = { data.data(), static_cast(data.size()) }; + _nodeAPI->setAttribute(_component, NODE_LIST_SCROLL_TO_INDEX, &item); +} + +void ListComponent::SetListAlignListItem(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ALIGN_LIST_ITEM, &item); +} + +void ListComponent::SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListComponent::SetListInitialIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_INITIAL_INDEX, &item); +} + +void ListComponent::SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupHeader(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_HEADER, &item); +} + +void ListItemGroupComponent::SetListItemGroupFooter(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_FOOTER, &item); +} + +void ListItemGroupComponent::SetListItemGroupDivider( + uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListItemGroupAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + int32_t start = index > 0 ? _groupList[index - 1] : 0, end = _groupList[index]; + if (end - start != 1) { + handle = UpdateNewItemByGroup(start, end); + } else { + handle = UpdateNewItem(start, end); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +void ListItemGroupAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + if (Component(item).GetChildren().size() == 1) { + _cachedListItems.emplace(_listItems[item]); + } else { + _cachedItems.emplace(_items[item]); + } +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItemByGroup(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto groupItem = std::make_shared(); + groupItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + groupItem->AddChild(_data[i]); + } + groupItem->SetBorderWidth(1); + handle = groupItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, groupItem); + } + return handle; +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItem(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedListItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedListItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedListItems.pop(); + } else { + // 创建新的元素。 + auto listItem = std::make_shared(); + listItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + listItem->AddChild(_data[i]); + } + handle = listItem->GetComponent(); + // 保持文本列表项的引用。 + _listItems.emplace(handle, listItem); + } + return handle; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h new file mode 100755 index 0000000000000000000000000000000000000000..badca14d13704d968fbd9b608b33285f57ba1cde --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_LIST_COMPONENT_H +#define CAPIDEMO_LIST_COMPONENT_H +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +typedef void (*OnOffsetChangeCallback)(float offset); +typedef void (*OnOffsetChangeWithUserDataCallback)(float offset, void* userData); +typedef void (*OnFinish)(void* userData); + +class ListItemSwipeActionOption { +public: + ListItemSwipeActionOption() : _option(OH_ArkUI_ListItemSwipeActionOption_Create()) {} + ~ListItemSwipeActionOption() + { + OH_ArkUI_ListItemSwipeActionOption_Dispose(_option); + } + + void SetStart(ArkUI_ListItemSwipeActionItem* item); + void SetEnd(ArkUI_ListItemSwipeActionItem* item); + void SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect); + int32_t GetEdgeEffect(); + void SetOnOffsetChange(OnOffsetChangeCallback callback); + void SetOnOffsetChangWithUserData(OnOffsetChangeWithUserDataCallback callback, void* userData); + + ArkUI_ListItemSwipeActionOption* GetOption() + { + return _option; + } + +private: + ArkUI_ListItemSwipeActionOption* _option; +}; + +class ListItemComponent : public Component { +public: + ListItemComponent() : Component(ARKUI_NODE_LIST_ITEM) {} + explicit ListItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemSwiperAction(ListItemSwipeActionOption* option); + std::shared_ptr GetSwipeActionOption() const + { + return _swipeActionOption; + } + void ReleaseSwipeActionOption() + { + _swipeActionOption.reset(); + } + +private: + std::shared_ptr _swipeActionOption; +}; + +class ListChildrenMainSizeOption { +public: + ListChildrenMainSizeOption() : _option(OH_ArkUI_ListChildrenMainSizeOption_Create()) {} + ~ListChildrenMainSizeOption() + { + OH_ArkUI_ListChildrenMainSizeOption_Dispose(_option); + } + int32_t SetDefaultMainSize(float defaultMainSize); + float GetDefaultMainSize(); + void Resize(int32_t totalSize); + int32_t Splice(int32_t index, int32_t deleteCount, int32_t addCount); + int32_t UpdateSize(int32_t index, float mainSize); + float GetMainSize(int32_t index); + + ArkUI_ListChildrenMainSize* GetOption() + { + return _option; + } + +private: + ArkUI_ListChildrenMainSize* _option; +}; + +class ListItemGroupComponent : public Component { +public: + ListItemGroupComponent() : Component(ARKUI_NODE_LIST_ITEM_GROUP) {} + explicit ListItemGroupComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemGroupHeader(Component* node); + void SetListItemGroupFooter(Component* node); + void SetListItemGroupDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + void SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize); + + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr _childrenMainSize; +}; + +class ListItemGroupAdapter : public ItemAdapter { +public: + explicit ListItemGroupAdapter(std::vector>& dataSource, + const std::vector& groupList) + : ItemAdapter(dataSource) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, groupList.size()); + int32_t sum = 0; + for (auto& item : groupList) { + sum += item; + _groupList.push_back(sum); + } + } + virtual ~ListItemGroupAdapter() {} + +protected: + void OnNewItemAttached(ArkUI_NodeAdapterEvent* event) override; + void OnItemDetached(ArkUI_NodeAdapterEvent* event) override; + ArkUI_NodeHandle UpdateNewItemByGroup(int32_t start, int32_t end); + ArkUI_NodeHandle UpdateNewItem(int32_t start, int32_t end); + +private: + std::vector _groupList; + // 缓存listItemComponent + std::stack> _cachedListItems; + // 存储list嵌套的单个listItem + std::unordered_map> _listItems; +}; + +class ListComponent : public Component { +public: + ListComponent() : Component(ARKUI_NODE_LIST) {} + explicit ListComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLazyAdapterByGroup(const std::shared_ptr& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _groupAdapter = adapter; + } + /** + * @param direction ArkUI_Axis + */ + void SetListDirection(int32_t direction); + /** + * @param stickyStyle ArkUI_StickyStyle + */ + void SetListSticky(int32_t stickyStyle); + void SetListSpace(float space); + void SetListCachedCount(int32_t count); + /** + * data[0].i32:The index value of the target element to be slid to in the current container.\n + * data[1]?.i32:Set whether there is an action when sliding to the index value of a list item in the list, where + * 1 indicates an action and 0 indicates no action. Default value: 0。\n + * data[2]?.i32:ArkUI_ScrollAlignment + */ + void SetListScrollToIndex(const std::vector& data); + /** + * @param align ArkUI_ListItemAlignment + */ + void SetListAlignListItem(int32_t align); + void SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize); + void SetListInitialIndex(int32_t index); + void SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetGroupAdapter() const + { + return _groupAdapter; + } + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr> _adapter; + std::shared_ptr _groupAdapter; + std::shared_ptr _childrenMainSize; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_LIST_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h new file mode 100755 index 0000000000000000000000000000000000000000..5b7422c615880b2b0f81e317773f0475d0c6470b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_NODE_ADAPTER_H +#define ARKUI_CAPI_DEMO_NODE_ADAPTER_H + +#include +#include +#include +#include +#include +#include + +#include "column_component.h" +namespace ArkUICApiDemo { +using AllItemCallBack = std::function, uint32_t)>; + +template +class ItemAdapter { +public: + explicit ItemAdapter(std::vector>& dataSource); + virtual ~ItemAdapter(); + ArkUI_NodeAdapterHandle GetAdapter() const + { + return _adapter; + } + void RemoveItem(int32_t index); + void RemoveItems(int32_t startPosition, int32_t itemCount); + void InsertItem(int32_t index, const std::shared_ptr& value); + void InsertItems(int32_t index, std::vector>& dataSource); + void MoveItem(int32_t oldIndex, int32_t newIndex); + void ReloadItem(int32_t index, const std::shared_ptr& value); + void ReloadItems(int32_t startPosition, std::vector>& dataSource); + void ReloadAllItem(); + void SetAllItem(AllItemCallBack callback); + void UnregisterEventReceiver(); + void SetNodeAdapterEvent(const std::function& callback); + void RegisterRemovedNodeCallback(std::function)> callback) + { + _removedNodeCallback = callback; + } + void SetTotalNodeCount(uint32_t count) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, count); + } + uint32_t GetTotalNodeCount() + { + return OH_ArkUI_NodeAdapter_GetTotalNodeCount(_adapter); + } + +protected: + static void OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event); + virtual void OnAdapterEvent(ArkUI_NodeAdapterEvent* event); + // 分配ID给需要显示的Item,用于ReloadAllItems场景的元素diff。 + virtual void OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event); + // 需要新的Item显示在可见区域。 + virtual void OnNewItemAttached(ArkUI_NodeAdapterEvent* event); + // Item从可见区域移除。 + virtual void OnItemDetached(ArkUI_NodeAdapterEvent* event); + + std::vector> _data; + ArkUI_NativeNodeAPI_1* _nodeAPI = nullptr; + ArkUI_NodeAdapterHandle _adapter = nullptr; + // 管理NodeAdapter生成的元素。 + std::unordered_map> _items; + // 管理回收复用组件池。 + std::stack> _cachedItems; + std::function _eventCallBack; + std::function)> _removedNodeCallback; +}; + +template +ItemAdapter::ItemAdapter(std::vector>& dataSource) + : _adapter(OH_ArkUI_NodeAdapter_Create()) +{ + // 使用NodeAdapter创建函数。 + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + std::swap(_data, dataSource); + // 设置懒加载数据。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); + // 设置懒加载回调事件。 + OH_ArkUI_NodeAdapter_RegisterEventReceiver(_adapter, this, OnStaticAdapterEvent); +} + +template +ItemAdapter::~ItemAdapter() +{ + // 释放创建的组件。 + while (!_cachedItems.empty()) { + _cachedItems.pop(); + } + _items.clear(); + // 释放Adapter相关资源。 + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); + OH_ArkUI_NodeAdapter_Dispose(_adapter); +} + +template +void ItemAdapter::RemoveItem(int32_t index) +{ + // 删除第index个数据。 + _data.erase(_data.begin() + index); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件删除元素, + // 根据是否有新增元素回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::RemoveItems(int32_t startPosition, int32_t itemCount) +{ + auto end = _data.begin() + startPosition + itemCount; + if (startPosition + itemCount > _data.size()) { + end = _data.end(); + } + _data.erase(_data.begin() + startPosition, end); + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, startPosition, itemCount); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItem(int32_t index, const std::shared_ptr& value) +{ + _data.insert(_data.begin() + index, value); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件, + // 根据是否有删除元素回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件。 + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItems(int32_t index, std::vector>& dataSource) +{ + _data.insert(_data.begin() + index, dataSource.begin(), dataSource.end()); + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, dataSource.size()); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::MoveItem(int32_t oldIndex, int32_t newIndex) +{ + auto temp = _data[oldIndex]; + _data.insert(_data.begin() + newIndex, temp); + _data.erase(_data.begin() + oldIndex); + // 移到位置如果未发生可视区域内元素的可见性变化,则不回调事件,反之根据新增和删除场景回调对应的事件。 + OH_ArkUI_NodeAdapter_MoveItem(_adapter, oldIndex, newIndex); +} + +template +void ItemAdapter::ReloadItem(int32_t index, const std::shared_ptr& value) +{ + _data[index] = value; + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, index, 1); +} + +template +void ItemAdapter::ReloadItems(int32_t startPosition, std::vector>& dataSource) +{ + if (startPosition + dataSource.size() > _data.size()) { + // 防止nodeAdapter崩溃 + return; + } + for (int32_t i = 0; i < dataSource.size(); i++) { + _data[startPosition + i] = dataSource[i]; + } + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, startPosition, dataSource.size()); +} + +template +void ItemAdapter::SetAllItem(AllItemCallBack callback) +{ + ArkUI_NodeHandle* items = nullptr; + uint32_t size = 0; + OH_ArkUI_NodeAdapter_GetAllItems(_adapter, &items, &size); + for (uint32_t i = 0; i < size; i++) { + if (!items[i]) { + continue; + } + auto temp = std::make_shared(items[i]); + if (callback) { + callback(temp, i); + } + } +} + +template +void ItemAdapter::UnregisterEventReceiver() +{ + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); +} + +template +void ItemAdapter::SetNodeAdapterEvent(const std::function& callback) +{ + _eventCallBack = callback; +} + +template +void ItemAdapter::ReloadAllItem() +{ + std::reverse(_data.begin(), _data.end()); + // 全部重新加载场景下,会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID接口获取新的组件ID, + // 根据新的组件ID进行对比,ID不发生变化的进行复用, + // 针对新增ID的元素,调用NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件创建新的组件, + // 然后判断老数据中遗留的未使用ID,调用NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素。 + OH_ArkUI_NodeAdapter_ReloadAllItems(_adapter); +} + +template +void ItemAdapter::OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + // 获取实例对象,回调实例事件。 + auto itemAdapter = reinterpret_cast(OH_ArkUI_NodeAdapterEvent_GetUserData(event)); + itemAdapter->OnAdapterEvent(event); +} + +template +void ItemAdapter::OnAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + auto type = OH_ArkUI_NodeAdapterEvent_GetType(event); + switch (type) { + case NODE_ADAPTER_EVENT_WILL_ATTACH_TO_NODE: + break; + case NODE_ADAPTER_EVENT_WILL_DETACH_FROM_NODE: + break; + case NODE_ADAPTER_EVENT_ON_GET_NODE_ID: + OnNewItemIdCreated(event); + break; + case NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER: + OnNewItemAttached(event); + break; + case NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER: + OnItemDetached(event); + break; + default: + break; + } + if (_eventCallBack) + _eventCallBack(event); +} +template +void ItemAdapter::OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + static std::hash hashId = std::hash(); + auto id = hashId(std::to_string(index)); + OH_ArkUI_NodeAdapterEvent_SetNodeId(event, id); +} + +// 需要新的Item显示在可见区域。 +template +void ItemAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + auto showNode = _data[index]; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + recycledItem->AddChild(showNode); + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto flowItem = std::make_shared(); + flowItem->RemoveAll(); + flowItem->AddChild(showNode); + handle = flowItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, flowItem); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +// Item从可见区域移除。 +template +void ItemAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + _cachedItems.emplace(_items[item]); +} +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_NODE_ADAPTER_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..02c85ad2bca935053185089689a839a8baac7c96 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 "radio_component.h" + +#include + +namespace ArkUICApiDemo { +constexpr size_t ALLOW_SIZE_3 = 3; +void RadioComponent::SetChecked(const bool& isChecked) +{ + ArkUI_NumberValue value[] = { { .i32 = static_cast(isChecked) } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_CHECKED, &item); +} +void RadioComponent::SetGroup(const std::string& group) +{ + ArkUI_AttributeItem item = { .string = group.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_GROUP, &item); +} +void RadioComponent::SetStyled(const uint32_t* colorArray, size_t size) +{ + if (size == ALLOW_SIZE_3) { + ArkUI_NumberValue radioStyle_value[] = { { .u32 = colorArray[0] }, { .u32 = colorArray[1] }, + { .u32 = colorArray[2] } }; + ArkUI_AttributeItem radioStyle_value_item = { radioStyle_value, ALLOW_SIZE_3 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_STYLE, &radioStyle_value_item); + } +} +void RadioComponent::SetValue(const std::string& value) +{ + ArkUI_AttributeItem item = { .string = value.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_VALUE, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h new file mode 100755 index 0000000000000000000000000000000000000000..244feba45818192f38c9421e8f71dd801c973a43 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RADIO_COMPONENT_H +#define ARKUI_CAPI_DEMO_RADIO_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RadioComponent : public Component { +public: + RadioComponent() : Component(ARKUI_NODE_RADIO) {} + explicit RadioComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetChecked(const bool& isChecked); + void SetGroup(const std::string& group); + void SetStyled(const uint32_t* colorArray, size_t size); + void SetValue(const std::string& value); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8b4e85c1714e9857e63ba2bb7b93fb68f9c4ca8e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 "refresh_component.h" + +#include + +namespace ArkUICApiDemo { + +void RefreshComponent::SetPullToRefresh(int32_t pullToRefresh) +{ + ArkUI_NumberValue value[] = { { .i32 = pullToRefresh } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_TO_REFRESH, &item); +} +void RefreshComponent::SetPullDownRatio(float pullDownRatio) +{ + ArkUI_NumberValue value[] = { { .f32 = pullDownRatio } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_DOWN_RATIO, &item); +} +void RefreshComponent::SetRefreshOffset(float refreshOffset) +{ + ArkUI_NumberValue value[] = { { .f32 = refreshOffset } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_OFFSET, &item); +} +void RefreshComponent::SetRefreshing(bool refreshing) +{ + ArkUI_NumberValue value[] = { { .i32 = refreshing } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_REFRESHING, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h new file mode 100755 index 0000000000000000000000000000000000000000..cee7645673001aa823fa5b2b25aa50fe131c3165 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H +#define ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RefreshComponent : public Component { +public: + RefreshComponent() : Component(ARKUI_NODE_REFRESH) {} + explicit RefreshComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetPullToRefresh(int32_t pullToRefresh); + void SetPullDownRatio(float pullDownRatio); + void SetRefreshOffset(float refreshOffset); + void SetRefreshing(bool refreshing); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h new file mode 100755 index 0000000000000000000000000000000000000000..1c1589619871109c307495af8bf344e67bc41dc6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H +#define ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H + +#include +#include + +#include "./relativeContainer/ruleOption.h" +#include "component.h" +namespace ArkUICApiDemo { +class RelativeContainerComponent : public Component { +public: + RelativeContainerComponent() : Component(ARKUI_NODE_RELATIVE_CONTAINER) {} + RelativeContainerComponent(ArkUI_NodeHandle handle) : Component(handle) {} + ~RelativeContainerComponent() = default; + + void SetRelativeContainerGuideLine(const std::shared_ptr guidelineOption) + { + ArkUI_AttributeItem item = { .object = guidelineOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_GUIDE_LINE, &item); + guidelineOption_ = guidelineOption; + } + + void SetRelativeContainerBarrier(const std::shared_ptr barrierOption) + { + ArkUI_AttributeItem item = { .object = barrierOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_BARRIER, &item); + barrierOption_ = barrierOption; + } + + std::shared_ptr GetRuleOption() const + { + return ruleOption_; + } + std::shared_ptr GetGuideLineOption() const + { + return guidelineOption_; + } + std::shared_ptr GetBarrierOption() const + { + return barrierOption_; + } + +private: + std::shared_ptr ruleOption_ = nullptr; + std::shared_ptr guidelineOption_ = nullptr; + std::shared_ptr barrierOption_ = nullptr; +}; +; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h new file mode 100755 index 0000000000000000000000000000000000000000..397e6c6824d62a2fff8cedc0e55b39363c129087 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_ROW_COMPONENT_H +#define ARKUI_CAPI_DEMO_ROW_COMPONENT_H + +#include "component.h" +namespace ArkUICApiDemo { +class RowComponent : public Component { +public: + RowComponent() : Component(ARKUI_NODE_ROW) {} + RowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_ROW_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5048fb4ce20b4ab0e9f316d6fc371576678871ed --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 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 "scroll_component.h" +namespace ArkUICApiDemo { + +void ScrollComponent::SetScrollScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void ScrollComponent::SetScrollScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void ScrollComponent::SetScrollScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void ScrollComponent::SetScrollScrollable(int32_t scrollable) +{ + ArkUI_NumberValue value[] = { { .i32 = scrollable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void ScrollComponent::SetScrollEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void ScrollComponent::SetScrollFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void ScrollComponent::SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination) +{ + auto value = new ArkUI_NumberValue[3 + static_cast(pagination.size())]; + value[0] = { .i32 = snapAlign }; + value[1] = { .i32 = enableSnapToStart }; + value[2] = { .i32 = enableSnapToEnd }; + for (int32_t i = 0; i < pagination.size(); i++) { + value[3 + i] = { .f32 = pagination[i] }; + } + ArkUI_AttributeItem item = { value, 3 + static_cast(pagination.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SNAP, &item); +} +void ScrollComponent::SetScrollNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void ScrollComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void ScrollComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void ScrollComponent::SetScrollEnablePaging(int32_t enablePaging) +{ + ArkUI_NumberValue value[] = { { .i32 = enablePaging } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_PAGING, &item); +} +void ScrollComponent::SetScrollPage(int32_t next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollPage(int32_t next, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void ScrollComponent::SetScrollScrollDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::AddChildWithNumber(int32_t number, ArkUI_NodeType type) +{ + SetBorderWidth(PARAM_2); + auto node = std::make_shared(type); + if (type == ARKUI_NODE_LIST) { + ArkUI_NumberValue value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL } }; + ArkUI_AttributeItem item = { value, 1 }; + node->setAttribute(NODE_LIST_DIRECTION, &item); + node->SetMargin(DEFAULT_MARGIN); + } + for (int32_t i = 0; i < number; ++i) { + auto column = std::make_shared(ARKUI_NODE_COLUMN); + column->SetWidth(SIZE_50); + column->SetHeight(SIZE_50); + column->SetMargin(DEFAULT_MARGIN); + if (number == 0) { + number = 1; + } + column->SetBackgroundColor((i * 0xFFFFFF / number) | 0xFF000000); + node->AddChild(column); + } + AddChild(node); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h new file mode 100755 index 0000000000000000000000000000000000000000..1e221aed7923b20045c7ca3982546aa5261732a0 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_SCROLL_COMPONENT_H +#define CAPIDEMO_SCROLL_COMPONENT_H + +#include "component.h" + +namespace ArkUICApiDemo { +class ScrollComponent : public Component { +public: + ScrollComponent() : Component(ARKUI_NODE_SCROLL) {} + explicit ScrollComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetScrollScrollBar(int32_t barState); + void SetScrollScrollBarWidth(float width); + void SetScrollScrollBarColor(uint32_t color); + void SetScrollScrollable(int32_t scrollable); + void SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + void SetScrollEnableScrollInteraction(bool enableScrollInteraction); + void SetScrollFriction(float friction); + void SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination); + void SetScrollNestedScroll(int32_t forward, int32_t backward); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollEnablePaging(int32_t enablePaging); + void SetScrollPage(int32_t next); + void SetScrollPage(int32_t next, int32_t animation); + void SetScrollBy(float hDistance, float vDistance); + void SetScrollScrollDirection(int32_t direction); + void AddChildWithNumber(int32_t number, ArkUI_NodeType type); +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SCROLL_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..86ea8643fcd1aae7d19c437dfd8b1414a2fd5afb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2024 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 "swiper_component.h" + +namespace ArkUICApiDemo { + +void SwiperComponent::SetSwiperLoop(int32_t loop) +{ + ArkUI_NumberValue value[] = { { .i32 = loop } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_LOOP, &item); +} + +void SwiperComponent::SetSwiperAutoPlay(int32_t status) +{ + ArkUI_NumberValue value[] = { { .i32 = status } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_AUTO_PLAY, &item); +} + +void SwiperComponent::SetSwiperPrevMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_PREV_MARGIN, &item); +} + +void SwiperComponent::SetSwiperNextMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NEXT_MARGIN, &item); +} + +void SwiperComponent::SetSwiperDisplayCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_DISPLAY_COUNT, &item); +} + +void SwiperComponent::SetSwiperIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDEX, &item); +} + +void SwiperComponent::SetSwiperVertical(int32_t vertical) +{ + ArkUI_NumberValue value[] = { { .i32 = vertical } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_VERTICAL, &item); +} + +void SwiperComponent::SetSwiperEffectMode(int32_t effect) +{ + ArkUI_NumberValue value[] = { { .i32 = effect } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_EDGE_EFFECT_MODE, &item); +} + +void SwiperComponent::SetSwiperNestedScroll(int32_t nestedScroll) +{ + ArkUI_NumberValue value[] = { { .i32 = nestedScroll } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NESTED_SCROLL, &item); +} + +void SwiperComponent::SetSwiperInterval(float interval) +{ + ArkUI_NumberValue value[] = { { .f32 = interval } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INTERVAL, &item); +} + +void SwiperComponent::SetSwiperDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_DIRECTION, &item); +} + +void SwiperComponent::SetSwiperIndicator(ArkUI_SwiperIndicator* indicator) +{ + ArkUI_NumberValue indicator_value[] = { { .i32 = ARKUI_SWIPER_INDICATOR_TYPE_DOT } }; + ArkUI_AttributeItem indicator_item = { indicator_value, sizeof(indicator_value) / sizeof(ArkUI_NumberValue), "", + indicator }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDICATOR, &indicator_item); +} + +void SwiperComponent::SetSwiperToIndex(int32_t index, int32_t useAnimation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = useAnimation } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_SWIPE_TO_INDEX, &item); +} + +void SwiperComponent::SetSwiperDuration(float duration) +{ + ArkUI_NumberValue value[] = { { .f32 = duration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_DURATION, &item); +} + +void SwiperComponent::RegisterOnGesture(const std::function& onGesture) +{ + onGesture_ = onGesture; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_GESTURE_SWIPE, 0, nullptr); +} + +void SwiperComponent::RegisterOnChange(const std::function& onChange) +{ + onChange_ = onChange; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CHANGE, 0, nullptr); +} + +void SwiperComponent::RegisterOnDidScrollContext(const std::function& onDid) +{ + onDid_ = onDid; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationStart(const std::function& onStart) +{ + onStart_ = onStart; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_START, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationEnd(const std::function& onEnd) +{ + onEnd_ = onEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_END, 0, nullptr); +} + +void SwiperComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + switch (eventType) { + case NODE_SWIPER_EVENT_ON_GESTURE_SWIPE: + if (onGesture_) { + onGesture_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CHANGE: + if (onChange_) { + onChange_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL: + if (onDid_) { + onDid_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_START: + if (onStart_) { + onStart_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_END: + if (onEnd_) { + onEnd_(event); + } + break; + default: + break; + } +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h new file mode 100755 index 0000000000000000000000000000000000000000..03b59d3c09d55bc7ad7fd8d90846073283a3bca4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_SWIPER_COMPONENT_H +#define CAPIDEMO_SWIPER_COMPONENT_H + +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +class SwiperComponent : public Component { +public: + SwiperComponent() : Component(ARKUI_NODE_SWIPER) {} + explicit SwiperComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetSwiperLoop(int32_t loop); + void SetSwiperAutoPlay(int32_t status); + void SetSwiperPrevMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperNextMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperDisplayCount(int32_t count); + void SetSwiperIndex(int32_t index); + void SetSwiperVertical(int32_t vertical); + void SetSwiperNestedScroll(int32_t nestedScroll); + void SetSwiperEffectMode(int32_t effect); + void SetSwiperInterval(float interval); + void SetSwiperDirection(int32_t direction); + void SetSwiperIndicator(ArkUI_SwiperIndicator* indicator); + void SetSwiperToIndex(int32_t index, int32_t useAnimation = false); + void SetSwiperDuration(float duration); + void RegisterOnGesture(const std::function& onGesture); + void RegisterOnChange(const std::function& onChange); + void RegisterOnDidScrollContext(const std::function& onDid); + void RegisterOnAnimationStart(const std::function& onStart); + void RegisterOnAnimationEnd(const std::function& onEnd); + void OnNodeEvent(ArkUI_NodeEvent* event) override; + + std::function onGesture_; + std::function onDid_; + std::function onChange_; + std::function onStart_; + std::function onEnd_; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SWIPER_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d1d1f88266d9d08d170bb141b0eaee8101612e7a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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 "text_component.h" + +namespace ArkUICApiDemo { + +void TextComponent::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void TextComponent::SetFontColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_COLOR, &item); +} +void TextComponent::SetTextContent(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_TEXT_CONTENT, &item); +} +void TextComponent::SetTextAlign(ArkUI_TextAlignment align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_TEXT_ALIGN, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h new file mode 100755 index 0000000000000000000000000000000000000000..c5f2e4f1fefcbc9c99c7085080475693f9134e5f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_TEXT_COMPONENT_H +#define ARKUI_CAPI_DEMO_TEXT_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class TextComponent : public Component { +public: + TextComponent() : Component(ARKUI_NODE_TEXT) {} + explicit TextComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetFontSize(float fontSize) override; + void SetFontColor(uint32_t color); + void SetTextContent(const std::string& content); + void SetTextAlign(ArkUI_TextAlignment align); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXT_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f98ea273822be29d204736f88eb47bc1804fd68 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 "toggle_component.h" + +namespace ArkUICApiDemo { + +void ToggleComponent::SetUnselectedColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_TOGGLE_UNSELECTED_COLOR, &item); +} + +void ToggleComponent::SetToggleValue(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_TOGGLE_VALUE, &item); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.h new file mode 100644 index 0000000000000000000000000000000000000000..06f51af66eb47b6637777aaa65d4c71ccc9f0727 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/toggle_component.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_TOGGLE_COMPONENT_H +#define ARKUI_CAPI_DEMO_TOGGLE_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ToggleComponent : public Component { +public: + ToggleComponent() : Component(ARKUI_NODE_TOGGLE) {} + explicit ToggleComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetUnselectedColor(uint32_t color); + void SetToggleValue(int32_t type); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TOGGLE_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f1540cb2fde1bee37e3e716903418cd6cd12f2fb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2024 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 "waterflow_component.h" + +namespace ArkUICApiDemo { + +void WaterFlowSectionOption::SetSection(int32_t index, WaterFlowSection section) +{ + OH_ArkUI_WaterFlowSectionOption_SetItemCount(_option, index, section.itemsCount); + OH_ArkUI_WaterFlowSectionOption_SetCrossCount(_option, index, section.crossCount); + OH_ArkUI_WaterFlowSectionOption_SetColumnGap(_option, index, section.columnsGap); + OH_ArkUI_WaterFlowSectionOption_SetRowGap(_option, index, section.rowsGap); + OH_ArkUI_WaterFlowSectionOption_SetMargin( + _option, index, section.margin.top, section.margin.right, section.margin.bottom, section.margin.left); + OH_ArkUI_WaterFlowSectionOption_RegisterGetItemMainSizeCallbackByIndex( + _option, index, section.onGetItemMainSizeByIndex); +} +WaterFlowSection WaterFlowSectionOption::GetSection(int32_t index) +{ + return { OH_ArkUI_WaterFlowSectionOption_GetItemCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetCrossCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetColumnGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetRowGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetMargin(_option, index) }; +} + +void WaterFlowSectionOption::SetSize(int32_t size) +{ + OH_ArkUI_WaterFlowSectionOption_SetSize(_option, size); +} +int32_t WaterFlowSectionOption::GetSize() +{ + return OH_ArkUI_WaterFlowSectionOption_GetSize(_option); +} + +void WaterFlowComponent::SetLayoutDirection(int32_t layoutDirection) +{ + ArkUI_NumberValue value[] = { { .i32 = layoutDirection } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_LAYOUT_DIRECTION, &item); +} + +void WaterFlowComponent::SetColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_TEMPLATE, &item); +} + +void WaterFlowComponent::SetRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_TEMPLATE, &item); +} + +void WaterFlowComponent::SetWaterFlowColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option) +{ + ArkUI_NumberValue value[] = { { .i32 = start } }; + ArkUI_AttributeItem item = { value, 1, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SECTION_OPTION, &item); + _sectionsOption = option; +} + +void WaterFlowComponent::SetWaterFlowCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_CACHED_COUNT, &item); +} + +void WaterFlowComponent::SetWaterFlowFooter(ArkUI_NodeHandle node) +{ + ArkUI_AttributeItem item = { .object = node }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_FOOTER, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation }, { .i32 = alignment } }; + ArkUI_AttributeItem item = { value, 3 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight) +{ + ArkUI_NumberValue value[] = { { .f32 = minWidth }, { .f32 = maxWidth }, { .f32 = minHeight }, + { .f32 = maxHeight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ITEM_CONSTRAINT_SIZE, &item); +} +void WaterFlowComponent::SetWaterFlowNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void WaterFlowComponent::SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void WaterFlowComponent::SetWaterFlowFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void WaterFlowComponent::SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void WaterFlowComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void WaterFlowComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next, bool animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void WaterFlowComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + switch (eventType) { + case NODE_ON_WILL_SCROLL: { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + int32_t source = result->data[2].i32; + if (_onWillScroll) { + _onWillScroll(offset, state, source); + } + break; + } + case NODE_SCROLL_EVENT_ON_REACH_START: + if (_onReachStart) { + _onReachStart(); + } + break; + case NODE_SCROLL_EVENT_ON_REACH_END: + if (_onReachEnd) { + _onReachEnd(); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_STOP: + if (_onScrollStop) { + _onScrollStop(); + } + break; + case NODE_WATER_FLOW_ON_DID_SCROLL: + if (_onDidScroll) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onDidScroll(offset, state); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN: + if (_onScrollFrameBegin) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onScrollFrameBegin(offset, state); + } + break; + case NODE_WATER_FLOW_ON_SCROLL_INDEX: + if (_onScrollIndex) { + int32_t first = result->data[0].i32; + int32_t last = result->data[1].i32; + _onScrollIndex(first, last); + } + break; + default: + break; + } +} +void WaterFlowComponent::SetOnWillScroll(OnWillScroll onWillScroll) +{ + _onWillScroll = onWillScroll; + _nodeAPI->registerNodeEvent(_component, NODE_ON_WILL_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnReachStart(OnReachStart onReachStart) +{ + _onReachStart = onReachStart; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_START, 0, nullptr); +} +void WaterFlowComponent::SetOnReachEnd(OnReachEnd onReachEnd) +{ + _onReachEnd = onReachEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_END, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollStop(OnScrollStop onScrollStop) +{ + _onScrollStop = onScrollStop; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_STOP, 0, nullptr); +} +void WaterFlowComponent::SetOnDidScroll(OnDidScroll onDidScroll) +{ + _onDidScroll = onDidScroll; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_DID_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin) +{ + _onScrollFrameBegin = onScrollFrameBegin; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollIndex(OnScrollIndex onScrollIndex) +{ + _onScrollIndex = onScrollIndex; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_SCROLL_INDEX, 0, nullptr); +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h new file mode 100755 index 0000000000000000000000000000000000000000..0f6fce90481cf1157cfdc906a4e43ef3e3971957 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H +#define ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H + +#include +#include + +#include "component.h" +#include "flowitem_component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +using OnWillScroll = std::function; +using OnReachStart = std::function; +using OnReachEnd = std::function; +using OnScrollStop = std::function; +using OnDidScroll = std::function; +using OnScrollFrameBegin = std::function; +using OnScrollIndex = std::function; + +struct WaterFlowSection { + int32_t itemsCount = 0; + int32_t crossCount; + float columnsGap; + float rowsGap; + // top right bottom left + ArkUI_Margin margin { 0, 0, 0, 0 }; + float (*onGetItemMainSizeByIndex)(int32_t itemIndex); + void* userData; +}; + +class WaterFlowSectionOption { +public: + WaterFlowSectionOption() : _option(OH_ArkUI_WaterFlowSectionOption_Create()) {} + ~WaterFlowSectionOption() + { + OH_ArkUI_WaterFlowSectionOption_Dispose(_option); + } + void SetSection(int32_t index, WaterFlowSection section); + WaterFlowSection GetSection(int32_t index); + + void SetSize(int32_t size); + int32_t GetSize(); + ArkUI_WaterFlowSectionOption* GetOption() + { + return _option; + } + +private: + ArkUI_WaterFlowSectionOption* _option; +}; + +class WaterFlowComponent : public Component { +public: + WaterFlowComponent() : Component(ARKUI_NODE_WATER_FLOW) {} + explicit WaterFlowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLayoutDirection(int32_t layoutDirection); + void SetColumnsTemplate(const std::string& str); + void SetRowsTemplate(const std::string& str); + void SetWaterFlowColumnsGap(float val); + void SetWaterFlowRowsGap(float val); + void SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option); + void SetWaterFlowCachedCount(int32_t cachedCount); + void SetWaterFlowFooter(ArkUI_NodeHandle node); + void SetWaterFlowScrollToIndex(int32_t index); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment); + void SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight); + void SetWaterFlowNestedScroll(int32_t forward, int32_t backward); + void SetWaterFlowScrollBar(int32_t barState); + void SetWaterFlowScrollBarWidth(float width); + void SetWaterFlowScrollBarColor(uint32_t color); + void SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction); + void SetWaterFlowFriction(float friction); + void SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollPage(bool next); + void SetScrollPage(bool next, bool animation); + void SetScrollBy(float hDistance, float vDistance); + + void OnNodeEvent(ArkUI_NodeEvent* event) override; + void SetOnWillScroll(OnWillScroll onWillScroll); + void SetOnReachStart(OnReachStart onReachStart); + void SetOnReachEnd(OnReachEnd onReachEnd); + void SetOnScrollStop(OnScrollStop onScrollStop); + void SetOnDidScroll(OnDidScroll onDidScroll); + void SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin); + void SetOnScrollIndex(OnScrollIndex onScrollIndex); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetSectionOption() const + { + return _sectionsOption; + } + void ReleaseSectionOption() + { + _sectionsOption.reset(); + } + +private: + std::shared_ptr _sectionsOption; + std::shared_ptr> _adapter; + + OnWillScroll _onWillScroll; + OnReachStart _onReachStart; + OnReachEnd _onReachEnd; + OnScrollStop _onScrollStop; + OnDidScroll _onDidScroll; + OnScrollFrameBegin _onScrollFrameBegin; + OnScrollIndex _onScrollIndex; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c21c3366f6f42b2cbff6d095c23e7c47f4fa88b6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 "imageanimator_common.h" +#include +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +void ImageAnimatorCommon::SetImageFrameInfo( + ArkUI_ImageAnimatorFrameInfo* frameInfo, const ImageFrameProps& props) +{ + if (frameInfo == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorCommon", "frame info is null"); + return; + } + + // set width + OH_ArkUI_ImageAnimatorFrameInfo_SetWidth(frameInfo, props.width); + // set height + OH_ArkUI_ImageAnimatorFrameInfo_SetHeight(frameInfo, props.height); + // set top + OH_ArkUI_ImageAnimatorFrameInfo_SetTop(frameInfo, props.top); + // set left + OH_ArkUI_ImageAnimatorFrameInfo_SetLeft(frameInfo, props.left); + // set duration + OH_ArkUI_ImageAnimatorFrameInfo_SetDuration(frameInfo, props.duration); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.h b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.h new file mode 100644 index 0000000000000000000000000000000000000000..d365333097c1f6ddd218c15e61e1ca348a7c00e1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_common.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMMON_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMMON_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { +struct ImageFrameProps { + int32_t width; + int32_t height; + int32_t top; + int32_t left; + int32_t duration; +}; +class ImageAnimatorCommon { +public: + ~ImageAnimatorCommon(); + static void SetImageFrameInfo(ArkUI_ImageAnimatorFrameInfo* frameInfo, const ImageFrameProps& props); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMMON_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de7bb3a533d6b59fc959ce13dbe9135d375f8d90 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2024 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 "imageanimator_frameinfo_test.h" + +#include "../manager/plugin_manager.h" +#include "column_component.h" +#include "imageanimator_common.h" +#include "imageanimator_component.h" + +namespace ArkUICApiDemo { +#define PARAM_96 96 + +static std::shared_ptr CreateImageAnimator(std::vector& vector) +{ + auto imageAnimator = std::make_shared(); + imageAnimator->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + imageAnimator->SetIteration(1); + imageAnimator->SetFixedSize(false); + imageAnimator->SetMargin(PARAM_10); + imageAnimator->SetImage(vector); + return imageAnimator; +} + +static ArkUI_DrawableDescriptor* CreateDescriptorFromPixelMap( + OH_Pixelmap_InitializationOptions* createOpts, OH_PixelmapNative* pixelmap) +{ + uint8_t data[PARAM_96]; + size_t dataSize = PARAM_96; + for (int i = 0; i < dataSize; i++) { + data[i] = i + 1; + } + // initialization Options + OH_PixelmapInitializationOptions_Create(&createOpts); + OH_PixelmapInitializationOptions_SetWidth(createOpts, PARAM_4); + OH_PixelmapInitializationOptions_SetHeight(createOpts, PARAM_6); + OH_PixelmapInitializationOptions_SetPixelFormat(createOpts, PIXEL_FORMAT_BGRA_8888); + OH_PixelmapInitializationOptions_SetAlphaType(createOpts, PIXELMAP_ALPHA_TYPE_PREMULTIPLIED); + // create Pixelmap instance + Image_ErrorCode errCode = OH_PixelmapNative_CreatePixelmap(data, dataSize, createOpts, &pixelmap); + if (errCode != IMAGE_SUCCESS) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CreateDescriptorFromPixelMap", "errCode is not IMAGE_SUCCESS"); + return nullptr; + } + if (pixelmap == nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CreateDescriptorFromPixelMap", "pixelmap is null"); + return nullptr; + } + return OH_ArkUI_DrawableDescriptor_CreateFromPixelMap(pixelmap); +} + +static ArkUI_ImageAnimatorFrameInfo* SetDrawableBasicData(ArkUI_DrawableDescriptor* drawable, ImageFrameProps& props) +{ + auto imageFrame = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromDrawableDescriptor(drawable); + ImageAnimatorCommon::SetImageFrameInfo(imageFrame, props); + return imageFrame; +} + +napi_value ImageAnimatorFrameInfoTest::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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + char* imageUrls[] = { + "./resources/base/media/background_red.png", + "./resources/base/media/background_green.png", + "./resources/base/media/background_blue.png", + }; + ImageFrameProps props = { SIZE_300, SIZE_300, SIZE_10, SIZE_30, SIZE_3000 }; + std::vector vec; + for (char* url : imageUrls) { + auto item = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(url); + vec.push_back(item); + ImageAnimatorCommon::SetImageFrameInfo(vec.back(), props); + } + auto imageAnimator = CreateImageAnimator(vec); + // parent node + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorFrameInfoTest::CreateNativeNodeAbnormal(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageFrameInfoTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + char* urlFirst = "./resources/base/media/background_red.png"; + auto frameFirst = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(urlFirst); + ImageFrameProps propsFirst = { SIZE_150, SIZE_150, 0, PARAM_NEGATIVE_5, SIZE_3000 }; + ImageAnimatorCommon::SetImageFrameInfo(frameFirst, propsFirst); + char* urlSecond = "./resources/base/media/background_green.png"; + auto frameSecond = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(urlSecond); + ImageFrameProps propsSecond = { PARAM_NEGATIVE_100, PARAM_NEGATIVE_100, PARAM_NEGATIVE_100, PARAM_NEGATIVE_100, + napi_undefined }; + ImageAnimatorCommon::SetImageFrameInfo(frameSecond, propsSecond); + char* urlThird = "./resources/base/media/icon.png"; + auto frameThird = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(urlThird); + ImageFrameProps propsThird = { SIZE_500, SIZE_800, 0, 0, SIZE_3000 }; + ImageAnimatorCommon::SetImageFrameInfo(frameThird, propsThird); + std::vector vec = { frameFirst, frameSecond, frameThird }; + auto imageAnimator = CreateImageAnimator(vec); + // parent node + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorFrameInfoTest::CreateNativeNodeDrawable(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + OH_Pixelmap_InitializationOptions* createOpts = nullptr; + OH_PixelmapNative* pixelmap = nullptr; + auto drawDes = CreateDescriptorFromPixelMap(createOpts, pixelmap); + if (drawDes == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", "Descriptor is null"); + return nullptr; + } + + ImageFrameProps propsFirst = { SIZE_50, SIZE_300, SIZE_10, SIZE_100, SIZE_3000 }; + auto frameFirst = SetDrawableBasicData(drawDes, propsFirst); + ImageFrameProps propsSecond = { SIZE_100, SIZE_100, SIZE_10, SIZE_10, SIZE_3000 }; + auto frameSecond = SetDrawableBasicData(drawDes, propsSecond); + ImageFrameProps propsThird = { SIZE_300, SIZE_100, SIZE_10, SIZE_10, SIZE_3000 }; + auto frameThird = SetDrawableBasicData(drawDes, propsThird); + std::vector vec = { frameFirst, frameSecond, frameThird }; + auto imageAnimator = CreateImageAnimator(vec); + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + OH_PixelmapNative_Release(pixelmap); + OH_PixelmapInitializationOptions_Release(createOpts); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorFrameInfoTest::CreateNativeNodeDrawableAbnormal(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + OH_Pixelmap_InitializationOptions* createOpts = nullptr; + OH_PixelmapNative* pixelmap = nullptr; + auto drawDes = CreateDescriptorFromPixelMap(createOpts, pixelmap); + ImageFrameProps propsFirst = { SIZE_500, SIZE_800, SIZE_10, SIZE_100, SIZE_3000 }; + auto frameFirst = SetDrawableBasicData(drawDes, propsFirst); + ImageFrameProps propsSecond = { PARAM_NEGATIVE_5, SIZE_150, SIZE_10, SIZE_10, SIZE_3000 }; + auto frameSecond = SetDrawableBasicData(drawDes, propsSecond); + ImageFrameProps propsThird = { SIZE_300, SIZE_300, SIZE_10, SIZE_10, SIZE_3000 }; + auto frameThird = SetDrawableBasicData(drawDes, propsThird); + std::vector vec = { frameFirst, frameSecond, frameThird }; + auto imageAnimator = CreateImageAnimator(vec); + // parent node + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + OH_PixelmapNative_Release(pixelmap); + OH_PixelmapInitializationOptions_Release(createOpts); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorFrameInfoTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.h new file mode 100644 index 0000000000000000000000000000000000000000..db1607df4c7c6a38eb91e4a7787375c279d050dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_frameinfo_test.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGEANIMATOR_FRAMEINFO_TEST_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_FRAMEINFO_TEST_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/common.h" +#include "napi/native_api.h" + +namespace ArkUICApiDemo { + +class ImageAnimatorFrameInfoTest { +public: + ~ImageAnimatorFrameInfoTest(); + // ImageAnimatorFrameInfoTest:testImageAnimatorFrameInfoTest001 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + // ImageAnimatorFrameInfoTest:testImageAnimatorFrameInfoTest002 + static napi_value CreateNativeNodeAbnormal(napi_env env, napi_callback_info info); + // ImageAnimatorFrameInfoTest:testImageAnimatorFrameInfoTest003 + static napi_value CreateNativeNodeDrawable(napi_env env, napi_callback_info info); + // ImageAnimatorFrameInfoTest:testImageAnimatorFrameInfoTest004 + static napi_value CreateNativeNodeDrawableAbnormal(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_FRAMEINFO_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89add00a807c8213bfb0b481a39efcd127c44f7b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.cpp @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2024 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 "imageanimator_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" +#include "button_component.h" +#include "column_component.h" +#include "imageanimator_common.h" +#include "imageanimator_component.h" +#include "text_component.h" + +namespace ArkUICApiDemo { + +static std::shared_ptr CreateImageAnimator(ImageFrameProps& properties, bool fixed = false) +{ + std::vector vec; + char* imageUrls[] = { + "./resources/base/media/icon.png", + "./resources/base/media/background_green.png", + "./resources/base/media/background_red.png", + "./resources/base/media/background_yellow.png", + "./resources/base/media/background_blue.png", + }; + for (char* url : imageUrls) { + auto item = OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(url); + vec.push_back(item); + if (!fixed) { + ImageAnimatorCommon::SetImageFrameInfo(vec.back(), properties); + } + } + auto imageAnimator = std::make_shared(); + imageAnimator->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + imageAnimator->SetIteration(1); + imageAnimator->SetMargin(PARAM_10); + imageAnimator->SetFixedSize(fixed); + imageAnimator->SetReverse(false); + imageAnimator->SetFillMode(ARKUI_ANIMATION_FILL_MODE_FORWARDS); + imageAnimator->SetImage(vec); + return imageAnimator; +} + +napi_value ImageAnimatorTest::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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + ImageFrameProps props = { SIZE_300, SIZE_100, SIZE_10, SIZE_30, SIZE_3000 }; + auto imageAnimator = CreateImageAnimator(props); + imageAnimator->SetState(ARKUI_ANIMATION_STATUS_INITIAL); + + auto imageAnimatorSecond = CreateImageAnimator(props); + imageAnimatorSecond->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + + auto imageAnimatorThird = CreateImageAnimator(props); + imageAnimatorThird->SetState(ARKUI_ANIMATION_STATUS_PAUSED); + + auto imageAnimatorFourth = CreateImageAnimator(props); + imageAnimatorFourth->SetState(ARKUI_ANIMATION_STATUS_STOPPED); + + auto imageAnimatorFifth = CreateImageAnimator(props); + imageAnimatorFifth->SetState(PARAM_NEGATIVE_1); + + auto imageAnimatorSixth = CreateImageAnimator(props); + imageAnimatorSixth->SetState(PARAM_4); + + // parent node + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + column->AddChild(imageAnimatorSecond); + column->AddChild(imageAnimatorThird); + column->AddChild(imageAnimatorFourth); + column->AddChild(imageAnimatorFifth); + column->AddChild(imageAnimatorSixth); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeDuration(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ImageFrameProps props = { SIZE_300, SIZE_300, SIZE_10, SIZE_30 }; + auto imageAnimator = CreateImageAnimator(props, true); + imageAnimator->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + imageAnimator->SetDuration(SIZE_3000); + imageAnimator->SetIteration(PARAM_NEGATIVE_1); + imageAnimator->SetWidth(SIZE_200); + imageAnimator->SetHeight(SIZE_100); + + auto imageAnimatorSecond = CreateImageAnimator(props, true); + imageAnimatorSecond->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + imageAnimatorSecond->SetDuration(0); + imageAnimatorSecond->SetIteration(PARAM_NEGATIVE_1); + imageAnimatorSecond->SetWidth(SIZE_200); + imageAnimatorSecond->SetHeight(SIZE_100); + + auto imageAnimatorThird = CreateImageAnimator(props, true); + imageAnimatorThird->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + imageAnimatorThird->SetDuration(PARAM_NEGATIVE_5); + imageAnimatorThird->SetIteration(PARAM_NEGATIVE_1); + imageAnimatorThird->SetWidth(SIZE_200); + imageAnimatorThird->SetHeight(SIZE_100); + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + column->AddChild(imageAnimatorSecond); + column->AddChild(imageAnimatorThird); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeReverse(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + ImageFrameProps props = { SIZE_300, SIZE_300, SIZE_10, SIZE_30, SIZE_2000 }; + auto animator = CreateImageAnimator(props); + animator->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + animator->SetReverse(false); + animator->SetFillMode(ARKUI_ANIMATION_FILL_MODE_FORWARDS); + + auto animatorSecond = CreateImageAnimator(props); + animatorSecond->SetState(ARKUI_ANIMATION_STATUS_RUNNING); + animatorSecond->SetReverse(true); + animatorSecond->SetFillMode(ARKUI_ANIMATION_FILL_MODE_BACKWARDS); + + auto column = new ColumnComponent(); + column->AddChild(animator); + column->AddChild(animatorSecond); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeFixedSize(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ImageFrameProps props = { SIZE_300, SIZE_300, SIZE_10, SIZE_30, SIZE_1000 }; + auto animator = CreateImageAnimator(props); + auto animatorSecond = CreateImageAnimator(props, true); + animatorSecond->SetWidth(SIZE_200); + animatorSecond->SetHeight(SIZE_100); + animatorSecond->SetDuration(SIZE_2000); + auto column = new ColumnComponent(); + column->AddChild(animator); + column->AddChild(animatorSecond); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeFillMode(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ImageFrameProps props = { SIZE_300, SIZE_100, SIZE_10, SIZE_30, SIZE_1000 }; + auto imageAnimator = CreateImageAnimator(props); + imageAnimator->SetFillMode(ARKUI_ANIMATION_FILL_MODE_NONE); + auto imageAnimatorSecond = CreateImageAnimator(props); + imageAnimatorSecond->SetFillMode(ARKUI_ANIMATION_FILL_MODE_FORWARDS); + auto imageAnimatorThird = CreateImageAnimator(props); + imageAnimatorThird->SetFillMode(ARKUI_ANIMATION_FILL_MODE_BACKWARDS); + auto imageAnimatorFourth = CreateImageAnimator(props); + imageAnimatorFourth->SetFillMode(ARKUI_ANIMATION_FILL_MODE_BOTH); + auto imageAnimatorFifth = CreateImageAnimator(props); + imageAnimatorFifth->SetFillMode(PARAM_NEGATIVE_1); + auto imageAnimatorSixth = CreateImageAnimator(props); + imageAnimatorSixth->SetFillMode(PARAM_4); + + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + column->AddChild(imageAnimatorSecond); + column->AddChild(imageAnimatorThird); + column->AddChild(imageAnimatorFourth); + column->AddChild(imageAnimatorFifth); + column->AddChild(imageAnimatorSixth); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeIteration(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + ImageFrameProps props = { SIZE_300, SIZE_100, SIZE_10, SIZE_30, SIZE_3000 }; + auto animator = CreateImageAnimator(props); + animator->SetIteration(1); + auto animatorSecond = CreateImageAnimator(props); + animatorSecond->SetIteration(0); + auto animatorThird = CreateImageAnimator(props); + animatorThird->SetIteration(PARAM_NEGATIVE_1); + + auto column = new ColumnComponent(); + column->AddChild(animator); + column->AddChild(animatorSecond); + column->AddChild(animatorThird); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} + +napi_value ImageAnimatorTest::CreateNativeNodeResetAttribute(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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ImageFrameProps props = { SIZE_300, SIZE_300, SIZE_10, SIZE_10, SIZE_3000 }; + auto imageAnimator = CreateImageAnimator(props, true); + imageAnimator->SetFillMode(ARKUI_ANIMATION_FILL_MODE_BACKWARDS); + imageAnimator->SetReverse(true); + imageAnimator->SetIteration(PARAM_NEGATIVE_1); + imageAnimator->SetDuration(SIZE_3000); + imageAnimator->SetWidth(SIZE_300); + imageAnimator->SetHeight(SIZE_200); + auto note = std::make_shared(); + note->SetWidth(SIZE_300); + note->SetHeight(SIZE_200); + note->SetBackgroundColor(COLOR_PINK); + auto button = std::make_shared(); + button->SetId("ResetImageAnimator"); + button->SetLable("ResetImageAnimator"); + button->SetMargin(PARAM_10); + button->RegisterOnClick([imageAnimator, note]() { + imageAnimator->resetAttribute(NODE_IMAGE_ANIMATOR_FILL_MODE); + imageAnimator->resetAttribute(NODE_IMAGE_ANIMATOR_FIXED_SIZE); + imageAnimator->resetAttribute(NODE_IMAGE_ANIMATOR_ITERATION); + imageAnimator->resetAttribute(NODE_IMAGE_ANIMATOR_REVERSE); + imageAnimator->resetAttribute(NODE_IMAGE_ANIMATOR_DURATION); + auto iterationItem = imageAnimator->getAttribute(NODE_IMAGE_ANIMATOR_ITERATION); + auto stateItem = imageAnimator->getAttribute(NODE_IMAGE_ANIMATOR_STATE); + auto fillItem = imageAnimator->getAttribute(NODE_IMAGE_ANIMATOR_FILL_MODE); + auto fixedSizeItem = imageAnimator->getAttribute(NODE_IMAGE_ANIMATOR_FIXED_SIZE); + std::string str = "iterationItem:" + std::to_string(iterationItem->value[0].i32) + "\n" + + "stateItem:" + std::to_string(stateItem->value[0].i32) + "\n" + + "fillItem:" + std::to_string(fillItem->value[0].i32) + "\n" + + "fixedSizeItem:" + std::to_string(fixedSizeItem->value[0].i32) + "\n"; + note->SetTextContent(str); + }); + auto column = new ColumnComponent(); + column->AddChild(imageAnimator); + column->AddChild(button); + column->AddChild(note); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageAnimatorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8e1ef35c0c2da1345b487e8171a5256333aaa0b5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/imageanimator/imageanimator_test.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGEANIMATOR_TEST_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { +class ImageAnimatorTest { +public: + ~ImageAnimatorTest(); + // ImageAnimatorTest:testImageAnimatorTest001 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest002 + static napi_value CreateNativeNodeDuration(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest003 + static napi_value CreateNativeNodeReverse(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest004 + static napi_value CreateNativeNodeFixedSize(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest005 + static napi_value CreateNativeNodeFillMode(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest006 + static napi_value CreateNativeNodeIteration(napi_env env, napi_callback_info info); + // ImageAnimatorTest:testImageAnimatorTest007 + static napi_value CreateNativeNodeResetAttribute(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1a052cd14a2d4faf31964e32ee40181ec8eac383 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2024 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 "plugin_manager.h" + +#include +#include +#include + +#include "./common/common.h" + +namespace ArkUICApiDemo { +PluginManager PluginManager::pluginManager_; + +PluginManager::~PluginManager() +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", "~PluginManager"); + for (auto iter = nativeXComponentMap_.begin(); iter != nativeXComponentMap_.end(); ++iter) { + if (iter->second != nullptr) { + delete iter->second; + iter->second = nullptr; + } + } + nativeXComponentMap_.clear(); +} + +napi_value PluginManager::GetContext(napi_env env, napi_callback_info info) +{ + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetContext env or info is null"); + return nullptr; + } + + size_t argCnt = 1; + napi_value args[1] = { nullptr }; + if (napi_get_cb_info(env, info, &argCnt, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetContext napi_get_cb_info failed"); + } + + if (argCnt != 1) { + napi_throw_type_error(env, NULL, "Wrong number of arguments"); + return nullptr; + } + + napi_valuetype valuetype; + if (napi_typeof(env, args[0], &valuetype) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_typeof failed"); + return nullptr; + } + + if (valuetype != napi_number) { + napi_throw_type_error(env, NULL, "Wrong type of arguments"); + return nullptr; + } + + int64_t value; + if (napi_get_value_int64(env, args[0], &value) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_get_value_int64 failed"); + return nullptr; + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +void PluginManager::Export(napi_env env, napi_value exports) +{ + if ((env == nullptr) || (exports == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: env or exports is null"); + return; + } + + napi_value exportInstance = nullptr; + if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_get_named_property fail"); + return; + } + + OH_NativeXComponent* nativeXComponent = nullptr; + if (napi_unwrap(env, exportInstance, reinterpret_cast(&nativeXComponent)) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_unwrap fail"); + return; + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_unwrap success"); + } + + char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = { '\0' }; + uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1; + if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: OH_NativeXComponent_GetXComponentId fail"); + return; + } + + std::string id(idStr); + auto context = PluginManager::GetInstance(); + if ((context != nullptr) && (nativeXComponent != nullptr)) { + context->SetNativeXComponent(id, nativeXComponent); + } +} + +void PluginManager::SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent) +{ + if (nativeXComponent == nullptr) { + return; + } + + if (nativeXComponentMap_.find(id) == nativeXComponentMap_.end()) { + nativeXComponentMap_[id] = nativeXComponent; + return; + } + + if (nativeXComponentMap_[id] != nativeXComponent) { + OH_NativeXComponent* tmp = nativeXComponentMap_[id]; + delete tmp; + tmp = nullptr; + nativeXComponentMap_[id] = nativeXComponent; + } +} + +OH_NativeXComponent* PluginManager::GetNativeXComponent(std::string& id) +{ + if (nativeXComponentMap_.find(id) == nativeXComponentMap_.end()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetNativeXComponent.%{public}s == nullptr", + id.c_str()); + return nullptr; + } + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", + "nativeXComponentMap_[%{public}s] == %{public}p", id.c_str(), nativeXComponentMap_[id]); + return nativeXComponentMap_[id]; +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h new file mode 100755 index 0000000000000000000000000000000000000000..6ee79d601f5b1512be5baee3d3628e43691b9474 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 NATIVE_XCOMPONENT_PLUGIN_MANAGER_H +#define NATIVE_XCOMPONENT_PLUGIN_MANAGER_H + +#include +#include +#include +#include +#include + +namespace ArkUICApiDemo { +class PluginManager { +public: + ~PluginManager(); + + static PluginManager* GetInstance() + { + return &PluginManager::pluginManager_; + } + + static napi_value GetContext(napi_env env, napi_callback_info info); + + void SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent); + OH_NativeXComponent* GetNativeXComponent(std::string& id); + void Export(napi_env env, napi_value exports); + +private: + static PluginManager pluginManager_; + + std::unordered_map nativeXComponentMap_; +}; +} // namespace ArkUICApiDemo +#endif // NATIVE_XCOMPONENT_PLUGIN_MANAGER_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6d6cdda843797b854bd24f94c80eca00bddb11ae --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 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 "imageanimator/imageanimator_frameinfo_test.h" +#include "imageanimator/imageanimator_test.h" +#include "manager/plugin_manager.h" +#include "toggle/toggle_unselectedcolor_test.h" + +using namespace ArkUICApiDemo; + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "Init begins"); + if ((env == nullptr) || (exports == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "env or exports is null"); + return nullptr; + } + + napi_property_descriptor desc[] = { + { "toggleUnSelectedColorTest", nullptr, ToggleUnSelectedColorTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "imageFrameInfoTest", nullptr, ImageAnimatorFrameInfoTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "imageFrameInfoAbnormalTest", nullptr, ImageAnimatorFrameInfoTest::CreateNativeNodeAbnormal, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "imageFrameInfoDrawableTest", nullptr, ImageAnimatorFrameInfoTest::CreateNativeNodeDrawable, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "imageFrameInfoDrawableAbnormalTest", nullptr, ImageAnimatorFrameInfoTest::CreateNativeNodeDrawableAbnormal, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "imageAnimatorTest", nullptr, ImageAnimatorTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "imageAnimatorDurationTest", nullptr, ImageAnimatorTest::CreateNativeNodeDuration, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "imageAnimatorReverseTest", nullptr, ImageAnimatorTest::CreateNativeNodeReverse, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "imageAnimatorFixedSizeTest", nullptr, ImageAnimatorTest::CreateNativeNodeFixedSize, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "imageAnimatorFillModeTest", nullptr, ImageAnimatorTest::CreateNativeNodeFillMode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "imageAnimatorIterationsTest", nullptr, ImageAnimatorTest::CreateNativeNodeIteration, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "imageAnimatorResetAttributeTest", nullptr, ImageAnimatorTest::CreateNativeNodeResetAttribute, nullptr, + nullptr, nullptr, napi_default, nullptr }, + }; + if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "napi_define_properties failed"); + return nullptr; + } + + ArkUICApiDemo::PluginManager::GetInstance()->Export(env, exports); + return exports; +} +EXTERN_C_END + +static napi_module nativerenderModule = { .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "nativerender", + .nm_priv = ((void*)0), + .reserved = { 0 } }; + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&nativerenderModule); +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f5c46d80ea669ff91acf6b333a8bb6beeab6408 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 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 "toggle_unselectedcolor_test.h" + +#include + +#include "../manager/plugin_manager.h" +#include "button_component.h" +#include "column_component.h" +#include "text_component.h" +#include "toggle_component.h" + +#define ON_CHANGE_TOGGLE_EVENT_ID 6006 +namespace ArkUICApiDemo { + +static std::shared_ptr CreateToggle(uint32_t value) +{ + auto toggle = std::make_shared(); + toggle->SetUnselectedColor(value); + toggle->SetToggleValue(false); + toggle->SetMargin(SIZE_30); + return toggle; +} + +static std::shared_ptr CreateTextComponent() +{ + auto note = std::make_shared(); + note->SetWidth(SIZE_300); + note->SetHeight(SIZE_50); + note->SetBackgroundColor(COLOR_PINK); + note->SetMargin(PARAM_10); + return note; +} + +napi_value ToggleUnSelectedColorTest::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); + size_t length = PARAM_64; + size_t strLength = 0; + char xComponentID[PARAM_64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ToggleUnSelectedColorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto toggle_first = CreateToggle(0xFFFF0000); + auto toggle_second = CreateToggle(COLOR_RED); + auto toggle_third = CreateToggle(SIZE_100); + auto toggle_reset = CreateToggle(0xFFFF0000); + auto note = CreateTextComponent(); + auto button = std::make_shared(); + button->SetId("ResetToggle"); + button->SetLable("ResetToggle"); + button->RegisterOnClick([toggle_reset, note]() { + toggle_reset->resetAttribute(NODE_TOGGLE_UNSELECTED_COLOR); + auto colorItem = toggle_reset->getAttribute(NODE_TOGGLE_UNSELECTED_COLOR); + std::string str = "colorItem:" + std::to_string(colorItem->value[0].u32) + "\n"; + note->SetTextContent(str); + }); + auto column = new ColumnComponent(); + column->AddChild(toggle_first); + column->AddChild(toggle_second); + column->AddChild(toggle_third); + column->AddChild(toggle_reset); + column->AddChild(button); + column->AddChild(note); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), + column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ToggleUnSelectedColorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..16190be55f7b80330d13ed9d7ff118f90fd2405a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/toggle/toggle_unselectedcolor_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_TOGGLE_UNSELECTEDCOLOR_TEST_H +#define ARKUI_CAPI_DEMO_TOGGLE_UNSELECTEDCOLOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class ToggleUnSelectedColorTest { +public: + ~ToggleUnSelectedColorTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TOGGLE_UNSELECTEDCOLOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..b93e462202442dbde6c516fc7587a287a547e284 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 toggleUnSelectedColorTest: (a: string) => void; + +export const imageFrameInfoTest: (a: string) => void; + +export const imageFrameInfoAbnormalTest: (a: string) => void; + +export const imageFrameInfoDrawableTest: (a: string) => void; + +export const imageFrameInfoDrawableAbnormalTest: (a: string) => void; + +export const imageAnimatorTest: (a: string) => void; + +export const imageAnimatorDurationTest: (a: string) => void; + +export const imageAnimatorReverseTest: (a: string) => void; + +export const imageAnimatorFixedSizeTest: (a: string) => void; + +export const imageAnimatorFillModeTest: (a: string) => void; + +export const imageAnimatorIterationsTest: (a: string) => void; + +export const imageAnimatorResetAttributeTest: (a: string) => void; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c696c592ecfee7f80e46f55e790cf8353ede0fb9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libnativerender.so", + "types": "./index.d.ts", + "version": "0.1.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1ee72503510a6c6a0d7a6c684c4d5bb9b6c1aad7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..831ac54dfe1ba983183a629f64819a0366d0c325 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..c7f4ee43788d45f15e56fb439ccf4f4b9aee167e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets b/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..4916aa2b5f51b09d6113574a586e25fe2ce8682c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 render from "libnativerender.so" +@Entry +@Component +struct Index { + build() { + Column() { + Column() { + + XComponent({ + id: 'xComponentId', + type: XComponentType.NODE, + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }).onAppear(() => { + + }).width('100%') + .height('100%') + }.margin({ + top: 27, + left: 12, + right: 12 + }) + .height('100%') + .width('100%') + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/module.json5 b/function/ui_compare/capidemo/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..8ac5e62f80c98914dd5680508a0177b99b91f913 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/module.json5 @@ -0,0 +1,45 @@ +{ + "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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/function/ui_compare/capidemo/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/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /dev/null +++ b/function/ui_compare/capidemo/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/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png new file mode 100755 index 0000000000000000000000000000000000000000..385aee55284cd8a5ebde3910bf82c494f057fecf Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png new file mode 100755 index 0000000000000000000000000000000000000000..742044d80325e183663d8dffd8a2e5a37c6bed90 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png new file mode 100755 index 0000000000000000000000000000000000000000..1fa2f73575caef6b5fcf736b6eb2e8ff34802713 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png new file mode 100755 index 0000000000000000000000000000000000000000..adb226051b3771a741509382c683606d029e5b25 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json b/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..16cf3219a2997a071cd6f0cd4816d3e173b18d15 --- /dev/null +++ b/function/ui_compare/capidemo/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/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg new file mode 100755 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..14bbd62cb9de385b1f5551945d749bb5e0e5fc2c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/en_US/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/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..cab069eb230dd1cc6d3c24cd0f1aa46d54af9cc9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..252a037b7bb5bb0fbeb7fc5fed3007a54b33392e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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 AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log('[Demo] MyAbilityStage onCreate'); + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..95e23de1a65c1baf1902e873a8252812cff9f025 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 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 Ability from '@ohos.app.ability.UIAbility'; +import Settings from '../test/common/Settings'; + +const TAG: string = '[createWindow]' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log(`${TAG} MainAbility onCreate`); + globalThis.abilityWant = want; + globalThis.abilityLaunchParam = launchParam; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log(`${TAG} MainAbility onDestroy`); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log(`${TAG} MainAbility onWindowStageCreate windowStage=` + windowStage); + globalThis.windowStage = windowStage; + globalThis.context = this.context; + + setTimeout(() => { + console.info(`${TAG} setTimeout`) + Settings.createWindow('MainAbility/pages/DemoIndex', { + width: 720, height: 1280, dpi: 230 + }) + }, 1000) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log(`${TAG} MainAbility onWindowStageDestroy`); + } + + onForeground() { + // Ability has brought to foreground + console.log(`${TAG} MainAbility onForeground`); + } + + onBackground() { + // Ability has back to background + console.log(`${TAG} MainAbility onBackground`); + } +}; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets new file mode 100755 index 0000000000000000000000000000000000000000..cd3064660aec25ff11ba1d30f4e9a335baad02b3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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. + */ + +@Component +export struct CommonView { + pageTag: string = ''; + + build() { + Column() { + Column({ space: 10 }) { + XComponent({ + id: this.pageTag, + type: 'node', + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }).backgroundColor('#FFEEEEEE') + .width('100%') + .height('100%') + }.margin(20) + .height('100%') + .width('100%') + } + .id(this.pageTag) + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets new file mode 100755 index 0000000000000000000000000000000000000000..a6b9102852b403ed32b49e742095547cfcc7a1cc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; + +@Entry +@Component +struct DemoIndex { + aboutToAppear() { + setTimeout(() => { + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, 2000) + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('ARKUI CAPI DEMO') + .fontSize(36) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorDurationTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorDurationTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b89f4ff414a17e540152eb3f27888743b89fc15 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorDurationTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorDurationTest { + PAGE_TAG: string = 'ImageAnimatorDurationTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorDurationTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFillModeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFillModeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..11220d1efea707edc6ef0fe66a68d02fbd5ad461 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFillModeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorFillModeTest { + PAGE_TAG: string = 'ImageAnimatorFillModeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorFillModeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFixedSizeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFixedSizeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..df439e60a4df2183e87b8b0aff05a1010b76571c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorFixedSizeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorFixedSizeTest { + PAGE_TAG: string = 'ImageAnimatorFixedSizeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorFixedSizeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorIterationsTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorIterationsTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..58550171d9e60f5491563d8ec602b2890ca65072 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorIterationsTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorIterationsTest { + PAGE_TAG: string = 'ImageAnimatorIterationsTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorIterationsTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorResetAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorResetAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..f819e90bbc8682d7afeeba319f95d57edb35a5af --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorResetAttributeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorResetAttributeTest { + PAGE_TAG: string = 'ImageAnimatorResetAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorResetAttributeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorReverseTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorReverseTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a67a2d801a1fff9049a8ffa9e6fa032f469c61d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorReverseTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageAnimatorReverseTest { + PAGE_TAG: string = 'ImageAnimatorReverseTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorReverseTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c1d020849184a0f9e7418d87ee057c0199f4e9f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageAnimatorTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageSrcTest { + PAGE_TAG: string = 'ImageAnimatorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageAnimatorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..15aea156ad0126f0aa1d1f672e18743460c75857 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoAbnormalTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageFrameInfoAbnormalTest { + PAGE_TAG: string = 'ImageFrameInfoAbnormalTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageFrameInfoAbnormalTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc4c23997fd56585a7fb311da04806578fe72579 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableAbnormalTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageFrameInfoDrawableAbnormalTest { + PAGE_TAG: string = 'ImageFrameInfoDrawableAbnormalTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageFrameInfoDrawableAbnormalTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0374b7d3668c0119bb5f8ac0abe8af7ee2d5f87 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoDrawableTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageFrameInfoDrawableTest { + PAGE_TAG: string = 'ImageFrameInfoDrawableTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageFrameInfoDrawableTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..6fdeb4046b1bb6e1a0f9a0207039d341cdafc5da --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/imageanimator/ImageFrameInfoTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ImageFrameInfoTest { + PAGE_TAG: string = 'ImageFrameInfoTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.imageFrameInfoTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/toggle/ToggleUnSelectedColorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/toggle/ToggleUnSelectedColorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..bad3343601367b01514da06b7c065f40715cea13 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/toggle/ToggleUnSelectedColorTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct ToggleUnSelectedColorTest { + PAGE_TAG: string = 'ToggleUnSelectedColorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.toggleUnSelectedColorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..890ed68f7fff2bf7207da62d490165f11d2622cf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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 toggleUnSelectedColorTest from './toggle/ToggleUnSelectedColorTest.test' +import imageAnimatorTest from './imageanimator/ImageAnimatorTest.test' +import imageFrameInfoTest from './imageanimator/ImageFrameInfoTest.test' + +export default function testsuite() { + toggleUnSelectedColorTest() + imageFrameInfoTest() + imageAnimatorTest() +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..1ad4cf063e2f0a6fe3fa8fb292f1dcf4f11b1b0b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 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 class ComponentInfo { + $type: string; + $rect: Object[]; +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts new file mode 100755 index 0000000000000000000000000000000000000000..9e47b1a646656f114dc650c0bdee25ee5fdad04e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 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 screen from '@ohos.screen'; +import window from '@ohos.window'; + +const TAG: string = '[SettingsCApiDemo]' + +class Settings { + sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + windowClass: window.Window = null + + //为悬浮窗设置位置 + changeWindowPosition(windowClass, X, Y) { + windowClass.moveWindowTo(X, Y, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to move the window. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + //为悬浮窗设置大小 + changeWindowSize(windowClass, width, height) { + windowClass.resize(width, height, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to change the window size. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + loadContent(windowClass, pageURI) { + //为悬浮窗加载对应的目标页面 + windowClass.setUIContent(pageURI, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in loading the content.`); + + //显示悬浮窗 + windowClass.showWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to show the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in showing the window.`); + }) + + }) + } + + // changeDpi(dpi) { + // let screenClass = null; + // screen.getAllScreens((err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to get all screens. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in geting all screens.`); + // + // screenClass = data[0]; + // //设置设备dpi + // screenClass.setDensityDpi(dpi, (err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to set the piexl density. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in seting the piexl density.`) + // }) + // }) + // } + + destroyWindow() { + //销毁窗口 + let windowClass = null; + try { + windowClass = window.findWindow('floatWindow'); + console.info(`${TAG}, find window success.`) + } catch (exception) { + console.error(`${TAG}, Fail to find the window. Cause: ${JSON.stringify(exception)}`); + } + windowClass.destroyWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to destroy the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in destroying the window.`) + }) + } + + createWindow(pageURI: String, {X=0,Y=0,width=1344,height=2560,dpi=400}={}) { + console.info(`${TAG}, params, pageURI=${pageURI}}, X=${X}, Y=${Y}, width=${width}, height=${height}, dpi=${dpi}`) + + // this.changeDpi(dpi); + this.sleep(1000); + let windowClass = null; + let config = { + name: 'floatWindow', windowType: window.WindowType.TYPE_FLOAT, ctx: globalThis.context + } + window.createWindow(config, (err, data) => { + if (err.code) { + console.error(`${TAG}, Fail to create the floatWindow. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in creating the floatWindow.`) + windowClass = data; + this.windowClass = data; + + this.changeWindowPosition(windowClass, X, Y) + this.changeWindowSize(windowClass, width, height) + this.loadContent(windowClass, pageURI) + }) + } +} + +export default new Settings() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts new file mode 100755 index 0000000000000000000000000000000000000000..827a1cb472983758539d2c9e278713cd72578f0b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2024 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 window from '@ohos.window'; +import image from '@ohos.multimedia.image'; +import fs from '@ohos.file.fs'; +import { Driver, Rect } from '@ohos.UiTest'; + +const TAG: string = '[WindowSnap]' +const INFO = { + 'img': { + prefix: 'IMG_', + suffix: '.webp' + }, + 'txt': { + prefix: 'TXT_', + suffix: '.txt' + } +} + +class WindowSnap { + async sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + createFile(context: any, type, page) { + console.info(`${TAG}, createFile start`) + let pathDir = context.filesDir; + console.info(`${TAG}, createFile pathDir = ${pathDir}`) + let name = page + let info = INFO[type] + let displayName = `${info.prefix}${name}${info.suffix}` + let filePath = pathDir + '/' + displayName + console.info(`${TAG}, createFile filePath = ${filePath}`) + let exists = fs.accessSync(filePath) + console.info(`${TAG}, oldFile exists = ${exists}`) + if (exists) { + fs.unlinkSync(filePath) + console.info(`${TAG}, remove file succeed`) + } + return fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) + } + + async save(data: image.PixelMap, context: any, page) { + console.info(`${TAG}, start save image`) + let packOpts: image.PackingOption = { + format: 'image/webp', quality: 100 + } + let imagePackerApi = image.createImagePacker() + let arrayBuffer = await imagePackerApi.packing(data, packOpts) + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + let fd = file.fd + console.info(`${TAG}, createFile fd = ${fd}`) + imagePackerApi.release() + try { + fs.writeSync(fd, arrayBuffer) + } catch (err) { + console.error(`${TAG}, write failed, code is ${err.code}, message is ${err.message}}`) + } + fs.closeSync(file) + console.info(`${TAG}, write picture done`) + } + + /** + * 获取窗口截图&文件保存 + * 入参必须为ability的context + * + * save:设备保存路径:/data/app/el2/100/base/{bundle_name}/haps/entry_test/files/IMG_test.webp + */ + async snapShot(context, page, done?) { + console.info(`${TAG}, start snapshot`) + await this.sleep(2000); + let windowClass = null + try { + windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotNext(context, page, done?) { + console.info(`${TAG}, start snapshot`) + let windowClass = null + try { + windowClass = window.findWindow('floatWindow'); + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + await this.sleep(600); + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotByDriver(context, page, done?) { + console.info(`Start snapshot by driver`) + await this.sleep(2000); + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + + try { + let windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + let windowRect = windowClass.getWindowProperties().windowRect; + console.info(`${TAG}, windowRct is ${JSON.stringify(windowRect)}`) + let driver = Driver.create(); + await driver.screenCapture(file.path, { + left: windowRect.left, + top: windowRect.top, + right: windowRect.width, + bottom: windowRect.height + }); + } catch (exception) { + console.error(`${TAG}, Failed to snap shot. Cause: ${JSON.stringify(exception)}`) + } + + if (done) { + done(); + } + } +} + +export default new WindowSnap() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets new file mode 100755 index 0000000000000000000000000000000000000000..da612f94c43222f36aa6d8816f256d12701fb0fd --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2024 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 events_emitter from '@ohos.events.emitter'; +import { Driver, ON, PointerMatrix, Rect } from '@ohos.UiTest'; +import { ComponentInfo } from './Interfaces'; +import systemDateTime from '@ohos.systemDateTime'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' +import fs from '@ohos.file.fs'; +import router from '@ohos.router'; + +export default class Utils { + static sleep(time: number) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve("ok") + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getSystemTime() { + return systemDateTime.getTime(true) / 1000 + } + + static getSandboxFileDir() { + let sandboxFileDir = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext().filesDir + "/" + console.log(`[getSandboxFileDir] return ${sandboxFileDir}`); + return sandboxFileDir; + } + + static deleteFile(filePath: string) { + console.info("[deleteFile] filePath:" + filePath); + try { + fs.unlinkSync(filePath) + } catch (error) { + console.info("[deleteFile] error:" + error); + } + } + + static isFileExist(filePath: string): boolean { + console.info("[isFileExist] filePath:" + filePath); + try { + let fileExist = fs.accessSync(filePath) + console.info("[isFileExist] return:" + fileExist); + return fileExist + } catch (error) { + console.info("[isFileExist] error:" + error); + return false + } + } + + static getComponentInfoByKey(key: string): ComponentInfo { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] current component info: ' + JSON.stringify(obj)); + return obj; + } + + + static async flingComponent(key: string, isHorizontal: boolean, isForward: boolean) { + let driver = Driver.create(); + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let X1 = centerX - 100; + let X2 = centerX + 100; + let Y1 = centerY - 100; + let Y2 = centerY + 100; + let stepLen = 20; + let speed = 10000; + if (isHorizontal) { + if (isForward) { + await driver.fling({ + x: X2, y: centerY + }, { + x: X1, y: centerY + }, stepLen, speed); + } else { + await driver.fling({ + x: X1, y: centerY + }, { + x: X2, y: centerY + }, stepLen, speed); + } + } else { + if (isForward) { + await driver.fling({ + x: centerX, y: Y2 + }, { + x: centerX, y: Y1 + }, stepLen, speed); + } else { + await driver.fling({ + x: centerX, y: Y1 + }, { + x: centerX, y: Y2 + }, stepLen, speed); + } + } + } + + static async clickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + } + + static async doubleClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + await component.click(); + } + + static async clickLocation(X: number, Y: number) { + let driver = Driver.create(); + await driver.click(X, Y); + } + + static async triggerKey(id: number) { + let driver = Driver.create(); + await driver.triggerKey(id); + } + + static async longClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.longClick(); + } + + static async clickComponentByText(text: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.text(text)); + await component.click(); + } + + static async fingerZoom(key: string, isOut: boolean) { + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let fingerUpCenterY = centerY - 100; + let fingerDownCenterY = centerY + 100; + let driver: Driver = Driver.create(); + let pointers: PointerMatrix = PointerMatrix.create(2, 3); + pointers.setPoint(0, 0, { + x: centerX, y: fingerUpCenterY - (isOut ? 40 : 120) + }); + pointers.setPoint(0, 1, { + x: centerX, y: fingerUpCenterY - 80 + }); + pointers.setPoint(0, 2, { + x: centerX, y: fingerUpCenterY - (isOut ? 120 : 40) + }); + pointers.setPoint(1, 0, { + x: centerX, y: fingerDownCenterY + (isOut ? 40 : 120) + }); + pointers.setPoint(1, 1, { + x: centerX, y: fingerDownCenterY + 80 + }); + pointers.setPoint(1, 2, { + x: centerX, y: fingerDownCenterY + (isOut ? 120 : 40) + }); + await driver.injectMultiPointerAction(pointers); + } + + static registerEvent(pageTag: string, eventId: number, callBack: Function) { + events_emitter.on({ + eventId: eventId, + priority: events_emitter.EventPriority.LOW + }, (eventData: events_emitter.EventData) => { + console.info("Value Change CallBack"); + if (eventData != null && eventData.data != null) { + if (pageTag == eventData.data.PAGE_TAG) { + console.info("CallBack value:" + JSON.stringify(eventData)); + callBack(eventData.data.VALUE); + } + } + }) + } + + static emitEvent(pageTag: string, emitValue: number | string | object, eventId: number) { + try { + let backData: events_emitter.EventData = { + data: { + "PAGE_TAG": pageTag, + "VALUE": emitValue + } + } + let backEvent: events_emitter.InnerEvent = { + eventId: eventId, + priority: events_emitter.EventPriority.LOW + } + console.info("start to emit page state"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit page state err: " + JSON.stringify(err)); + } + } + + static async pushPage(pageTag: string, done?: Function) { + let options: router.RouterOptions = { + url: `MainAbility/pages/${pageTag}`, + } + try { + router.clear(); + let pages = router.getState(); + console.info(`get ${pageTag} state success ` + JSON.stringify(pages)); + if (pageTag.indexOf(pages.name) < 0) { + console.info(`get ${pageTag} state success ` + JSON.stringify(pages.name)); + let result = await router.pushUrl(options); + await Utils.sleep(2000); + console.info(`push ${pageTag} page success ` + JSON.stringify(result)); + } + } catch (err) { + console.error(`push ${pageTag} page error: ` + err); + } + if (done) { + done(); + } + } + + static getComponentRect(key: string): Rect { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] key is: ' + key); + return Utils.getComponentRectByObj(obj); + } + + static getComponentRectByObj(obj: ComponentInfo): Rect { + console.info('[getInspectorByKey] current component is: ' + obj.$type); + let rectInfo: Object[] = JSON.parse('[' + obj.$rect + ']'); + let rect_value: Rect = { + left: JSON.parse('[' + rectInfo[0] + ']')[0], + top: JSON.parse('[' + rectInfo[0] + ']')[1], + right: JSON.parse('[' + rectInfo[1] + ']')[0], + bottom: JSON.parse('[' + rectInfo[1] + ']')[1] + }; + console.info(JSON.stringify(rect_value)); + return rect_value; + } + + static getRectHorizontalCenterX(rect: Rect): number { + return Number.parseInt(Number((rect.right - rect.left) / 2 + rect.left).toFixed(0)); + } + + static getRectVerticalCenterY(rect: Rect): number { + return Number.parseInt(Number((rect.bottom - rect.top) / 2 + rect.top).toFixed(0)); + } + + static async mouseMoveTo(X: number, Y: number) { + let driver = Driver.create(); + await driver.mouseMoveTo({ + x: X, y: Y + }); + } + + static async mouseMoveToCurrentComponent(componentId: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(componentId)); + let point = await component.getBounds(); + await driver.mouseMoveTo({ + x: point.left + 10, y: point.bottom - 10 + }); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageAnimatorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageAnimatorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..05a95291e82014a351ccf5c26b974e22ad13898f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageAnimatorTest.test.ets @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver } from '@ohos.UiTest'; + +async function doIt(done: Function) { + await Utils.sleep(2000) + WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(1000) + done() +} + +export default function imageAnimatorTest() { + describe('ImageAnimatorTest', () => { + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // ImageAnimator组件state属性设置正常值、异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_INITIAL, + // ARKUI_ANIMATION_STATUS_RUNNING, + // ARKUI_ANIMATION_STATUS_PAUSED, + // ARKUI_ANIMATION_STATUS_STOPPED, + // -1, + // 4 + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:100, left:10, top:30, duration:3000 + // NODE_IMAGE_ANIMATOR_ITERATION:1 + // NODE_IMAGE_ANIMATOR_FIXED_SIZE: false + // NODE_IMAGE_ANIMATOR_REVERSE: false + // NODE_IMAGE_ANIMATOR_FILL_MODE:ARKUI_ANIMATION_FILL_MODE_FORWARDS + it('testImageAnimator001', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件duration属性设置正常值、异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_DURATION:3000, 0, -5 + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:300, left:10, top:30 + // NODE_IMAGE_ANIMATOR_ITERATION: -1 + // NODE_IMAGE_ANIMATOR_FIXED_SIZE: true + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + // 组件宽度:200,高度:100 + it('testImageAnimator002', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorDurationTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件reverse属性设置正常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_REVERSE: true, false + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:100, left:10, top:30, duration:3000 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + // NODE_IMAGE_ANIMATOR_FILL_MODE:ARKUI_ANIMATION_FILL_MODE_FORWARDS, ARKUI_ANIMATION_FILL_MODE_BACKWARDS + it('testImageAnimator003', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorReverseTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件fixedSize属性设置正常值、异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_FIXED_SIZE: false, true + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:300, left:10, top:30, duration:1000 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + // 组件宽度:200,高度:100 + it('testImageAnimator004', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorFixedSizeTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件fillMode属性设置正常值、异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_FILL_MODE:ARKUI_ANIMATION_FILL_MODE_NONE, + // ARKUI_ANIMATION_FILL_MODE_FORWARDS, + // ARKUI_ANIMATION_FILL_MODE_BACKWARDS, + // ARKUI_ANIMATION_FILL_MODE_BOTH, + // -1, + // 4 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + // NODE_IMAGE_ANIMATOR_FIXED_SIZE: false + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:100, left:10, top:30, duration:1000 + it('testImageAnimator005', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorFillModeTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件iterations属性设置正常值、异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_IMAGES:输入5张图片, width:300, height:300, left:10, top:30, duration:3000 + // NODE_IMAGE_ANIMATOR_ITERATION: -5, 0, -1 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + it('testImageAnimator006', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorIterationsTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件reset fillMode, fixedSize, iteration属性显示结果测试 + // 触发Button组件onClick事件,事件内处理reset属性值 + it('testImageAnimator007', 0, async (done: Function) => { + let PAGE_TAG = 'ImageAnimatorResetAttributeTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await Utils.clickComponent("ResetImageAnimator"); + WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(5000) + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageFrameInfoTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageFrameInfoTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4b8c127adcbafe0badd36b9b0d4f00f38e80537 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/imageanimator/ImageFrameInfoTest.test.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 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, afterEach } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver } from '@ohos.UiTest'; + +async function doIt(done: Function) { + await Utils.sleep(2000) + WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(1000) + done() +} + +export default function imageFrameInfoTest() { + + describe('ImageFrameInfoTest', () => { + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // ImageAnimator组件ImageFrameInfo的src,width, height, left, top,duration设置正常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_IMAGES:输入3张图片 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + it('testImageFrameInfo001', 0, async (done: Function) => { + let PAGE_TAG = 'ImageFrameInfoTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件ImageFrameInfo的src,width, height, left, top,duration设置异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_IMAGES:输入3张图片 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + it('testImageFrameInfo002', 0, async (done: Function) => { + let PAGE_TAG = 'ImageFrameInfoAbnormalTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件ImageFrameInfo:src(drawable), width, height, left, top,duration设置正常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_IMAGES:输入3张图片 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + it('testImageFrameInfo003', 0, async (done: Function) => { + let PAGE_TAG = 'ImageFrameInfoDrawableTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + + // ImageAnimator组件ImageFrameInfo:src(drawable), width, height, left, top,duration设置异常值的显示效果测试 + // NODE_IMAGE_ANIMATOR_IMAGES:输入3张图片 + // NODE_IMAGE_ANIMATOR_STATE:ARKUI_ANIMATION_STATUS_RUNNING + it('testImageFrameInfo004', 0, async (done: Function) => { + let PAGE_TAG = 'ImageFrameInfoDrawableAbnormalTest'; + await Utils.pushPage(`imageanimator/${PAGE_TAG}`); + await doIt(done); + await Utils.sleep(2000); + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/toggle/ToggleUnSelectedColorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/toggle/ToggleUnSelectedColorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f27815134365e7e55434314c4d8911b9570d31f9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/toggle/ToggleUnSelectedColorTest.test.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function toggleUnSelectedColorTest() { + + describe('ToggleUnSelectedColorTest', () => { + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // Toggle组件触发NODE_TOGGLE_UNSELECTED_COLOR以及reset的显示效果测试 + // NODE_TOGGLE_VALUE:false + // NODE_TOGGLE_UNSELECTED_COLOR:0xFFFF0000,COLOR_RED,100 + // NODE_MARGIN:30 + it('testToggleUnSelectedColor001', 0, async (done: Function) => { + let PAGE_TAG = 'ToggleUnSelectedColorTest'; + await Utils.pushPage(`toggle/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await Utils.clickComponent("ResetToggle"); + WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(5000) + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100755 index 0000000000000000000000000000000000000000..02823b530ec8c6074063266c903d39823509bacf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 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 TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]); + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a MainAbility' + + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + let debug = abilityDelegatorArguments.parameters['-D']; + if (debug == 'true') { + cmd += ' -D'; + } + console.info('cmd : ' + cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }); + console.info('OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..d5c61594f391ce3885ed9482b43d28a0f3257a58 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 @@ -0,0 +1,47 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntry": "./ets/Application/AbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntry": "./ets/MainAbility/MainAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/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/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..789ad804a9877b106f6c08be3ad7dc31d1812eab --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json @@ -0,0 +1,24 @@ +{ + "float": [ + { + "name": "300vp", + "value": "300vp" + }, + { + "name": "200vp", + "value": "200vp" + }, + { + "name": "100vp", + "value": "100vp" + }, + { + "name": "50vp", + "value": "50vp" + } + ,{ + "name": "10vp", + "value": "10vp" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/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/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..bbe9979eda9db82793df2873701e4beae14c44cc Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png new file mode 100755 index 0000000000000000000000000000000000000000..0ec2e1692ed4a280147f41fa7491fa6595958153 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..4b68e9b07b4c30539ff093e43c193cfd61dc59fd Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg new file mode 100755 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..0245a9a9187849b2043ade5c9980fe92cd5ce9e1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json @@ -0,0 +1,17 @@ +{ + "src": [ + "MainAbility/pages/DemoIndex", + "MainAbility/pages/toggle/ToggleUnSelectedColorTest", + "MainAbility/pages/imageanimator/ImageFrameInfoTest", + "MainAbility/pages/imageanimator/ImageFrameInfoAbnormalTest", + "MainAbility/pages/imageanimator/ImageFrameInfoDrawableTest", + "MainAbility/pages/imageanimator/ImageFrameInfoDrawableAbnormalTest", + "MainAbility/pages/imageanimator/ImageAnimatorTest", + "MainAbility/pages/imageanimator/ImageAnimatorDurationTest", + "MainAbility/pages/imageanimator/ImageAnimatorReverseTest", + "MainAbility/pages/imageanimator/ImageAnimatorFixedSizeTest", + "MainAbility/pages/imageanimator/ImageAnimatorFillModeTest", + "MainAbility/pages/imageanimator/ImageAnimatorIterationsTest", + "MainAbility/pages/imageanimator/ImageAnimatorResetAttributeTest" + ] +} diff --git a/function/ui_compare/capidemo/hvigor/hvigor-config.json5 b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4886e292b5c51a798793e64804b56fd936d4f45 --- /dev/null +++ b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 @@ -0,0 +1,5 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/hvigorfile.ts b/function/ui_compare/capidemo/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..159890e9ee8c4dc8cfff2a03e6207edb86abb0b5 --- /dev/null +++ b/function/ui_compare/capidemo/hvigorfile.ts @@ -0,0 +1,6 @@ +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. */ +} diff --git a/function/ui_compare/capidemo/oh-package.json5 b/function/ui_compare/capidemo/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..43db2326cd8ae2711424045885d23a5c4c7bb394 --- /dev/null +++ b/function/ui_compare/capidemo/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} \ No newline at end of file