diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets index fe45b632df0a8f6d861a31bbd4fccef7ec29539f..cbf94592d4ad2c4be521bacbe46021c96aa2cc0a 100755 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start import_os_account] import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_os_account] import { router } from '@kit.ArkUI'; +// [Start get_account_manager] let osAccountMgr = osAccount.getAccountManager(); +// [End get_account_manager] @Entry @Component @@ -24,21 +28,26 @@ struct ManageDomainAccounts { @State message: string = 'Hello World'; private async domainAccountExists(): Promise { + // [Start domain_account_exists] let domainAccountInfo: osAccount.DomainAccountInfo = { accountName: 'testAccountName', domain: 'testDomain' } let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); + // [StartExclude domain_account_exists] console.log('domainAccount isAccountExisted:' + isAccountExisted); if(isAccountExisted) { this.message = 'Domain account already exists'; } else { this.message = 'Domain account does not exist'; } + // [EndExclude domain_account_exists] + // [End domain_account_exists] } private async createDomainAccount(): Promise { + // [Start create_domain_account] let domainInfo: osAccount.DomainAccountInfo = { domain: 'testDomain', accountName: 'testAccountName' @@ -49,15 +58,21 @@ struct ManageDomainAccounts { (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ console.log('createOsAccountForDomain err:' + JSON.stringify(err)); console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude create_domain_account] this.message = 'Account creation information: ' + JSON.stringify(osAccountInfo.localName); + // [EndExclude create_domain_account] }); } catch (e) { console.error('createOsAccountForDomain exception: ' + JSON.stringify(e)); + // [StartExclude create_domain_account] this.message = 'Account creation failed: ' + JSON.stringify(e); + // [EndExclude create_domain_account] } + // [End create_domain_account] } private async deleteDomainAccount(): Promise { + // [Start delete_domain_account] let domainInfo: osAccount.DomainAccountInfo = { domain: 'testDomain', accountName: 'testAccountName' @@ -67,25 +82,32 @@ struct ManageDomainAccounts { localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); } catch (err) { console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); + // [StartExclude delete_domain_account] this.message = 'Failed to get account deletion information: ' + JSON.stringify(err); + // [EndExclude delete_domain_account] } try { osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ if (err) { console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude delete_domain_account] this.message = 'Failed to delete account: ' + JSON.stringify(err); + // [EndExclude delete_domain_account] } else { console.log('removeOsAccount successfully'); + // [StartExclude delete_domain_account] this.message = 'Successfully deleted account'; + // [EndExclude delete_domain_account] } }); } catch (err) { console.error('removeOsAccount exception: ' + JSON.stringify(err)); } - + // [End delete_domain_account] } private async queryDomainAccount(): Promise { + // [Start get_domain_account_info] let options: osAccount.GetDomainAccountInfoOptions = { domain: 'testDomain', accountName: 'testAccountName' @@ -95,16 +117,23 @@ struct ManageDomainAccounts { (err: BusinessError, result: osAccount.DomainAccountInfo) => { if (err) { console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); + // [StartExclude get_domain_account_info] this.message = 'Query failed: ' + JSON.stringify(err); + // [EndExclude get_domain_account_info] } else { console.log('getAccountInfo result: ' + result); + // [StartExclude get_domain_account_info] this.message = 'Queried account information: ' + JSON.stringify(result.accountName); + // [EndExclude get_domain_account_info] } }); } catch (err) { console.error('getAccountInfo exception = ' + JSON.stringify(err)); + // [StartExclude get_domain_account_info] this.message = 'Failed to query account information: ' + JSON.stringify(err); + // [EndExclude get_domain_account_info] } + // [End get_domain_account_info] } build() { diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets index 8a74171a47d1cb37bc6ee0fc6600111ee4f0c0c6..49a59901e6c790752e95653b80b4b81ed9d52341 100755 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets @@ -13,9 +13,13 @@ * limitations under the License. */ +// [Start import_os_account_01] import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_os_account_01] +// [Start get_account_manager_01] let accountManager = osAccount.getAccountManager(); +// [End get_account_manager_01] @Entry @Component @@ -24,47 +28,60 @@ struct ManageSystemAccounts { @State createLocalId: number = -1; private async createOsAccount(): Promise { + // [Start create_os_account] let name: string = 'Bob'; let type: osAccount.OsAccountType = osAccount.OsAccountType.NORMAL; accountManager.createOsAccount(name, type, (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ console.log('createOsAccount err:' + JSON.stringify(err)); console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude create_os_account] if (!err) { this.message = 'Account creation successful. Account name: ' + JSON.stringify(osAccountInfo.localName); this.createLocalId = osAccountInfo.localId; } else { this.message = 'Failed to create account: ' + JSON.stringify(err); } + // [EndExclude create_os_account] }); + // [End create_os_account] } private async findAllOsAccount(): Promise { + // [Start query_all_os_account] accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); + // [StartExclude query_all_os_account] if (!err) { this.message = 'Query account successful. Account name:' + JSON.stringify(accountArr[0].localName); } else { this.message = 'Query account failed: ' + JSON.stringify(err); } + // [EndExclude query_all_os_account] }); + // [End query_all_os_account] } private async findOsAccount(): Promise { + // [Start query_id_os_account] let localId: number = 100; accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ console.log('queryOsAccountById err:' + JSON.stringify(err)); console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); + // [StartExclude query_id_os_account] if (!err) { this.message = 'Query account successful. Account name for account 100: ' + JSON.stringify(accountInfo.localName); } else { this.message = 'Query account failed: ' + JSON.stringify(err); } + // [EndExclude query_id_os_account] }); + // [End query_id_os_account] } private async changeOsAccountHead(): Promise { + // [Start set_os_account_photo] let localId: number = 100; localId = this.createLocalId; let newPhoto: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ @@ -74,19 +91,24 @@ struct ManageSystemAccounts { accountManager.setOsAccountProfilePhoto(localId, newPhoto, (err: BusinessError)=>{ console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); + // [StartExclude set_os_account_photo] if(!err) { this.message = 'Successfully updated system account avatar' } else { this.message = 'Failed to update system account avatar: ' + JSON.stringify(err); } + // [EndExclude set_os_account_photo] }); + // [End set_os_account_photo] } private async changeOsAccountName(): Promise { + // [Start set_os_account_name] let localId: number = 100; localId = this.createLocalId; let newName: string = 'Tom'; accountManager.setOsAccountName(localId, newName, (err: BusinessError) => { + // [StartExclude set_os_account_name] if (err) { console.error('setOsAccountName failed, error: ' + JSON.stringify(err)); this.message = 'Failed to modify system account name: ' + JSON.stringify(err); @@ -94,13 +116,17 @@ struct ManageSystemAccounts { console.log('setOsAccountName successfully'); this.message = 'Successfully modified system account name'; } + // [EndExclude set_os_account_name] }); + // [End set_os_account_name] } private async activateOsAccount(): Promise { + // [Start activate_os_account] let localId: number = 101; localId = this.createLocalId; accountManager.activateOsAccount(localId, (err: BusinessError)=>{ + // [StartExclude activate_os_account] if (err) { console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); this.message = 'Failed to activate system account: ' + err.code; @@ -108,13 +134,17 @@ struct ManageSystemAccounts { console.log('activateOsAccount successfully'); this.message = 'Successfully activated system account' } + // [EndExclude activate_os_account] }); + // [End activate_os_account] } private async deleteOsAccount(): Promise { + // [Start delete_os_account] let localId: number = 101; localId = this.createLocalId; accountManager.removeOsAccount(localId, (err: BusinessError)=>{ + // [StartExclude activate_os_account] if (err) { console.error('removeOsAccount failed, error: ' + JSON.stringify(err)); this.message = 'Failed to delete system account: ' + JSON.stringify(err); @@ -122,7 +152,9 @@ struct ManageSystemAccounts { console.log('removeOsAccount successfully'); this.message = 'Successfully deleted system account' } + // [EndExclude activate_os_account] }); + // [End activate_os_account] } build() { diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets index 3a5acacc09fcd027a548498c66ac124bf390312f..b28d403d69428724904bf35dda21fbb590bdcc1c 100755 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start import_os_account_02] import { osAccount } from '@kit.BasicServicesKit'; +// [End import_os_account_02] import { router } from '@kit.ArkUI'; +// [Start get_account_manager_02] let accountManager = osAccount.getAccountManager(); +// [End get_account_manager_02] @Entry @Component @@ -24,28 +28,38 @@ struct UseConstraintManagementSystemAccount { @State message: string = 'No work done'; private async setOsAccountConstraints(): Promise { + // [Start set_os_account_constraints] let localId: number = 100; let constraint: string[] = [ 'constraint.wifi.set' ]; try { accountManager.setOsAccountConstraints(localId, constraint, true); console.log('setOsAccountConstraints successfully'); + // [StartExclude set_os_account_constraints] this.message = 'Successfully set the constraint list for the specified system account'; + // [EndExclude set_os_account_constraints] } catch (err) { console.error('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); + // [StartExclude set_os_account_constraints] this.message = 'Failed to set the constraint list for the specified system account'; + // [EndExclude set_os_account_constraints] } + // [End set_os_account_constraints] } private async isOsAccountConstraintEnabled(): Promise { + // [Start is_os_account_constraints_enabled] let localId: number = 100; let constraint: string = 'constraint.wifi.set'; let isEnabled: boolean = await accountManager.isOsAccountConstraintEnabled(localId, constraint); if (isEnabled) { // your business logic + // [StartExclude is_os_account_constraints_enabled] this.message = 'Set the constraint list for the specified system account'; } else { this.message = 'Can not set the constraint list for the specified system account'; } + // [EndExclude is_os_account_constraints_enabled] + // [End is_os_account_constraints_enabled] } build() { diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 index aea44a0d28aa56a4d432a4a3ce22fa622312e5ea..110bc2d681f63ac6ab8cc5c11e96073d41894d6a 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 @@ -47,7 +47,7 @@ "x86_64", "armeabi-v7a" ] - } + }, }, "buildOptionSet": [ { diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts index ee23dfc10e8c3c5c7533a3eb1f136c195859ada9..27eb9617d25b96bff253c65e175409784697cd34 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const add: (a: number, b: number) => number; \ No newline at end of file +// [Start hap_const_dynamic_import_native] +export const add: (a: number, b: number) => number; +// [End hap_const_dynamic_import_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets index 591ad6994e8a1151843d46a2dc078a1fdde9b44a..606453a50db5c26c26696742b3d97d43ade54552 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start hap_const_dynamic_import_add] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End hap_const_dynamic_import_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets index 6eacb0025008ddd888ac7b6e2462400070ef8b0d..1ba61845df6f9afc8e1d52adde501435eea6139c 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets @@ -70,6 +70,7 @@ struct Index { .fontSize(16) .onClick(() => { if (item === resourceToString($r('app.string.business_expansion_scenario'))) { + // [Start dynamic_load_har_module_reflect_call] import('harlibrary').then((ns: ESObject) => { ns.Calc.staticAdd(8, 9); // 调用静态成员函数staticAdd() let calc: ESObject = new ns.Calc(); // 实例化类Calc @@ -86,47 +87,65 @@ struct Index { calc1[methodName](14, 15); // 调用成员函数instanceAdd() ns[functionName](16, 17); // 调用全局方法addHarlibrary() }) + // [End dynamic_load_har_module_reflect_call] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_name'))) { + // [Start const_dynamic_import_har_name] //HAP常量动态import HAR模块名 import('myhar').then((ns: ESObject) => { console.info(ns.add(3, 5)); }) + // [End const_dynamic_import_har_name] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_path'))) { + // [Start const_dynamic_import_har_path] // HAP常量动态import HAR模块文件路径 import('myhar/Index').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_har_path] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_name'))) { + // [Start const_dynamic_import_hsp_name] // HAP常量动态import HSP模块名 import('myhsp').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_hsp_name] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_path'))) { + // [Start const_dynamic_import_hsp_path] // HAP常量动态import HSP模块名文件路径 import('myhsp/Index').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_hsp_path] } else if (item === resourceToString($r('app.string.dynamic_import_remote_HAR_name'))) { + // [Start const_dynamic_import_crypto] // HAP常量动态import远程HAR模块名 import('@ohos/crypto-js').then((ns: ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.src); }); + // [End const_dynamic_import_crypto] } else if (item === resourceToString($r('app.string.dynamic_import_ohpm'))) { + // [Start const_dynamic_import_ohpm] // HAP常量动态import ohpm包 import('@ohos/hypium').then((ns: ESObject) => { console.info('DynamicImport @ohos/hypium: ', ns.TestType.FUNCTION.toString()); }); + // [End const_dynamic_import_ohpm] } else if (item === resourceToString($r('app.string.dynamic_import_file'))) { + // [Start hap_const_dynamic_import] // HAP常量动态import自己的单文件 import('../Calc').then((ns: ESObject) => { console.info(ns.add(3, 5)); }) + // [End hap_const_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_native'))) { + // [Start hap_const_dynamic_import_native_index] // HAP常量动态import自己的Native库 import('libentry.so').then((ns: ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); + // [End hap_const_dynamic_import_native_index] } else if (item === resourceToString($r('app.string.dynamic_import_system_app'))) { + // [Start hap_const_dynamic_import_api] // HAP常量动态import加载API import('@system.app').then((ns: ESObject) => { ns.default.getInfo(); @@ -147,55 +166,73 @@ struct Index { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); hilog.info(0x000, 'testTag', '%{public}s', ns.default.LogLevel.DEBUG); }); + // [End hap_const_dynamic_import_api] } else if (item === resourceToString($r('app.string.dynamic_import_module_myhar'))) { + // [Start variable_dynamic_import] // 变量动态import其他模块myHar let harName = 'myhar'; import(harName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [StartExclude variable_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_module_file'))) { + // [EndExclude variable_dynamic_import] // 变量动态import本模块自己的单文件 let filePath = '../utils/Calc'; import(filePath).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End variable_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_name_variable'))) { + // [Start hap_variable_dynamic_import_har] // HAP变量动态import HAR模块名 let harPackageName = 'myhar'; import(harPackageName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_har] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_name_variable'))) { + // [Start hap_variable_dynamic_import_hsp] // HAP变量动态import HSP模块名 let hspPackageName = 'myhsp'; import(hspPackageName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_hsp] } else if (item === resourceToString($r('app.string.dynamic_import_remote_HAR_name_variable'))) { + // [Start hap_variable_dynamic_import_har_crypto] // HAP变量动态import远程HAR模块名 let remoteHarPackageName = '@ohos/crypto-js'; import(remoteHarPackageName).then((ns: ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.src); }); + // [End hap_variable_dynamic_import_har_crypto] } else if (item === resourceToString($r('app.string.dynamic_import_ohpm_variable'))) { + // [Start hap_variable_dynamic_import_ohpm] // HAP变量动态import ohpm包 let ohpmPackageName = '@ohos/hypium'; import(ohpmPackageName).then((ns: ESObject) => { console.info('DynamicImport @ohos/hypium: ', ns.TestType.FUNCTION.toString()); }); + // [End hap_variable_dynamic_import_ohpm] } else if (item === resourceToString($r('app.string.dynamic_import_file_variable'))) { + // [Start hap_variable_dynamic_import_calc] // HAP变量动态import自己的单文件 let calcFilePath = '../Calc'; import(calcFilePath).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_calc] } else if (item === resourceToString($r('app.string.dynamic_import_native_variable'))) { + // [Start hap_variable_dynamic_import_native] // HAP变量动态import自己的Native库 let soName = 'libentry.so'; import(soName).then((ns: ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); + // [End hap_variable_dynamic_import_native] } else if (item === resourceToString($r('app.string.dynamic_import_system_app_variable'))) { + // [Start hap_variable_dynamic_import_api] // HAP变量动态import加载API let packageName = '@system.app'; import(packageName).then((ns: ESObject) => { @@ -219,11 +256,14 @@ struct Index { import(packageName).then((ns: ESObject) => { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); }) + // [End hap_variable_dynamic_import_api] } else if (item === resourceToString($r('app.string.dynamic_import_HAR'))) { + // [Start hap_variable_dynamic_import_har1] let harName = 'har1'; import(harName).then((ns: ESObject) => { console.info('DynamicImport addHar1 4 + 5 = ' + ns.addHar1(4, 5)); }); + // [End hap_variable_dynamic_import_har1] } }) } diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets index a5b03f1cd6c3ae32d58a2ba56c657b44ce0a78ac..e0345cb61d753496fc4de59a5e8d08c67e695009 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage'; +// [Start export_add_har1] export { addHar1 } from './src/main/ets/utils/Calc'; +// [End export_add_har1] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets index 91ff3de13565e5b0a6c883ec691a8befcbb24712..7cc5071259ad983e4117ffe8cfbc4be961d60b17 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start function_add_har1] export function addHar1(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am har1, %d + %d = %d', a, b, c); @@ -22,4 +23,5 @@ export function addHar1(a: number, b: number): number { console.info('DynamicImport addHar2 4 + 5 = ' + ns.addHar2(4, 5)); }); return c; -} \ No newline at end of file +} +// [End function_add_har1] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets index 2a6f2ea192c7f21c0440bb861a02d807a5b7e4f4..248cad021d26d33980fb855f19ae7cba8ea59f2b 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage'; +// [Start export_add_har2] export { addHar2 } from './src/main/ets/utils/Calc' +// [End export_add_har2] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets index d32c0d2b4b44acb46735adf36c9baef6200dab20..13cc0fe20a97836f97a2dca506a6d7705a088812 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start function_add_har2] export function addHar2(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am har2, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End function_add_har2] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets index e73569c227acc4ed4e1011c1421adfa0371b337b..ce8819144b46a1b13a52e65fac1975f790871cd7 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage' -export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' \ No newline at end of file +// [Start module_members_export] +export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' +// [End module_members_export] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets index 6e327fcdbe8c38c8b557e6cf7c3fdec3607377e4..022d3ccd82446561cd408adad7c1764bf76dd418 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dynamic_call_add] export class Calc { public static staticAdd(a: number, b: number): number { let c = a + b; @@ -31,4 +32,5 @@ export function addHarlibrary(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am harlibrary in addHarlibrary, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End dynamic_call_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets index 4cb302f7806f6f036712fd300917cf92cc4134ed..04b0c498128340aa4d66aca8ab42b5fc575c14f0 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets @@ -15,8 +15,10 @@ export { MainPage } from './src/main/ets/components/MainPage' +// [Start const_dynamic_import_har] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HAR, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End const_dynamic_import_har] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets index 4e5d57e9a1e475627b975e874ab1740d657d8d17..5166a860b1b3511064990194a968074e21ef5244 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start const_dynamic_import_hsp] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HSP, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End const_dynamic_import_hsp] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 index cd2a037ba51404d6eec4ac5fbe92037cde2eb048..472a9260420cea77f8d432f967a475169d6cea87 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 @@ -15,6 +15,7 @@ { "apiType": "stageMode", + // [Start hap_load_native_dependence_01] "buildOption": { "arkOptions": { "runtimeOnly": { @@ -23,6 +24,7 @@ ] } }, + // [StartExclude hap_load_native_dependence_01] "externalNativeOptions": { "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", @@ -32,8 +34,10 @@ "x86_64", "armeabi-v7a" ] - } + }, + // [EndExclude hap_load_native_dependence_01] }, + // [End hap_load_native_dependence_01] "buildOptionSet": [ { "name": "release", diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 index 16d8311f8d087adc540a27323b460dded7358b13..d11c699914c5da1f6f69880a2bbcc07a1f26de71 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 @@ -20,7 +20,9 @@ "main": "", "author": "", "license": "", + // [Start hap_load_native_dependence] "dependencies": { "libentry.so": "file:./src/main/cpp/types/libentry" - } + }, + // [End hap_load_native_dependence] } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts index ee23dfc10e8c3c5c7533a3eb1f136c195859ada9..0069b64ba2422995f2a96e701ec78bd063c26d64 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const add: (a: number, b: number) => number; \ No newline at end of file +// [Start hap_load_native] +export const add: (a: number, b: number) => number; +// [End hap_load_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets index 82e54f7fe6437b37ce3118ba5ff7bf7f112dd086..169d519a7c4425b187148d5b091ce29c37c7f9d2 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets @@ -24,9 +24,11 @@ struct Index { .width('50%') .margin({ bottom: 3 }) .onClick(() => { + // [Start hap_load_system_module] //HAP加载系统库模块 let hilog: ESObject = loadNativeModule('@ohos.hilog'); hilog.info(0, 'testTag', 'loadNativeModule ohos.hilog success'); + // [End hap_load_system_module] this.message = 'loadNativeModule ohos.hilog success' }) @@ -34,9 +36,11 @@ struct Index { .width('50%') .margin({ bottom: 3 }) .onClick(() => { + // [Start load_native_module_libentry] //HAP加载Native库 let module: ESObject = loadNativeModule('libentry.so'); let sum: number = module.add(1, 2); + // [End load_native_module_libentry] this.message = 'loadNativeModule libentry.so success result: ' + sum.toString(); }) Text(this.message) diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets index f0961f349aecf97460e15ac863382e58d8a2a1bc..b26b2ae4786ceae9c5fad9e8e9a52fa97748b557 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start export_variable_a] import { c } from './B'; console.info(c); +// [End export_variable_a] -export { c }; \ No newline at end of file +export { c }; diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets index 109e5bb9e12cb7bb4e57716b5f8b6cbb87366cc0..4928cba69da43798c536046b6110d12cd07419b1 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start export_variable_a_ns] import * as ns from './B'; console.info(ns.c); +// [End export_variable_a_ns] export { ns }; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets index 7db34e2051a952dca1407bd7360194e0d922f40c..4a67139893e0bb4992088dce946d7c82d846e3e8 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_variable_b] import lazy { c } from './C'; // 从'C'内获取c对象,标记为延迟加载 -export { c }; \ No newline at end of file +export { c }; +// [End export_variable_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets index 8fd891992df1365fb1e7b0491137be2d6af4c4b5..0e13c989d5b8f13b8082abfcbc0c24f06dd73491 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_variable_c] let c = 'c'; -export { c }; \ No newline at end of file +export { c }; +// [End export_variable_c] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets index 24e9cd4a0a6613cbdebfb9b0a6b7df9537c57f93..31fe7cfc716a1a936e3a93b758596c4a53d79c8e 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets @@ -13,17 +13,28 @@ * limitations under the License. */ +// [Start import_module] +// [Start import_lazy_module] import lazy { a } from './mod1'; // 'mod1' 未执行 +// [StartExclude import_lazy_module] import { c } from './mod2'; // 'mod2' 执行 +// [EndExclude import_lazy_module] import { b } from './mod1'; // 'mod1' 执行 import { hilog } from '@kit.PerformanceAnalysisKit'; +// [End import_lazy_module] +// [End import_module] + +// [Start main_running_info] console.info('main executed'); while (false) { let xx = a; + // [StartExclude main_running_info] let xy = b; let xz = c; + // [EndExclude main_running_info] } +// [End main_running_info] @Entry @Component diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets index 155a9f710cc3a3b119b3dcd880afebcc8de039ab..520baeafa3141c7677697bc0e0d82f5949e1f612 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets @@ -13,10 +13,12 @@ * limitations under the License. */ +// [Start export_module_variable_01] export let a = 'mod1 a executed'; console.info(a); export let b = 'mod1 b executed'; -console.info(b); \ No newline at end of file +console.info(b); +// [End export_module_variable_01] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets index 0fa63554af43423f62a03a28bbc65ac810cf8487..bab31537ac4767071e97d06e2cf5cd487db70adf 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_module_variable_02] export let c = 'mod2 c executed'; -console.info(c); \ No newline at end of file +console.info(c); +// [End export_module_variable_02] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets index 8c53919574f65a6bcbb1ed81fb35ba98d2e6c287..77afe81b29fc135ba68bdf81d4e3e23a62f8b176 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start import_global_module_data] export let data = 'data from module'; -globalThis.someGlobalVar = 100; \ No newline at end of file +globalThis.someGlobalVar = 100; +// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets index 1a27e4033f44c61dd0d478a98578118bc1c1d86a..b726221ea2d0e54934b0d82071ac5ecf76fce14d 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start import_global_module_data] +// [Start lazy_import_global_module_data] import lazy { data } from './module'; import lazy { dataOptimize, initialize } from './moduleOptimize'; @@ -25,6 +27,7 @@ struct moduleUseGlobalVar { build() { Column() { Row() { + // [StartExclude lazy_import_global_module_data] Button('LazyImportSideEffect') .width('40%') .height(30) @@ -33,6 +36,7 @@ struct moduleUseGlobalVar { this.message1 = 'SideEffect: ' + globalThis.someGlobalVar; console.log(data); // 使用到module模块的变量,此时module模块执行,someGlobalVar的值变为100 }) + // [EndExclude lazy_import_global_module_data] Divider() .vertical(true) .margin({ left: 8, right: 8 }) @@ -66,4 +70,6 @@ struct moduleUseGlobalVar { .height('100%') .width('100%') } -} \ No newline at end of file +} +// [End lazy_import_global_module_data] +// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets index 08dd8307b56d379a85d5d6123fa4f19a5ae5a5cc..e000c0c023b5ad1182418ca77e83c3d9212a8a56 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start import_change_global_var] import { data1 } from './module'; // 将全局变量someGlobalVar的值改为100 import { data2 } from './sideEffectModule'; // 又将全局变量someGlobalVar的值改为200 import { useGlobalVar } from './moduleUseGlobalVar'; @@ -24,6 +25,7 @@ function maybeNotCalledAtAll() { console.log(data1); console.log(data2); } +// [End import_change_global_var] function maybeNotCalledAtAllOptimize() { console.log(dataOptimize1); diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets index 0b9edc98a191c7def3160454c9fac5b78d8675a5..78c9caab64651ec67f1edfaa3218bbf684010c83 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_change_global_data_100] export let data1 = 'data from module'; -globalThis.someGlobalVar = 100; // 改变了全局状态 \ No newline at end of file +globalThis.someGlobalVar = 100; // 改变了全局状态 +// [End export_change_global_data_100] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets index 784d4c1c31765a9653b8bc83b6054cb2c23efd06..91c18c7516e5c64b92d3519fe94878b1a83d4189 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets @@ -13,9 +13,11 @@ * limitations under the License. */ +// [Start export_change_some_global_var] import { data1 } from './module'; // 此时可能预期全局变量someGlobalVar的值为100 export function useGlobalVar() { console.log(data1); console.log(globalThis.someGlobalVar); // 此时由于main.ets中加载了sideEffectModule模块,someGlobalVar的值已经被改为200 -} \ No newline at end of file +} +// [End export_change_some_global_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets index a101beca7bcdd7787a57f88cdd59d44af94744a7..1f401a0dfdccf84e16662d7bd38a18daa3ae29f8 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_change_global_data_200] export let data2 = 'data from side effect module'; -globalThis.someGlobalVar = 200; // 也变了全局状态 \ No newline at end of file +globalThis.someGlobalVar = 200; // 也变了全局状态 +// [End export_change_global_data_200] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets index 3393ab0ce064a143bfaa5a00f2f239bc8a26846f..bd12a8a0a2886136879620db995e1c1bdb31d537 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets @@ -16,6 +16,7 @@ import { data } from './module'; // 将AppStorage中的SomeAppStorageVar改为200 import { dataOptimize } from './moduleOptimize'; +// [Start set_app_storage_var_200] @Entry @Component struct Index { @@ -59,6 +60,7 @@ struct Index { function maybeNotCalledAtAll() { console.log(data); } +// [End set_app_storage_var_200] function maybeNotCalledAtAllOptimize() { console.log(dataOptimize); diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets index f8f18ff872c35ebc439ec8c454926a4b6db618e3..8d84ffea4937a5161a0840123a26f27b6459e53f 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start set_app_storage_var] export let data = 'data from module'; -AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 \ No newline at end of file +AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 +// [End set_app_storage_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets index 5f4ebc64d3ee535c5cb7e070082d37b79c9b22cb..2d5fc12b0819cc5ea08d1b49435f701386dab24a 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start module_cycle_dependence_a] import { b } from './b'; console.log('Module A: ', b); -export const a = 'A'; \ No newline at end of file +export const a = 'A'; +// [End module_cycle_dependence_a] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets index 95cb78fa443941dd6316118c51582d994c541bd5..106641288af9a5e5fe0fb47e006d1f2f50124bc7 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start module_cycle_dependence_b] import { a } from './a'; console.log('Module B: ', a); -export const b = 'B'; \ No newline at end of file +export const b = 'B'; +// [End module_cycle_dependence_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets index 3dc293c62260fc2c2eb54eb39b59457da69abdbf..5a06290dd99809176464a385cf826c600b961725 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start call_modify_array_prototype_include] import { hilog } from '@kit.PerformanceAnalysisKit'; function resourceToString(resource: Resource) { @@ -70,4 +71,5 @@ struct main { .height('100%') .width('100%') } -} \ No newline at end of file +} +// [End call_modify_array_prototype_include] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts index 86a995366ad31acc10cffc37b054c085f797d8bc..e67a9730726c1de2fc16c23abd5786c58bfb2943 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start array_prototype_include] export let data = 'data from modifyPrototype'; Array.prototype.includes = function (value) { return this.indexOf(value) == -1; }; +// [End array_prototype_include] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets index 696f15d26f1a8424b562788a023851e20f4d8e00..d327b4e0df14c133ba8fed5008dc9d68347b69ce 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets @@ -13,9 +13,11 @@ * limitations under the License. */ +// [Start import_put_console_log] import { data } from './topCodeModule'; // 导入时,module.ets中的console.log会执行,产生输出。 import { dataOptimizeOne } from './topCodeModuleOptimize'; import { dataOptimizeTwo } from './module'; +// [End import_put_console_log] @Entry @Component diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets index db345a6e210e4f81fb0948f87e8896a5fd9818fd..d83291a9749632fe4fed48fec4b3e90ca3097958 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets @@ -13,8 +13,12 @@ * limitations under the License. */ +// [Start module_load_directly] export function initialize() { console.log('Module loaded!'); } +// [End module_load_directly] +// [Start module_load_optimize] export const dataOptimizeTwo = 1; +// [End module_load_optimize] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp index 1efb7bb64304a191872801990808bde21f08a0ea..a8f6b91fab1083322638a4df17c076a6451905e6 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_create_queue_async_work] static constexpr int INT_ARGS_2 = 2; // 入参索引 struct CallbackData { @@ -24,12 +25,16 @@ struct CallbackData { double result = 0; }; +// [StartExclude napi_create_queue_async_work] +// [Start napi_async_first_call_back_work] static void ExecuteCB(napi_env env, void *data) { CallbackData *callbackData = reinterpret_cast(data); callbackData->result = callbackData->args[0] + callbackData->args[1]; } +// [End napi_async_first_call_back_work] +// [Start napi_async_second_call_back_work] static void CompleteCB(napi_env env, napi_status status, void *data) { CallbackData *callbackData = reinterpret_cast(data); @@ -47,6 +52,8 @@ static void CompleteCB(napi_env env, napi_status status, void *data) napi_delete_async_work(env, callbackData->asyncWork); delete callbackData; } +// [End napi_async_second_call_back_work] +// [EndExclude napi_create_queue_async_work] napi_value AsyncWork(napi_env env, napi_callback_info info) { @@ -68,7 +75,9 @@ napi_value AsyncWork(napi_env env, napi_callback_info info) napi_queue_async_work(env, asyncContext->asyncWork); return nullptr; } +// [End napi_create_queue_async_work] +// [Start napi_value_init] // 模块初始化 static napi_value Init(napi_env env, napi_value exports) { @@ -78,6 +87,7 @@ static napi_value Init(napi_env env, napi_value exports) napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); return exports; } +// [End napi_value_init] static napi_module demoModule = { .nm_version = 1, diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp index ea5f1cee10d72b39f017d5b722b7f7b86d446595..9ec67bd35e443d9eb0032d95bfa957d5fab7442b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_create_async_work] struct CallbackData { napi_async_work asyncWork = nullptr; napi_deferred deferred = nullptr; @@ -23,12 +24,16 @@ struct CallbackData { double result = 0; }; +// [StartExclude napi_create_async_work] +// [Start napi_first_call_back_work] static void ExecuteCB(napi_env env, void *data) { CallbackData *callbackData = reinterpret_cast(data); callbackData->result = callbackData->args; } +// [End napi_first_call_back_work] +// [Start napi_second_call_back_main] static void CompleteCB(napi_env env, napi_status status, void *data) { CallbackData *callbackData = reinterpret_cast(data); @@ -43,6 +48,8 @@ static void CompleteCB(napi_env env, napi_status status, void *data) napi_delete_async_work(env, callbackData->asyncWork); delete callbackData; } +// [End napi_second_call_back_main] +// [EndExclude napi_create_async_work] static napi_value AsyncWork(napi_env env, napi_callback_info info) { @@ -67,6 +74,7 @@ static napi_value AsyncWork(napi_env env, napi_callback_info info) return promise; } +// [End napi_create_async_work] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp index 8ad42a351f37866a1e866f7893e294208f7c6894..bc1c616708d72f587cd7d5f551d40a7bf29169ab 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include #include "napi/native_api.h" +// [Start napi_create_array] static constexpr int INT_NUMBER_5 = 5; // 入参索引 static constexpr int INT_ARGS_2 = 2; // 入参索引 @@ -34,7 +35,9 @@ static napi_value CreateArray(napi_env env, napi_callback_info info) // 返回已创建好的数组 return jsArray; } +// [End napi_create_array] +// [Start napi_create_array_with_length] // 使用Node-API接口进行array相关开发 napi_create_array_with_length static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) { @@ -51,7 +54,9 @@ static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) // 返回数组 return jsArray; } +// [End napi_create_array_with_length] +// [Start napi_get_array_length] // 使用Node-API接口进行array相关开发 napi_get_array_length static napi_value GetArrayLength(napi_env env, napi_callback_info info) { @@ -73,7 +78,9 @@ static napi_value GetArrayLength(napi_env env, napi_callback_info info) napi_create_uint32(env, length, &result); return result; } +// [End napi_get_array_length] +// [Start napi_is_array] // 使用Node-API接口进行array相关开发 napi_is_array static napi_value IsArray(napi_env env, napi_callback_info info) { @@ -94,7 +101,9 @@ static napi_value IsArray(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_array] +// [Start napi_set_element] // 使用Node-API接口进行array相关开发 napi_set_element static napi_value NapiSetElement(napi_env env, napi_callback_info info) { @@ -117,7 +126,9 @@ static napi_value NapiSetElement(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_set_element] +// [Start napi_get_element] // 使用Node-API接口进行array相关开发 napi_get_element static napi_value NapiGetElement(napi_env env, napi_callback_info info) { @@ -134,7 +145,9 @@ static napi_value NapiGetElement(napi_env env, napi_callback_info info) return result; } +// [End napi_get_element] +// [Start napi_has_element] // 使用Node-API接口进行array相关开发 napi_has_element static napi_value NapiHasElement(napi_env env, napi_callback_info info) { @@ -153,7 +166,9 @@ static napi_value NapiHasElement(napi_env env, napi_callback_info info) napi_get_boolean(env, hasElement, &result); return result; } +// [End napi_has_element] +// [Start napi_delete_element] // 使用Node-API接口进行array相关开发 napi_delete_element static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) { @@ -172,7 +187,9 @@ static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) napi_get_boolean(env, deleted, &result); return result; } +// [End napi_delete_element] +// [Start napi_create_typed_array] // 使用Node-API接口进行array相关开发 napi_create_typedarray static napi_value CreateTypedArray(napi_env env, napi_callback_info info) { @@ -227,7 +244,9 @@ static napi_value CreateTypedArray(napi_env env, napi_callback_info info) napi_create_typedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); return typedArray; } +// [End napi_create_typed_array] +// [Start napi_is_typed_array] // 使用Node-API接口进行array相关开发 napi_is_typedarray static napi_value IsTypedarray(napi_env env, napi_callback_info info) { @@ -248,7 +267,9 @@ static napi_value IsTypedarray(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_typed_array] +// [Start napi_get_typed_array_info] // 使用Node-API接口进行array相关开发 napi_get_typedarray_info static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) { @@ -298,7 +319,9 @@ static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_typed_array_info] +// [Start napi_create_data_view] // 使用Node-API接口进行array相关开发 napi_create_dataview static napi_value CreateDataView(napi_env env, napi_callback_info info) { @@ -332,7 +355,9 @@ static napi_value CreateDataView(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_data_view] +// [Start napi_is_data_view] // 使用Node-API接口进行array相关开发 napi_is_dataview static napi_value IsDataView(napi_env env, napi_callback_info info) { @@ -354,7 +379,9 @@ static napi_value IsDataView(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_data_view] +// [Start napi_get_data_view_info] // 使用Node-API接口进行array相关开发 napi_get_dataview_info static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) { @@ -396,7 +423,9 @@ static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_data_view_info] +// [Start change_use_napi_process] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { @@ -431,6 +460,7 @@ static napi_value Init(napi_env env, napi_value exports) return exports; } EXTERN_C_END +// [End change_use_napi_process] static napi_module demoModule = { .nm_version = 1, diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts index 029d6122165ce73a1ce2f474436527711aee401f..655f5726fddd983bb692c96b87b02df4a7b4572e 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,25 +13,42 @@ * limitations under the License. */ +// [Start napi_create_array_api] export const createArray: () => number[]; // 使用Node-API接口进行array相关开发 napi_create_array +// [End napi_create_array_api] +// [Start napi_create_array_with_length_api] export const createArrayWithLength: (length: number) => void[]; // 使用Node-API接口进行array相关开发 napi_create_array_with_length +// [End napi_create_array_with_length_api] +// [Start napi_get_array_length_api] export const getArrayLength: (arr: Array) => number | void; // 使用Node-API接口进行array相关开发 napi_get_array_length +// [End napi_get_array_length_api] +// [Start napi_is_array_api] export const isArray: (data: Array | T) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_array +// [End napi_is_array_api] +// [Start napi_set_element_api] export const napiSetElement: (arr: Array, index: number, value: T) => void; // 使用Node-API接口进行array相关开发 napi_set_element +// [End napi_set_element_api] +// [Start napi_get_element_api] export const napiGetElement: (arr: Array, index: number) => number | string | Object | boolean | undefined; // 使用Node-API接口进行array相关开发 napi_get_element +// [End napi_get_element_api] +// [Start napi_has_element_api] export const napiHasElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_has_element +// [End napi_has_element_api] +// [Start napi_delete_element_api] export const napiDeleteElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_delete_element +// [End napi_delete_element_api] +// [Start napi_create_typed_array_api] export const enum TypedArrayTypes { INT8_ARRAY = 0, UINT8_ARRAY, @@ -47,15 +64,26 @@ export const enum TypedArrayTypes { } export const createTypedArray: (type: TypedArrayTypes) => T; // 使用Node-API接口进行array相关开发 napi_create_typedarray +// [End napi_create_typed_array_api] +// [Start napi_is_typed_array_api] export const isTypedarray: (data: Object) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_typedarray +// [End napi_is_typed_array_api] +// [Start napi_get_typed_array_info_api] export const getTypedarrayInfo: (typeArray: T, infoType: number) => ArrayBuffer | number | boolean; // 使用Node-API接口进行array相关开发 napi_get_typedarray_info +// [End napi_get_typed_array_info_api] +// [Start napi_create_data_view_api] export const createDataView: (arraybuffer: ArrayBuffer) => DataView | void; // 使用Node-API接口进行array相关开发 napi_create_dataview +// [End napi_create_data_view_api] +// [Start napi_is_data_view_api] export const isDataView: (date: DataView | string) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_dataview +// [End napi_is_data_view_api] +// [Start napi_get_data_view_info_api] export const getDataViewInfo: (dataView: DataView, infoType: number) => ArrayBuffer | number; // 使用Node-API接口进行array相关开发 napi_get_dataview_info +// [End napi_get_data_view_info_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets index 5834bc1974d890398e6bea4b2e469ef9d5eebdac..c85ea228c169b9174c1f1b01c83b27c7bd507a8f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets @@ -59,22 +59,29 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateArray') { + // [Start ark_napi_create_array] //使用Node-API接口进行array相关开发 napi_create_array hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array:%{public}s', JSON.stringify(testNapi.createArray())); + // [End ark_napi_create_array] this.result = 'napiCreateArraySuccess'; } else if (item === '2.napiCreateArrayWithLength') { + // [Start ark_napi_create_array_with_length] // 使用Node-API接口进行array相关开发 napi_create_array_with_length let array = testNapi.createArrayWithLength(6); hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array_with_length:%{public}d', array.length); + // [End ark_napi_create_array_with_length] this.result = 'napiCreateArrayWithLengthSuccess'; } else if (item === '3.napiGetArrayLength') { + // [Start ark_napi_get_array_length] // 使用Node-API接口进行array相关开发 napi_get_array_length const arr = [0, 1, 2, 3, 4, 5]; hilog.info(0x0000, 'testTag', 'Test Node-API get_array_length:%{public}d', testNapi.getArrayLength(arr)); + // [End ark_napi_get_array_length] this.result = 'napiGetArrayLengthSuccess'; } else if (item === '4.napiIsArray') { + // [Start ark_napi_is_array] // 使用Node-API接口进行array相关开发 napi_is_array try { let value = new Array(1); @@ -83,12 +90,18 @@ struct Index { testNapi.isArray(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', testNapi.isArray(data)); + // [StartExclude ark_napi_is_array] this.result = 'napiIsArraySuccess'; + // [EndExclude ark_napi_is_array] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_array error: %{public}s', error.message); + // [StartExclude ark_napi_is_array] this.result = 'napiIsArrayFail'; + // [EndExclude ark_napi_is_array] } + // [End ark_napi_is_array] } else if (item === '5.napiSetElement') { + // [Start ark_napi_set_element] // 使用Node-API接口进行array相关开发 napi_set_element let arr = [10, 20, 30]; testNapi.napiSetElement(arr, 1, 'newElement'); @@ -108,8 +121,10 @@ struct Index { testNapi.napiSetElement(arr, 4, obj); let objAsString = JSON.stringify(arr[4]); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[4]: %{public}s', objAsString); + // [End ark_napi_set_element] this.result = 'napiSetElementSuccess'; } else if (item === '6.napiGetElement') { + // [Start ark_napi_get_element] // 使用Node-API接口进行array相关开发 napi_get_element interface MyObject { first: number; @@ -133,16 +148,20 @@ struct Index { JSON.stringify(testNapi.napiGetElement(arr, 4))); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[null]: %{public}s', testNapi.napiGetElement(arr, 5)); + // [End ark_napi_get_element] this.result = 'napiGetElementSuccess'; } else if (item === '7.napiHasElement') { + // [Start ark_napi_has_element] // 使用Node-API接口进行array相关开发 napi_has_element let arr = [10, 'hello', null, 'world']; hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[7]: %{public}s', testNapi.napiHasElement(arr, 7)); + // [End ark_napi_has_element] this.result = 'napiHasElementSuccess'; } else if (item === '8.napiDeleteElement') { + // [Start ark_napi_delete_element] // 使用Node-API接口进行array相关开发 napi_delete_element let arr = [10, 'hello', null, 'world']; hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', @@ -153,20 +172,28 @@ struct Index { testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', testNapi.napiGetElement(arr, 0)); + // [End ark_napi_delete_element] this.result = 'napiDeleteElementSuccess'; } else if (item === '9.napiCreateTypedArray') { + // [Start ark_napi_create_typed_array] // 使用Node-API接口进行array相关开发 napi_create_typedarray let typedArray = testNapi.createTypedArray(testNapi.TypedArrayTypes["INT8_ARRAY"]); if (typedArray instanceof Int8Array) { hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Int8Array'); + // [StartExclude ark_napi_create_typed_array] this.result = 'napiCreateInt8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] } let uint8Array = testNapi.createTypedArray(testNapi.TypedArrayTypes["UINT8_ARRAY"]); if (uint8Array instanceof Uint8Array) { hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Uint8Array'); + // [StartExclude ark_napi_create_typed_array] this.result = 'napiCreateUint8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] } + // [End ark_napi_create_typed_array] } else if (item === '10.napiIsTypedArray') { + // [Start ark_napi_is_typed_array] // 使用Node-API接口进行array相关开发 napi_is_typedarray try { let value = new Uint8Array([1, 2, 3, 4]); @@ -175,12 +202,18 @@ struct Index { testNapi.isTypedarray(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', testNapi.isTypedarray(data)); + // [StartExclude ark_napi_is_typed_array] this.result = 'napiIsTypedArraySuccess'; + // [EndExclude ark_napi_is_typed_array] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_typedarray error: %{public}s', error.message); + // [StartExclude ark_napi_is_typed_array] this.result = 'napiIsTypedArrayFail'; + // [EndExclude ark_napi_is_typed_array] } + // [End ark_napi_is_typed_array] } else if (item === '11.napiGetTypedArrayInfo') { + // [Start ark_napi_get_typed_array_info] // 使用Node-API接口进行array相关开发 napi_get_typedarray_info // 传入TypedArray类型数据。TypedArray是一种用来描述二进制数据的类数组数据视图,没有直接构造器,可以用其子类构造类数组 // TypedArray的子类有: Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array等 @@ -202,15 +235,19 @@ struct Index { testNapi.getTypedarrayInfo(int8Array, InfoType.LENGTH)); hilog.info(0x0000, 'Node-API', 'get_typedarray_info_byte_offset: %{public}d', testNapi.getTypedarrayInfo(int8Array, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_typed_array_info] this.result = 'napiGetTypedArrayInfoSuccess'; } else if (item === '12.napiCreateDataView') { + // [Start ark_napi_create_data_view] // 使用Node-API接口进行array相关开发 napi_create_dataview const arrayBuffer = new ArrayBuffer(16); const dataView = testNapi.createDataView(arrayBuffer) as DataView; hilog.info(0x0000, 'testTag', 'Test Node-API dataView:%{public}d', dataView.byteLength); hilog.info(0x0000, 'testTag', 'Test Node-API dataView第一个数据:%{public}d', dataView.getInt8(0)); + // [End ark_napi_create_data_view] this.result = 'napiCreateDataViewSuccess'; } else if (item === '13.napiIsDataView') { + // [Start ark_napi_is_data_view] // 使用Node-API接口进行array相关开发 napi_is_dataview try { let buffer = new ArrayBuffer(16); @@ -220,12 +257,18 @@ struct Index { testNapi.isDataView(dataView)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', testNapi.isDataView(data)); + // [StartExclude ark_napi_is_data_view] this.result = 'napiIsDataViewSuccess'; + // [EndExclude ark_napi_is_data_view] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_dataview error: %{public}s', error.message); + // [StartExclude ark_napi_is_data_view] this.result = 'napiIsDataViewFail'; + // [EndExclude ark_napi_is_data_view] } + // [End ark_napi_is_data_view] } else if (item === '14.napiGetDataViewInfo') { + // [Start ark_napi_get_data_view_info] // 使用Node-API接口进行array相关开发 napi_get_dataview_info // 创建一个ArrayBuffer let arrayBuffer = new Int8Array([2, 5]).buffer; @@ -248,6 +291,7 @@ struct Index { // 传入DataView类型参数查询DataView开始投影的数据缓冲区中的字节偏移量 hilog.info(0x0000, 'Node-API', 'get_dataview_info_byteoffset %{public}d', testNapi.getDataViewInfo(dataView, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_data_view_info] this.result = 'napiGetDataViewInfoSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp index e7a8b5444a786210cb7f3871b953a175e7c43a3f..0371f4cf45ce542e5c06667d3c23c934e80949ff 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_is_arraybuffer] // napi_is_arraybuffer static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) { @@ -34,7 +35,9 @@ static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_is_arraybuffer] +// [Start napi_get_arraybuffer_info] // napi_get_arraybuffer_info static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) { @@ -69,7 +72,9 @@ static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) napi_set_named_property(env, result, "buffer", bufferData); return result; } +// [End napi_get_arraybuffer_info] +// [Start napi_detach_arraybuffer] // napi_detach_arraybuffer static napi_value DetachedArraybuffer(napi_env env, napi_callback_info info) { @@ -98,7 +103,9 @@ static napi_value IsDetachedArraybuffer(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_detach_arraybuffer] +// [Start napi_create_arraybuffer] // napi_create_arraybuffer static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) { @@ -121,6 +128,7 @@ static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) // 返回ArrayBuffer return result; } +// [End napi_create_arraybuffer] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts index 9f6763309a3f82247780debf8a994f9680283c51..3bcabf7866b12bc1291c2c8e68259966208b6934 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,17 +13,25 @@ * limitations under the License. */ +// [Start napi_is_arraybuffer_api] export const isArrayBuffer: (arrayBuffer: T) => boolean | void; // napi_is_arraybuffer +// [End napi_is_arraybuffer_api] +// [Start napi_get_arraybuffer_info_api] export class ArrayBufferInfo { byteLength: number; buffer: Object; } export const getArraybufferInfo: (data: ArrayBuffer) => ArrayBufferInfo | void; // napi_get_arraybuffer_info +// [End napi_get_arraybuffer_info_api] +// [Start napi_detach_arraybuffer_api] export const detachedArraybuffer: (buffer: ArrayBuffer) => ArrayBuffer; // napi_detach_arraybuffer export const isDetachedArraybuffer: (arrarBeffer: ArrayBuffer) => boolean; //napi_is_detached_arraybuffer +// [End napi_detach_arraybuffer_api] -export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer \ No newline at end of file +// [Start napi_create_arraybuffer_api] +export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer +// [End napi_create_arraybuffer_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets index 1256ffa0219532fc76d550fa94aed89ebb50bbdb..3b51abe806f5354d26375c1dbdcc9786614870d8 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets @@ -48,6 +48,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiIsArraybuffer') { + // [Start ark_napi_is_arraybuffer] // napi_is_arraybuffer try { let value = new ArrayBuffer(1); @@ -56,19 +57,27 @@ struct Index { testNapi.isArrayBuffer(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', testNapi.isArrayBuffer(data)); + // [StartExclude ark_napi_is_arraybuffer] this.result = 'napiIsArraybufferSuccess'; + // [EndExclude ark_napi_is_arraybuffer] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer error: %{public}s', error.message); + // [StartExclude ark_napi_is_arraybuffer] this.result = 'napiIsArraybufferFail'; + // [EndExclude ark_napi_is_arraybuffer] } + // [End ark_napi_is_arraybuffer] } else if (item === '2.napiGetArraybufferInfo') { + // [Start ark_napi_get_arraybuffer_info // napi_get_arraybuffer_info const buffer = new ArrayBuffer(10); hilog.info(0x0000, 'testTag', 'Test Node-API get_arraybuffer_info:%{public}s ', JSON.stringify(testNapi.getArraybufferInfo(buffer))); + // [End ark_napi_get_arraybuffer_info] this.result = 'napiGetArraybufferInfoSuccess'; } else if (item === '3.napiDetachArraybuffer') { + // [Start ark_napi_detach_arraybuffer] // napi_detach_arraybuffer and napi_is_detached_arraybuffer try { const bufferArray = new ArrayBuffer(8); @@ -76,16 +85,23 @@ struct Index { testNapi.isDetachedArraybuffer(bufferArray)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer two: %{public}s ', testNapi.isDetachedArraybuffer(testNapi.detachedArraybuffer(bufferArray))); + // [StartExclude ark_napi_detach_arraybuffer] this.result = 'napiDetachArraybufferSuccess'; + // [EndExclude ark_napi_detach_arraybuffer] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer error: %{public}s', error.message); + // [StartExclude ark_napi_detach_arraybuffer] this.result = 'napiDetachArraybufferFail'; + // [EndExclude ark_napi_detach_arraybuffer] } + // [End ark_napi_detach_arraybuffer] } else if (item === '4.napiCreateArraybuffer') { + // [Start ark_napi_create_arraybuffer] // napi_create_arraybuffer hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_arraybuffer:%{public}s', testNapi.createArraybuffer(10).toString()); + // [End ark_napi_create_arraybuffer] this.result = 'napiCreateArraybufferSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp index ab8e421cfbb162c4cb8820bd8348d0b4ee6df768..e752683274f9874834d213a1ed4bd58aa24398b2 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_get_value_uint32] // napi_get_value_uint32 static napi_value GetValueUint32(napi_env env, napi_callback_info info) { @@ -36,7 +37,9 @@ static napi_value GetValueUint32(napi_env env, napi_callback_info info) napi_create_uint32(env, number, &result); return result; } +// [End napi_get_value_uint32] +// [Start napi_get_value_int32] // napi_get_value_int32 static napi_value GetValueInt32(napi_env env, napi_callback_info info) { @@ -56,7 +59,9 @@ static napi_value GetValueInt32(napi_env env, napi_callback_info info) napi_create_int32(env, result32, &napiResult32); return napiResult32; } +// [End napi_get_value_int32] +// [Start napi_get_value_int64] // napi_get_value_int64 static napi_value GetValueInt64(napi_env env, napi_callback_info info) { @@ -76,7 +81,9 @@ static napi_value GetValueInt64(napi_env env, napi_callback_info info) napi_create_int64(env, result64, &napiResult64); return napiResult64; } +// [End napi_get_value_int64] +// [Start napi_get_value_double] // napi_get_value_double static napi_value GetDouble(napi_env env, napi_callback_info info) { @@ -93,7 +100,9 @@ static napi_value GetDouble(napi_env env, napi_callback_info info) napi_create_double(env, value, &result); return result; } +// [End napi_get_value_double] +// [Start napi_create_int32] // napi_create_int32 static napi_value CreateInt32(napi_env env, napi_callback_info info) { @@ -109,7 +118,9 @@ static napi_value CreateInt32(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_int32] +// [Start napi_create_uint32] // napi_create_uint32 static napi_value CreateUInt32(napi_env env, napi_callback_info info) { @@ -127,7 +138,9 @@ static napi_value CreateUInt32(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_uint32] +// [Start napi_create_int64] // napi_create_int64 static napi_value CreateInt64(napi_env env, napi_callback_info info) { @@ -143,7 +156,9 @@ static napi_value CreateInt64(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_int64] +// [Start napi_create_double] // napi_create_double static napi_value CreateDouble(napi_env env, napi_callback_info info) { @@ -157,6 +172,7 @@ static napi_value CreateDouble(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_double] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts index 920b4ba9aa69197d859f46ff8a3ff0debc49de91..1901dd8f17bf869c5e3357e4cbac52b5fbffebed 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,18 +13,34 @@ * limitations under the License. */ +// [Start napi_get_value_uint32_api] export const getValueUint32: (data: T) => number | void; // napi_get_value_uint32 +// [End napi_get_value_uint32_api] +// [Start napi_get_value_int32_api] export const getValueInt32: (value: number | string) => number | void; // napi_get_value_int32 +// [End napi_get_value_int32_api] +// [Start napi_get_value_int64_api] export const getValueInt64: (value: number | string) => number | void; // napi_get_value_int64 +// [End napi_get_value_int64_api] +// [Start napi_get_value_double_api] export const getDouble: (value: number | string) => number | void; // napi_get_value_double +// [End napi_get_value_double_api] +// [Start napi_create_int32_api] export const createInt32: () => number; // napi_create_int32 +// [End napi_create_int32_api] +// [Start napi_create_uint32_api] export const createUInt32: () => number; // napi_create_uint32 +// [End napi_create_uint32_api] +// [Start napi_create_int64_api] export const createInt64: () => number; // napi_create_int64 +// [End napi_create_int64_api] -export const createDouble: () => number; // napi_create_double \ No newline at end of file +// [Start napi_create_double_api] +export const createDouble: () => number; // napi_create_double +// [End napi_create_double_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets index 94a2a780f19dbe5e06483b92c45d25aa0e1bbf54..20023e52c93bdf946ccd234b71fc3af77213ccb4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets @@ -52,6 +52,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetValueUint32') { + // [Start ark_napi_get_value_uint32] // napi_get_value_uint32 let value = testNapi.getValueUint32(111111111111); let data = testNapi.getValueUint32("sssss"); @@ -61,8 +62,10 @@ struct Index { // 传入uint32范围内的数字100时函数返回原数字 hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', testNapi.getValueUint32(100)); + // [End ark_napi_get_value_uint32] this.result = 'napiGetValueUint32Success'; } else if (item === '2.napiGetValueInt32') { + // [Start ark_napi_get_value_int32] // napi_get_value_int32 // 传入非数字“ss”时函数返回undefined hilog.info(0x0000, 'Node-API', 'get_value_int32_not_number %{public}s', testNapi.getValueInt32('ss')); @@ -80,8 +83,10 @@ struct Index { testNapi.getValueInt32(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int32_number_-Infinity %{public}d', testNapi.getValueInt32(-Infinity)); + // [End ark_napi_get_value_int32] this.result = 'napiGetValueInt32Success'; } else if (item === '3.napiGetValueInt64') { + // [Start ark_napi_get_value_int64] // napi_get_value_int64 // 输入不超过int64表示范围的数字,会返回该数字 hilog.info(0x0000, 'Node-API', 'get_value_int64_number %{public}d', testNapi.getValueInt64(80)); @@ -97,29 +102,40 @@ struct Index { testNapi.getValueInt64(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int64_number_-Infinity %{public}d', testNapi.getValueInt64(-Infinity)); + // [End ark_napi_get_value_int64] this.result = 'napiGetValueInt64Success'; } else if (item === '4.napiGetValueDouble') { + // [Start ark_napi_get_value_double] // napi_get_value_double // 输入数字,返回该数字 hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.getDouble(80.885)); // 传入非数字,获得函数返回的值应为undefined hilog.info(0x0000, 'Node-API', 'get_value_double_not_number %{public}s', testNapi.getDouble('sAs')); + // [End ark_napi_get_value_double] this.result = 'napiGetValueDoubleSuccess'; } else if (item === '5.napiCreateInt32') { + // [Start ark_napi_create_int32] // napi_create_int32 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int32:' + testNapi.createInt32()); + // [End ark_napi_create_int32] this.result = 'napiCreateInt32Success'; } else if (item === '6.napiCreateUint32') { + // [Start ark_napi_create_uint32] // napi_create_uint32 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_uint32: ' + testNapi.createUInt32()); + // [End ark_napi_create_uint32] this.result = 'napiCreateUint32Success'; } else if (item === '7.napiCreateInt64') { + // [Start ark_napi_create_int64] // napi_create_int64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int64: ' + testNapi.createInt64()); + // [End ark_napi_create_int64] this.result = 'napiCreateInt64Success'; } else if (item === '8.napiCreateDouble') { + // [Start ark_napi_create_double] // napi_create_double hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_double: ' + testNapi.createDouble()); + // [End ark_napi_create_double] this.result = 'napiCreateDoubleSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp index 557e9203010ab377ac0ae5bf18f3f67434388565..0dc16e8bebe36cb06e4246d118b02851783dd24a 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "napi/native_api.h" #include "hilog/log.h" +// [Start napi_create_bigint_int64] // napi_create_bigint_int64 static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) { @@ -26,7 +27,9 @@ static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) napi_create_bigint_int64(env, value, &returnValue); return returnValue; } +// [End napi_create_bigint_int64] +// [Start napi_create_bigint_uint64] // napi_create_bigint_uint64 static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) { @@ -37,7 +40,9 @@ static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) napi_create_bigint_uint64(env, value, &returnValue); return returnValue; } +// [End napi_create_bigint_uint64] +// [Start napi_create_bigint_words] // napi_create_bigint_words static napi_value CreateBigintWords(napi_env env, napi_callback_info info) { @@ -53,7 +58,9 @@ static napi_value CreateBigintWords(napi_env env, napi_callback_info info) } return returnValue; } +// [End napi_create_bigint_words] +// [Start napi_get_value_bigint_int64] // napi_get_value_bigint_int64 static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) { @@ -74,7 +81,9 @@ static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) napi_get_boolean(env, status == napi_ok, &returnValue); return returnValue; } +// [End napi_get_value_bigint_int64] +// [Start napi_get_value_bigint_uint64] // napi_get_value_bigint_uint64 static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) { @@ -95,7 +104,9 @@ static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) napi_get_boolean(env, status == napi_ok, &returnValue); return returnValue; } +// [End napi_get_value_bigint_uint64] +// [Start napi_get_value_bigint_words] // napi_get_value_bigint_words static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) { @@ -121,6 +132,7 @@ static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) napi_create_int32(env, signBit, &returnValue); return returnValue; } +// [End napi_get_value_bigint_words] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts index c456f8f1c9d4f2895bf4bb923e0c445a3cfc37d4..9a160cff4e70a20d2556da8fe782d46ade730bde 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,26 @@ * limitations under the License. */ +// [Start napi_create_bigint_int64_api] export const createBigintInt64t: () => bigint; // napi_create_bigint_int64 +// [End napi_create_bigint_int64_api] +// [Start napi_create_bigint_uint64_api] export const createBigintUint64t: () => bigint; // napi_create_bigint_uint64 +// [End napi_create_bigint_uint64_api] +// [Start napi_create_bigint_words_api] export const createBigintWords: () => bigint | void; // napi_create_bigint_words +// [End napi_create_bigint_words_api] +// [Start napi_get_value_bigint_int64_api] export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void; // napi_get_value_bigint_int64 +// [End napi_get_value_bigint_int64_api] +// [Start napi_get_value_bigint_uint64_api] export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void; // napi_get_value_bigint_uint64 +// [End napi_get_value_bigint_uint64_api] -export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words \ No newline at end of file +// [Start napi_get_value_bigint_words_api] +export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words +// [End napi_get_value_bigint_words_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets index 06d29338e9d9a75902100f91de76e377738d7e90..2da3dcf00cba72d736c8097bf2f17383edcd0fa4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets @@ -52,48 +52,71 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateBigintInt64') { + // [Start ark_napi_create_bigint_int64] // napi_create_bigint_int64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', testNapi.createBigintInt64t()); + // [End ark_napi_create_bigint_int64] this.result = 'napiCreateBigintInt64Success'; } else if (item === '2.napiCreateBigintUint64') { + // [Start ark_napi_create_bigint_uint64] // napi_create_bigint_uint64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', testNapi.createBigintUint64t()); + // [End ark_napi_create_bigint_uint64] this.result = 'napiCreateBigintUint64Success'; } else if (item === '3.napiCreateBigintWords') { + // [Start ark_napi_create_bigint_words] // napi_create_bigint_words try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_words: %{public}d', testNapi.createBigintWords()); + // [StartExclude ark_napi_create_bigint_words] this.result = 'napiCreateBigintWordsSuccess'; + // [EndExclude ark_napi_create_bigint_words] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_create_bigint_words] this.result = 'napiCreateBigintWordsFail'; + // [EndExclude ark_napi_create_bigint_words] } + // [End ark_napi_create_bigint_words] } else if (item === '4.napiGetValueBigintInt64') { + // [Start ark_napi_get_value_bigint_int64] // napi_get_value_bigint_int64 let bigInt = BigInt(-5555555555555555); try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_int64: %{public}s', JSON.stringify(testNapi.getValueBigintInt64t(bigInt))); + // [StartExclude ark_napi_get_value_bigint_int64] this.result = 'napiGetValueBigintInt64Success'; + // [EndExclude ark_napi_get_value_bigint_int64] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_int64] this.result = 'napiGetValueBigintInt64Fail'; + // [EndExclude ark_napi_get_value_bigint_int64] } + // [End ark_napi_get_value_bigint_int64] } else if (item === '5.napiGetValueBigintUint64') { + // [Start ark_napi_get_value_bigint_uint64] // napi_get_value_bigint_uint64 let bigUint = BigInt(5555555555555555); try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_uint64: %{public}s', JSON.stringify(testNapi.getValueBigintUint64t(bigUint))); + // [StartExclude ark_napi_get_value_bigint_uint64] this.result = 'napiGetValueBigintUint64Success'; + // [EndExclude ark_napi_get_value_bigint_uint64] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_uint64] this.result = 'napiGetValueBigintUint64Fail'; + // [EndExclude ark_napi_get_value_bigint_uint64] } + // [End ark_napi_get_value_bigint_uint64] } else if (item === '6.napiGetValueBigintWords') { + // [Start ark_napi_get_value_bigint_words] // napi_get_value_bigint_words let bigInt = BigInt(-5555555555555555); let bigUint = BigInt(5555555555555555); @@ -102,11 +125,16 @@ struct Index { testNapi.getValueBigintWords(bigInt)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', testNapi.getValueBigintWords(bigUint)); + // [StartExclude ark_napi_get_value_bigint_words] this.result = 'napiGetValueBigintWordsSuccess'; + // [EndExclude ark_napi_get_value_bigint_words] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_words] this.result = 'napiGetValueBigintWordsFail'; + // [EndExclude ark_napi_get_value_bigint_words] } + // [End ark_napi_get_value_bigint_words] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp index d8cb01c5d61004bc7d417312010b5c6199177860..22f52d776fdf54e196c50fdda0816331708d6541 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp @@ -19,6 +19,7 @@ static constexpr int INT_ARG_18 = 18; // 入参索引 +// [Start napi_new_instance] // napi_new_instance static napi_value NewInstance(napi_env env, napi_callback_info info) { @@ -31,7 +32,9 @@ static napi_value NewInstance(napi_env env, napi_callback_info info) napi_new_instance(env, args[0], 1, &args[1], &result); return result; } +// [End napi_new_instance] +// [Start napi_wrap_unwrap_remove_wrap] struct Object { std::string name; int32_t age; @@ -89,6 +92,7 @@ static napi_value UnWrap(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "Node-API age: %{public}d", data->age); return nullptr; } +// [End napi_wrap_unwrap_remove_wrap] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts index 3ba0ba16861ff0dfe9a9ac47fa2700df19dd7f33..9e0e5aa76de9946bc3dd33a0dfe55fd720debdae 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start napi_new_instance_api] export const newInstance: (obj: Object, param: string) => Object // napi_new_instance +// [End napi_new_instance_api] +// [Start napi_wrap_unwrap_remove_wrap_api] export const wrap: (obj: Object) => Object; // napi_wrap export const unWrap: (obj: Object) => void; // napi_unwrap -export const removeWrap: (obj: Object) => void; // napi_remove_wrap \ No newline at end of file +export const removeWrap: (obj: Object) => void; // napi_remove_wrap +// [End napi_wrap_unwrap_remove_wrap_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets index 08f8b58942d22a7ee34bab386a938e4a8347507d..c3092dc54e1ef5f757bfc8e33bfbc259c3abd752 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets @@ -16,6 +16,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; +// [Start ark_napi_new_instance] class Fruit { name: string; @@ -24,6 +25,7 @@ class Fruit { } } +// [StartExclude ark_napi_new_instance] @Entry @Component struct Index { @@ -55,13 +57,16 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiNewInstance') { + // [EndExclude ark_napi_new_instance] // napi_new_instance // 调用函数,用变量obj接收函数返回的实例化对象 let obj = testNapi.newInstance(Fruit, 'test'); // 打印实例化对象obj的信息 hilog.info(0x0000, 'Node-API', 'napi_new_instance %{public}s', JSON.stringify(obj)); + // [End ark_napi_new_instance] this.result = 'napiNewInstanceSuccess'; } else if (item === '2.napiRemoveWrap') { + // [Start ark_napi_wrap_unwrap_remove_wrap] try { class Obj { } @@ -70,11 +75,16 @@ struct Index { testNapi.wrap(obj) // napi_wrap testNapi.unWrap(obj) // napi_unwrap testNapi.removeWrap(obj) // napi_remove_wrap + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] this.result = 'napiRemoveWrapSuccess'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API error: %{public}s', error.message); + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] this.result = 'napiRemoveWrapFail'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] } + // [End ark_napi_wrap_unwrap_remove_wrap] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp index a0433d5b336069522b75e890e4dbf8e54de82176..0d5588f21e2dbe152501dc27e5826b1c49bab53b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_remove_add_env_cleanup_hook] #include #include #include @@ -29,10 +30,12 @@ typedef struct { void ExternalFinalize(napi_env env, void *finalizeData, void *finalizeHint) { Memory *wrapper = (Memory *)finalizeHint; + // [StartExclude napi_remove_add_env_cleanup_hook] if (wrapper == nullptr) { //处理内存分配失败的情况 return; } + // [EndExclude napi_remove_add_env_cleanup_hook] free(wrapper->data); free(wrapper); OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook ExternalFinalize"); @@ -51,10 +54,12 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) // 分配内存并复制字符串数据到内存中 std::string str("Hello from Node-API!"); Memory *wrapper = (Memory *)malloc(sizeof(Memory)); + // [StartExclude napi_remove_add_env_cleanup_hook] if (wrapper == nullptr) { //处理内存分配失败的情况 return nullptr; } + // [End napi_remove_add_env_cleanup_hook] wrapper->data = static_cast(malloc(str.size())); strcpy(wrapper->data, str.c_str()); wrapper->size = str.size(); @@ -82,7 +87,9 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) // 返回创建的外部缓冲区对象 return buffer; } +// [End napi_remove_add_env_cleanup_hook] +// [Start napi_add_remove_async_cleanup_hook] typedef struct { napi_env env; void *testData; @@ -135,10 +142,12 @@ static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) { // 分配AsyncContent内存 AsyncContent *data = reinterpret_cast(malloc(sizeof(AsyncContent))); + // StartExclude napi_add_remove_async_cleanup_hook] if (data == nullptr) { //处理内存分配失败的情况 return nullptr; } + // [EndExclude napi_add_remove_async_cleanup_hook] data->env = env; data->cleanupHandle = nullptr; // 分配内存并复制字符串数据 @@ -156,6 +165,7 @@ static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) napi_get_boolean(env, true, &result); return result; } +// [End napi_add_remove_async_cleanup_hook] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts index 6766aa4cebff9796adab515b926d40e13bf1a0fe..b48f7cfd466f8f5e34d86a59e05f5460583af8bd 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,6 +13,10 @@ * limitations under the License. */ +// [Start napi_remove_add_env_cleanup_hook_api] export const napiEnvCleanUpHook: () => Object | void; +// [End napi_remove_add_env_cleanup_hook_api] -export const napiAsyncCleanUpHook: () => boolean | void; \ No newline at end of file +// [Start napi_add_remove_async_cleanup_hook_api] +export const napiAsyncCleanUpHook: () => boolean | void; +// [End napi_add_remove_async_cleanup_hook_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets index bb2ffec336f6bb07611b029f888373fc5a33ca3d..6b502b025668f190e817b190f1b240b3991498b4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets @@ -48,6 +48,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiRemoveEnvCleanupHook') { + // [Start connect_with_worker] let wk = new worker.ThreadWorker('entry/ets/workers/worker.ts'); // 发送消息到worker线程 wk.postMessage('test NapiEnvCleanUpHook'); @@ -57,18 +58,25 @@ struct Index { JSON.stringify(message)); wk.terminate(); }; + // [End connect_with_worker] this.result = 'napiRemoveEnvCleanupHookSuccess'; } else if (item === '2.napiRemoveAsyncCleanupHook') { + // [Start ark_napi_remove_add_env_cleanup_hook] try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook: %{public}s', testNapi.napiAsyncCleanUpHook()); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] this.result = 'napiRemoveAsyncCleanupHookSuccess'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook error.message: %{public}s', error.message); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] this.result = 'napiRemoveAsyncCleanupHookFail'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] } + // [End ark_napi_remove_add_env_cleanup_hook] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts index e73b154e151cec1c982f55bfd6ee852d29cf035d..263ec4cd73b5139daa1a52fa05fe5b7595ac9470 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start connect_with_main_thread] import hilog from '@ohos.hilog'; import worker from '@ohos.worker'; import testNapi from 'libentry.so'; @@ -23,4 +24,5 @@ parent.onmessage = function(message) { hilog.info(0x0000, 'testTag', 'Test Node-API message from main thread: %{public}s', JSON.stringify(message)); // 发送消息到主线程 parent.postMessage('Test Node-API worker:' + testNapi.napiEnvCleanUpHook()); -} \ No newline at end of file +} +// [End connect_with_main_thread] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp index 79ab15c6723d8535dfe890ef516a9922a1ae868d..f4fc6dc4926ddf520cc70ff22c601d496f3698d3 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_create_date] #include #include "napi/native_api.h" @@ -26,7 +27,9 @@ static napi_value CreateDate(napi_env env, napi_callback_info info) napi_create_date(env, value, &returnValue); return returnValue; } +// [End napi_create_date] +// [Start napi_get_date_value] // napi_get_date_value static napi_value GetDateValue(napi_env env, napi_callback_info info) { @@ -50,7 +53,9 @@ static napi_value GetDateValue(napi_env env, napi_callback_info info) napi_create_double(env, value, &returnValue); return returnValue; } +// [End napi_get_date_value] +// [Start napi_is_date] // napi_is_date static napi_value IsDate(napi_env env, napi_callback_info info) { @@ -72,6 +77,7 @@ static napi_value IsDate(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_date] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts index aa417c78b8959a51abc3765e448db8309a127dee..8492f673288d7b15cfa02aa7134b9aca9866c4c2 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,8 +13,14 @@ * limitations under the License. */ +// [Start napi_create_date_api] export const createDate: () => Date; // napi_create_date +// [End napi_create_date_api] +// [Start napi_get_date_value_api] export const getDateValue: (date: Date) => number | void; // napi_get_date_value +// [End napi_get_date_value_api] -export const isDate: (date: T) => boolean | void; // napi_is_date \ No newline at end of file +// [Start napi_is_date_api] +export const isDate: (date: T) => boolean | void; // napi_is_date +// [End napi_is_date_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets index 77b014627730285610230e2347f3c24fdad23bbf..ef8032c3650b9ede7bfe73d4a8329d20a3521a71 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets @@ -48,35 +48,49 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateDate') { + // [Start ark_napi_create_date] // napi_create_date hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_date: %{public}s', testNapi.createDate().toString()); + // [End ark_napi_create_date] this.result = 'napiCreateDateSuccess'; } else if (item === '2.napiGetDateValue') { + // [Start ark_napi_get_date_value] // napi_get_date_value try { const date = new Date(); hilog.info(0x0000, 'testTag', 'Node-API: output the Unix Time Stamp: %{public}d', date.getTime()); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_date_value: %{public}d', testNapi.getDateValue(date)); + // [StartExclude ark_napi_get_date_value] this.result = 'napiGetDateValueSuccess'; + // [EndExclude ark_napi_get_date_value] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_date_value error: %{public}s', error.message); + // [StartExclude ark_napi_get_date_value] this.result = 'napiGetDateValueFail'; + // [EndExclude ark_napi_get_date_value] } + // [End ark_napi_get_date_value] } else if (item === '3.napiIsDate') { + // [Start ark_napi_is_date] // napi_is_date try { let now: Date = new Date(); let date = "123"; hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(now)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(date)); + // [StartExclude ark_napi_is_date] this.result = 'napiIsDateSuccess'; + // [EndExclude ark_napi_is_date] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_date error: %{public}s', error.message); + // [StartExclude ark_napi_is_date] this.result = 'napiIsDateFail'; + // [EndExclude ark_napi_is_date] } + // [End ark_napi_is_date] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp index f6e441f7a7cec54d0e8d6310d1719ea6c400954c..4edf62a527fde6747aff0038f86a2bd53c8bc57a 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_set_instance_data] #include #include "napi/native_api.h" @@ -51,7 +52,9 @@ static napi_value SetInstanceData(napi_env env, napi_callback_info info) } return result; } +// [End napi_set_instance_data] +// [Start napi_get_instance_data] // napi_get_instance_data static napi_value GetInstanceData(napi_env env, napi_callback_info info) { @@ -62,6 +65,7 @@ static napi_value GetInstanceData(napi_env env, napi_callback_info info) napi_create_int32(env, resData->value, &result); return result; } +// [End napi_get_instance_data] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts index 5d22262414831bfe5a44b4c5b2fa33488eba5a48..2ed58066893cc90d6037199a635616821e58d221 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,6 +13,10 @@ * limitations under the License. */ +// [Start napi_set_instance_data_api] export const setInstanceData: (data: number) => boolean; // napi_set_instance_data +// [End napi_set_instance_data_api] -export const getInstanceData: () => number; // napi_get_instance_data \ No newline at end of file +// [Start napi_get_instance_data_api] +export const getInstanceData: () => number; // napi_get_instance_data +// [End napi_get_instance_data_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets index 020f9da88f1cfcfc4b3523915e5f09b7f83c2130..2d276e0e8d91fa7013602965df758ccb14403d08 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets @@ -47,17 +47,21 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiSetInstanceData') { + // [Start ark_napi_set_instance_data] // napi_set_instance_data let data = 5; let value = testNapi.setInstanceData(data); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}s', value); + // [End ark_napi_set_instance_data] this.result = 'napiSetInstanceDataSuccess'; } else if (item === '2.napiGetInstanceData') { + // [Start ark_napi_get_instance_data] // napi_get_instance_data let data = 5; testNapi.setInstanceData(data); let value = testNapi.getInstanceData(); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}d', value); + // [End ark_napi_get_instance_data] this.result = 'napiGetInstanceDataSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp index 6e11f230084f254744ce1ae1aca0b872c2b07ca1..e589bfa6570cacbe8cb7f9aa2018f6ac23f1699f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "hilog/log.h" #include "napi/native_api.h" +// [Start napi_get_last_error_info] // napi_get_last_error_info static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) { @@ -42,7 +43,9 @@ static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) napi_create_string_utf8(env, errorInfo->error_message, NAPI_AUTO_LENGTH, &result); return result; } +// [End napi_get_last_error_info] +// [Start napi_create_type_error] // napi_create_type_error static napi_value CreatTypeError(napi_env env, napi_callback_info info) { @@ -56,7 +59,9 @@ static napi_value CreatTypeError(napi_env env, napi_callback_info info) napi_create_type_error(env, errorCode, errorMessage, &error); return error; } +// [End napi_create_type_error] +// [Start napi_create_range_error] // napi_create_range_error static napi_value CreatRangeError(napi_env env, napi_callback_info info) { @@ -70,7 +75,9 @@ static napi_value CreatRangeError(napi_env env, napi_callback_info info) napi_create_range_error(env, errorCode, errorMessage, &error); return error; } +// [End napi_create_range_error] +// [Start napi_create_error] // napi_create_error and napi_throw static napi_value NapiThrow(napi_env env, napi_callback_info info) { @@ -88,7 +95,9 @@ static napi_value NapiThrow(napi_env env, napi_callback_info info) napi_throw(env, error); return nullptr; } +// [End napi_create_error] +// [Start napi_throw_error] // napi_throw_error // 这里直接抛出一个带有errorMessage的错误 static napi_value NapiThrowErrorMessage(napi_env env, napi_callback_info info) @@ -115,7 +124,9 @@ static napi_value NapiThrowError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_throw_error] +// [Start napi_throw_type_error] // napi_throw_type_error // 这里直接抛出一个带有errorMessage的TypeError static napi_value ThrowTypeErrorMessage(napi_env env, napi_callback_info info) @@ -141,7 +152,9 @@ static napi_value ThrowTypeError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_throw_type_error] +// [Start napi_throw_range_error] // napi_throw_range_error // 这里直接抛出一个带有errorMessage的RangeError static napi_value ThrowRangeErrorMessage(napi_env env, napi_callback_info info) @@ -173,7 +186,9 @@ static napi_value ThrowRangeError(napi_env env, napi_callback_info info) napi_create_double(env, result, &resultValue); return resultValue; } +// [End napi_throw_range_error] +// [Start napi_is_error] // napi_is_error static napi_value NapiIsError(napi_env env, napi_callback_info info) { @@ -190,7 +205,9 @@ static napi_value NapiIsError(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_is_error] +// [Start napi_get_and_clear_last_exception] // napi_get_and_clear_last_exception static napi_value GetAndClearLastException(napi_env env, napi_callback_info info) { @@ -204,7 +221,9 @@ static napi_value GetAndClearLastException(napi_env env, napi_callback_info info } return result; } +// [End napi_get_and_clear_last_exception] +// [Start napi_is_exception_pending] // napi_is_exception_pending static napi_value IsExceptionPending(napi_env env, napi_callback_info info) { @@ -229,7 +248,9 @@ static napi_value IsExceptionPending(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_is_exception_pending] +// [Start napi_fatal_error] // napi_fatal_error static napi_value FatalError(napi_env env, napi_callback_info info) { @@ -242,7 +263,9 @@ static napi_value FatalError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_fatal_error] +// [Start napi_fatal_exception] // napi_fatal_exception static napi_value FatalException(napi_env env, napi_callback_info info) { @@ -261,6 +284,7 @@ static napi_value FatalException(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_fatal_exception] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts index 26e38791920b4b89f885a7616fc7c83103026366..6458d55543619b58032d3e77de2462da0920af14 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,37 +13,63 @@ * limitations under the License. */ +// [Start napi_get_last_error_info_api] export const getLastErrorInfo: (str: string) => string; // napi_get_last_error_info +// [End napi_get_last_error_info_api] +// [Start napi_create_type_error_api] export const creatTypeError: () => Error; // napi_create_type_error +// [End napi_create_type_error_api] +// [Start napi_create_range_error_api] export const creatRangeError: () => Error; // napi_create_range_error +// [End napi_create_range_error_api] +// [Start napi_create_error_api] export const napiThrow: () => void; // napi_create_error and napi_throw +// [End napi_create_error_api] +// [Start napi_throw_error_api] export const napiThrowErrorMessage: () => void; // napi_throw_error export const napiThrowError: (dividend: number, divisor: number) => void; // napi_throw_error +// [End napi_throw_error_api] +// [Start napi_throw_type_error_api] export const throwTypeErrorMessage: () => void; // napi_throw_type_error export const throwTypeError: (message: string) => void; // napi_throw_type_error +// [End napi_throw_type_error_api] +// [Start napi_throw_range_error_api] export const throwRangeErrorMessage: () => void; // napi_throw_range_error export const throwRangeError: (num: number) => number | void; // napi_throw_range_error +// [End napi_throw_range_error_api] +// [Start napi_is_error_api] export const napiIsError: (obj: T) => boolean; // napi_is_error +// [End napi_is_error_api] +// [Start napi_get_and_clear_last_exception_api] export const getAndClearLastException: () => Error | void; // napi_get_and_clear_last_exception +// [End napi_get_and_clear_last_exception_api] +// [Start ark_napi_is_exception_pending_interface] export interface MyObject { code: string; message: string; } +// [End ark_napi_is_exception_pending_interface] +// [Start napi_is_exception_pending_api] export const isExceptionPending: () => Object | void; // napi_is_exception_pending +// [End napi_is_exception_pending_api] +// [Start napi_fatal_error_api] export const fatalError: () => void; // napi_fatal_error +// [End napi_fatal_error_api] -export const fatalException: (err: Error) => void; // napi_fatal_exception \ No newline at end of file +// [Start napi_fatal_exception_api] +export const fatalException: (err: Error) => void; // napi_fatal_exception +// [End napi_fatal_exception_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets index 85b5226b84ceb7556aacbd223ce90c5010198757..117809f4f7503145892a08e6cf735c32c33c8936 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets @@ -57,117 +57,174 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetLastErrorInfo') { + // [Start ark_napi_get_last_error_info] // napi_get_last_error_info try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info: %{public}s', testNapi.getLastErrorInfo('message')); + // [StartExclude ark_napi_get_last_error_info] this.result = 'napiGetLastErrorInfoSuccess'; + // [EndExclude ark_napi_get_last_error_info] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info error: %{public}s', error); + // [StartExclude ark_napi_get_last_error_info] this.result = 'napiGetLastErrorInfoFail'; + // [EndExclude ark_napi_get_last_error_info] } + // [End ark_napi_get_last_error_info] } else if (item === '2.napiCreateTypeError') { + // [Start ark_napi_create_type_error] try { + // [StartExclude ark_napi_create_type_error] this.result = 'napiCreateTypeErrorSuccess'; + // [EndExclude ark_napi_create_type_error] throw testNapi.creatTypeError(); } catch (error) { // napi_create_type_error hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_type_error errorCode: %{public}s, errorMessage %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_type_error] this.result = 'napiCreateTypeErrorFail'; + // [EndExclude ark_napi_create_type_error] } + // [End ark_napi_create_type_error] } else if (item === '3.napiCreateRangeError') { + // [Start ark_napi_create_range_error] // napi_create_range_error try { + // [StartExclude ark_napi_create_range_error] this.result = 'napiCreateRangeErrorSuccess'; + // [EndExclude ark_napi_create_range_error] throw testNapi.creatRangeError(); } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_range_error] this.result = 'napiCreateRangeErrorFail'; + // [EndExclude ark_napi_create_range_error] } + // [End ark_napi_create_range_error] } else if (item === '4.napiCreateErrorAndNapiThrow') { + // [Start ark_napi_create_error] // napi_create_error and napi_throw try { testNapi.napiThrow(); + // [StartExclude ark_napi_create_error] this.result = 'napiCreateErrorAndNapiThrowSuccess'; + // [EndExclude ark_napi_create_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_error] this.result = 'napiCreateErrorAndNapiThrowFail'; + // [EndExclude ark_napi_create_error] } + // [End ark_napi_create_error] } else if (item === '5.napiThrowError') { + // [Start ark_napi_throw_error] // napi_throw_error try { testNapi.napiThrowErrorMessage(); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorMessageSuccess'; + // [EndExclude ark_napi_throw_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_error error code: %{public}s , message: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorMessageFail'; + // [EndExclude ark_napi_throw_error] } try { testNapi.napiThrowError(5, 0); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorSuccess'; + // [EndExclude ark_napi_throw_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_error errorCode: %{public}s , errorManager: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorFail'; + // [EndExclude ark_napi_throw_error] } + // [End ark_napi_throw_error] } else if (item === '6.napiThrowTypeError') { + // [Start ark_napi_throw_type_error] // napi_throw_type_error try { testNapi.throwTypeErrorMessage(); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_type_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorMessageFail'; + // [EndExclude ark_napi_throw_type_error] } try { testNapi.throwTypeError('str'); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorSuccess'; + // [EndExclude ark_napi_throw_type_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorFail'; + // [EndExclude ark_napi_throw_type_error] } + // [End ark_napi_throw_type_error] } else if (item === '7.napiThrowRangeError') { + // [Start ark_napi_throw_range_error] // napi_throw_range_error try { testNapi.throwRangeErrorMessage(); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_range_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorMessageFail'; + // [EndExclude ark_napi_throw_range_error] } try { testNapi.throwRangeError(1); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorSuccess'; + // [EndExclude ark_napi_throw_range_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorFail'; + // [EndExclude ark_napi_throw_range_error] } + // [End ark_napi_throw_range_error] } else if (item === '8.napiIsError') { + // [Start ark_napi_is_error] // napi_is_error try { + // [StartExclude ark_napi_is_error] this.result = 'napiIsErrorSuccess'; + // [EndExclude ark_napi_is_error] throw new Error("throwing an error"); } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', @@ -176,43 +233,62 @@ struct Index { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', testNapi.napiIsError(1) .toString()); + // [StartExclude ark_napi_is_error] this.result = 'napiIsErrorFail'; + // [EndExclude ark_napi_is_error] } + // [End ark_napi_is_error] } else if (item === '9.napiGetAndClearLastException') { + // [Start ark_napi_get_and_clear_last_exception] // napi_get_and_clear_last_exception // 这里获取到最后一个未处理的异常 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_and_clear_last_exception, error.message: %{public}s', testNapi.getAndClearLastException()); + // [End ark_napi_get_and_clear_last_exception] this.result = 'napiGetAndClearLastExceptionSuccess'; } else if (item === '10.napiIsExceptionPending') { + // [Start ark_napi_is_exception_pending] // napi_is_exception_pending try { let result = testNapi.isExceptionPending() as MyObject; hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending, error.Code: %{public}s, error.message: %{public}s', result.code, result.message); + // [StartExclude ark_napi_is_exception_pending] this.result = 'napiIsExceptionPendingSuccess'; + // [EndExclude ark_napi_is_exception_pending] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending error'); + // [StartExclude ark_napi_is_exception_pending] this.result = 'napiIsExceptionPendingFail'; + // [EndExclude ark_napi_is_exception_pending] } + // [End ark_napi_is_exception_pending] } else if (item === '11.napiFatalError') { + // [Start ark_napi_fatal_error] // napi_fatal_error 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 // 模拟一个致命错误条件 try { testNapi.fatalError(); + // [StartExclude ark_napi_fatal_error] this.result = 'napiFatalErrorSuccess'; + // [EndExclude ark_napi_fatal_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_error error'); + // [StartExclude ark_napi_fatal_error] this.result = 'napiFatalErrorFail'; + // [EndExclude ark_napi_fatal_error] } + // [End ark_napi_fatal_error] } else if (item === '12.napiFatalException') { // napi_fatal_exception 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 // 模拟一个致命错误条件 try { + // [Start ark_napi_fatal_exception] const err = new Error("a fatal exception occurred"); testNapi.fatalException(err); + // [End ark_napi_fatal_exception] this.result = 'napiFatalExceptionSuccess'; } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_exception error'); diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp index 932f6bc8151962e01df519119f1e3294ba8e8ded..98fe63d9c102d4f90fe7242fdcad492a3e72b962 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp @@ -22,6 +22,7 @@ static constexpr int INT_ARG_100 = 100; // 入参索引 +// [Start node_api_module_add] // 模块加载 static napi_value Add(napi_env env, napi_callback_info info) { @@ -43,6 +44,9 @@ static napi_value Add(napi_env env, napi_callback_info info) return sum; } + +// [StartExclude node_api_module_add] +// [Start node_api_module_create_object_properties] // ArkTS Object相关 napi_create_object_with_properties static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info info) { @@ -62,6 +66,8 @@ static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info in return object; } } +// [End node_api_module_create_object_properties] +// [Start node_api_module_create_object_name_properties] // ArkTS Object相关 napi_create_object_with_named_properties static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_info info) { @@ -84,6 +90,8 @@ static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_inf } return obj; } +// [End node_api_module_create_object_name_properties] +// [Start node_api_module_run_script_path] // 运行指定abc文件 napi_run_script_path static napi_value RunScriptPath(napi_env env, napi_callback_info info) { @@ -101,7 +109,9 @@ static napi_value RunScriptPath(napi_env env, napi_callback_info info) } return returnValue; } +// [End node_api_module_run_script_path] // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object +// [Start napi_coerce_to_native_binding_object] class Object { public: Object() = default; @@ -264,6 +274,8 @@ napi_value AttachCallback(napi_env env, void *value, void *hint) napi_coerce_to_native_binding_object(env, object, DetachCallback, AttachCallback, value, hint); return object; } +// [StartExclude napi_coerce_to_native_binding_object] +// [Start napi_serialize_deserialize_delete_serialization_data] // 序列化和反序列化 static napi_value AboutSerialize(napi_env env, napi_callback_info info) { @@ -299,6 +311,8 @@ static napi_value AboutSerialize(napi_env env, napi_callback_info info) // 返回获取到的属性值 return number; } +// [End napi_serialize_deserialize_delete_serialization_data] +// [Start napi_is_sendable] // Sendable相关 napi_is_sendable static napi_value IsSendable(napi_env env, napi_callback_info info) { @@ -311,7 +325,9 @@ static napi_value IsSendable(napi_env env, napi_callback_info info) napi_get_boolean(env, isSendable, &result); return result; } +// [End napi_is_sendable] +// [Start napi_define_sendable_class] static napi_value func(napi_env env, napi_callback_info info) { napi_value val; @@ -353,6 +369,8 @@ static napi_value DefineSendableClass(napi_env env) return sendableClass; } +// [End napi_define_sendable_class] +// [Start napi_create_sendable_object_with_properties] // Sendable相关 napi_create_sendable_object_with_properties static napi_value GetSendableObject(napi_env env, napi_callback_info info) { @@ -365,6 +383,8 @@ static napi_value GetSendableObject(napi_env env, napi_callback_info info) napi_create_sendable_object_with_properties(env, 1, desc1, &obj); return obj; } +// [End napi_create_sendable_object_with_properties +// [Start napi_create_sendable_array] // Sendable相关 napi_create_sendable_array static napi_value GetSendableArray(napi_env env, napi_callback_info info) { @@ -372,6 +392,8 @@ static napi_value GetSendableArray(napi_env env, napi_callback_info info) napi_create_sendable_array(env, &result); return result; } +// [End napi_create_sendable_array] +// [Start napi_create_sendable_array_with_length] // Sendable相关 napi_create_sendable_array_with_length static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info info) { @@ -379,6 +401,8 @@ static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info in napi_create_sendable_array_with_length(env, 1, &result); return result; } +// End napi_create_sendable_array_with_length] +// [Start napi_create_sendable_arraybuffer] // Sendable相关 napi_create_sendable_arraybuffer static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) { @@ -391,6 +415,8 @@ static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "isArrayBuffer: %{public}d", isArrayBuffer); return result; } +// [End napi_create_sendable_arraybuffer] +// [Start napi_create_sendable_typed_array] // Sendable相关 napi_create_sendable_typedarray static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) { @@ -407,6 +433,8 @@ static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "isTypedArray: %{public}d", isTypedArray); return result; } +// [End napi_create_sendable_typed_array] +// [Start napi_wrap_sendable] // Sendable相关 napi_wrap_sendable static napi_value WrapSendable(napi_env env, napi_callback_info info) { @@ -424,6 +452,8 @@ static napi_value WrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_wrap_sendable] +// [Start napi_wrap_sendable_with_size] // Sendable相关 napi_wrap_sendable_with_size static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) { @@ -441,6 +471,8 @@ static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_wrap_sendable_with_size] +// [Start napi_unwrap_sendable] // Sendable相关 napi_unwrap_sendable static napi_value UnwrapSendable(napi_env env, napi_callback_info info) { @@ -462,6 +494,8 @@ static napi_value UnwrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_unwrap_sendable] +// [Start napi_remove_wrap_sendable] // Sendable相关 napi_remove_wrap_sendable static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) { @@ -483,6 +517,10 @@ static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_remove_wrap_sendable] +// [EndExclude napi_coerce_to_native_binding_object] +// [EndExclude node_api_module_add] + // C++函数Init用于初始化插件,用于将ArkTS层的函数或属性与C++层的函数进行关联 EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) @@ -522,7 +560,7 @@ static napi_value Init(napi_env env, napi_value exports) return exports; } EXTERN_C_END - + // 插件的初始化被定义在一个名为demoModule的结构体中,其中包含了模块的基本信息,比如模块的版本号、注册函数等 static napi_module demoModule = { .nm_version = 1, @@ -536,3 +574,5 @@ static napi_module demoModule = { // 在RegisterEntryModule函数中,使用napi_module_register函数注册并导出了这个插件 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End node_api_module_add] + diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts index 6108c3c906d846e99dd943ad292cc16d43b0d951..4f111a684b312d30bdbc185139a80dae0d9220e6 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,22 @@ * limitations under the License. */ +// [Start node_api_module_add_api] export const add: (a: number, b: number) => number; // 模块加载 +// [End node_api_module_add_api] +// [Start node_api_module_create_object_properties_api] export const createObjectWithProperties: (data: string) => Object; // ArkTS Object相关 napi_create_object_with_properties +// [End node_api_module_create_object_properties_api] +// [Start node_api_module_create_object_name_properties_api] export const createObjectWithNameProperties: (data: string) => string | { name: string }; // ArkTS Object相关 napi_create_object_with_named_properties +// [End node_api_module_create_object_name_properties_api] +// [Start node_api_module_run_script_path_api] export const runScriptPath: () => boolean; // 运行指定abc文件 napi_run_script_path - +// [End node_api_module_run_script_path_api] +// [Start napi_coerce_to_native_binding_object_api] // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object export const getAddress: () => number; @@ -31,11 +39,17 @@ export const store: (a: number) => void; export const erase: (a: number) => void; export const clear: () => void; +// [End napi_coerce_to_native_binding_object_api] +// [Start napi_serialize_deserialize_delete_serialization_data_api] export const aboutSerialize: (obj: Object) => number; // 序列化和反序列化 +// [End napi_serialize_deserialize_delete_serialization_data_api] +// [Start napi_is_sendable_api] export const isSendable: (a: T) => boolean; // Sendable相关 napi_is_sendable +// [End napi_is_sendable_api] +// [Start napi_define_sendable_class_api] @Sendable export class SendableClass { static staticStr: string; @@ -43,22 +57,40 @@ export class SendableClass { str: string; func(): string; } // Sendable相关 napi_define_sendable_class +// [End napi_define_sendable_class_api] +// [Start napi_create_sendable_object_with_properties_api] export const getSendableObject: () => { x: true }; // Sendable相关 napi_create_sendable_object_with_properties +// [End napi_create_sendable_object_with_properties_api] +// [Start napi_create_sendable_array_api] export const getSendableArray: () => []; // Sendable相关 napi_create_sendable_array +// [End napi_create_sendable_array_api] +// [Start napi_create_sendable_array_with_length_api] export const getSendableArrayWithLength: () => []; // Sendable相关 napi_create_sendable_array_with_length +// [End napi_create_sendable_array_with_length_api] +// [Start napi_create_sendable_arraybuffer_api] export const getSendableArrayBuffer: () => void; // Sendable相关 napi_create_sendable_arraybuffer +// [End napi_create_sendable_arraybuffer_api] +// [Start napi_create_sendable_typed_array_api] export const getSendableTypedArray: () => void; // Sendable相关 napi_create_sendable_typedarray +// [End napi_create_sendable_typed_array_api] +// [Start napi_wrap_sendable_api] export const wrapSendable: () => void; // Sendable相关 napi_wrap_sendable +// [End napi_wrap_sendable_api] +// [Start napi_wrap_sendable_with_size_api] export const wrapSendableWithSize: () => void; // Sendable相关 napi_wrap_sendable_with_size +// [End napi_wrap_sendable_with_size_api] +// [Start napi_unwrap_sendable_api] export const unwrapSendable: () => void; // Sendable相关 napi_unwrap_sendable +// [End napi_unwrap_sendable_api] +// [Start napi_remove_wrap_sendable_api] export const removeWrapSendable: () => void; // Sendable相关 napi_remove_wrap_sendable - +// [End napi_remove_wrap_sendable_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets index 8e0af9761ba8dd5f70fe5a7b148f32445fb45f5c..f1dc444030c2482a8a7d7531f058dee6c4d9d48d 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets @@ -13,10 +13,12 @@ * limitations under the License. */ + import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; import taskpool from '@ohos.taskpool'; +// [Start ark_napi_coerce_to_native_binding_object] @Concurrent function getAddress() { let address: number = testNapi.getAddress(); @@ -74,10 +76,13 @@ async function test01(): Promise { let task6 = new taskpool.Task(clear); await taskpool.execute(task6); } +// [End ark_napi_coerce_to_native_binding_object] +// [Start ark_napi_serialize_deserialize_delete_serialization_data] class Obj { numKey: number = 0; } +// [StartExclude ark_napi_serialize_deserialize_delete_serialization_data] @Entry @Component @@ -125,91 +130,127 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiLoadModule') { + // [Start ark_node_api_module_add] hilog.info(0x0000, 'testTag', 'Test Node-API 2 + 3 = %{public}d', testNapi.add(2, 3)); + // [End ark_node_api_module_add] this.result = 'napiLoadModuleSuccess'; } else if (item === '2.napiCreateObjectWithProperties') { + // [Start ark_node_api_module_create_object_properties] // ArkTS Object相关 napi_create_object_with_properties let value1 = testNapi.createObjectWithProperties('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_properties:%{public}s', JSON.stringify(value1)); + // [End ark_node_api_module_create_object_properties] this.result = 'napiCreateObjectWithPropertiesSuccess'; } else if (item === '3.napiCreateObjectWithNamedProperties') { + // [Start ark_node_api_module_create_object_name_properties] // ArkTS Object相关 napi_create_object_with_named_properties let value2 = testNapi.createObjectWithNameProperties('ls'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_named_properties:%{public}s', JSON.stringify(value2)); + // [End ark_node_api_module_create_object_name_properties] this.result = 'napiCreateObjectWithNamedPropertiesSuccess'; } else if (item === '4.napiRunScriptPath') { + // [Start ark_node_api_module_run_script_path] // 运行指定abc文件 napi_run_script_path try { // 在此处执行错误返回false,成功就返回true hilog.info(0x0000, 'testTag', 'Test Node-API napi_run_script_path: %{public}s', testNapi.runScriptPath()); + // [StartExclude ark_node_api_module_run_script_path] this.result = 'napiRunScriptPathSuccess'; + // [EndExclude ark_node_api_module_run_script_path] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_run_script_path errorMessage: %{public}s', error.message); + // [StartExclude ark_node_api_module_run_script_path] this.result = 'napiRunScriptPathFail'; + // [EndExclude ark_node_api_module_run_script_path] } + // [End ark_node_api_module_run_script_path] } else if (item === '5.napiCoerceToNativeBindingObject') { // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object test01(); this.result = 'napiCoerceToNativeBindingObjectSuccess'; } else if (item === '6.napiAboutSerialize') { + // [EndExclude ark_napi_serialize_deserialize_delete_serialization_data] // 序列化和反序列化 let obj: Obj = { numKey: 500 }; hilog.info(0x0000, 'testTag', ' Node-API aboutSerialize: %{public}d', testNapi.aboutSerialize(obj)); + // [End ark_napi_serialize_deserialize_delete_serialization_data] this.result = 'napiAboutSerializeSuccess'; } else if (item === '7.napiIsSendable') { + // [Start ark_napi_is_sendable] // Sendable相关 napi_is_sendable let value = testNapi.isSendable('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_is_sendable: %{public}s', JSON.stringify(value)); + // [End ark_napi_is_sendable] this.result = 'napiIsSendableSuccess'; } else if (item === '8.napiDefineSendableClass') { + // [Start ark_napi_define_sendable_class] // Sendable相关 napi_define_sendable_class let value = new testNapi.SendableClass(); hilog.info(0x0000, 'testTag', 'Node-API napi_define_sendable_class: %{public}s', value.str); + // [End ark_napi_define_sendable_class] this.result = 'napiDefineSendableClassSuccess'; } else if (item === '9.napiCreateSendableObjectWithProperties') { + // [Start ark_napi_create_sendable_object_with_properties] // Sendable相关 napi_create_sendable_object_with_properties let value = testNapi.getSendableObject(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_object_with_properties: %{public}s', JSON.stringify(value)); + // [End ark_napi_create_sendable_object_with_properties] this.result = 'napiCreateSendableObjectWithPropertiesSuccess'; } else if (item === '10.napiCreateSendableArray') { + // [Start ark_napi_create_sendable_array] // Sendable相关 napi_create_sendable_array let value = testNapi.getSendableArray(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array: %{public}s', JSON.stringify(value)); + // [End ark_napi_create_sendable_array] this.result = 'napiCreateSendableArraySuccess'; } else if (item === '11.napiCreateSendableArrayWithLength') { + // [Start ark_napi_create_sendable_array_with_length] // Sendable相关 napi_create_sendable_array_with_length let value = testNapi.getSendableArrayWithLength(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array_with_length: %{public}s', JSON.stringify(value.length)); + // [End ark_napi_create_sendable_array_with_length] this.result = 'napiCreateSendableArrayWithLengthSuccess'; } else if (item === '12.napiCreateSendableArraybuffer') { + // [Start ark_napi_create_sendable_arraybuffer] // Sendable相关 napi_create_sendable_arraybuffer testNapi.getSendableArrayBuffer(); + // [End ark_napi_create_sendable_arraybuffer] this.result = 'napiCreateSendableArraybufferSuccess'; } else if (item === '13.napiCreateSendableTypedArray') { + // [Start ark_napi_create_sendable_typed_array] // Sendable相关 napi_create_sendable_typedarray testNapi.getSendableTypedArray(); + // [End ark_napi_create_sendable_typed_array] this.result = 'napiCreateSendableTypedArraySuccess'; } else if (item === '14.napiWrapSendable') { + // [Start ark_napi_wrap_sendable] // Sendable相关 napi_wrap_sendable testNapi.wrapSendable(); + // [End ark_napi_wrap_sendable] this.result = 'napiWrapSendableSuccess'; } else if (item === '15.napiWrapSendableWithSize') { + // [Start ark_napi_wrap_sendable_with_size] // Sendable相关 napi_wrap_sendable_with_size testNapi.wrapSendableWithSize(); + // [End ark_napi_wrap_sendable_with_size] this.result = 'napiWrapSendableWithSizeSuccess'; } else if (item === '16.napiUnwrapSendable') { + // [Start ark_napi_unwrap_sendable] // Sendable相关 napi_unwrap_sendable testNapi.unwrapSendable(); + // [End ark_napi_unwrap_sendable] this.result = 'napiUnwrapSendableSuccess'; } else if (item === '17.napiRemoveWrapSendable') { + // [Start ark_napi_remove_wrap_sendable] // Sendable相关 napi_remove_wrap_sendable testNapi.removeWrapSendable(); + // [End ark_napi_remove_wrap_sendable] this.result = 'napiRemoveWrapSendableSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp index c31af30060ffd248466e3b806cf7df3b859f9953..22cb880f7b51477e0721a2532696abb6d89ea750 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_get_cb_info] #include "napi/native_api.h" // napi_get_cb_info @@ -42,7 +43,9 @@ static napi_value GetCbContext(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, nullptr); return thisArg; } +// [End napi_get_cb_info] +// [Start napi_call_function] // napi_call_function static napi_value CallFunction(napi_env env, napi_callback_info info) { @@ -73,7 +76,9 @@ static napi_value ObjCallFunction(napi_env env, napi_callback_info info) napi_call_function(env, argv[0], argv[1], argc, argv, &result); return result; } +// [End napi_call_function] +// [Start napi_create_function] // napi_create_function static napi_value CalculateArea(napi_env env, napi_callback_info info) { @@ -89,6 +94,7 @@ static napi_value CalculateArea(napi_env env, napi_callback_info info) napi_create_double(env, width * height, &area); return area; } +// [End napi_create_function] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts index 6cba5001afacca52dde5d68a6b603134706b729a..ceacdececee0e5fa1b91eef00e7d814a977edafa 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,16 +13,21 @@ * limitations under the License. */ +// [Start napi_get_cb_info_api] export const getCbArgs: (arg: T) => T; // napi_get_cb_info // getCbArgQuantity的入参由用户自定义,在此用例中,我们用两个入参,一个是string,一个是number export const getCbArgQuantity: (str: string, num: number) => number; export const getCbContext: () => Object; +// [End napi_get_cb_info_api] +// [Start napi_call_function_api] export const callFunction: (func: Function) => number; // napi_call_function export const objCallFunction: (obj: Object, func: Function) => number; +// [End napi_call_function_api] +// [Start napi_create_function_api] export const calculateArea: (width: number, height: number) => number; // napi_create_function - +// [End napi_create_function_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets index 25b4b7a0295971a7e9c96cc78a012a53af10e2c1..1734ab6667ce6688a375971976dc3382d9f47505 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_get_cb_info] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; @@ -40,6 +41,8 @@ class Student { } } +// [StartExclude ark_napi_get_cb_info] +// [Start ark_napi_call_function] function returnNumber() { return 10; } @@ -50,6 +53,7 @@ class Person { } } +// [StartExclude ark_napi_call_function] @Entry @Component struct Index { @@ -82,6 +86,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetCbInfo') { + // [EndExclude ark_napi_get_cb_info] // napi_get_cb_info let student = new Student('Alice', 18, 100); // 获取参数 @@ -103,19 +108,24 @@ struct Index { // 获取上下文 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get thisArg:%{public}s ', testNapi.getCbContext().toString()); + // [End ark_napi_get_cb_info] this.result = 'napiGetCbInfoSuccess'; } else if (item === '2.napiCallFunction') { + // [EndExclude ark_napi_call_function] // napi_call_function const person = new Person(); hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', testNapi.callFunction(returnNumber)); hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', testNapi.objCallFunction(person, person.age)); + // [End ark_napi_call_function] this.result = 'napiCallFunctionSuccess'; } else if (item === '3.napiCreateFunction') { + // [Start ark_napi_create_function] // napi_create_function hilog.info(0x0000, 'testTag', 'Test Node-API create_function:%{public}d ', testNapi.calculateArea(1.2, 4)); + // [End ark_napi_create_function] this.result = 'napiCreateFunctionSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp index 72d771da59a2bf106e7eeb9125eaf6b4d0d542bf..cdc6424c3e792be4a362d4808b767d9d74594fb4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "hilog/log.h" #include "napi/native_api.h" +// [Start napi_open_close_handle_scope] // napi_open_handle_scope、napi_close_handle_scope static napi_value HandleScopeTest(napi_env env, napi_callback_info info) { @@ -57,7 +58,9 @@ static napi_value HandleScope(napi_env env, napi_callback_info info) napi_get_named_property(env, obj, "key", &result); return result; } +// [End napi_open_close_handle_scope] +// [Start napi_open_close_escapable_handle_scope] // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info) { @@ -82,7 +85,9 @@ static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info napi_get_named_property(env, escapedObj, "key", &result); return result; } +// [End napi_open_close_escapable_handle_scope] +// [Start napi_create_delete_reference] // 创建一个指向napi_ref类型的指针,用于存储创建的引用。在调用napi_create_reference函数之前,你需要分配一个napi_ref类型的变量,并将其地址传递给result位置的参数 napi_ref g_ref; @@ -100,12 +105,14 @@ static napi_value CreateReference(napi_env env, napi_callback_info info) napi_create_string_utf8(env, "CreateReference", NAPI_AUTO_LENGTH, &value); // 将键值对添加到对象中 napi_set_named_property(env, obj, "key", value); + // [StartExclude napi_create_delete_reference] // 创建对ArkTS对象的引用 napi_status status = napi_create_reference(env, obj, 1, &g_ref); if (status != napi_ok) { napi_throw_error(env, nullptr, "napi_create_reference fail"); return nullptr; } + // [EndExclude napi_create_delete_reference] // 添加终结器 void *data = {}; napi_add_finalizer(env, obj, data, Finalizer, nullptr, &g_ref); @@ -158,6 +165,7 @@ static napi_value DeleteReference(napi_env env, napi_callback_info info) napi_create_string_utf8(env, "napi_delete_reference success", NAPI_AUTO_LENGTH, &returnResult); return returnResult; } +// [End napi_create_delete_reference] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts index 4ae102eb299c45825a6ebc23016f343a8ed28380..d1886bc913f35ffb10177099d09722454563eebc 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,20 @@ * limitations under the License. */ +// [Start napi_open_close_handle_scope_api] export const handleScopeTest: () => string; // napi_open_handle_scope、napi_close_handle_scope export const handleScope: () => string; +// [End napi_open_close_handle_scope_api] +// [Start napi_open_close_escapable_handle_scope_api] export const escapableHandleScopeTest: () => string; // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle +// [End napi_open_close_escapable_handle_scope_api] +// [Start napi_create_delete_reference_api] export const createReference: () => Object | void; // napi_add_finalizer export const useReference: () => Object | void; -export const deleteReference: () => string | void; \ No newline at end of file +export const deleteReference: () => string | void; +// [End napi_create_delete_reference] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets index 0408fbb5ef31d11facd29124175beb3678323ff1..4d86ca8563117a28404d3a418541002143cdd23e 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets @@ -48,32 +48,45 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiOpenHandleScope') { + // [Start ark_napi_open_close_handle_scope] // napi_open_handle_scope napi_close_handle_scope try { hilog.info(0x0000, 'testTag', 'Test Node-API handleScopeTest: %{public}s', testNapi.handleScopeTest()); hilog.info(0x0000, 'testTag', 'Test Node-API handleScope: %{public}s', testNapi.handleScope()); + // [StartExclude ark_napi_open_close_handle_scope] this.result = 'napiOpenHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_handle_scope] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API handleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_open_close_handle_scope] this.result = 'napiOpenHandleScopeFail'; + // [EndExclude ark_napi_open_close_handle_scope] } + // [End ark_napi_open_close_handle_scope] } else if (item === '2.napiOpenEscapableHandleScope') { + // [Start ark_napi_open_close_escapable_handle_scope] // napi_open_escapable_handle_scope napi_close_escapable_handle_scope、napi_escape_handle try { hilog.info(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest: %{public}s', testNapi.escapableHandleScopeTest()); + // [StartExclude ark_napi_open_close_escapable_handle_scope] this.result = 'napiOpenEscapableHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_open_close_escapable_handle_scope] this.result = 'napiOpenEscapableHandleScopeFail'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] } + // [End ark_napi_open_close_escapable_handle_scope] } else if (item === '3.napiAddFinalizer') { + // [Start ark_napi_create_delete_reference] // napi_add_finalizer try { hilog.info(0x0000, 'testTag', 'Test Node-API createReference: %{public}s', @@ -82,13 +95,18 @@ struct Index { JSON.stringify(testNapi.useReference())); hilog.info(0x0000, 'testTag', 'Test Node-API deleteReference: %{public}s', testNapi.deleteReference()); + // [StartExclude ark_napi_create_delete_reference] this.result = 'napiAddFinalizerSuccess'; + // [EndExclude ark_napi_create_delete_reference] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API ReferenceTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_delete_reference] this.result = 'napiAddFinalizerFail'; + // [EndExclude ark_napi_create_delete_reference] } + // [End ark_napi_create_delete_reference] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp index 98e0e564652c9f752189fe23df752aa46e595271..be73865685ad6cd3b7a88416d748eceb1010747f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_coerce_to_bool] // napi_coerce_to_bool static napi_value CoerceToBool(napi_env env, napi_callback_info info) { @@ -28,7 +29,9 @@ static napi_value CoerceToBool(napi_env env, napi_callback_info info) // 返回强转之后的ArkTS boolean值 return result; } +// [End napi_coerce_to_bool] +// [Start napi_coerce_to_number] // napi_coerce_to_number static napi_value CoerceToNumber(napi_env env, napi_callback_info info) { @@ -41,7 +44,9 @@ static napi_value CoerceToNumber(napi_env env, napi_callback_info info) napi_coerce_to_number(env, args[0], &result); return result; } +// [End napi_coerce_to_number] +// [Start napi_coerce_to_object] // napi_coerce_to_object static napi_value CoerceToObject(napi_env env, napi_callback_info info) { @@ -54,7 +59,9 @@ static napi_value CoerceToObject(napi_env env, napi_callback_info info) napi_coerce_to_object(env, args[0], &obj); return obj; } +// [End napi_coerce_to_object] +// [Start napi_coerce_to_string] // napi_coerce_to_string static napi_value CoerceToString(napi_env env, napi_callback_info info) { @@ -67,7 +74,9 @@ static napi_value CoerceToString(napi_env env, napi_callback_info info) napi_coerce_to_string(env, args[0], &str); return str; } +// [End napi_coerce_to_string] +// [Start napi_get_boolean] // napi_get_boolean static napi_value GetBoolean(napi_env env, napi_callback_info info) { @@ -87,7 +96,9 @@ static napi_value GetBoolean(napi_env env, napi_callback_info info) // 返回结果 return returnValue; } +// [End napi_get_boolean] +// [Start napi_get_value_bool] // napi_get_value_bool static napi_value GetValueBool(napi_env env, napi_callback_info info) { @@ -105,7 +116,9 @@ static napi_value GetValueBool(napi_env env, napi_callback_info info) napi_get_boolean(env, boolC, &boolNapi); return boolNapi; } +// [End napi_get_value_bool] +// [Start napi_get_global] // napi_get_global static napi_value GetGlobal(napi_env env, napi_callback_info info) { @@ -114,7 +127,9 @@ static napi_value GetGlobal(napi_env env, napi_callback_info info) napi_get_global(env, &global); return global; } +// [End napi_get_global] +// [Start napi_get_null] // napi_get_null static napi_value GetNull(napi_env env, napi_callback_info info) { @@ -122,7 +137,9 @@ static napi_value GetNull(napi_env env, napi_callback_info info) napi_get_null(env, &nullValue); return nullValue; } +// [End napi_get_null] +// [Start napi_get_undefined] // napi_get_undefined static napi_value GetUndefined(napi_env env, napi_callback_info info) { @@ -142,6 +159,7 @@ static napi_value GetUndefined(napi_env env, napi_callback_info info) napi_get_boolean(env, isEqual, &result); return result; } +// [End napi_get_undefined] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts index 73c69c9ac1ff12ff6a71aae2a5627404b13e8052..c1f99a1279c4d6cfce7f73d6573b38e400db5a53 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,20 +13,38 @@ * limitations under the License. */ +// [Start napi_coerce_to_bool_api] export const coerceToBool: (data: T) => boolean; // napi_coerce_to_bool +// [End napi_coerce_to_bool_api] +// [Start napi_coerce_to_number_api] export const coerceToNumber: (data: T) => number; // napi_coerce_to_number +// [End napi_coerce_to_number_api] +// [Start napi_coerce_to_object_api] export const coerceToObject: (data: T) => Object; // napi_coerce_to_object +// [End napi_coerce_to_object_api] +// [Start napi_coerce_to_string_api] export const coerceToString: (data: T) => string; // napi_coerce_to_string +// [End napi_coerce_to_string_api] +// [Start napi_get_boolean_api] export const getBoolean: (data: T, value: String) => boolean; // napi_get_boolean +// [End napi_get_boolean_api] +// [Start napi_get_value_bool_api] export const getValueBool: (value: boolean | string) => boolean | void; // napi_get_value_bool +// [End napi_get_value_bool_api] +// [Start napi_get_global_api] export const getGlobal: () => Object; // napi_get_global +// [End napi_get_global_api] +// [Start napi_get_null_api] export const getNull: () => null; // napi_get_null +// [End napi_get_null_api] +// [Start napi_get_undefined_api] export const getUndefined: (value: undefined) => boolean; // napi_get_undefined +// [End napi_get_undefined_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets index 49d462c07a632f51e5f325d8a57437a27103a089..c2c5c922289138ffe28d225db64fc0f809134d35 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets @@ -54,6 +54,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCoerceToBool') { + // [Start ark_napi_coerce_to_bool] // napi_coerce_to_bool let value = testNapi.coerceToBool(0); let str = testNapi.coerceToBool('111111111'); @@ -68,8 +69,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', res); // false hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', result); + // [End ark_napi_coerce_to_bool] this.result = 'napiCoerceToBoolSuccess'; } else if (item === '2.napiCoerceToNumber') { + // [Start ark_napi_coerce_to_number] // napi_coerce_to_number let value = testNapi.coerceToNumber('2556'); let str = testNapi.coerceToNumber('sssss'); @@ -79,8 +82,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', str); // 返回的是1 hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', bool); + // [End ark_napi_coerce_to_number] this.result = 'napiCoerceToNumberSuccess'; } else if (item === '3.napiCoerceToObject') { + // [Start ark_napi_coerce_to_object] // napi_coerce_to_object let value = testNapi.coerceToObject('222222'); let result = testNapi.coerceToObject(111); @@ -90,8 +95,10 @@ struct Index { } else { hilog.info(0x0000, 'testTag', 'Node-API The value is not an object.'); } + // [End ark_napi_coerce_to_object] this.result = 'napiCoerceToObjectSuccess'; } else if (item === '4.napiCoerceToString') { + // [Start ark_napi_coerce_to_string] // napi_coerce_to_string let value = testNapi.coerceToString(212); let obj = new Object(); @@ -100,39 +107,50 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', value); hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', typeof res); hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', bool); + // [End ark_napi_coerce_to_string] this.result = 'napiCoerceToStringSuccess'; } else if (item === '5.napiGetBoolean') { + // [Start ark_napi_get_boolean] // napi_get_boolean let value = testNapi.getBoolean(1, '1'); let data = testNapi.getBoolean('sss', '1'); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', value); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', data); + // [End ark_napi_get_boolean] this.result = 'napiGetBooleanSuccess'; } else if (item === '6.napiGetValueBool') { + // [Start ark_napi_get_value_bool] // napi_get_value_bool // // 分别传入布尔值和非布尔值检测接口,传入布尔值将返回原布尔值,传入其他类型返回undefined hilog.info(0x0000, 'Node-API', 'get_value_bool_not_bool %{public}s', testNapi.getValueBool('你好123')); hilog.info(0x0000, 'Node-API', 'get_value_bool_true %{public}s', testNapi.getValueBool(true)); hilog.info(0x0000, 'Node-API', 'get_value_bool_false %{public}s', testNapi.getValueBool(false)); + // [End ark_napi_get_value_bool] this.result = 'napiGetValueBoolSuccess'; } else if (item === '7.napiGetGlobal') { + // [Start ark_napi_get_global] // napi_get_global let globalObj = testNapi.getGlobal(); // 判断获取的global是否具有global的自身属性 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_global:%{public}s', globalObj.hasOwnProperty!("undefined")); + // [End ark_napi_get_global] this.result = 'napiGetGlobalSuccess'; } else if (item === '8.napiGetNull') { + // [Start ark_napi_get_null] // napi_get_null let value = testNapi.getNull(); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_null:%{public}s', value); + // [End ark_napi_get_null] this.result = 'napiGetNullSuccess'; } else if (item === '9.napiGetUndefined') { + // [Start ark_napi_get_undefined] // napi_get_undefined let data: undefined = undefined; let value = testNapi.getUndefined(data); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_undefined:%{public}s', value); + // [End ark_napi_get_undefined] this.result = 'napiGetUndefinedSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp index 468a9d0e107e1dacba12afa01010639fce6d4df4..9e72fdba12e91d25a44542b63a2d5088157c213d 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp @@ -17,6 +17,7 @@ static constexpr int INT_ARGS_2 = 2; // 入参索引 +// [Start napi_is_promise] // napi_is_promise static napi_value IsPromise(napi_env env, napi_callback_info info) { @@ -37,7 +38,9 @@ static napi_value IsPromise(napi_env env, napi_callback_info info) napi_get_boolean(env, isPromise, &result); return result; } +// [End napi_is_promise] +// [Start napi_resolve_reject_deferred] // napi_resolve_deferred & napi_reject_deferred static napi_value CreatePromise(napi_env env, napi_callback_info info) { @@ -85,7 +88,7 @@ static napi_value ResolveRejectDeferred(napi_env env, napi_callback_info info) // 返回设置了resolve或reject的Promise对象 return promise; } - +// [End napi_resolve_reject_deferred] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts index 2080cc960b743ea2426541f1f3ac6a37e2a7f2e2..2f3624c69c21e659798cd3f64d9e4ae64ad26875 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,8 +13,12 @@ * limitations under the License. */ +// [Start napi_is_promise_api] export const isPromise: (value: T) => boolean; // napi_is_promise +// [End napi_is_promise_api] +// [Start napi_resolve_reject_deferred_api] export const createPromise: () => boolean | void; // napi_resolve_deferred & napi_reject_deferred -export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; \ No newline at end of file +export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; +// [End napi_resolve_reject_deferred_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets index 2eb40f9a96dbc567f80a494caf6f04cdd4cbbc9d..b9820ecdd9cb094126273774290fa8a5e235a283 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets @@ -47,13 +47,16 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiIsPromise') { + // [Start ark_napi_is_promise] // napi_is_promise let value = Promise.resolve(); // 传入的对象为Promise时,返回true,否则返回false hilog.info(0x0000, 'Node-API', 'napi_is_promise %{public}s', testNapi.isPromise(value)); hilog.info(0x0000, 'Node-API', 'napi_is_promise string %{public}s', testNapi.isPromise('')); + // [End ark_napi_is_promise] this.result = 'napiIsPromiseSuccess'; } else if (item === '2.napiDeferred') { + // [Start ark_napi_resolve_reject_deferred] // napi_resolve_deferred & napi_reject_deferred // 创建promise如果创建成功返回true,创建失败返回false hilog.info(0x0000, 'Node-API', 'napi_create_promise %{public}s', testNapi.createPromise()); @@ -63,21 +66,30 @@ struct Index { testNapi.resolveRejectDeferred('success', 'fail', true) as Promise; promiseSuccess.then((res) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] }).catch((err: Error) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] }) // Promise状态为false时设置reject,返回结果在catch函数中获得 let promiseFail: Promise = testNapi.resolveRejectDeferred('success', 'fail', false) as Promise; promiseFail.then((res) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] }).catch((err: Error) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] }) + // [End ark_napi_resolve_reject_deferred] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp index 715c6c91cb9d3664d858a61816225e9844cb8c11..115c9bd479733b830d009b59c79611da1a297993 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp @@ -18,6 +18,7 @@ static constexpr int INT_ARG_2 = 2; // 入参索引 +// [Start napi_get_property_names] // napi_get_property_names static napi_value GetPropertyNames(napi_env env, napi_callback_info info) { @@ -34,7 +35,9 @@ static napi_value GetPropertyNames(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_property_names] +// [Start napi_set_property] // napi_set_property static napi_value SetProperty(napi_env env, napi_callback_info info) { @@ -54,7 +57,9 @@ static napi_value SetProperty(napi_env env, napi_callback_info info) // 返回设置成功的object对象 return args[0]; } +// [End napi_set_property] +// [Start napi_get_property] // napi_get_property static napi_value GetProperty(napi_env env, napi_callback_info info) { @@ -71,7 +76,9 @@ static napi_value GetProperty(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_property] +// [Start napi_has_property] // napi_has_property static napi_value HasProperty(napi_env env, napi_callback_info info) { @@ -93,7 +100,9 @@ static napi_value HasProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnResult); return returnResult; } +// [End napi_has_property] +// [Start napi_delete_property] // napi_delete_property // 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 static napi_value DeleteProperty(napi_env env, napi_callback_info info) @@ -121,7 +130,9 @@ static napi_value DeleteProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &ret); return ret; } +// [End napi_delete_property] +// [Start napi_has_own_property] // napi_has_own_property static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) { @@ -155,7 +166,9 @@ static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, hasProperty, &result); return result; } +// [End napi_has_own_property] +// [Start napi_set_named_property] // napi_set_named_property static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) { @@ -184,7 +197,9 @@ static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) // 返回设置了命名属性的对象newObj return newObj; } +// [End napi_set_named_property] +// [Start napi_get_named_property] // napi_get_named_property static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) { @@ -207,7 +222,9 @@ static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) // 返回result return result; } +// [End napi_get_named_property] +// [Start napi_has_named_property] // napi_has_named_property static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) { @@ -232,7 +249,9 @@ static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, hasProperty, &result); return result; } +// [End napi_has_named_property] +// [Start napi_define_properties] // napi_define_properties static napi_value DefineMethodPropertiesExample(napi_env env, napi_callback_info info) { @@ -311,7 +330,9 @@ static napi_value CreateStringWithGetterSetter(napi_env env, napi_callback_info napi_define_properties(env, obj, 1, &desc); return obj; } +// [End napi_define_properties] +// [Start napi_get_all_property_names] // napi_get_all_property_names static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) { @@ -332,6 +353,7 @@ static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) return result; } +// [End napi_get_all_property_names] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts index 1c243cbc39b5bc6ef4c63ed37fecfedb82b2ce88..e2f3372d4c6df3002b515aaf21c5747252096900 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,25 +13,44 @@ * limitations under the License. */ +// [Start napi_get_property_names_api] export const getPropertyNames: (obj: Object) => Array | void; // napi_get_property_names +// [End napi_get_property_names_api] +// [Start napi_set_property_api] export const setProperty: (obj: Object, key: String, value: string) => Object | void; // napi_set_property +// [End napi_set_property_api] +// [Start napi_get_property_api] export const getProperty: (obj: Object, key: string) => string | void; // napi_get_property +// [End napi_get_property_api] +// [Start napi_has_property_api] export const hasProperty: (obj: Object, key: number | string) => boolean | void; // napi_has_property +// [End napi_has_property_api] +// [Start napi_delete_property_api] export const deleteProperty: (obj: Object, key: string) => boolean; // napi_delete_property +// [End napi_delete_property_api] +// [Start napi_has_own_property_api] export const napiHasOwnProperty: (obj: Object, key: string) => boolean | void; // napi_has_own_property +// [End napi_has_own_property_api] +// [Start napi_set_named_property_api] export const napiSetNamedProperty: (key: string) => Object | void; // napi_set_named_property +// [End napi_set_named_property_api] +// [Start napi_get_named_property_api] export const napiGetNamedProperty: (obj: Object, key: string) => boolean | number | string | Object | void; // napi_get_named_property +// [End napi_get_named_property_api] +// [Start napi_has_named_property_api] export const napiHasNamedProperty: (obj: Object, key: string) => boolean | void; // napi_has_named_property +// [End napi_has_named_property_api] +// [Start napi_define_properties_api] export class DefineMethodObj { defineMethodPropertiesExample: Function; } @@ -50,5 +69,8 @@ export const defineMethodProperties: () => DefineMethodObj; // napi_define_prope export const defineStringProperties: () => DefineStringObj; export const createStringWithGetterSetter: () => DefineGetterSetterObj; +// [End napi_define_properties_api] -export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names \ No newline at end of file +// [Start napi_get_all_property_names_api] +export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names +// [End napi_get_all_property_names_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets index 1c7881dd93a22cea2c79c03bdd6cfbb9c8c5e88d..a8e26c51f7a544c359f25a21fbaad99fec02da59 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets @@ -58,6 +58,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetPropertyNames') { + // [Start ark_napi_get_property_names] // napi_get_property_names try { class Obj { @@ -72,14 +73,20 @@ struct Index { propertyNames[0]); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', propertyNames[1]); + // [StartExclude ark_napi_get_property_names] this.result = 'napiGetPropertyNamesSuccess'; + // [EndExclude ark_napi_get_property_names] } } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_property_names error: %{public}s', error.message); + // [StartExclude ark_napi_get_property_names] this.result = 'napiGetPropertyNamesFail'; + // [EndExclude ark_napi_get_property_names] } + // [End ark_napi_get_property_names] } else if (item === '2.napiSetProperty') { + // [Start ark_napi_set_property] // napi_set_property try { class Obj { @@ -91,12 +98,18 @@ struct Index { let result = testNapi.setProperty(obj, 'code', 'hi'); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property: %{public}s', JSON.stringify(result)); + // [StartExclude ark_napi_set_property] this.result = 'napiSetPropertySuccess'; + // [EndExclude ark_napi_set_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property error: %{public}s', error.message); + // [StartExclude ark_napi_set_property] this.result = 'napiSetPropertyFail'; + // [EndExclude ark_napi_set_property] } + // [End ark_napi_set_property] } else if (item === '3.napiGetProperty') { + // [Start ark_napi_get_property] // napi_get_property try { class Obj { @@ -107,12 +120,18 @@ struct Index { let obj: Obj = { data: 0, message: 'hello world' }; hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property: %{public}s', testNapi.getProperty(obj, 'message')); + // [StartExclude ark_napi_get_property] this.result = 'napiGetPropertySuccess'; + // [EndExclude ark_napi_get_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property error: %{public}s', error.message); + // [StartExclude ark_napi_get_property] this.result = 'napiGetPropertyFail'; + // [EndExclude ark_napi_get_property] } + // [End ark_napi_get_property] } else if (item === '4.napiHasProperty') { + // [Start ark_napi_has_property] // napi_has_property try { class Obj { @@ -127,11 +146,16 @@ struct Index { JSON.stringify(resultFalse)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', JSON.stringify(resultTrue)); + // [StartExclude ark_napi_has_property] this.result = 'napiHasPropertySuccess'; + // [EndExclude ark_napi_has_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property error: %{public}s', error.message); + // [StartExclude ark_napi_has_property] this.result = 'napiHasPropertyFail'; + // [EndExclude ark_napi_has_property] } + // [End ark_napi_has_property] } else if (item === '5.napiDeleteProperty') { // napi_delete_property napiDeleteProperty(); @@ -141,12 +165,15 @@ struct Index { napiHasOwnProperty(); this.result = 'napiHasOwnPropertySuccess'; } else if (item === '7.napiSetNamedProperty') { + // [Start ark_napi_set_named_property] // napi_set_named_property let obj = testNapi.napiSetNamedProperty('myProperty'); let objAsString = JSON.stringify(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_named_property: %{public}s', objAsString); + // [End ark_napi_set_named_property] this.result = 'napiSetNamedPropertySuccess'; } else if (item === '8.napiGetNamedProperty') { + // [Start ark_napi_get_named_property] // napi_get_named_property interface NestedObj { nestedStr: string; @@ -177,8 +204,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', objAsString); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', testNapi.napiGetNamedProperty(obj, 'null')); + // [End ark_napi_get_named_property] this.result = 'napiGetNamedPropertySuccess'; } else if (item === '9.napiHasNamedProperty') { + // [Start ark_napi_has_named_property] // napi_has_named_property interface NestedObj { nestedStr: string; @@ -204,8 +233,10 @@ struct Index { testNapi.napiHasNamedProperty(obj, 'nestedStr')); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', testNapi.napiHasNamedProperty(obj, 'bol')); + // [End ark_napi_has_named_property] this.result = 'napiHasNamedPropertySuccess'; } else if (item === '10.napiDefineProperties') { + // [Start ark_napi_define_properties] // napi_define_properties // 定义method类型的属性 hilog.info(0x0000, 'testTag', 'Test Node-API define_method_properties:%{public}d', @@ -222,8 +253,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API setter::%{public}s ', testNapi.createStringWithGetterSetter() .setterCallback('set data')); + // [End ark_napi_define_properties] this.result = 'napiDefinePropertiesSuccess'; } else if (item === '11.napiGetAllPropertyNames') { + // [Start ark_napi_get_all_property_names] // napi_get_all_property_names try { class Obj { @@ -235,12 +268,17 @@ struct Index { let propertyNames = testNapi.getAllPropertyNames(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names: %{public}s', JSON.stringify(propertyNames)); + // [StartExclude ark_napi_get_all_property_names] this.result = 'napiGetAllPropertyNamesSuccess'; + // [EndExclude ark_napi_get_all_property_names] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names error: %{public}s', error.message); + // [StartExclude ark_napi_get_all_property_names] this.result = 'napiGetAllPropertyNamesFail'; + // [EndExclude ark_napi_get_all_property_names] } + // [End ark_napi_get_all_property_names] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts index a0d21ac804a9d932b7044f2c2aef4121fa31ea18..9c3a8b3383117625d4b182f8fe8f8895c6309f6b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_delete_property] import testNapi from 'libentry.so'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -32,4 +33,5 @@ export function napiDeleteProperty() { }) hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property config: %{public}s', testNapi.deleteProperty(obj, 'config')); -} \ No newline at end of file +} +// [End ark_napi_delete_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts index 9fdde4e8ca393f394f24a30f630275d5aa094ffa..ada41ab3209c4e78b75f9ff8473af5c9380463bc 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_has_own_property] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; @@ -25,4 +26,5 @@ export function napiHasOwnProperty() { testNapi.napiHasOwnProperty(myObj, 'myProperty')); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property inherited: %{public}s', testNapi.napiHasOwnProperty(myObj, 'inheritedProperty')); -} \ No newline at end of file +} +// [End ark_napi_has_own_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp index 6d5f43fc01f0dc95ae2361fccf10889b16690903..40da20536c6dd2181b10e5c06b7ec00d6586cc45 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_async_open_close_callback_scope] #include "napi/native_api.h" static constexpr int INT_ARG_3 = 3; // 入参索引 @@ -68,6 +69,7 @@ static napi_value AsynchronousWork(napi_env env, napi_callback_info info) napi_async_destroy(env, context); return result; } +// [End napi_async_open_close_callback_scope] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts index 54873ce49e5628c1772897b21d0ee58ca53cd446..9c9248788fc85a8c6867c39e5eaf52d45dae4874 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; \ No newline at end of file +// [Start napi_async_open_close_callback_scope_api] +export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; +// [End napi_async_open_close_callback_scope_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets index b1cb7da5da5f89f997c3f9353009a00d0cdfff1e..e4e96d5ce3e21044466eabdc935a27907f9ee299 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets @@ -13,10 +13,12 @@ * limitations under the License. */ +// [Start ark_napi_async_open_close_callback_scope] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; import process from '@ohos.process'; +// [StartExclude ark_napi_async_open_close_callback_scope] @Entry @Component struct Index { @@ -39,6 +41,7 @@ struct Index { .borderRadius(30) .backgroundColor(Color.White) .onClick(() => { + // [EndExclude ark_napi_async_open_close_callback_scope] try { hilog.info(0x0000, 'testTag', 'Test Node-API asynchronousWork: %{public}d', testNapi.asynchronousWork({}, process.ProcessManager, (num: number) => { @@ -49,6 +52,7 @@ struct Index { hilog.error(0x0000, 'testTag', 'Test Node-API asynchronousWork error: %{public}s', error.message); this.result = 'customAsyncFail'; } + // [End ark_napi_async_open_close_callback_scope] }) } }.scrollBar(BarState.Off) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp index 065c0919da52c0449300201f11b71bbcf21a41c0..ca0393188e61dae127322c2ddb3d6b6b61010a94 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp @@ -19,6 +19,7 @@ static const int MAX_BUFFER_SIZE = 128; +// [Start napi_get_value_string_utf8] static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -43,7 +44,9 @@ static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) }; return result; } +// [End napi_get_value_string_utf8] +// [Start napi_create_string_utf8] static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) { const char *str = u8"你好, World!, successes to create UTF-8 string! 111"; @@ -56,7 +59,9 @@ static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_utf8] +// [Start napi_get_value_string_utf16] static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -76,7 +81,9 @@ static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) // 返回结果 return result; } +// [End napi_get_value_string_utf16] +// [Start napi_create_string_utf16] static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) { const char16_t *str = u"你好, World!, successes to create UTF-16 string! 111"; @@ -89,7 +96,9 @@ static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_utf16] +// [Start napi_get_value_string_latin1] static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -106,7 +115,9 @@ static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) napi_create_string_latin1(env, buf, length, &napi_Res); return napi_Res; } +// [End napi_get_value_string_latin1] +// [Start napi_create_string_latin1] static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) { const char *str = "Hello, World! éçñ, successes to create Latin1 string! 111"; @@ -120,6 +131,7 @@ static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_latin1] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts index 6f4af695d6c8a1811f7d3c081c34871898bf44f3..905a15b94b99fd538f941e31bf2548463e4df799 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,26 @@ * limitations under the License. */ +// [Start napi_get_value_string_utf8_api] export const getValueStringUtf8: (param: string | number) => string | void; +// [End napi_get_value_string_utf8_api] +// [Start napi_create_string_utf8_api] export const createStringUtf8: () => string | void; +// [End napi_create_string_utf8_api] +// [Start napi_get_value_string_utf16_api] export const getValueStringUtf16: (data: string) => string; +// [End napi_get_value_string_utf16_api] +// [Start napi_create_string_utf16_api] export const createStringUtf16: () => string | void; +// [End napi_create_string_utf16_api] +// [Start napi_get_value_string_latin1_api] export const getValueStringLatin1: (param: number | string) => string | void; +// [End napi_get_value_string_latin1_api] -export const createStringLatin1: () => string | void; \ No newline at end of file +// [Start napi_create_string_latin1_api] +export const createStringLatin1: () => string | void; +// [End napi_create_string_latin1_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets index 9542523cea693e9080afc43d94434c6d02d5e4db..01466b983d3f514bf81df8212e8e56e4c1628540 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets @@ -46,17 +46,26 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiString') { + // [Start ark_napi_get_value_string_utf8] // 分别传入字符和非字符检测接口,传入字符串类型的数据将返回原字符串,传入其他类型返回undefined hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_string %{public}s', testNapi.getValueStringUtf8('aaBC+-$%^你好123')); hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_not_string %{public}s', testNapi.getValueStringUtf8(50)); + // [End ark_napi_get_value_string_utf8] + // [Start ark_napi_create_string_utf8] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf8:%{public}s', testNapi.createStringUtf8()); + // [End ark_napi_create_string_utf8] + // [Start ark_napi_get_value_string_utf16] let result = testNapi.getValueStringUtf16('hello,'); hilog.info(0x0000, 'testTag', 'Node-API napi_get_value_string_utf16:%{public}s', result); + // [End ark_napi_get_value_string_utf16] + // [Start ark_napi_create_string_utf16] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf16:%{public}s ', testNapi.createStringUtf16()); + // [End ark_napi_create_string_utf16] + // [Start ark_napi_get_value_string_latin1] // 传入非字符型数据,函数返回undefined hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_not_string %{public}s', testNapi.getValueStringLatin1(10)); @@ -66,8 +75,11 @@ struct Index { // 传入其他字符,不会乱码 hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string %{public}s', testNapi.getValueStringLatin1('abo ABP=-&*/')); + // [End ark_napi_get_value_string_latin1] + // [Start ark_napi_create_string_latin1] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_latin1:%{public}s', testNapi.createStringLatin1()); + // End ark_napi_create_string_latin1] this.result = 'napiStringSuccess'; } }) diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets index b47e7359122f2fce22ae618f984455637a45f77c..8cb5d2a71f9063a82cbfcc6dbb2e9728cd728b52 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets @@ -21,6 +21,7 @@ export struct CreateButton { return getContext(this).resourceManager.getStringSync(resource); } + // [Start create_button] build() { NavDestination() { Column({ space: 12 }) { @@ -51,4 +52,5 @@ export struct CreateButton { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.CreateButton_title'))) } + // [End create_button] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets index 243cffb38a64025a7e1a1c7e818843adca7d1c99..a1d19f4f9910a3ed9f50198bb9ef855ae2c4abd6 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets @@ -31,40 +31,50 @@ export struct SetButtonType { title: $r('app.string.SetButtonType_titleOne'), description: $r('app.string.SetButtonType_descriptionOne') }) { + // [Start set_button_type_capsule] Button('Button', { type: ButtonType.Capsule }) .id('Capsule') + // [End set_button_type_capsule] } ComponentCard({ title: $r('app.string.SetButtonType_titleTwo'), description: $r('app.string.SetButtonType_descriptionTwo') }) { + // [Start set_button_type_circle] Button('Button', { type: ButtonType.Circle }) .id('Circle') .width(80) + // [End set_button_type_circle] } ComponentCard({ title: $r('app.string.SetButtonType_titleThree'), description: $r('app.string.SetButtonType_descriptionThree') }) { + // [Start set_button_type_normal] Button('Button', { type: ButtonType.Normal }) .id('Normal') + // [End set_button_type_normal] } ComponentCard({ title: $r('app.string.SetButtonType_titleFour'), description: $r('app.string.SetButtonType_descriptionFour') }) { + // [Start set_button_type_four] Button('Button', { type: ButtonType.ROUNDED_RECTANGLE }) .id('Round') + // [End set_button_type_four] } } .width('100%') .height('100%') .padding({ left: 12, right: 12 }) } + // [Start set_button_type_title] .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.SetButtonType_title'))) + // [End set_button_type_title] } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets index f6285254271822fc892a8d4964550e0205f0e2ae..e0e81c3aaa99a2f352e979ba91b2f34fcd33d97c 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_radio_event] import { promptAction } from '@kit.ArkUI'; @Entry @@ -83,4 +84,5 @@ export struct RadioSample { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.RadioSample_title'))) } -} \ No newline at end of file +} +// [End set_radio_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets index 91dd2d56afcdbd750cbaad73f9cf1911d853ba19..689e07ceb72a6c59ee96949cd83d9fee744deb22 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets @@ -30,20 +30,25 @@ export struct CreateToggle { ComponentCard({ title: 'ToggleType is Checkbox', }) { + // [Start create_checkbox_without_components] Toggle({ type: ToggleType.Checkbox, isOn: false }).id('toggle1') Toggle({ type: ToggleType.Checkbox, isOn: true }).id('toggle2') + // [End create_checkbox_without_components] } ComponentCard({ title: 'ToggleType is Switch', }) { + // [Start create_switch_without_components] Toggle({ type: ToggleType.Switch, isOn: false }).id('toggle3') Toggle({ type: ToggleType.Switch, isOn: true }).id('toggle4') + // [End create_switch_without_components] } ComponentCard({ title: 'ToggleType is Button', }) { + // [Start create_button_components] Toggle({ type: ToggleType.Button, isOn: false }) { Text('status button') .fontColor('#182431') @@ -55,6 +60,7 @@ export struct CreateToggle { .fontColor('#182431') .fontSize(12) }.width(100).id('toggle6') + // [End create_button_components] } } .width('100%') diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets index 4fe1617145d6ff43543388050bf3a63eb649c8d6..002028d643c6c2a8a61556559fcf4f1f6b4a4c4d 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets @@ -25,6 +25,7 @@ export struct ToggleSample { return getContext(this).resourceManager.getStringSync(resource); } + // [Start create_toggle_events] build() { NavDestination() { Column({ space: 8 }) { @@ -60,4 +61,5 @@ export struct ToggleSample { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.ToggleCaseExample_title'))) } + // [End create_toggle_events] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets index c6a8d8ffb1982525211d93a7d5d75e383821a205..7a091ed85163290138733388814c91806537f60d 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets @@ -31,32 +31,46 @@ export struct CustomStyle { title: $r('app.string.ToggleCustomStyle_titleOne'), description: $r('app.string.ToggleCustomStyle_descriptionOne') }) { + // [Start set_toggle_background_color] Toggle({ type: ToggleType.Button, isOn: true }) { Text('status button') .fontColor(Color.White) .fontSize(12) }.width(100) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle1') + // [EndExclude set_toggle_background_color] Toggle({ type: ToggleType.Checkbox, isOn: true }) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle2') + // [EndExclude set_toggle_background_color] Toggle({ type: ToggleType.Switch, isOn: true }) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle3') + // [EndExclude set_toggle_background_color] + // [End set_toggle_background_color] } ComponentCard({ title: $r('app.string.ToggleCustomStyle_titleTwo'), description: $r('app.string.ToggleCustomStyle_descriptionTwo') }) { + // [Start set_switch_point_color] Toggle({ type: ToggleType.Switch, isOn: false }) .switchPointColor(Color.Pink) + // [StartExclude set_switch_point_color] .id('toggle4') + // [EndExclude set_switch_point_color] Toggle({ type: ToggleType.Switch, isOn: true }) .switchPointColor(Color.Pink) + // [StartExclude set_switch_point_color] .id('toggle5') + // [EndExclude set_switch_point_color] + // [End set_switch_point_color] } } .width('100%') diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/common/PromptActionClass.ts b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/common/PromptActionClass.ts index f68734fd7740c085dc03aee7fbb3ace1aea54bc7..b76828c66366e8118265b204c86b639463db7626 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/common/PromptActionClass.ts +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/common/PromptActionClass.ts @@ -14,6 +14,7 @@ */ // PromptActionClass.ts +// [Start open_close_update_custom_dialog] import { BusinessError } from '@kit.BasicServicesKit'; import { ComponentContent, window } from '@kit.ArkUI'; import { UIContext } from '@ohos.arkui.UIContext'; @@ -35,6 +36,7 @@ export class PromptActionClass { this.options = options; } + // [Start call_open_custom_dialog] static openDialog() { if (this.contentNode !== null) { this.ctx.getPromptAction().openCustomDialog(this.contentNode, this.options) @@ -48,7 +50,9 @@ export class PromptActionClass { }) } } + // [End call_open_custom_dialog] + // [Start call_close_custom_dialog] static closeDialog() { if (this.contentNode !== null) { this.ctx.getPromptAction().closeCustomDialog(this.contentNode) @@ -62,7 +66,9 @@ export class PromptActionClass { }) } } + // [End call_close_custom_dialog] + // [Start update_custom_dialog_property] static updateDialog(options: Object) { if (this.contentNode !== null) { this.ctx.getPromptAction().updateCustomDialog(this.contentNode, options) @@ -76,4 +82,6 @@ export class PromptActionClass { }) } } -} \ No newline at end of file + // [End update_custom_dialog_property] +} +// [End open_close_update_custom_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Index2.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Index2.ets index b01bc1145e3714affc0fc17588bf25664cf68154..97e111f9102eb8cc33133c9e5c9b4deadfe558e6 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Index2.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Index2.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dialog_route_jump_back] @Entry @Component struct Index2 { @@ -31,4 +32,5 @@ struct Index2 { }) }.width('100%').height('100%').margin({ top: 20 }) } -} \ No newline at end of file +} +// [End dialog_route_jump_back] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Menu/CreateMenu.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Menu/CreateMenu.ets index b6c65808534e46a6b6bd7b1e9dc2430357237d8b..e6c8f9d3123eb4a748aa4871a0a9e1ec16aa2bb7 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Menu/CreateMenu.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Menu/CreateMenu.ets @@ -15,6 +15,7 @@ import { PromptAction } from '@kit.ArkUI'; +// [Start builder_menu_content] class Tmp { private iconStr2: ResourceStr = $r('app.media.app_icon') @@ -75,9 +76,11 @@ export struct menuExample { } } build() { + // [StartExclude builder_menu_content] NavDestination() { Column({ space: 12 }) { + // [Start call_bind_menu] Button($r('app.string.menu_default')) .bindMenu([ { @@ -87,16 +90,21 @@ export struct menuExample { } } ]) + // [End call_bind_menu] .width(160) .height(50) + // [Start bind_menu_property] Button($r('app.string.menu_bind')) .bindMenu(this.MyMenu) + // [End bind_menu_property] .width(160) .height(50) + // [Start create_right_click_menu] Button($r('app.string.menu_rightClick')) .bindContextMenu(this.MyMenu, ResponseType.RightClick) + // [End create_right_click_menu] .width(160) .height(50) @@ -108,4 +116,6 @@ export struct menuExample { .backgroundColor('#f1f2f3') .title($r('app.string.create_menu')) } -} \ No newline at end of file + // [EndExclude builder_menu_content] +} +// [End builder_menu_content] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Toast/CreateToast.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Toast/CreateToast.ets index d137c48a1a8e8661ac419394ffd595d9f3912725..878844d16a59752fb3664e363cad27b69d7e9841 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Toast/CreateToast.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/Toast/CreateToast.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_toast] import { PromptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -49,4 +50,5 @@ export struct CreateToastExample { .backgroundColor('#f1f2f3') .title($r('app.string.CreateToast_title')) } -} \ No newline at end of file +} +// [End create_toast] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets index c249fbd4d283c2a6c3ec8dd0be63aca6e69112ab..55f609efe0d0a6dbe00f3e1543982c1e60af1b64 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets @@ -16,6 +16,7 @@ import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; +// [Start create_custom_dialog_example] @CustomDialog struct CustomDialogExample { controller: CustomDialogController = new CustomDialogController({ @@ -34,7 +35,10 @@ struct CustomDialogExample { }) } } +// [End create_custom_dialog_example] +// [Start click_event_pop_dialog] +// [Start create_custom_dialog_controller] @Entry @Component export struct CreateDialog { @@ -42,6 +46,7 @@ export struct CreateDialog { builder: CustomDialogExample(), }) + // [StartExclude create_custom_dialog_controller] build() { NavDestination() { Column({ space: 12 }) { @@ -61,4 +66,7 @@ export struct CreateDialog { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_create')) } + // [EndExclude create_custom_dialog_controller] + // [End create_custom_dialog_controller] + // [End click_event_pop_dialog] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets index 09484b44ad3ea2d790a59074ad3274a93b8bb683..ef1db50a608622474ab3f5bb6ee194aef17914cf 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_animation] @CustomDialog struct CustomDialogExample { controller?: CustomDialogController; @@ -74,4 +75,5 @@ export struct DialogAnimation { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_Animation1')) } -} \ No newline at end of file +} +// [End set_dialog_animation] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets index 9cd96af5b2b776050e930f6fc3c97fbd4c1fdead..825f321088c3ab12c74b8c2e2da45d79afc7a1c1 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets @@ -16,6 +16,7 @@ import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; +// [Start custom_dialog_build_button] @CustomDialog struct CustomDialogExample { cancel?: () => void; @@ -62,7 +63,9 @@ struct CustomDialogExample { } } +// [End custom_dialog_build_button] +// [Start dialog_constructor_accept] @Entry @Component export struct DialogInteraction { @@ -104,4 +107,5 @@ export struct DialogInteraction { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_interaction')) } + // [End dialog_constructor_accept] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets index b9080bc7ef59d1c420e3d8991f766bd6867d8a0d..3cacbb789607cf2a6600caf083824e45f95a2e68 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dialog_route_jump] @CustomDialog struct CustomDialogExample { @Link textValue: string; @@ -147,4 +148,5 @@ export struct DialogInteraction1 { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_interaction1')) } -} \ No newline at end of file +} +// [End dialog_route_jump] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets index 2475a81a05c5a6aa8f3d4b26c3b0bd76d1710641..0c5de5322fb338d46f715839f40a9b362098e301 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_style] @CustomDialog struct CustomDialogExample { controller?: CustomDialogController; @@ -82,4 +83,5 @@ export struct DialogStyle { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_style')) } -} \ No newline at end of file +} +// [End set_dialog_style] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets index 32f1356c419d36b2e168e9641b3bc27b8d83cb3e..5ce2b1ffb785052718478ba3a1b73d2d725860ba 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_nest] @CustomDialog struct CustomDialogExampleTwo { controllerTwo?: CustomDialogController; @@ -167,4 +168,5 @@ export struct NestDialog { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_nest')) } -} \ No newline at end of file +} +// [End set_dialog_nest] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/ActionSheet.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/ActionSheet.ets index a0f5aa844651bbfa353f8da21912a65db16c42bc..edc3baea8251f17286cc909df2d52b26188d1a94 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/ActionSheet.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/ActionSheet.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start action_sheet_dialog] @Entry @Component export struct showActionSheetExample { @@ -80,4 +81,5 @@ export struct showActionSheetExample { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_ActionSheet')) } -} \ No newline at end of file +} +// [End action_sheet_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/AlertDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/AlertDialog.ets index 3c662e1a0bd8eff011a6675a6f001d1b6ef67595..825c1f7ed93b7d661c5f189dd8687986f9fd4156 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/AlertDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/AlertDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start alert_dialog] import { PromptAction } from '@kit.ArkUI'; @Entry @@ -70,4 +71,5 @@ export struct showAlertDialogExample { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_AlertDialog')) } -} \ No newline at end of file +} +// [End alert_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/CalendarPickerDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/CalendarPickerDialog.ets index 5674c4cdc47a3674bf9379474323c6d791a14b04..c12418f2f7f837b719ee5397d8abf7f582edab93 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/CalendarPickerDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/CalendarPickerDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start calender_picker_dialog] import { PromptAction } from '@kit.ArkUI'; @Entry @@ -59,4 +60,5 @@ export struct CalendarDialog { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_calender')) } -} \ No newline at end of file +} +// [End calender_picker_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/DatePickerDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/DatePickerDialog.ets index 65a9abd17f21093d5e42ec9d8025c6ec5553cc5a..28caa25d66d07d063b681ea5dffbd8df5398b73b 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/DatePickerDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/DatePickerDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start date_picker_dialog] import { PromptAction } from '@kit.ArkUI'; @Entry @@ -50,4 +51,5 @@ export struct DatePickerDialogExample { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_date')) } -} \ No newline at end of file +} +// [End date_picker_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TextPickerDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TextPickerDialog.ets index 150d4fbe57c60f1f864d9cc15fdb52132a824db9..165285fbc1f7f2aba0988c88d2e2f3362c770aa0 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TextPickerDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TextPickerDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start text_picker_dialog] import { PromptAction } from '@kit.ArkUI'; @Entry @@ -63,4 +64,5 @@ export struct TextPickerDialogExample { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_text')) } -} \ No newline at end of file +} +// [End text_picker_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TimePickerDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TimePickerDialog.ets index 2b7365809b75930b0c20282147f4a30d1793b25d..7f0393367b4ae9594a1ea01c6ad12f8a11ff8c59 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TimePickerDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/fixedstyledialog/TimePickerDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start time_picker_dialog] import { PromptAction } from '@kit.ArkUI'; @Entry @@ -56,4 +57,5 @@ export struct TimePickerDialogExample { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_time')) } -} \ No newline at end of file +} +// [End time_picker_dialog] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets index f2b78545ff9d8a63af5c764800da8daa8531f188..4c65b64e1ef59c54bca7f93660fa1f1240079549 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_component_content] import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; @@ -89,8 +90,10 @@ function buildText(params: Params) { export struct openCustomDialog { @State message: string = 'hello' private ctx: UIContext = this.getUIContext(); + // [Start create_component_content] private contentNode: ComponentContent = new ComponentContent(this.ctx, wrapBuilder(buildText), new Params(this.message)); + // [End create_component_content] aboutToAppear(): void { PromptActionClass.setContext(this.ctx); @@ -126,4 +129,5 @@ export struct openCustomDialog { .backgroundColor('#f1f2f3') .title($r('app.string.open_customDialog')) } -} \ No newline at end of file +} +// [End open_close_component_content] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/ButtonPopup.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/ButtonPopup.ets index a67c40277b67aaf3bc9cbed815eee6972c23e663..114fc049e35955c71c3d11ac88db751f19cf9efb 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/ButtonPopup.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/ButtonPopup.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start button_popup] @Entry @Component export struct ButtonPopupExample { @@ -58,4 +59,5 @@ export struct ButtonPopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.button_popup')) } -} \ No newline at end of file +} +// [End button_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/CustomPopup.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/CustomPopup.ets index d8e133aeade78502268c2af3cd4b705cdbe24583..c533a4f49056d7da52b8086304a12e3c1a6a0f5c 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/CustomPopup.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/CustomPopup.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start custom_popup] @Entry @Component export struct CustomPopupExample { @@ -58,4 +59,5 @@ export struct CustomPopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.custom_popup')) } -} \ No newline at end of file +} +// [End custom_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupAnimation.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupAnimation.ets index 686b519bc6ceaa10ac7b5947a02ac28bed55dae7..2ef0e99f872fd0f9298ce1a88b6978aeff8f87a7 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupAnimation.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupAnimation.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start animation_popup] @Entry @Component export struct AnimationPopupExample { @@ -81,4 +82,5 @@ export struct AnimationPopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.AnimationPopup_title')) } -} \ No newline at end of file +} +// [End animation_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStateChange.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStateChange.ets index a76171f7b731f9badb933064bfc0836240eb372c..a9fc84f9844ebac1f5f2c79e7ef5b8336be22a42 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStateChange.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStateChange.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start state_popup] @Entry @Component export struct StatePopupExample { @@ -46,4 +47,5 @@ export struct StatePopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.onStateChange_title')) } -} \ No newline at end of file +} +// [End state_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStyle.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStyle.ets index 34127bc9495fc3a445842e2b8e9d13a1d6e44568..32426e33258fcf5b3976588d19b7bd58eaac91de 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStyle.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/PopupStyle.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start style_popup] @Entry @Component export struct StylePopupExample { @@ -58,4 +59,5 @@ export struct StylePopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.StylePopup_title')) } -} \ No newline at end of file +} +// [End style_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/TextPrompts.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/TextPrompts.ets index 9e81530b5ae638154f48d662f7b583a2b2b986bc..4ff872db5c2306411b3e34fabc9154d8771fc316 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/TextPrompts.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/popup/TextPrompts.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start text_popup] @Entry @Component export struct TextPopupExample { @@ -41,4 +42,5 @@ export struct TextPopupExample { .backgroundColor('#f1f2f3') .title($r('app.string.TextPopup_title')) } -} \ No newline at end of file +} +// [End text_popup] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/ClickEvent.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/ClickEvent.ets index aa5cf871aecb1a50e5216f5aee4b04533b30d586..84555db100b8e1c1ad81f4dc1be3f189d24286d5 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/ClickEvent.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/ClickEvent.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start click_event_handle] @Entry @Component export struct Click { @@ -48,4 +49,5 @@ export struct Click { .backgroundColor('#f1f2f3') .title($r('app.string.Touch_ClickEvent_title')) } -} \ No newline at end of file +} +// [End click_event_handle] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/TouchEvent.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/TouchEvent.ets index 435d175e86c6e516e5fae8aba7a6e87416d31081..d423f073d40410c426dba4ca19877c7c52290f7c 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/TouchEvent.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/Touch/TouchEvent.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start touch_event_handle] @Entry @Component export struct Touch { @@ -70,4 +71,5 @@ export struct Touch { .backgroundColor('#f1f2f3') .title($r('app.string.Touch_TouchEvent_title')) } -} \ No newline at end of file +} +// [End touch_event_handle] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/HoverEffect.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/HoverEffect.ets index 2d9c8e303471c92f1ed63d6cae081b687ddf3a2e..198de86e063fb71801303866048a561921b6471d 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/HoverEffect.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/HoverEffect.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start mouse_hover_effect] @Entry @Component export struct HoverEffectSample { @@ -47,4 +48,5 @@ export struct HoverEffectSample { .backgroundColor('#f1f2f3') .title($r('app.string.HoverEffectSample_title')) } -} \ No newline at end of file +} +// [End mouse_hover_effect] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnHover.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnHover.ets index 1fd6b22d4b518b61ae1f262e00d6636a65893d14..6992c005cee95ca32fa5a6fffdd837e37af9470c 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnHover.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnHover.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dynamic_response_mouse_hover] @Entry @Component export struct Hover { @@ -46,4 +47,5 @@ export struct Hover { .backgroundColor('#f1f2f3') .title($r('app.string.Device_OnHover_title')) } -} \ No newline at end of file +} +// [End dynamic_response_mouse_hover] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKey.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKey.ets index 785cf406e017e591ff1bd0c984c8b0a93b7f127d..eaa8bc571e56996e40634da472ab23320ec88691 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKey.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKey.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start listen_response_key_event] @Entry @Component export struct OnKey { @@ -73,4 +74,5 @@ export struct OnKey { .backgroundColor('#f1f2f3') .title($r('app.string.Device_OnKey_title')) } -} \ No newline at end of file +} +// [End listen_response_key_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKeyPreIme.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKeyPreIme.ets index d5fba8b194ba60c99868d0e2866703303402ffa7..32edef1b979e0a2bcf6ad0dabc73691f2f26872b 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKeyPreIme.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnKeyPreIme.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start key_event_intercept] import { KeyCode } from '@kit.InputKit'; @Entry @@ -50,4 +51,5 @@ export struct PreIme { .backgroundColor('#f1f2f3') .title($r('app.string.Device_OnKeyPreIme_title')) } -} \ No newline at end of file +} +// [End key_event_intercept] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnMouse.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnMouse.ets index 209e6c58432dbb5d0a4ad11d0195822489ba5135..baab41e24e74633e70a408537ae47d37aa2d4bcb 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnMouse.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/device/OnMouse.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start listen_response_mouse_event] @Entry @Component export struct Mouse { @@ -76,4 +77,5 @@ export struct Mouse { .backgroundColor('#f1f2f3') .title($r('app.string.Device_OnMouse_title')) } -} \ No newline at end of file +} +// [End listen_response_mouse_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/DefaultDrag.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/DefaultDrag.ets index 22e6b2e2e81f86a9cfe9a00f3be81069bb5b0b85..0da469af667fa7068e24b1aff4bea53e180bfa17 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/DefaultDrag.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/DefaultDrag.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start default_drag] import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData'; import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -27,6 +28,7 @@ export struct DefaultDrag { @State imgState: Visibility = Visibility.Visible; @State pixmap: image.PixelMap | undefined = undefined; + // [Start generate_pix_map] @Builder pixelMapBuilder() { Column() { @@ -37,6 +39,8 @@ export struct DefaultDrag { } } + // [StartExclude generate_pix_map] + // [Start data_delayed_retry] getDataFromUdmfRetry(event: DragEvent, callback: (data: DragEvent) => void) { try { let data: UnifiedData = event.getData(); @@ -64,6 +68,8 @@ export struct DefaultDrag { this.getDataFromUdmfRetry(event, callback); }, 1500); } + // [End data_delayed_retry] + // [EndExclude generate_pix_map] // 调用componentSnapshot中的createFromBuilder接口截取自定义builder的截图 private getComponentSnapshot(): void { @@ -78,6 +84,7 @@ export struct DefaultDrag { this.pixmap = pixmap; }) } + // [End generate_pix_map] // 长按50ms时提前准备自定义截图的pixmap private PreDragChange(preDragStatus: PreDragStatus): void { @@ -99,15 +106,20 @@ export struct DefaultDrag { .margin(10) .backgroundColor('#008888') Row() { + // [Start module_draggable] Image($r('app.media.app_icon')) .width(100) .height(100) .draggable(true) .margin({ left: 15 }) + // [StartExclude module_draggable] .visibility(this.imgState)// 绑定平行手势,可同时触发应用自定义长按手势 + // [Start bind_parallel_gesture] .parallelGesture(LongPressGesture().onAction(() => { promptAction.showToast({ duration: 100, message: 'Long press gesture trigger' }); })) + // [End bind_parallel_gesture] + // [EndExclude module_draggable] .onDragStart((event) => { let data: unifiedDataChannel.Image = new unifiedDataChannel.Image(); data.imageUri = 'common/pic/img.png'; @@ -119,10 +131,15 @@ export struct DefaultDrag { extraInfo: 'this is extraInfo', }; return dragItemInfo; - })// 提前准备拖拽自定义背板图 + }) + // [End module_draggable] + // 提前准备拖拽自定义背板图 + // [Start set_custom_drag_status] .onPreDrag((status: PreDragStatus) => { this.PreDragChange(status); }) + // [End set_custom_drag_status] + // [Start set_on_drag_end] .onDragEnd((event) => { // onDragEnd里取到的result值在接收方onDrop设置 if (event.getResult() === DragResult.DRAG_SUCCESSFUL) { @@ -131,6 +148,7 @@ export struct DefaultDrag { promptAction.showToast({ duration: 100, message: 'Drag failed' }); } }) + // [End set_on_drag_end] } Text('Drag Target Area') @@ -146,11 +164,16 @@ export struct DefaultDrag { .draggable(true) .margin({ left: 15 }) .border({ color: Color.Black, width: 1 })// 控制角标显示类型为MOVE,即不显示角标 + // [Start set_drag_behavior_move] .onDragMove((event) => { event.setResult(DragResult.DROP_ENABLED) event.dragBehavior = DragBehavior.MOVE + // [End set_drag_behavior_move] }) + // [Start allow_drag_type] .allowDrop([uniformTypeDescriptor.UniformDataType.IMAGE]) + // [End allow_drag_type] + // [Start set_on_drop_call] .onDrop((dragEvent?: DragEvent) => { // 获取拖拽数据 this.getDataFromUdmf((dragEvent as DragEvent), (event: DragEvent) => { @@ -164,7 +187,8 @@ export struct DefaultDrag { event.setResult(DragResult.DRAG_SUCCESSFUL); }) }) - } + // [End set_on_drop_call] + }allowDrop } .width('100%') .height('100%') @@ -179,4 +203,5 @@ export struct DefaultDrag { .backgroundColor('#f1f2f3') .title($r('app.string.Drag_DefaultDrag_title')) } -} \ No newline at end of file +} +// [End default_drag] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/MoreDrag.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/MoreDrag.ets index 62b030bd7cc540ec6980422ec5e37a5651bbd6a6..85b1a0ed9793fb3ec1f1585146043477cb2e6676 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/MoreDrag.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/drag/MoreDrag.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start more_drag] import { KeyCode } from '@kit.InputKit'; import { image } from '@kit.ImageKit'; @@ -60,6 +61,7 @@ export struct MoreDrag { Column({ space: 12 }) { Column({ space: 5 }) { + // [Start create_grid_item_module] Grid() { ForEach(this.numbers, (idx: number) => { GridItem() { @@ -70,6 +72,7 @@ export struct MoreDrag { .opacity(1.0) .id('grid' + idx) } + // [StartExclude create_grid_item_module] .dragPreview(this.previewData[idx]) .selectable(true) .selected(this.isSelectedGrid[idx]) @@ -78,8 +81,10 @@ export struct MoreDrag { normal: this.normalStyles, selected: this.selectStyles }) + // [Start grid_item_module_selected_true] .onClick(() => { this.isSelectedGrid[idx] = !this.isSelectedGrid[idx]; + // [StartExclude grid_item_module_selected_true] if (this.isSelectedGrid[idx]) { this.numberBadge++; let gridItemName = 'grid' + idx; @@ -95,14 +100,20 @@ export struct MoreDrag { } else { this.numberBadge--; } + // [EndExclude grid_item_module_selected_true] }) + // [End grid_item_module_selected_true] // 使能多选拖拽,右上角数量角标需要应用设置numberBadge参数 + // [EndExclude create_grid_item_module] + // [Start drag_preview_options] .dragPreviewOptions({ numberBadge: this.numberBadge }, { isMultiSelectionEnabled: true, defaultAnimationBeforeLifting: true }) + // [End drag_preview_options] .onDragStart(() => { }) }, (idx: string) => idx) } + // [End create_grid_item_module] .columnsTemplate('1fr 1fr 1fr 1fr 1fr') .columnsGap(5) .rowsGap(10) @@ -117,4 +128,5 @@ export struct MoreDrag { .backgroundColor('#f1f2f3') .title($r('app.string.Drag_MoreDrag_title')) } -} \ No newline at end of file +} +// [End more_drag] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/DefaultFocus.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/DefaultFocus.ets index 17950d8453aeba1abd5c901a2731836790826419..96fe7d74e62b4d7baefe941af59b78203e29ad20 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/DefaultFocus.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/DefaultFocus.ets @@ -15,6 +15,7 @@ import { KeyCode } from '@kit.InputKit'; +// [Start focus_visualization_manage] @Entry @Component export struct DefaultFocus { @@ -81,4 +82,5 @@ export struct DefaultFocus { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_DefaultFocus_title')) } -} \ No newline at end of file +} +// [End focus_visualization_manage] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusAndClick.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusAndClick.ets index 7a745a6606bb42947ab7a74049b87ba33732d70e..f5aebe743e29b644ce9d13c1570b2d3e3a0c67d4 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusAndClick.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusAndClick.ets @@ -16,6 +16,7 @@ import { KeyCode } from '@kit.InputKit'; import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'; +// [Start dynamic_focus_click_count] @Entry @Component export struct FocusAndClick { @@ -49,4 +50,5 @@ export struct FocusAndClick { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_FocusAndClick_title')) } -} \ No newline at end of file +} +// [End dynamic_focus_click_count] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusController.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusController.ets index 20790003985759fb3b7e4eb50e091054278e5a4e..9a282c3093f866dfe7ccbde177ac57bee2000714 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusController.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusController.ets @@ -16,6 +16,7 @@ import { KeyCode } from '@kit.InputKit'; import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'; +// [Start dynamic_focus_control_demo] @Entry @Component export struct FocusControl { @@ -95,4 +96,5 @@ export struct FocusControl { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_FocusController_title')) } -} \ No newline at end of file +} +// [End dynamic_focus_control_demo] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusPriority.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusPriority.ets index e98641f80a174ee0c85ca8a282d1ff6d4262dc57..23e38577d10744c6646b7e14a48721f925a340b6 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusPriority.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusPriority.ets @@ -15,6 +15,7 @@ import { KeyCode } from '@kit.InputKit'; +// [Start focus_priority_manage] @Entry @Component export struct FocusPrioritySample { @@ -43,4 +44,5 @@ export struct FocusPrioritySample { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_FocusPriority_title')) } -} \ No newline at end of file +} +// [End focus_priority_manage] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusScopePriority.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusScopePriority.ets index d4293025b8c5a4ae8f335e9b064b2edf3a67c16d..eae88de81d087426eb3206cbec9568109abaef5d 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusScopePriority.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusScopePriority.ets @@ -16,6 +16,7 @@ import { KeyCode } from '@kit.InputKit'; import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'; +// [Start focus_scope_navigation] @Entry @Component export struct FocusScopePriority { @@ -145,4 +146,5 @@ export struct FocusScopePriority { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_FocusScopePriority_title')) } -} \ No newline at end of file +} +// [End focus_scope_navigation] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusStyle.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusStyle.ets index 29826442789b710f246a79fe15f31ff897b8aa49..2841736de10f5d549f62ef9d926e3379de825a06 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusStyle.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/FocusStyle.ets @@ -16,6 +16,7 @@ import { KeyCode } from '@kit.InputKit'; import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'; +// [Start focus_style_manage] @Entry @Component export struct FocusStyle { @@ -48,4 +49,5 @@ export struct FocusStyle { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_FocusStyle_title')) } -} \ No newline at end of file +} +// [End focus_style_manage] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/Focusable.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/Focusable.ets index 5dae705e3b2a5bc53eba530398882b58beb3f6ab..27a7def39df2e59a8edbc2b4e226db96179e677a 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/Focusable.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/Focusable.ets @@ -12,9 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + import { KeyCode } from '@kit.InputKit'; +// [Start dynamic_focus_control_manage] @Entry @Component export struct FocusableExample { @@ -108,4 +109,5 @@ export struct FocusableExample { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_Focusable_title')) } -} \ No newline at end of file +} +// [End dynamic_focus_control_manage] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/onFocusBlur.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/onFocusBlur.ets index 15d3549b87944bf4c7cd371ad915d25f6b70ba7e..4f993f6bef8dd5b4ac138a13fd380803d05b4748 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/onFocusBlur.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/focus/onFocusBlur.ets @@ -15,6 +15,7 @@ import { KeyCode } from '@kit.InputKit'; +// [Start focus_dynamic_reflect] @Entry @Component export struct OnFocusBlur { @@ -79,4 +80,5 @@ export struct OnFocusBlur { .backgroundColor('#f1f2f3') .title($r('app.string.Focus_OnFocusBlur_title')) } -} \ No newline at end of file +} +// [End focus_dynamic_reflect] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/gesturejudge/GestureJudge.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/gesturejudge/GestureJudge.ets index 08a2fd5be452bf51c898fabe92a3bc67d6f372ee..bce286e8def63f96f3a88484190dc3e8038fe788 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/gesturejudge/GestureJudge.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/gesturejudge/GestureJudge.ets @@ -13,15 +13,19 @@ * limitations under the License. */ +// [Start gesture_judge] +// [Start set_gesture_judge] @Entry @Component export struct GestureJudge { scroller: Scroller = new Scroller(); + // [StartExclude set_gesture_judge] scroller2: Scroller = new Scroller(); private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; private childRecognizer: GestureRecognizer = new GestureRecognizer(); private currentRecognizer: GestureRecognizer = new GestureRecognizer(); private lastOffset: number = 0; + // [EndExclude set_gesture_judge] build() { NavDestination() { @@ -115,6 +119,7 @@ export struct GestureJudge { } return GestureJudgeResult.CONTINUE; }) + // [StartExclude set_gesture_judge] .parallelGesture( // 绑定一个Pan手势作为动态控制器 PanGesture() .onActionUpdate((event: GestureEvent) => { @@ -151,6 +156,7 @@ export struct GestureJudge { this.lastOffset = event.offsetY; }) ) + // [EndExclude set_gesture_judge] }.width('100%').height('90%').backgroundColor(0xDCDCDC) } .width('100%') @@ -160,4 +166,6 @@ export struct GestureJudge { .backgroundColor('#f1f2f3') .title($r('app.string.gesture_GestureJudge_title')) } -} \ No newline at end of file +} +// [End set_gesture_judge] +// [End gesture_judge] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Exclusive.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Exclusive.ets index 628a7f590ad9e5d39e865e00b4d480aa541b0d65..a72dfbf7621f6bdfc0372a6a8093d27657d67be9 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Exclusive.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Exclusive.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start exclusive_recognition_gesture] @Entry @Component export struct Exclusive { @@ -52,4 +53,5 @@ export struct Exclusive { .backgroundColor('#f1f2f3') .title($r('app.string.groupgesture_Exclusive_title')) } -} \ No newline at end of file +} +// [End exclusive_recognition_gesture] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Parallel.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Parallel.ets index 2159c4570a59f2c01443e97784a32d26c58895f0..e08c5b8b0f39a0e7c3f1fd940f071033b311f7eb 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Parallel.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Parallel.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start parallel_recognition_gesture] @Entry @Component export struct Parallel { @@ -52,4 +53,5 @@ export struct Parallel { .backgroundColor('#f1f2f3') .title($r('app.string.groupgesture_Parallel_title')) } -} \ No newline at end of file +} +// [End parallel_recognition_gesture] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Sequence.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Sequence.ets index 9d0269584e25902ff583f948c0f5cdc3ce363e13..9f88c3236bfa63699cb0056f1c62165e458ae999 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Sequence.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/groupgesture/Sequence.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sequence_recognition_gesture] @Entry @Component export struct Sequence { @@ -88,4 +89,5 @@ export struct Sequence { .backgroundColor('#f1f2f3') .title($r('app.string.groupgesture_Sequence_title')) } -} \ No newline at end of file +} +// [End sequence_recognition_gesture] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/LongPressGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/LongPressGesture.ets index 87adf25560d3d58519f6aa869ee513ba786d17d4..ddf02d55f8e294dec314a645bcc821231df11515 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/LongPressGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/LongPressGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_long_press_event] @Entry @Component export struct LongPress { @@ -51,4 +52,5 @@ export struct LongPress { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_LongPressGesture_title')) } -} \ No newline at end of file +} +// [End catch_long_press_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PanGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PanGesture.ets index 509ace4e30312692104ad555a66307be2d5f4f42..7afb75ff6ca1b5cf15717cd7e7de66d46703d35c 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PanGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PanGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_pan_gesture_event] @Entry @Component export struct Pan { @@ -62,4 +63,5 @@ export struct Pan { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_PanGesture_title')) } -} \ No newline at end of file +} +// [End catch_pan_gesture_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PinchGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PinchGesture.ets index deea7cc9e1627d1b5b5f2556602f17f937a62521..9d538513c66b652bdc2f018ab2a6e39680133f94 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PinchGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/PinchGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_pinch_gesture_event] @Entry @Component export struct Pinch { @@ -62,4 +63,5 @@ export struct Pinch { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_PinchGesture_title')) } -} \ No newline at end of file +} +// [End catch_pinch_gesture_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/RotationGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/RotationGesture.ets index 959d1ae81909c25d5fd3a54eef3b9a10fd9b5f09..89d5775e8815a222812b4917c7c2244d310c5f7f 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/RotationGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/RotationGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_rotation_gesture_event] @Entry @Component export struct Rotation { @@ -61,4 +62,5 @@ export struct Rotation { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_RotationGesture_title')) } -} \ No newline at end of file +} +// [End catch_rotation_gesture_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/SwipeGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/SwipeGesture.ets index 1416456ea1526681e55fd4f96c4966476d75e774..4b4363855344f460e3efba6f37bba0e5c8b15bdb 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/SwipeGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/SwipeGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_swipe_gesture_event] @Entry @Component export struct Swipe { @@ -53,4 +54,5 @@ export struct Swipe { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_SwipeGesture_title')) } -} \ No newline at end of file +} +// [End catch_swipe_gesture_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/TapGesture.ets b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/TapGesture.ets index eec1a1b5bc7403412b51e63adea3ffe7f592da54..bc0f24b52c56514c5b2140e60fb35d3dde4f6769 100644 --- a/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/TapGesture.ets +++ b/code/DocsSample/ArkUISample/EventProject/entry/src/main/ets/pages/singlegesture/TapGesture.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start catch_click_twice_event] @Entry @Component export struct Tap { @@ -46,4 +47,5 @@ export struct Tap { .backgroundColor('#f1f2f3') .title($r('app.string.singlegesture_TapGesture_title')) } -} \ No newline at end of file +} +// [End catch_click_twice_event] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets index 3a845244f9ca8c3dfdd5f00e6eb0b3a9fbc93e4f..0c104b48a2ba0e7c08c630b861c30a083d4bef52 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start init_download_task] import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -69,3 +70,4 @@ struct WebComponent { } } } +// [End init_download_task] diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets index 4d6612a40560a8a2b3405e9df10ee3ae0a0fe4df..733a26d4b9600db7f50a41cc0b338561f1584951 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start download_delegate] import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -63,3 +64,4 @@ struct WebComponent { } } } +// [End download_delegate] diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets index fa69ed291fe6f405122648403b039d9a5109dd2d..b2c4f7002135a74ccd926353c21365c0dd4abebb 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start recovery_download_task] import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; import { DownloadUtil, fileName, filePath } from './downloadUtil'; // downloadUtil.ets 见下文 @@ -101,4 +102,5 @@ struct WebComponent { Web({ src: 'www.example.com', controller: this.controller }) } } -} \ No newline at end of file +} +// [End recovery_download_task] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets index ce5815e73d211fc2c3d7f260848386de8847db74..f5e26614ec7193c00bd97c8ca7aca9b5d14d66b1 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start web_file_upload] import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; import { picker } from '@kit.CoreFileKit'; @@ -44,3 +45,4 @@ struct WebComponent { } } } +// [End web_file_upload] diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets index 7f24d7ddfced52a4352da6174243d98f6bd399c5..f00bbab9c0e8316aad81218c0b74d66ec93d7f06 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start task_info_persistence_util] import { util } from '@kit.ArkTS'; import fileStream from '@ohos.file.fs'; @@ -63,4 +64,5 @@ export namespace DownloadUtil { return fileStream.readTextSync(dir + '/' + fileName); } -} \ No newline at end of file +} +// [End task_info_persistence_util] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp index f14eb24d0031ba09886a6d712e16888291afe1a4..1e1319c00baf08c21e23d1bfd47a4f2b5053fd34 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_intercept_web_module_request_example] #include "hilog/log.h" #include "napi/native_api.h" #include "rawfile_request.h" @@ -23,7 +24,9 @@ #undef LOG_TAG #define LOG_TAG "ss-handler" +// [Start set_intercept_web_module_request] ArkWeb_SchemeHandler *g_schemeHandler; +// [StartExclude set_intercept_web_module_request] ArkWeb_SchemeHandler *g_schemeHandlerForSW; NativeResourceManager *g_resourceManager; @@ -31,11 +34,13 @@ NativeResourceManager *g_resourceManager; static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) { OH_LOG_INFO(LOG_APP, "register custom schemes"); + // [Start register_set_custom_schemes] OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); OH_ArkWeb_RegisterCustomSchemes( "custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); + // [End register_set_custom_schemes] return nullptr; } @@ -95,21 +100,27 @@ void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) { OH_LOG_INFO(LOG_APP, "set scheme handler"); + // [EndExclude set_intercept_web_module_request] + // [Start set_intercept_web_module_request_custom] OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); + // [StartExclude set_intercept_web_module_request_custom] OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); + // [EndExclude set_intercept_web_module_request_custom] OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); + // [End set_intercept_web_module_request_custom] OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); + // [End set_intercept_web_module_request] OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); return nullptr; @@ -150,4 +161,5 @@ static napi_module demoModule = { extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); -} \ No newline at end of file +} +// [End set_intercept_web_module_request_example] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp index 233eb0c157de78cca7000c937e1aa08019ffff1a..f3ddb6e476513246ed79cc57d0229abc1e604efb 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start intercepted_request_processing_cpp] #include "rawfile_request.h" #include "threads.h" @@ -118,6 +119,7 @@ RawfileRequest::~RawfileRequest() {} void RawfileRequest::Start() { OH_LOG_INFO(LOG_APP, "start a rawfile request."); + // [Start get_intercepted_request_info] char* url; OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); std::string urlStr(url); @@ -126,14 +128,19 @@ void RawfileRequest::Start() rawfilePath_ = urlStr.substr(position + 1); } OH_ArkWeb_ReleaseString(url); + // [End get_intercepted_request_info] + // [Start set_intercepted_request_response] OH_ArkWeb_CreateResponse(&response_); + // [StartExclude set_intercepted_request_response] OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); if (stream_) { OH_LOG_ERROR(LOG_APP, "have http body stream"); + // [Start get_put_post_request_data] OH_ArkWebHttpBodyStream_SetUserData(stream_, this); OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); + // [End get_put_post_request_data] } else { thrd_t th; if (thrd_create(&th, ReadRawfileOnWorkerThread, static_cast(this)) != thrd_success) { @@ -180,7 +187,9 @@ void RawfileRequest::ReadRawfileDataOnWorkerThread() if (!rawfile) { OH_ArkWebResponse_SetStatus(response(), HTTP_NOT_FOUND); } else { + // EndExclude set_intercepted_request_response] OH_ArkWebResponse_SetStatus(response(), HTTP_OK); + // [StartExclude set_intercepted_request_response] } for (auto &urlInfo : urlInfos) { @@ -189,10 +198,15 @@ void RawfileRequest::ReadRawfileDataOnWorkerThread() break; } } + // [StartExclude set_intercepted_request_response] OH_ArkWebResponse_SetCharset(response(), "UTF-8"); + // [EndExclude set_intercepted_request_response] + // [StartExclude set_intercepted_request_response] long len = OH_ResourceManager_GetRawFileSize(rawfile); + // EndExclude set_intercepted_request_response] OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); + // [StartExclude set_intercepted_request_response] DidReceiveResponse(); long consumed = 0; @@ -236,7 +250,9 @@ void RawfileRequest::DidReceiveResponse() OH_LOG_INFO(LOG_APP, "did receive response."); std::lock_guard guard(mutex_); if (!stopped_) { + // [EndExclude set_intercepted_request_response] OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); + // [StartExclude set_intercepted_request_response] } } @@ -245,7 +261,9 @@ void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) OH_LOG_INFO(LOG_APP, "did receive data."); std::lock_guard guard(mutex_); if (!stopped_) { + // EndExclude set_intercepted_request_response] OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); + // [StartExclude set_intercepted_request_response] } } @@ -254,7 +272,9 @@ void RawfileRequest::DidFinish() OH_LOG_INFO(LOG_APP, "did finish."); std::lock_guard guard(mutex_); if (!stopped_) { + // [EndExclude set_intercepted_request_response] OH_ArkWebResourceHandler_DidFinish(resourceHandler_); + // End set_intercepted_request_response] } } @@ -264,4 +284,5 @@ void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) if (!stopped_) { OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); } -} \ No newline at end of file +} +// [End intercepted_request_processing_cpp] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h index 047e3fbe96aeb8a0327bbc26c2960f6e7a74d3a6..8a8cdbc0d915566dec521726fd6b4980229e66b9 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start rawfile_request_head] #ifndef RAWFILE_REQUEST_H #define RAWFILE_REQUEST_H @@ -57,4 +58,5 @@ private: std::mutex mutex_; }; -#endif // RAWFILE_REQUEST_H \ No newline at end of file +#endif // RAWFILE_REQUEST_H +// [End rawfile_request_head] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts index 421d8dd56c181c43f04ba1950bad7776d88419c3..39fae16db3893f5f4dce323474c7840e6ada0f52 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts @@ -15,6 +15,8 @@ import { resourceManager } from "@kit.LocalizationKit"; +// [Start export_register_set_init_schemes] export const registerCustomSchemes: () => void; export const setSchemeHandler: () => void; -export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; \ No newline at end of file +export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; +// [End export_register_set_init_schemes] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets index becf66a83e050134286b4ce280bf32e8b33931c0..2a39089b66159b4964c23ae0a2062b7544c16b93 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,12 +13,14 @@ * limitations under the License. */ +// [Start register_init_scheme_example] import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; import testNapi from 'libentry.so'; import { webview } from '@kit.ArkWeb'; +// [Start register_init_scheme] export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { // 注册三方协议的配置。 @@ -29,6 +31,7 @@ export default class EntryAbility extends UIAbility { testNapi.setSchemeHandler(); } + // [StartExclude register_init_scheme] onDestroy(): void { } @@ -52,4 +55,7 @@ export default class EntryAbility extends UIAbility { onBackground(): void { } -}; \ No newline at end of file + // [EndExclude register_init_scheme] +}; +// [End register_init_scheme] +// [End register_init_scheme_example] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets index 26f1b893f9dbe047664a1bdd484b38bb176e192b..360bb38ae0f3e9d91621a55173595d62fe84dbd0 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_test_html] import testNapi from 'libentry.so'; import { webview } from '@kit.ArkWeb'; import { resourceManager } from '@kit.LocalizationKit'; @@ -45,4 +46,5 @@ struct Index { } .height('100%') } -} \ No newline at end of file +} +// [End set_test_html] \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js index 1c4da6421155719389a427a144544549b7e76645..d345c85fd525de0327d486b257be1f74a478d0a6 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js @@ -13,7 +13,9 @@ * limitations under the License. */ +// [Start csp_rules_java_script] const body = document.body; const element = document.createElement('div'); element.textContent = 'csp_script.js bypass the csp rules'; body.appendChild(element); +// [End csp_rules_java_script] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js index 2e2dde4c9f107b616d3c897b7cc0ddbe29992734..e1e912d400a89483d5e08755ebdef83f1363583e 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js @@ -13,5 +13,7 @@ * limitations under the License. */ +// [Start isolated_script_java_script] const element = document.getElementById('isolated_test'); element.textContent = 'isolated_script.js not blocked'; +// [End isolated_script_java_script] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js index b68be374a917688cc814fdb498b61c0b4d346c40..0e7da82dee18bd301dce810b91e5a977a26be9aa 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js @@ -13,5 +13,7 @@ * limitations under the License. */ +// [Start local_script_java_script] const element = document.getElementById('local_test'); element.textContent = 'local_script.js not blocked.'; +// [End local_script_java_script] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js index 05bca835cd697dda090f9b16cf0ea3df08366240..fe14cf8d505edfdcd13cb5bc03499fee5f775db7 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start add_event_listener_java_script] self.addEventListener('install', event => { console.log('v1 installing'); event.waitUntil( @@ -23,3 +24,4 @@ self.addEventListener('install', event => { self.addEventListener('activate', event => { console.log('v1 now redy to handle fetches.'); }); +// [End add_event_listener_java_script] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets index 772019f7dbf631ec081f1e1a88611f34c37033ac..b6c293ba8d523dc3ab6850d91e24a3b040e39e44 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start web_module_open_bf_cache] import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -27,6 +28,7 @@ export default class Entry2Ability extends UIAbility { webview.WebviewController.initializeWebEngine(); AppStorage.setOrCreate('abilityWant', want); } + // [End web_module_open_bf_cache] onDestroy(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets index a6e79e86581eb88991673a97d811f32b71210385..9364a623c7f9d2d9376a23a2c781bc929366f490 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets @@ -1,4 +1,4 @@ -/* +z/* * 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. @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start web_module_page_set] import { webview } from '@kit.ArkWeb'; @Entry @@ -42,3 +43,4 @@ struct Index { .width('100%') } } +// [End Web_module_page_set] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets index aad8855ea697dce833c927d3ea957701800947fe..ec13ab90b8a5d809e5b72e6105043d3c7c705c0d 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -16,8 +16,10 @@ import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +// [Start create_main_window] import { createNWeb, defaultUrl } from '../pages/common'; +// [StartExclude create_main_window] export default class Entry3Ability extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); @@ -26,6 +28,7 @@ export default class Entry3Ability extends UIAbility { onDestroy(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); } + // [EndExclude create_main_window] onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability @@ -41,6 +44,7 @@ export default class Entry3Ability extends UIAbility { hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); } + // [End create_main_window] onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets index 89f4e9ac489ffc6c84e2b59cff085847474a02e2..2aa69cc19dbf5dde17260f3b99bc5d5683d0303c 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start web_module_dynamic_attach_detach] // 使用NodeController的Page页 import { getBuilderNode, MyNodeController, defaultUrl, getWebviewController } from './common'; @@ -47,4 +48,5 @@ struct Index { .height('100%') } } +// [End web_module_dynamic_attach_detach] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets index b096393478eac3afd1e3c68d6d669646a417dbea..2c84144ae34ae280cc201bfff2c187d97a4d3910 100755 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start dynamic_web_module_manage] // 提供动态挂载Web组件能力 import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; import { webview } from '@kit.ArkWeb'; @@ -113,4 +114,5 @@ export const getBuilderNode = (url : string) : BuilderNode<[Data]> | undefined = export const getWebviewController = (url : string) : webview.WebviewController | undefined => { return webControllerMap.get(url); } +// [End dynamic_web_module_manage] diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets index c9e7f1d91c51393569c727ddda14c1fc3527bae2..30eecf7173f0c347787a368ec2b185ff925d4e3d 100755 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start create_web_print_document] import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; import { print } from '@kit.BasicServicesKit'; @@ -37,3 +38,4 @@ struct WebComponent { } } } +// [End create_web_print_document] diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets index dc29699f17f516faf0e518597a9ec8a8d4ee9ac5..7d1281e593d6ba6c272dcd97a49da7cc006a16c2 100755 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start w3c_print_html] import { webview } from '@kit.ArkWeb'; @Entry @@ -31,3 +32,4 @@ struct Index { .height('100%') } } +// [End w3c_print_html] diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets index 4314ecdac9649a5c608c38b2b8d628048d1edc77..8e8d12a1db0b38d703bfa99e0ba9c9408e69f2fb 100755 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start web_module_create_load_pdf] import { webview } from '@kit.ArkWeb'; @Entry @@ -34,3 +35,4 @@ struct WebComponent { } } } +// [End web_module_create_load_pdf] diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 index 3bd75df6f68922e5bb0e9020d8a692b688acc2e0..35af445a0c60a856a7d4c049de0a4de2661ddd38 100755 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 @@ -62,13 +62,21 @@ ] } ], + // [Start web_module_print_html] + // [Start web_module_preview_pdf] "requestPermissions":[ + // [StartExclude web_module_preview_pdf] { "name" : "ohos.permission.PRINT" }, + // EndExclude web_module_preview_pdf] + // [StartExclude web_module_print_html] { "name" : "ohos.permission.INTERNET" } - ] + // [EndExclude web_module_print_html] + ], + // [End web_module_preview_pdf] + // [End web_module_print_html] } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets index f1725a0155ea31cd34f47a5681b38a1ded6bf503..4c6650113cb3d21077fed1d1bd453fb428878b5d 100755 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start draw_x_component_av_player_button] // 创建NodeController import { webview } from '@kit.ArkWeb'; import { UIContext, NodeController, BuilderNode, NodeRenderType, FrameNode } from '@kit.ArkUI'; @@ -212,3 +213,4 @@ struct WebIndex { } } } +// [End draw_x_component_av_player_button] diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets index 7e298f41f40aab35e88dad2477b7e8b4d1d7d0a1..69eb5079b95cc92d9e8dce3c93db08cccb74b365 100755 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start mp4_player_example] import { media } from '@kit.MediaKit'; import { BusinessError } from '@ohos.base'; @@ -99,3 +100,4 @@ export class AVPlayerDemo { avPlayer.url = 'xxx/demo.mp4'; } } +// [End mp4_player_example] diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets index 5ad45c2b350ab4baf0ef968086a660cc3e88b234..3423db539ced44ca6fa04f0e1dd5251b7009ce50 100755 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_web_peer_render] import webview from '@ohos.web.webview'; import { UIContext } from '@ohos.arkui.UIContext'; import { NodeController, BuilderNode, NodeRenderType, FrameNode } from '@ohos.arkui.node'; @@ -36,6 +37,7 @@ declare class NodeControllerParams { } // 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 +// [Start control_reflect_node_container] class MyNodeController extends NodeController { private rootNode: BuilderNode<[Params]> | undefined | null; private embedId_: string = ''; @@ -102,7 +104,9 @@ class MyNodeController extends NodeController { return this.rootNode?.postTouchEvent(event) as boolean; } } +// [End control_reflect_node_container] +// [Start create_custom_module] @Component struct TextInputComponent { @Prop params: Params; @@ -132,6 +136,7 @@ function textInputBuilder(params:Params) { .height(params.height) .backgroundColor(Color.White) } +// [End create_custom_module] @Entry @Component @@ -145,6 +150,8 @@ struct Page{ @State positionMap: Map = new Map(); @State edges: Edges = {}; + // [Start listen_peer_renders_life_cycle] + // [Start peer_renders_gesture_event] build() { Row() { Column() { @@ -156,13 +163,16 @@ struct Page{ .height(this.heightMap.get(componentId)) }, (embedId: string) => embedId) // Web组件加载本地test2.html页面。 + // [Start register_object_label] Web({src: $rawfile('test2.html'), controller: this.browserTabController}) // 注册同层标签为'object',类型为'test'前缀 .registerNativeEmbedRule('object', 'test') + // [End register_object_label] // 配置同层渲染开关开启。 .enableNativeEmbedMode(true) // 获取embed标签的生命周期变化数据。 .onNativeEmbedLifecycleChange((embed) => { + // [StartExclude peer_renders_gesture_event] console.log('NativeEmbed surfaceId' + embed.surfaceId); // 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id const componentId = embed.info?.id?.toString() as string; @@ -213,7 +223,10 @@ struct Page{ } else { console.log('NativeEmbed status' + embed.status); } - })// 获取同层渲染组件触摸事件信息。 + // [EndExclude peer_renders_gesture_event] + }) + // [StartExclude listen_peer_renders_life_cycle] + // 获取同层渲染组件触摸事件信息。 .onNativeEmbedGestureEvent((touch) => { console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); this.componentIdArr.forEach((componentId: string) => { @@ -233,8 +246,12 @@ struct Page{ } }) }) + // [EndExclude listen_peer_renders_life_cycle] } } } } + // [End peer_renders_gesture_event] + // [End listen_peer_renders_life_cycle] } +// [End set_web_peer_render] diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 index 2c83e592f05cb9ca9a559f88072d1aa0994dc389..0755ae2a6bd487a8633c41d9f999e752842bdec1 100755 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 @@ -62,11 +62,13 @@ ] } ], + // [Start request_permissions] "requestPermissions":[ { "name" : "ohos.permission.INTERNET" } - ] + ], + // [End request_permissions] } } \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets index cea579ee8f92c9b5a23085e0ce5503c1382d2b84..a617ae7da17475cbf16787084698a355e6e17f2b 100644 --- a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets @@ -67,6 +67,7 @@ struct serialCommunication { }).height('40vp').width('70%') }.width('80%') + // [Start server_write_client] Button('listenSocket') .width('50%') .id('listenSocket') @@ -130,6 +131,7 @@ struct serialCommunication { } }) + // [Start socket_spp_connect] Button('connectDevice') .width('50%') .backgroundColor('#8CE072') @@ -156,6 +158,7 @@ struct serialCommunication { } }) + // [End socket_spp_connect] Button('writeData') .width('50%') @@ -251,9 +254,10 @@ struct serialCommunication { console.info(TAG, 'sppCloseClientSocket success'); this.toastReport.showResult('sppCloseClientSocket success'); }) + // [End server_write_client] } .width('100%') .height('100%') .backgroundColor('#E6F7FF') } -} \ No newline at end of file +} diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets index fc8b1e1d4bbbe74e6166bcf6340d8b91cd92a628..eeb5607a72dd59148f34fbd691dd5dc120e5350b 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_hce_swipe_ets] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -92,4 +93,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_hce_swipe_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 index 53fd0f2b1275fb7d8c81dc86c96d37504fd2eaa8..2cfceef20355988871217991d41ec936ddcfd544 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start front_hce_swipe] "abilities": [ { "name": "EntryAbility", @@ -59,6 +60,7 @@ "reason": "$string:app_name", } ], + // [End front_hce_swipe] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets index aa74877badfb699324f5477a5c4f9b77f3b0ddf7..5b05f8f9d3defa62694ab78ea5c5307adf1812de 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start back_hce_swipe_ets] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -82,4 +83,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [Start back_hce_swipe_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 index c6ada203f0ae8ef00a8695e418396459bf0c42d5..38684d0ac45a6f49987eb05e5d7a1827318f0e02 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_hce_swipe] "abilities": [ { "name": "Entry1Ability", @@ -67,6 +68,7 @@ "reason": "$string:app_name", } ], + // [End back_hce_swipe] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets index 7a39747af998d8dc03073665e467c4ed96d9371b..d244d203a7ac9748313094b307a1437a9d9963d5 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_get_nfc_tag_ets] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -131,4 +132,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_get_nfc_tag_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 index 36701bff5e4b7db3e40fd98912cc9669f79317d0..87decab6f7ac9bda49589578fa100e0cdafbdb89 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // {Start front_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -57,6 +58,7 @@ "reason": "$string:app_name", } ], + // [End front_get_nfc_tag] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets index 199867b3f18085135137566ba976baabcdca8cc9..6817624c7c39356c31ccca986b5e08a00aca232f 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start back_get_nfc_tag_ets] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -89,4 +90,5 @@ export default class EntryAbility extends UIAbility { return; } } -} \ No newline at end of file +} +// [End back_get_nfc_tag_ets] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 index 734f2658cb744d2fdfdca02c2672b0bf23469ec1..22892b5f3d62846171900494d250662792c59271 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -65,6 +66,7 @@ "reason": "$string:app_name", } ], + // [End back_get_nfc_tag] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets index 0a6a087ff5d5077714e4fe4888b39d202b356b33..a680111a4717a0a59153a21b5a944793178513f0 100644 --- a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start access_security_unit] import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -120,3 +121,4 @@ export default class EntryAbility extends UIAbility { } } +// [End access_security_unit] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets index 708757a74a1712f7b2421c58de005f5a01540213..d71da61e3784d8725ee5039d23ed59ee01b816e2 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_p2p_connect] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PConnectMananger { @@ -79,3 +80,4 @@ export class P2PConnectMananger { let p2pConnectManager = new P2PConnectMananger(); export default p2pConnectManager as P2PConnectMananger; +// [End create_p2p_connect] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets index 01c764fd88c4294b683043da62772251f15a0f05..d3c62deba090a1088bcb3cb05fcfbd7964cc776c 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_delete_p2p_group] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PManager { @@ -51,4 +52,5 @@ export class P2PManager { // 默认导出let let p2pManager = new P2PManager(); -export default p2pManager as P2PManager; \ No newline at end of file +export default p2pManager as P2PManager; +// [End create_delete_p2p_group] \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp index 5fd01b3fc62be76efd146091f68376fe5d396b4f..76129259f81a98a52365775ad320fe30c6e05ad7 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start crypt_decrypt_flow] #include "CryptoArchitectureKit/crypto_common.h" #include "CryptoArchitectureKit/crypto_sym_cipher.h" #include @@ -74,4 +75,5 @@ end: OH_Crypto_FreeDataBlob(&outUpdate); OH_Crypto_FreeDataBlob(&decUpdate); return ret; -} \ No newline at end of file +} +// [End crypt_decrypt_flow] \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets index b1dc75ede5e4648634c9d5cbeff4678ea76f98bd..d5e657a6a6e5b548b3944a0b0df334dce12efb22 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start async_symmetry_encrypt_decrypt] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -56,6 +57,7 @@ async function main() { console.error('decrypt failed'); } } +// [End async_symmetry_encrypt_decrypt] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets index c124ad89aedd445263347d5953b8cbd891f7c7fb..6e4f3404f746b7251b58447851f74a5200605400 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sync_symmetry_encrypt_decrypt] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -56,6 +57,7 @@ function main() { console.error('decrypt failed'); } } +// [End sync_symmetry_encrypt_decrypt] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp index 9ee7c83de4404a64949d958cb4662e6f458cb57e..366a53a790a7adedb74f93d0f6a00b0d6e9272e8 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp @@ -13,10 +13,13 @@ * limitations under the License. */ +// [Start crypt_decrypt_sm4_cbc] #include "CryptoArchitectureKit/crypto_common.h" #include "CryptoArchitectureKit/crypto_sym_cipher.h" #include +// [StartExclude crypt_decrypt_sm4_cbc] #include "file.h" +// [EndExclude crypt_decrypt_sm4_cbc] OH_Crypto_ErrCode doTestSm4Cbc() { @@ -91,3 +94,4 @@ end: OH_Crypto_FreeDataBlob(&decUpdate); return ret; } +// [End crypt_decrypt_sm4_cbc] diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp index 3d0b4f1ea3502a13c565bdff87ac362c836a5018..1031db9133388efa1e143d2183d2b5f21a0de592 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp @@ -13,10 +13,13 @@ * limitations under the License. */ +// [Start crypt_decrypt_sm4_ecb] #include "CryptoArchitectureKit/crypto_common.h" #include "CryptoArchitectureKit/crypto_sym_cipher.h" #include +// [StartExclude crypt_decrypt_sm4_ecb] #include "file.h" +// [EndExclude crypt_decrypt_sm4_ecb] OH_Crypto_ErrCode doTestSm4Ecb() { @@ -83,3 +86,4 @@ end: OH_Crypto_FreeDataBlob(&decUpdate); return ret; } +// [End crypt_decrypt_sm4_ecb] diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp index b3925630118f9e621793a816ca97a8b21ddc2bc5..1811c13a19524ff17c013dcea1189e1d002c7e9e 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp @@ -13,10 +13,13 @@ * limitations under the License. */ +// [Start crypt_decrypt_sm4_gcm] #include "CryptoArchitectureKit/crypto_common.h" #include "CryptoArchitectureKit/crypto_sym_cipher.h" #include +// [StartExclude crypt_decrypt_sm4_gcm] #include "file.h" +// [EndExclude crypt_decrypt_sm4_gcm] OH_Crypto_ErrCode doTestSm4Gcm() { @@ -114,3 +117,4 @@ end: OH_Crypto_FreeDataBlob(&tagOutPut); return ret; } +// [End crypt_decrypt_sm4_gcm] diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp index 882ae37606d2eec1be17caeab8dad06a3c8b5809..6635d2ab25aa3411733cc85636b68aaf4320f5db 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start crypt_decrypt_sm4_gcm_seg] #include #include "CryptoArchitectureKit/crypto_common.h" #include "CryptoArchitectureKit/crypto_sym_cipher.h" @@ -140,3 +141,4 @@ end: OH_Crypto_FreeDataBlob(&decUpdate); return ret; } +// [End crypt_decrypt_sm4_gcm_seg] diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets index aac7e1ebaeadc46467ac09702778f379924082a9..20fef92877bbea39749ab8e093467ed9b98428d2 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start async_symmetry_encrypt_decrypt_sm4_cbc] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -75,6 +76,7 @@ async function main() { console.error(`SM4 “${error}“, error code: ${error.code}`); } } +// [End async_symmetry_encrypt_decrypt_sm4_cbc] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets index fc8dc5499bdc3066c5f21a53862cf03d57469aae..4f2ba41c801f7437ff85950e2fd54d912455cc6a 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sync_symmetry_encrypt_decrypt_sm4_cbc] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -75,6 +76,7 @@ function main() { console.error(`SM4 “${error}“, error code: ${error.code}`); } } +// [End sync_symmetry_encrypt_decrypt_sm4_cbc] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets index a18ba8bda22d76a51559fb0abb4f5e19fd435132..3b24ee43ce4fa5228da66aba01411b1f2206630b 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start async_symmetry_encrypt_decrypt_sm4] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -54,6 +55,7 @@ async function main() { console.error('decrypt failed'); } } +// [End async_symmetry_encrypt_decrypt_sm4] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets index 5bdb7b760773fc23954490ecf1120b6b1945140e..912041ec509af6e2cfa2ce2c96f4b4132680768a 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sync_symmetry_encrypt_decrypt_sm4] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -54,6 +55,7 @@ function main() { console.error('decrypt failed'); } } +// [End sync_symmetry_encrypt_decrypt_sm4] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets index 3917f0a4e909f9d3fc5832e2abd21706e0fc4c98..fc6d4372cfc15c4b4c4642d6f23933f989605d37 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start async_symmetry_encrypt_decrypt_sm4_gcm] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -89,6 +90,7 @@ async function main() { console.error('decrypt failed'); } } +// [End async_symmetry_encrypt_decrypt_sm4_gcm] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets index f4809e31f33fa824cc8231177a79af547688ba45..06f7badc93d1e989d518fadb82b7d182c6070b43 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sync_symmetry_encrypt_decrypt_sm4_gcm] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -89,6 +90,7 @@ function main() { console.error('decrypt failed'); } } +// [End sync_symmetry_encrypt_decrypt_sm4_gcm] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets index 734538cfbd7c1dab5450cf717e9d1deefb1cda0a..32394d2e5369f28cb47569e3f2e2e77c50351634 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start async_symmetry_encrypt_decrypt_sm4_gcm_seg] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -113,6 +114,7 @@ async function sm4() { console.error('decrypt failed'); } } +// [End async_symmetry_encrypt_decrypt_sm4_gcm_seg] @Entry @Component diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets index edeb079d9f27acdb0dd1a4784aa19ab81daedd25..1b59b325c638ec9b7e7606c7a09e71df0234f790 100755 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start sync_symmetry_encrypt_decrypt_sm4_gcm_seg] import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { buffer } from '@kit.ArkTS'; @@ -113,6 +114,7 @@ function main() { console.error('decrypt failed'); } } +// [End sync_symmetry_encrypt_decrypt_sm4_gcm_seg] @Entry @Component diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets index 0c1f374b6e9cfd99f8274fa0fdf9f7be8e4421fa..bcba2b8db0f36d93056e5cad460cf48707182874 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_advertising] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ToastReport } from '../common/ToastReport'; @@ -179,4 +180,5 @@ export class BleAdvertisingManager { let bleAdvertisingManager = new BleAdvertisingManager(); -export default bleAdvertisingManager as BleAdvertisingManager; \ No newline at end of file +export default bleAdvertisingManager as BleAdvertisingManager; +// [End open_close_advertising] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets index b590b6a95ff5d30474ade362e5859db49bd8f78c..8aa2cecd90b87c3bae89f8d6fc682c9d145093e4 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_scan] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ScanData } from '../common/ScanData'; @@ -76,11 +77,13 @@ export class BleScanManager { if (data.length > 0) { console.info(TAG, 'BLE scan result = ' + data[0].deviceId); this.parseScanResult(data[0].data); + // [StartExclude open_close_scan] this.toastReport.showResult(data[0].deviceId); if (!this.scanDataList.some(item => item.getDeviceName() === data[0].deviceName)) { this.scanDataList.push(new ScanData(data[0].deviceId, data[0].deviceName, data[0].rssi, data[0].connectable, new Uint8Array(data[0].data))); } + // [EndExclude open_close_scan] } }); } @@ -232,6 +235,7 @@ export class BleScanManager { // manufactureData: manufactureData.buffer, manufactureDataMask: manufactureDataMask.buffer, }; + // [StartExclude open_close_scan] if (this.deviceName) { console.info('===lyk=== deviceName is not null ' + this.deviceName) scanFilter.name = this.deviceName; @@ -239,6 +243,8 @@ export class BleScanManager { if (this.deviceId) { scanFilter.deviceId = this.deviceId; } + // [EndExclude open_close_scan] + // 2.2 构造扫描参数 let scanOptions: ble.ScanOptions = { interval: this.interval, @@ -246,13 +252,19 @@ export class BleScanManager { matchMode: ble.MatchMode.MATCH_MODE_AGGRESSIVE, } try { + // [StartExclude open_close_scan] this.scanDataList = []; + // [EndExclude open_close_scan] this.onScanResult(); // 订阅扫描结果 ble.startBLEScan([scanFilter], scanOptions); + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'startBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -264,10 +276,14 @@ export class BleScanManager { console.info(TAG, 'off success'); }); ble.stopBLEScan(); + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'stopBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -276,3 +292,4 @@ export class BleScanManager { let bleScanManager = new BleScanManager(); export default bleScanManager as BleScanManager; +// [End open_close_scan] diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets index bb3829f54eaf2e3f55d52304f1224bd2a78772c2..5b10dd2adb8c4e4c2203f8d15408b98ee53e5e2e 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// [Start open_close_bluetooth] import { access } from '@kit.ConnectivityKit'; export class BluetoothSwitch { public openBluetooth() { + access.off('stateChange'); access.enableBluetooth(); access.on('stateChange', (data) => { @@ -52,7 +53,6 @@ export class BluetoothSwitch { } console.info('bluetooth statues: ' + btStateMessage); }); - } public closeBluetooth() { @@ -92,3 +92,4 @@ export class BluetoothSwitch { }); } } +// [End open_close_bluetooth] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets index f4eef513ec16857e6f4fac81b671e7b0d9a2770e..745998b1d900c8c1ac7fe3bd76253b7cadac20af 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start generic_attribute] import { ble } from '@kit.ConnectivityKit'; import { constant } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -20,7 +21,9 @@ import { ToastReport } from '../common/ToastReport'; import util from '@ohos.util'; const TAG: string = 'GattClientManager'; +// [StartExclude generic_attribute] let encoder = new util.TextEncoder(); +// [EndExclude generic_attribute] export class GattData { public serviceUuid: string = '00001810-0000-1000-8000-00805F9B34FB'; @@ -83,7 +86,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private logDescriptor(des: ble.BLEDescriptor) { @@ -94,7 +99,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private checkService(services: Array): boolean { @@ -179,10 +186,14 @@ export class GattClientManager { try { this.onGattClientStateChange(); // 2.2 订阅连接状态 this.gattClient.connect(); // 2.3 发起连接 + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect success'); console.info(TAG, 'startConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -197,12 +208,16 @@ export class GattClientManager { try { await this.gattClient.getServices().then((result: Array) => { console.info(TAG, 'getServices success: ' + JSON.stringify(result)); + // [StartExclude generic_attribute] this.serviceResult = JSON.stringify(result); this.toastReport.showResult('getServices success: ' + JSON.stringify(result)); + // [EndExclude generic_attribute] this.found = this.checkService(result); // 要确保server端的服务内容有业务所需要的服务 }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('getServices fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -211,12 +226,16 @@ export class GattClientManager { public readCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -226,9 +245,13 @@ export class GattClientManager { this.gattClient.readCharacteristicValue(characteristic).then((outData: ble.BLECharacteristic) => { this.logCharacteristic(outData); }) + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -237,12 +260,16 @@ export class GattClientManager { public writeCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -255,12 +282,16 @@ export class GattClientManager { 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); return; } + // [StartExclude generic_attribute] this.toastReport.showResult('writeCharacteristicValue success'); + // [EndExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue success'); }); } catch (err) { + // [StartExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue fail'); this.toastReport.showResult('writeCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -269,12 +300,16 @@ export class GattClientManager { public readDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -285,9 +320,13 @@ export class GattClientManager { this.gattClient.readDescriptorValue(descriptor).then((outData: ble.BLEDescriptor) => { this.logDescriptor(outData); }); + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -296,12 +335,16 @@ export class GattClientManager { public writeDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -319,10 +362,14 @@ export class GattClientManager { return; } console.info(TAG, 'writeDescriptorValue success'); + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue success'); + // [EndExclude generic_attribute] }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -340,9 +387,13 @@ export class GattClientManager { this.gattClient.off('BLEConnectionStateChange', (stateInfo: ble.BLEConnectionChangeState) => { }); this.gattClient.close() // 8.2 如果不再使用此gattClient,则需要close + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -350,4 +401,5 @@ export class GattClientManager { let gattClientManager = new GattClientManager(); -export default gattClientManager as GattClientManager; \ No newline at end of file +export default gattClientManager as GattClientManager; +// [End generic_attribute] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets index 89570dc8815ec20cc1a728b2898e6cd6d68b08ac..aa38c2fb43a87c6f629c9894e4e3283cdc51546e 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattServerManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start gatt_server_manage] import { ble } from '@kit.ConnectivityKit'; import { constant } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -292,4 +293,5 @@ export class GattServerManager { let gattServerManager = new GattServerManager(); -export default gattServerManager as GattServerManager; \ No newline at end of file +export default gattServerManager as GattServerManager; +// [End gatt_server_manage] \ No newline at end of file