diff --git a/README.en.md b/README.en.md
index 18ad8143d0a1ffd48adfa6c30d3026a1ba96f86a..d9aaa6d875f9b53452c657a0d9d76e860697fee4 100644
--- a/README.en.md
+++ b/README.en.md
@@ -1,10 +1,10 @@
-# Simple Native C++ Examples
+# Implements the function of invoking the C standard library using NAPI
### Introduction
This codelab describes how to use DevEco Studio to create a native C++ app and call the C standard library to calculate the square root of the sum of squares of two given numbers. The following figure shows the effect.
-
+
### Concepts
@@ -23,5 +23,5 @@ N/A
1. The sample is only supported on Huawei phones with standard systems.
2. HarmonyOS: HarmonyOS 5.0.5 Release or later.
-3. DevEco Studio: DevEco Studio 5.0.5 Release or later.
-4. HarmonyOS SDK: HarmonyOS 5.0.5 Release SDK or later.
+3. DevEco Studio: DevEco Studio 6.0.0 Release or later.
+4. HarmonyOS SDK: HarmonyOS 6.0.0 Release SDK or later.
diff --git a/README.md b/README.md
index 00d49d0b7978a45b8842e6f173d788cc92b684d1..6232763584d0a373f70b3f7f37b2e32e98efa044 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-# 简易Native C++ 示例
+# 实现使用NAPI调用C标准库的功能
### 简介
本篇Codelab介绍如何使用DevEco Studio创建一个Native C++应用,调用C标准库实现计算两个给定数平方和的平方根。界面效果如图所示:
-
+
### 相关概念
@@ -23,5 +23,5 @@
1. 本示例仅支持标准系统上运行,支持设备:华为手机。
2. HarmonyOS系统:HarmonyOS 5.0.5 Release及以上。
-3. DevEco Studio版本:DevEco Studio 5.0.5 Release及以上。
-4. HarmonyOS SDK版本:HarmonyOS 5.0.5 Release SDK及以上。
+3. DevEco Studio版本:DevEco Studio 6.0.0 Release及以上。
+4. HarmonyOS SDK版本:HarmonyOS 6.0.0 Release SDK及以上。
diff --git a/build-profile.json5 b/build-profile.json5
index 69cf13d77e884ca9452a4542f84e6475705b0474..e3d08e8c0605a9fb38009bc1c6de13fe99f6e2fe 100644
--- a/build-profile.json5
+++ b/build-profile.json5
@@ -6,7 +6,7 @@
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.5(17)",
- "targetSdkVersion": "5.0.5(17)",
+ "targetSdkVersion": "6.0.0(20)",
"runtimeOS": "HarmonyOS"
}
]
diff --git a/entry/src/main/cpp/CMakeLists.txt b/entry/src/main/cpp/CMakeLists.txt
index 4baef5757089601e22a9cd4a55d68e3e1a0cd9b9..0ef65b90fe0fb45e154b9211f34f1c67af7031dd 100644
--- a/entry/src/main/cpp/CMakeLists.txt
+++ b/entry/src/main/cpp/CMakeLists.txt
@@ -1,5 +1,5 @@
# Declare the minimum CMake version number.
-cmake_minimum_required(VERSION 3.4.1)
+cmake_minimum_required(VERSION 3.5.0)
# Configure project information
project(NativeTemplateDemo)
diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets
index 8bab2c5b48b49b4ce5abaa3d12a0543eb0fb5390..6e84d336f5f2295461b18234b49026b6b9da6ee1 100644
--- a/entry/src/main/ets/entryability/EntryAbility.ets
+++ b/entry/src/main/ets/entryability/EntryAbility.ets
@@ -16,41 +16,70 @@
import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
+import { BusinessError } from '@kit.BasicServicesKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onCreate');
}
onDestroy() {
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
-
- windowStage.loadContent('pages/Index', (err, data) => {
- if (err.code) {
- hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
- return;
- }
- hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
- });
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onWindowStageCreate');
+
+ try {
+ windowStage.getMainWindow((err: BusinessError, windowClass) => {
+ if (err.code) {
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'getMainWindow failed');
+ return;
+ }
+ windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => {
+ hilog.error(0x0000, 'EntryAbility',
+ `setWindowLayoutFullScreen failed. code=${err.code}, message=${err.message}`);
+ })
+
+ let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR;
+ let avoidArea = windowClass.getWindowAvoidArea(type);
+ let bottomRectHeight = avoidArea.bottomRect.height;
+ AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
+
+ type = window.AvoidAreaType.TYPE_SYSTEM;
+ avoidArea = windowClass.getWindowAvoidArea(type);
+ let topRectHeight = avoidArea.topRect.height;
+ AppStorage.setOrCreate('topRectHeight', topRectHeight);
+ })
+
+ windowStage.loadContent('pages/Index', (err, data) => {
+ if (err.code) {
+ hilog.error(0x0000, 'EntryAbility', 'Failed to load the content. Cause: %{public}s',
+ JSON.stringify(err) ?? '');
+ return;
+ }
+ hilog.info(0x0000, 'EntryAbility', 'Succeeded in loading the content. Data: %{public}s',
+ JSON.stringify(data) ?? '');
+ });
+ } catch (error) {
+ let err = error as BusinessError;
+ hilog.error(0x0000, 'EntryAbility', `onWindowStageCreate failed. code=${err.code}, message=${err.message}`);
+ }
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
+ hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onBackground');
}
};
\ No newline at end of file
diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets
index 04e37593ef5e3990fbd3dccde8c144b88d702083..305303524f78843f15782b3303c87b14c5fd17c6 100644
--- a/entry/src/main/ets/pages/Index.ets
+++ b/entry/src/main/ets/pages/Index.ets
@@ -19,6 +19,8 @@ import CommonContants from '../../common/CommonContants';
@Entry
@Component
struct NativeTemplate {
+ @StorageLink('topRectHeight') topRectHeight: number = 0;
+ @StorageLink('bottomRectHeight') bottomRectHeight: number = 0;
@State result: string = '0';
@State numX: number = 0.0;
@State numY: number = 0.0;
@@ -43,6 +45,7 @@ struct NativeTemplate {
right: $r('app.float.text_padding_left'),
top: $r('app.float.text_padding_top')
})
+
Row() {
Text($r('app.string.message'))
.fontSize($r('app.float.message_font_size'))
@@ -59,6 +62,7 @@ struct NativeTemplate {
.padding({ left: $r('app.float.text_padding_left'), right: $r('app.float.text_padding_left') })
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Bottom)
+
Column() {
Row() {
Text($r('app.string.result_tip'))
@@ -74,6 +78,7 @@ struct NativeTemplate {
bottom: $r('app.float.tips_result_padding_bottom'),
right: $r('app.float.tips_result_padding_right')
})
+
Row() {
Text(this.result)
.textAlign(TextAlign.End)
@@ -87,6 +92,7 @@ struct NativeTemplate {
.padding({ right: $r('app.float.result_padding_right') })
.width(CommonContants.FULL_PARENT)
.justifyContent(FlexAlign.End)
+
Row() {
Text($r('app.string.input_x_value'))
.fontColor(Color.Black)
@@ -106,6 +112,7 @@ struct NativeTemplate {
.padding({ left: $r('app.float.text_input_padding'), right: $r('app.float.text_input_padding') })
.width(CommonContants.FULL_PARENT)
.justifyContent(FlexAlign.Start)
+
Row() {
Text($r('app.string.input_y_value'))
.fontColor(Color.Black)
@@ -130,6 +137,7 @@ struct NativeTemplate {
.borderRadius($r('app.float.function_area_border_radius'))
.height($r('app.float.function_area_height'))
.backgroundColor(Color.White)
+
Row() {
Button($r('app.string.submit_button'))
.fontSize($r('app.float.submit_button_font_size'))
@@ -153,5 +161,9 @@ struct NativeTemplate {
.width(CommonContants.FULL_PARENT)
.height(CommonContants.FULL_PARENT)
.backgroundColor($r('app.color.background_color'))
+ .padding({
+ top: this.topRectHeight,
+ bottom: this.bottomRectHeight
+ })
}
}
\ No newline at end of file
diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5
index f70ecd4112d94f9aa555adf898d53f18bf58f3e9..03377a956ba7a27d9afab0e284166613e7999fcb 100644
--- a/hvigor/hvigor-config.json5
+++ b/hvigor/hvigor-config.json5
@@ -1,5 +1,5 @@
{
- "modelVersion": "5.0.0",
+ "modelVersion": "6.0.0",
"dependencies": {
}
}
\ No newline at end of file
diff --git a/oh-package.json5 b/oh-package.json5
index 71b6703fcf39abde9f7e89f28cb9ae08bd99dd66..a365d7816c8b699c6c44345820233eb71d38283a 100644
--- a/oh-package.json5
+++ b/oh-package.json5
@@ -1,5 +1,5 @@
{
- "modelVersion": "5.0.0",
+ "modelVersion": "6.0.0",
"license": "",
"devDependencies": {
},
diff --git a/screenshots/device/native_template.en.gif b/screenshots/device/native_template.en.gif
deleted file mode 100644
index 5cbeade049ff0c18a01e948fa27af9627f98a7a5..0000000000000000000000000000000000000000
Binary files a/screenshots/device/native_template.en.gif and /dev/null differ
diff --git a/screenshots/device/native_template.en.png b/screenshots/device/native_template.en.png
new file mode 100644
index 0000000000000000000000000000000000000000..9a9bc7f6ccacf939a58a53edac768b1da1370ab4
Binary files /dev/null and b/screenshots/device/native_template.en.png differ
diff --git a/screenshots/device/native_template.gif b/screenshots/device/native_template.gif
deleted file mode 100644
index fa6c5c7d4a8d61cfb00f297e4a3b61b3b6e2451d..0000000000000000000000000000000000000000
Binary files a/screenshots/device/native_template.gif and /dev/null differ
diff --git a/screenshots/device/native_template.png b/screenshots/device/native_template.png
new file mode 100644
index 0000000000000000000000000000000000000000..00b4b6f399ff846ae9e9d7f5156ff288af494633
Binary files /dev/null and b/screenshots/device/native_template.png differ