From a807d8b8b0f6c709853cc9d0e292b11063fd0ba6 Mon Sep 17 00:00:00 2001 From: zhangxCode Date: Mon, 9 Jun 2025 16:15:32 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9AFAQ=E5=90=8C=E6=BA=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=81=97=E6=BC=8F=E9=83=A8=E5=88=86=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/PidMsg.ets | 8 +++ .../entry/src/main/module_myability.json5 | 11 ++-- AbilityKit/entry/src/main/module_remove.json5 | 15 ++++-- .../entry/src/main/ets/pages/Hidebug.ets | 14 +++++ ArkTS/entry/src/main/cpp/napi_call.cpp | 5 +- ArkTS/entry/src/main/cpp/napi_callback.cpp | 4 +- ArkTS/entry/src/main/cpp/napi_promise.cpp | 5 +- ArkTS/entry/src/main/ets/pages/RegExp.ets | 11 ++++ ArkTS/entry/src/main/ets/pages/Uuid.ets | 9 ++++ .../entryability/EntryAbilityForHideBar.ets | 54 +++++++++++++++++++ ArkUI/entry/src/main/ets/pages/ClearFocus.ets | 31 +++++++++++ .../src/main/ets/pages/DetermineValue.js | 8 +++ .../src/main/ets/pages/FontResources.ets | 27 ++++++++++ .../entry/src/main/ets/pages/ImageStrPath.ets | 7 +++ .../main/ets/pages/LoadUnicodeCharacters.ets | 15 ++++++ ArkUI/entry/src/main/module.json5 | 10 +++- .../main/resources/rawfile/font/gealova.otf | 0 .../cpp/build-profile_test.json5 | 43 +++++++++++++++ .../UnknownType/src/main/cpp/CMakeLists.txt | 4 +- PackageStructureKit/entry/build-profile.json5 | 11 ++-- 20 files changed, 271 insertions(+), 21 deletions(-) create mode 100644 AbilityKit/entry/src/main/ets/pages/PidMsg.ets create mode 100644 AnalysisKit/entry/src/main/ets/pages/Hidebug.ets create mode 100644 ArkTS/entry/src/main/ets/pages/RegExp.ets create mode 100644 ArkTS/entry/src/main/ets/pages/Uuid.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityForHideBar.ets create mode 100644 ArkUI/entry/src/main/ets/pages/ClearFocus.ets create mode 100644 ArkUI/entry/src/main/ets/pages/DetermineValue.js create mode 100644 ArkUI/entry/src/main/ets/pages/FontResources.ets create mode 100644 ArkUI/entry/src/main/ets/pages/ImageStrPath.ets create mode 100644 ArkUI/entry/src/main/resources/rawfile/font/gealova.otf create mode 100644 CompilingAndBuilding/cpp/build-profile_test.json5 diff --git a/AbilityKit/entry/src/main/ets/pages/PidMsg.ets b/AbilityKit/entry/src/main/ets/pages/PidMsg.ets new file mode 100644 index 0000000..ba28d98 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/PidMsg.ets @@ -0,0 +1,8 @@ +/** + * FAQ:如何查询应用进程的pid信息 + */ +// [Start get_pid] +import { process } from '@kit.ArkTS'; + +let pid = process.pid; +// [End get_pid] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_myability.json5 b/AbilityKit/entry/src/main/module_myability.json5 index b23cc2d..ddafb4a 100644 --- a/AbilityKit/entry/src/main/module_myability.json5 +++ b/AbilityKit/entry/src/main/module_myability.json5 @@ -1,14 +1,13 @@ /* * FAQ:如何使用AbilityStage的生命周期函数 */ - +// [Start my_ability_entry] { "module": { "name": "entry", "type": "entry", - // [Start my_ability_entry] "srcEntry": "./ets/myabilitystage/MyAbilityStage.ets", - // [End my_ability_entry] + // [StartExclude my_ability_entry] "description": "$string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ @@ -54,6 +53,8 @@ } ], } - ] + ], + // [EndExclude my_ability_entry] } -} \ No newline at end of file +} +// [End my_ability_entry] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_remove.json5 b/AbilityKit/entry/src/main/module_remove.json5 index c65392a..5cb03f9 100644 --- a/AbilityKit/entry/src/main/module_remove.json5 +++ b/AbilityKit/entry/src/main/module_remove.json5 @@ -1,9 +1,10 @@ /* * FAQ:如何在UIAbility调用terminateSelf()后设置不保留最近任务列表中的快照 */ - +// [Start remove_mission] { "module": { + // [StartExclude remove_mission] "name": "entry", "type": "entry", "description": "$string:module_desc", @@ -16,8 +17,10 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [EndExclude remove_mission] "abilities": [ { + // [StartExclude remove_mission] "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", @@ -36,11 +39,11 @@ ] } ], - // [Start remove_mission] + // [EndExclude remove_mission] "removeMissionAfterTerminate": true, - // [End remove_mission] } ], + // [StartExclude remove_mission] "extensionAbilities": [ { "name": "EntryBackupAbility", @@ -54,6 +57,8 @@ } ], } - ] + ], + // [EndExclude remove_mission] } -} \ No newline at end of file +} +// [End remove_mission] \ No newline at end of file diff --git a/AnalysisKit/entry/src/main/ets/pages/Hidebug.ets b/AnalysisKit/entry/src/main/ets/pages/Hidebug.ets new file mode 100644 index 0000000..7dc0224 --- /dev/null +++ b/AnalysisKit/entry/src/main/ets/pages/Hidebug.ets @@ -0,0 +1,14 @@ +/** + * FAQ:如何查询应用当前CPU占用 + * FAQ:如何查询应用堆内存的已分配内存大小和堆内存的空闲内存大小 + */ +import { hidebug } from '@kit.PerformanceAnalysisKit'; + +// [Start cup_sage] +let cpuUsage: number = hidebug.getCpuUsage(); +// [End cup_sage] + +// [Start get_heap_size] +let nativeHeapAllocatedSize: bigint = hidebug.getNativeHeapAllocatedSize(); // Get the allocated memory size of the heap memory in this application +let nativeHeapFreeSize: bigint = hidebug.getNativeHeapFreeSize(); // Get the free memory size of the heap memory in this application +// [End get_heap_size] \ No newline at end of file diff --git a/ArkTS/entry/src/main/cpp/napi_call.cpp b/ArkTS/entry/src/main/cpp/napi_call.cpp index 1e2b3e6..747db71 100644 --- a/ArkTS/entry/src/main/cpp/napi_call.cpp +++ b/ArkTS/entry/src/main/cpp/napi_call.cpp @@ -3,7 +3,7 @@ // // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, // please include "napi/native_api.h". - +// [Start call_napi] static napi_value CallNapi(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value object = nullptr; @@ -17,4 +17,5 @@ NAPI_MODULE_INIT() { }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); return exports; -} \ No newline at end of file +} +// [End call_napi] \ No newline at end of file diff --git a/ArkTS/entry/src/main/cpp/napi_callback.cpp b/ArkTS/entry/src/main/cpp/napi_callback.cpp index f3b34ba..d3fa0ca 100644 --- a/ArkTS/entry/src/main/cpp/napi_callback.cpp +++ b/ArkTS/entry/src/main/cpp/napi_callback.cpp @@ -4,6 +4,7 @@ // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, // please include "napi/native_api.h". +// [Start native_call] #include "napi/native_api.h" #include static napi_value NativeCall(napi_env env, napi_callback_info info) { @@ -51,4 +52,5 @@ static napi_module module = { }; extern "C" __attribute__((constructor)) void RegisterCallbackModule(void) { napi_module_register(&module); -} \ No newline at end of file +} +// [End native_call] \ No newline at end of file diff --git a/ArkTS/entry/src/main/cpp/napi_promise.cpp b/ArkTS/entry/src/main/cpp/napi_promise.cpp index e8f1e50..1a6cc1c 100644 --- a/ArkTS/entry/src/main/cpp/napi_promise.cpp +++ b/ArkTS/entry/src/main/cpp/napi_promise.cpp @@ -3,7 +3,7 @@ // // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, // please include "napi/native_api.h". - +// [Start native_call_promise] #include "napi/native_api.h" // Empty value so that macros here are able to return NULL or void #define NAPI_RETVAL_NOTHING // Intentionally blank @@ -110,4 +110,5 @@ static napi_module demoModule = { }; extern "C" __attribute__((constructor)) void RegisterPromiseModule(void) { napi_module_register(&demoModule); -} \ No newline at end of file +} +// [End native_call_promise] \ No newline at end of file diff --git a/ArkTS/entry/src/main/ets/pages/RegExp.ets b/ArkTS/entry/src/main/ets/pages/RegExp.ets new file mode 100644 index 0000000..ba2bac6 --- /dev/null +++ b/ArkTS/entry/src/main/ets/pages/RegExp.ets @@ -0,0 +1,11 @@ +/** + * FAQ:如何使用正则表达式 + */ +// [Start new_reg] +const reg = new RegExp('ba'); +// [End new_reg] + +// [Start reg_test] +const res = reg.test('bar'); +console.info('result', res); +// [End reg_test] \ No newline at end of file diff --git a/ArkTS/entry/src/main/ets/pages/Uuid.ets b/ArkTS/entry/src/main/ets/pages/Uuid.ets new file mode 100644 index 0000000..91d7e9c --- /dev/null +++ b/ArkTS/entry/src/main/ets/pages/Uuid.ets @@ -0,0 +1,9 @@ +/** + * FAQ:如何生成UUID的字符串 + */ +import { util } from '@kit.ArkTS'; + +// [Start get_uuid] +let uuid = util.generateRandomUUID(true); +console.info("RFC 4122 Version 4 UUID:" + uuid); // Output randomly generated UUID +// [End get_uuid] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityForHideBar.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityForHideBar.ets new file mode 100644 index 0000000..bfbbad9 --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityForHideBar.ets @@ -0,0 +1,54 @@ +/** + * FAQ:应用如何设置隐藏顶部的状态栏 + */ +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'); + } + + // [Start hide_bar] + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.getMainWindowSync().setWindowSystemBarEnable([]) + // [StartExclude hide_bar] + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + AppStorage.setOrCreate('windowStage',windowStage); + 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.'); + const context = windowStage.getMainWindowSync().getUIContext(); + AppStorage.setOrCreate("context", context); + // [EndExclude hide_bar] + }); + } + // [End hide_bar] + + 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/ArkUI/entry/src/main/ets/pages/ClearFocus.ets b/ArkUI/entry/src/main/ets/pages/ClearFocus.ets new file mode 100644 index 0000000..e613582 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/ClearFocus.ets @@ -0,0 +1,31 @@ +/** + * FAQ:如何清除输入框焦点? + */ +@Component +struct ClearFocus { + @State message: string = 'Hello World'; + + aboutToAppear(): void { + // [Start clear_focus] + this.getUIContext().getFocusController().clearFocus() + // [End clear_focus] + } + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/DetermineValue.js b/ArkUI/entry/src/main/ets/pages/DetermineValue.js new file mode 100644 index 0000000..078525d --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/DetermineValue.js @@ -0,0 +1,8 @@ +/** + * FAQ:如何判断JS对象中是否存在某个值 + */ +const val = 1; +const array = [1,2,3,4] +// [Start array_index_of] +var res = array.indexOf(val) +// [End array_index_of] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/FontResources.ets b/ArkUI/entry/src/main/ets/pages/FontResources.ets new file mode 100644 index 0000000..6db9295 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/FontResources.ets @@ -0,0 +1,27 @@ +/** + * FAQ:自定义字体的注册方式是什么,如何从资源存放路径中取出字体资源? + */ +import { font } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + aboutToAppear(): void { + // [Start set_font] + font.registerFont({ + familyName: 'Gealova', + familySrc: $rawfile('font/gealova.otf') + }) + // [End set_font] + } + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ImageStrPath.ets b/ArkUI/entry/src/main/ets/pages/ImageStrPath.ets new file mode 100644 index 0000000..67ffd59 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/ImageStrPath.ets @@ -0,0 +1,7 @@ +/** + * FAQ:Image或者ImageSpan传入一个string类型的路径时无法加载图片 + */ +let localImageName:ResourceStr = ''; +// [Start image_name] +localImageName = $r( 'app.media.icon' ) +// [End image_name] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/LoadUnicodeCharacters.ets b/ArkUI/entry/src/main/ets/pages/LoadUnicodeCharacters.ets index 99e144f..d79f644 100644 --- a/ArkUI/entry/src/main/ets/pages/LoadUnicodeCharacters.ets +++ b/ArkUI/entry/src/main/ets/pages/LoadUnicodeCharacters.ets @@ -17,6 +17,21 @@ * FAQ:Text 组件如何加载Unicode字符 */ +const StrToUnicode = ()=>{ + // [Start str_to_Unicode] + let chineseStr: string = "中文"; + const encodedStr = Array.from(chineseStr).map(char =>`\\u${char.codePointAt(0)!.toString(16).padStart(4, '0')}`).join(""); + // [End str_to_Unicode] +} + +const UnicodeToStr = ()=>{ + // [Start Unicode_to_str] + let unicodeStr: string = "\\u4e2d\\u6587"; + const decodedStr = unicodeStr.replace(/\\u([\dA-Fa-f]{4})/g,(_,p1:string) => String.fromCodePoint(parseInt(p1, 16))); + // [End Unicode_to_str] +} + + // [Start load_unicode_characters] @Entry @Component diff --git a/ArkUI/entry/src/main/module.json5 b/ArkUI/entry/src/main/module.json5 index f35283f..f610218 100644 --- a/ArkUI/entry/src/main/module.json5 +++ b/ArkUI/entry/src/main/module.json5 @@ -71,7 +71,15 @@ { "name": "ohos.permission.PRIVACY_WINDOW" } - ] + ], // [End request_privacy_window] + // [Start load_parent_temp] + "metadata": [ + { + "name": "ContextResourceConfigLoadFromParentTemp", + "value": "true" + } + ], + // [End load_parent_temp] } } \ No newline at end of file diff --git a/ArkUI/entry/src/main/resources/rawfile/font/gealova.otf b/ArkUI/entry/src/main/resources/rawfile/font/gealova.otf new file mode 100644 index 0000000..e69de29 diff --git a/CompilingAndBuilding/cpp/build-profile_test.json5 b/CompilingAndBuilding/cpp/build-profile_test.json5 new file mode 100644 index 0000000..fd46138 --- /dev/null +++ b/CompilingAndBuilding/cpp/build-profile_test.json5 @@ -0,0 +1,43 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "", + // [Start arguments_value] + "arguments": "-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link -DCMAKE_JOB_POOLS:STRING=compile=2;link=2", + // [End arguments_value] + "cppFlags": "" + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [ + "**/3.so" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Ndk/Ndk2/UnknownType/src/main/cpp/CMakeLists.txt b/Ndk/Ndk2/UnknownType/src/main/cpp/CMakeLists.txt index 2049524..a7ede13 100644 --- a/Ndk/Ndk2/UnknownType/src/main/cpp/CMakeLists.txt +++ b/Ndk/Ndk2/UnknownType/src/main/cpp/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(myProgram SHARED src/main.cpp src/myLibrary.cpp) set(CMAKE_VERBOSE_MAKEFILE ON) # [End CMAKE_VERBOSE_MAKEFILE] -# [Start msgDirectory] +# [Start msg_directory] message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}") message(STATUS "Include directories: ${CMAKE_INCLUDE_PATH}") -# [Start msgDirectory] \ No newline at end of file +# [Start msg_directory] \ No newline at end of file diff --git a/PackageStructureKit/entry/build-profile.json5 b/PackageStructureKit/entry/build-profile.json5 index 4d61187..2b91a71 100644 --- a/PackageStructureKit/entry/build-profile.json5 +++ b/PackageStructureKit/entry/build-profile.json5 @@ -1,3 +1,5 @@ +// FAQ:如何避免模块下文件打包进HAR包后,存在的不可预期的资料、配置或信息安全风险。 +// [Start obfuscation_set] { "apiType": "stageMode", "buildOption": { @@ -8,7 +10,7 @@ "arkOptions": { "obfuscation": { "ruleOptions": { - "enable": false, + "enable": true, "files": [ "./obfuscation-rules.txt" ] @@ -17,6 +19,7 @@ } }, ], + // [StartExclude obfuscation_set] "targets": [ { "name": "default" @@ -24,5 +27,7 @@ { "name": "ohosTest", } - ] -} \ No newline at end of file + ], + // [EndExclude obfuscation_set] +} +// [Start obfuscation_set] \ No newline at end of file -- Gitee