diff --git a/ArkUIKit/DrawableDescriptorSample/.gitignore b/ArkUIKit/DrawableDescriptorSample/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/AppScope/app.json5 b/ArkUIKit/DrawableDescriptorSample/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..88a035e9b13b9eb549359f3816ca3653a683bc7f --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.example.drawabledescriptorsample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/element/string.json b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..833ce65b7f60f6fed7641d995c6ff11cb80d41d1 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DrawableDescriptorSample" + } + ] +} diff --git a/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/background.png b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/foreground.png b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/layered_image.json b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/README_zh.md b/ArkUIKit/DrawableDescriptorSample/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..0966a6e1741f8acfab620ff66262c354c63aaa01 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/README_zh.md @@ -0,0 +1,62 @@ +# ArkUI使用drawableDescriptor指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好的理解并合理使用ArkUI提供的组件以及组件属性。该工程通过drawableDescriptor创建IMAGE组件并可以设置duration、iteration属性。该工程中代码详细描述可参考[显示图片 (Image)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.0-Release/zh-cn/application-dev/ui/arkts-graphics-display.md)。 + +### 效果预览 + +| 首页 | 设置属性 | +|------------------------------------|---------------------------------| +| ![](screenshots/device/image1.png) |![](screenshots/device/result.png) | + +### 使用说明 + +1. 在主界面,通过文本输入,设置属性值。 + +2. 在"设置duration"和"设置iteration"文本输入框中,分别输入属性值。 + +3. 分别点击"应用",查看已设置的属性值。 + +### 工程目录 +``` +entry/src/main/cpp +|---CMakeLists.txt // 编译脚本 +|---napi_init.cpp // 实现资源创建、属性设置 +|---drawable_manager.cpp // 管理drawableDescriptor节点 +|---types + |---Index.d.ts // napi对外接口定义 +entry/src/main/ets/ +|---entryability +|---pages +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---index.test.ets // 示例代码测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例支持标准系统上运行, 支持设备:RK3568等。 + +2.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.47,镜像版本号:OpenHarmony_5.0.2.57。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUIDocSample/DrawableDescriptorSample > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/build-profile.json5 b/ArkUIKit/DrawableDescriptorSample/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c5c306c17201eac740b3cd0f643265c4115a7e8e --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "compatibleSdkVersion": 20, + "targetSdkVersion": 20, + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/code-linter.json5 b/ArkUIKit/DrawableDescriptorSample/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/code-linter.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/.gitignore b/ArkUIKit/DrawableDescriptorSample/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/build-profile.json5 b/ArkUIKit/DrawableDescriptorSample/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..fcbb581c6ee4e176c8656bcd80f0b20493e5cfd4 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/build-profile.json5 @@ -0,0 +1,40 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["armeabi-v7a","arm64-v8a","x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/hvigorfile.ts b/ArkUIKit/DrawableDescriptorSample/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/obfuscation-rules.txt b/ArkUIKit/DrawableDescriptorSample/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/oh-package.json5 b/ArkUIKit/DrawableDescriptorSample/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..75d2e499a804dc9c4875b133326ee877cc980c65 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..d7612559e4b2182dff7d488f7f0cde5b86e47d49 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,28 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(DrawableDescriptorSample) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +find_library( + libace-lib + ace_ndk.z +) + +# 查找系统库 +find_library(ace_ndk_lib ace_ndk.z.so image_lib image.z.so) + +add_library(entry SHARED napi_init.cpp drawable_manager.cpp) +target_link_libraries(entry PUBLIC + ${libace-lib} + libace_napi.z.so + libpixelmap_ndk.z.so + libhilog_ndk.z.so +) \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.cpp b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1360b8387ea9bd70e4ac49af30490640c2870ebe --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "drawable_manager.h" + +DrawableManager& DrawableManager::GetInstance() +{ + static DrawableManager instance; + return instance; +} + +DrawableManager::~DrawableManager() +{ + std::lock_guard lock(mutex_); + for (auto& pair : drawableMap_) { + if (pair.second != nullptr) { + OH_ArkUI_DrawableDescriptor_Dispose(pair.second); + } + } + drawableMap_.clear(); +} + +int32_t DrawableManager::AddDrawable(ArkUI_DrawableDescriptor* descriptor) +{ + if (descriptor == nullptr) { + return -1; + } + + std::lock_guard lock(mutex_); + int32_t id = nextId_++; + drawableMap_[id] = descriptor; + return id; +} + +ArkUI_DrawableDescriptor* DrawableManager::GetDrawable(int32_t id) +{ + std::lock_guard lock(mutex_); + auto it = drawableMap_.find(id); + if (it != drawableMap_.end()) { + return it->second; + } + return nullptr; +} + +void DrawableManager::RemoveDrawable(int32_t id) +{ + std::lock_guard lock(mutex_); + auto it = drawableMap_.find(id); + if (it != drawableMap_.end()) { + if (it->second != nullptr) { + OH_ArkUI_DrawableDescriptor_Dispose(it->second); + } + drawableMap_.erase(it); + } +} + \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.h b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.h new file mode 100755 index 0000000000000000000000000000000000000000..b67de298ea0854a639f74083d1b70b5a5640d475 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/drawable_manager.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DRAWABLE_MANAGER_H +#define DRAWABLE_MANAGER_H + +#include +#include +#include + +class DrawableManager { +public: + static DrawableManager& GetInstance(); + + DrawableManager(const DrawableManager&) = delete; + DrawableManager& operator=(const DrawableManager&) = delete; + + int32_t AddDrawable(ArkUI_DrawableDescriptor* descriptor); + + ArkUI_DrawableDescriptor* GetDrawable(int32_t id); + + void RemoveDrawable(int32_t id); + +private: + DrawableManager() = default; + ~DrawableManager(); + + std::map drawableMap_; + std::mutex mutex_; + int32_t nextId_ = 1; +}; + +#endif // DRAWABLE_MANAGER_H + \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/napi_init.cpp new file mode 100755 index 0000000000000000000000000000000000000000..430be3cd95f4ff99792b47c32f29b3a2ed9bda91 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "drawable_manager.h" +#include +#include +#include +#include +#include +#include + +// 从PixelMap创建Drawable描述符 +static napi_value CreateFromPixelMap(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); + + void *temp = nullptr; + napi_unwrap(env, args[0], &temp); + OH_PixelmapNative *nativePixelMap = reinterpret_cast(temp); + + ArkUI_DrawableDescriptor *descriptor = OH_ArkUI_DrawableDescriptor_CreateFromPixelMap(nativePixelMap); + if (descriptor == nullptr) { + return nullptr; + } + + OH_PixelmapNative *newHandle = OH_ArkUI_DrawableDescriptor_GetStaticPixelMap(descriptor); + if (nativePixelMap == newHandle) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "Drawable", "GetStaticPixelMap success"); + } + + int32_t imagePixelMapId = DrawableManager::GetInstance().AddDrawable(descriptor); + napi_value result; + napi_create_int32(env, imagePixelMapId, &result); + return result; +} + +// 从PixelMap创建Drawable描述符 +static napi_value CreateFromAnimatedPixelMap(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + void *temp = nullptr; + napi_unwrap(env, args[0], &temp); + OH_PixelmapNative *nativePixelMapArray = reinterpret_cast(temp); + + int32_t size; + napi_get_value_int32(env, args[1], &size); + + // 创建Drawable描述符 + ArkUI_DrawableDescriptor *descriptor = OH_ArkUI_DrawableDescriptor_CreateFromAnimatedPixelMap( + &nativePixelMapArray, size); + if (descriptor == nullptr) { + return nullptr; + } + + OH_PixelmapNativeHandle *newHandle = OH_ArkUI_DrawableDescriptor_GetAnimatedPixelMapArray(descriptor); + if (nativePixelMapArray == *newHandle) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "Drawable", "GetAnimatedPixelMapArray success"); + } + int32_t arraySize = OH_ArkUI_DrawableDescriptor_GetAnimatedPixelMapArraySize(descriptor); + if (arraySize == size) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "Drawable", "GetAnimatedPixelMapArraySize success"); + } + + // 将Drawable添加到管理器并获取ID + int32_t imagePixelMapId = DrawableManager::GetInstance().AddDrawable(descriptor); + napi_value result; + napi_create_int32(env, imagePixelMapId, &result); + return result; +} + +// 释放Drawable描述符 +static napi_value DisposeDrawable(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t imagePixelMapId; + napi_get_value_int32(env, args[0], &imagePixelMapId); + DrawableManager::GetInstance().RemoveDrawable(imagePixelMapId); + return nullptr; +} + +static napi_value SetAnimationDuration(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t imagePixelMapId; + napi_get_value_int32(env, args[0], &imagePixelMapId); + int32_t duration; + napi_get_value_int32(env, args[1], &duration); + + ArkUI_DrawableDescriptor* descriptor = DrawableManager::GetInstance().GetDrawable(imagePixelMapId); + if (descriptor == nullptr) { + return nullptr; + } + OH_ArkUI_DrawableDescriptor_SetAnimationDuration(descriptor, duration); + return nullptr; +} + +static napi_value GetAnimationDuration(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t imagePixelMapId; + napi_get_value_int32(env, args[0], &imagePixelMapId); + + ArkUI_DrawableDescriptor* descriptor = DrawableManager::GetInstance().GetDrawable(imagePixelMapId); + if (descriptor == nullptr) { + return nullptr; + } + + // 获取动画时长 + int32_t duration = OH_ArkUI_DrawableDescriptor_GetAnimationDuration(descriptor); + napi_value result; + napi_create_int32(env, duration, &result); + return result; +} + + +static napi_value SetAnimationIteration(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t imagePixelMapId; + napi_get_value_int32(env, args[0], &imagePixelMapId); + int32_t iteration; + napi_get_value_int32(env, args[1], &iteration); + // 获取Drawable描述符 + ArkUI_DrawableDescriptor* descriptor = DrawableManager::GetInstance().GetDrawable(imagePixelMapId); + if (descriptor == nullptr) { + return nullptr; + } + OH_ArkUI_DrawableDescriptor_SetAnimationIteration(descriptor, iteration); + return nullptr; +} + +static napi_value GetAnimationIteration(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 解析参数 + int32_t imagePixelMapId; + napi_get_value_int32(env, args[0], &imagePixelMapId); + + ArkUI_DrawableDescriptor* descriptor = DrawableManager::GetInstance().GetDrawable(imagePixelMapId); + if (descriptor == nullptr) { + return nullptr; + } + int32_t iteration = OH_ArkUI_DrawableDescriptor_GetAnimationIteration(descriptor); + napi_value result; + napi_create_int32(env, iteration, &result); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + // 注册Native方法到ArkTS + napi_property_descriptor desc[] = { + {"createFromPixelMap", nullptr, CreateFromPixelMap, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createFromAnimatedPixelMap", nullptr, CreateFromAnimatedPixelMap, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"disposeDrawable", nullptr, DisposeDrawable, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setAnimationDuration", nullptr, SetAnimationDuration, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAnimationDuration", nullptr, GetAnimationDuration, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setAnimationIteration", nullptr, SetAnimationIteration, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAnimationIteration", nullptr, GetAnimationIteration, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc)/sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..a5ac31e915fc792a0a2b8ac1430d63bb56f6653b --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import image from "@ohos.multimedia.image"; + +export const createFromPixelMap: (pMap: image.PixelMap) => number; +export const createFromAnimatedPixelMap: (pMap: image.PixelMap, size: number) => number; +export const disposeDrawable: (imagePixelMapId: number) => void; +export const setAnimationDuration: (imagePixelMapId: number, duration: number) => void; +export const getAnimationDuration: (imagePixelMapId: number) => number; +export const setAnimationIteration: (imagePixelMapId: number, iteration: number) => void; +export const getAnimationIteration: (imagePixelMapId: number) => number; \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c69ca2198f11d3288b2ac61227a583604b647c78 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..44bcd860455af6a6737d6952e09d47807be58e45 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..ced5661da1d94764d0ac8f5b902ae0683b942606 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/pages/Index.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..7074e40dfe2dea6a9ba01f00ac1253baf515d238 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import image from '@ohos.multimedia.image'; +import hilog from '@ohos.hilog'; +import testNapi from 'libentry.so'; + +const TAG = 'DrawableDemo'; + +@Entry +@Component +struct DrawablePage { + @State imagePixelMap: image.PixelMap | null = null + @State imagePixelMapId: number = -1 // 用于存储图片描述符的引用ID + + @State imagePixelMapArray: image.PixelMap | null = null + @State imagePixelMapArrayId: number = -1 // 用于存储图片描述符的引用ID + @State animationDuration: number = 0 + @State newDuration: number = 1000 + @State animationIteration: number = 0 + @State newIteration: number = 10 + + async aboutToAppear() { + // 从资源加载图片并转换为PixelMap + await this.loadImageFromResource(); + await this.loadImageArrayFromResource(); + } + + // 从资源加载图片并转换为PixelMap + async loadImageFromResource() { + try { + const resMgr = getContext().resourceManager; + const imageData = await resMgr.getRawFileContent('startIcon.png'); + + // 创建图像解码器 + const imageSource = image.createImageSource(imageData.buffer); + const pixelMap = await imageSource.createPixelMap({}); + + this.imagePixelMap = pixelMap; + hilog.info(0x0000, TAG, '图片startIcon加载成功'); + + // 从PixelMap创建Drawable描述符 + this.createPixelMap(); + } catch (err) { + hilog.error(0x0000, TAG, `图片startIcon加载失败: ${JSON.stringify(err)}`); + } + } + + async loadImageArrayFromResource() { + try { + const resMgr = getContext().resourceManager; + const imageData = await resMgr.getRawFileContent('test.jpg'); + + // 创建图像解码器 + const imageSource = image.createImageSource(imageData.buffer); + const pixelMap = await imageSource.createPixelMap({}); + + this.imagePixelMapArray = pixelMap; + hilog.info(0x0000, TAG, '图片test加载成功'); + + this.createPixelMapAarry(); + } catch (err) { + hilog.error(0x0000, TAG, `图片test加载失败: ${JSON.stringify(err)}`); + } + } + + // 从PixelMap创建Drawable描述符 + createPixelMap() { + if (!this.imagePixelMap) { + return; + } + + // 调用Native方法创建Drawable + this.imagePixelMapId = testNapi.createFromPixelMap(this.imagePixelMap); + + if (this.imagePixelMapId >= 0) { + hilog.error(0x0000, TAG, 'imagePixelMap创建成功'); + // 获取默认动画时长 + this.animationDuration = testNapi.getAnimationDuration(this.imagePixelMapId); + } else { + hilog.error(0x0000, TAG, 'imagePixelMap创建失败'); + } + } + + createPixelMapAarry() { + if (!this.imagePixelMapArray) { + return; + } + + // 调用Native方法创建Drawable + this.imagePixelMapArrayId = testNapi.createFromAnimatedPixelMap(this.imagePixelMapArray, 1); + + if (this.imagePixelMapArrayId >= 0) { + hilog.error(0x0000, TAG, 'imagePixelMapArray创建成功'); + } else { + hilog.error(0x0000, TAG, 'imagePixelMapArray创建失败'); + } + } + + // 设置新的动画时长 + setNewDuration() { + if (this.imagePixelMapArrayId < 0) { + hilog.error(0x0000, TAG, 'imagePixelMapArrayId < 0, return'); + return; + } + + testNapi.setAnimationDuration(this.imagePixelMapArrayId, this.newDuration); + this.animationDuration = testNapi.getAnimationDuration(this.imagePixelMapArrayId); + } + + // 设置新的动画时长 + setNewIteration() { + if (this.imagePixelMapArrayId < 0) { + hilog.error(0x0000, TAG, 'imagePixelMapArrayId < 0, return'); + return; + } + + testNapi.setAnimationIteration(this.imagePixelMapArrayId, this.newIteration); + this.animationIteration = testNapi.getAnimationIteration(this.imagePixelMapArrayId); + } + + // 页面销毁时释放资源 + aboutToDisappear() { + if (this.imagePixelMapId >= 0) { + testNapi.disposeDrawable(this.imagePixelMapId); + this.imagePixelMapId = -1; + } + if (this.imagePixelMap) { + this.imagePixelMap.release(); + this.imagePixelMap = null; + } + + if (this.imagePixelMapArrayId >= 0) { + testNapi.disposeDrawable(this.imagePixelMapArrayId); + this.imagePixelMapArrayId = -1; + } + if (this.imagePixelMapArray) { + this.imagePixelMapArray.release(); + this.imagePixelMapArray = null; + } + } + + build() { + Column() { + Text('Drawable功能示例') + .fontSize(24) + .margin(20) + .fontWeight(FontWeight.Bold) + + if (this.imagePixelMap) { + Image(this.imagePixelMap) + .width(100) + .height(100) + .margin(20) + .objectFit(ImageFit.Auto) + } else { + Text('加载图片失败,请检查资源文件') + .fontSize(16) + .margin(20) + } + + if (this.imagePixelMapArray) { + Image(this.imagePixelMapArray) + .width(100) + .height(100) + .margin(20) + .objectFit(ImageFit.Auto) + } else { + Text('加载图片失败,请检查资源文件') + .fontSize(16) + .margin(20) + } + + Column() { + Text(`当前animationDuration: ${this.animationDuration}ms`) + .fontSize(18) + .margin(10) + Text(`当前animationIteration: ${this.animationIteration}`) + .fontSize(18) + .margin(10) + + Row() { + Text('设置duration:') + .fontSize(16) + .margin({ right: 10 }) + + TextInput({ + text: this.newDuration.toString() + }) + .width(100) + .onChange((value) => { + this.newDuration = parseInt(value) || 0; + }) + + Button('应用') + .margin({ left: 10 }) + .onClick(() => this.setNewDuration()) + } + .margin(10) + + Row() { + Text('设置iteration:') + .fontSize(16) + .margin({ right: 10 }) + + TextInput({ + text: this.newIteration.toString() + }) + .width(100) + .onChange((value) => { + this.newIteration = parseInt(value) || 0; + }) + + Button('应用') + .margin({ left: 10 }) + .onClick(() => this.setNewIteration()) + } + .margin(10) + } + .width('100%') + .padding(20) + .backgroundColor('#f5f5f5') + .borderRadius(10) + + Text('提示: 请确保资源文件存在于rawfile目录') + .fontSize(14) + .margin({ top: 20 }) + } + .width('100%') + .height('100%') + .padding(15) + .backgroundColor('#ffffff') + } +} diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/module.json5 b/ArkUIKit/DrawableDescriptorSample/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..78a72362efdf4ef6d9c8400b25527133d926dd45 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/color.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/float.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/string.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/background.png b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/dark/element/color.json b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/startIcon.png b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/startIcon.png differ diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/test.jpg b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/test.jpg new file mode 100755 index 0000000000000000000000000000000000000000..4a3fa2b98624b4678db7c8f911ede21aa75d1e66 Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/entry/src/main/resources/rawfile/test.jpg differ diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/mock/Libentry.mock.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/mock/Libentry.mock.ets new file mode 100755 index 0000000000000000000000000000000000000000..82fa70b5693ddab96d237d2d17d943d866b61465 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/mock/mock-config.json5 b/ArkUIKit/DrawableDescriptorSample/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/mock/mock-config.json5 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7f30942b81554a399e89aa253c7089eca4f8d8d1 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/module.json5 b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..15985f07ded51de709b7c68483df86e9071ade0b --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/test/List.test.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/entry/src/test/LocalUnit.test.ets b/ArkUIKit/DrawableDescriptorSample/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/hvigor/hvigor-config.json5 b/ArkUIKit/DrawableDescriptorSample/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..70879912169503ff02665211233887556b8f4ae8 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/DrawableDescriptorSample/hvigorfile.ts b/ArkUIKit/DrawableDescriptorSample/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/DrawableDescriptorSample/oh-package.json5 b/ArkUIKit/DrawableDescriptorSample/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..463ba600e57f685bdc2b1d5a759cd939fe9f1762 --- /dev/null +++ b/ArkUIKit/DrawableDescriptorSample/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/DrawableDescriptorSample/screenshots/device/image1.jpeg b/ArkUIKit/DrawableDescriptorSample/screenshots/device/image1.jpeg new file mode 100755 index 0000000000000000000000000000000000000000..be8922bcd94f5783c1b987bd5ab3d1e9f1d53d38 Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/screenshots/device/image1.jpeg differ diff --git a/ArkUIKit/DrawableDescriptorSample/screenshots/device/result.jpeg b/ArkUIKit/DrawableDescriptorSample/screenshots/device/result.jpeg new file mode 100755 index 0000000000000000000000000000000000000000..bc34403a7bd9ade820a3b6ea036a87b3eeae400e Binary files /dev/null and b/ArkUIKit/DrawableDescriptorSample/screenshots/device/result.jpeg differ