From 417fd70a3409840b16ee1232b62cd290e17d763e Mon Sep 17 00:00:00 2001 From: lloyd <754415+llince@user.noreply.gitee.com> Date: Mon, 16 Sep 2024 11:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Native=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E3=80=91=E9=80=82=E9=85=8D=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 208 +++++++++--------- .../main/resources/base/element/float.json | 4 + .../main/resources/base/element/string.json | 2 +- .../main/resources/en_US/element/string.json | 2 +- 4 files changed, 107 insertions(+), 109 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index b3ffbda..1f99c8a 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -24,122 +24,116 @@ struct Index { imageName: string = ''; build() { - Column() { - // display the sample title - Row() { - Text($r('app.string.sample_title')) - .fontSize($r('app.float.title_text_font_size')) - .fontWeight(FontWeight.Bold) - } - .height($r('app.float.title_area_height')) - .width(Constants.FULL_PARENT) - .padding({ left: $r('app.float.title_area_left_padding') }) - - // show the initial image - Row() { - Image(this.imagePath) - .borderRadius($r('app.float.image_border_radius')) - .backgroundColor(Color.White) - .onError(() => { - hilog.info(0x0000, 'testTag', 'load imagePath fail: %{public}s.', this.imagePath); - // when the target image is not found (path loading fails), a warning dialog box is displayed. - AlertDialog.show({ - title: $r('app.string.image_error_dialog_title'), - message: $r('app.string.image_error_dialog_message'), - autoCancel: true, - alignment: DialogAlignment.Bottom, - offset: { dx: $r('app.float.error_dialog_offset_dx'), dy: $r('app.float.error_dialog_offset_dy') }, - primaryButton: { - value: $r('app.string.error_dialog_primary_button'), - action: () => { - hilog.info(0x0000, 'testTag', 'dialog click cancel.'); - } - }, - secondaryButton: { - value: $r('app.string.error_dialog_secondary_button'), - action: () => { - hilog.info(0x0000, 'testTag', 'dialog click confirm.'); + Navigation() { + Column() { + // show the initial image + Row() { + Image(this.imagePath) + .borderRadius($r('app.float.image_border_radius')) + .backgroundColor(Color.White) + .onError(() => { + hilog.info(0x0000, 'testTag', 'load imagePath fail: %{public}s.', this.imagePath); + // when the target image is not found (path loading fails), a warning dialog box is displayed. + AlertDialog.show({ + title: $r('app.string.image_error_dialog_title'), + message: $r('app.string.image_error_dialog_message'), + autoCancel: true, + alignment: DialogAlignment.Bottom, + offset: { dx: $r('app.float.error_dialog_offset_dx'), dy: $r('app.float.error_dialog_offset_dy') }, + primaryButton: { + value: $r('app.string.error_dialog_primary_button'), + action: () => { + hilog.info(0x0000, 'testTag', 'dialog click cancel.'); + } + }, + secondaryButton: { + value: $r('app.string.error_dialog_secondary_button'), + action: () => { + hilog.info(0x0000, 'testTag', 'dialog click confirm.'); + } } - } + }) }) - }) - } - .height($r('app.float.image_area_height')) - .width(Constants.FULL_PARENT) - .padding({ left: $r('app.float.image_area_left_padding'), right: $r('app.float.image_area_right_padding') }) + } + .height($r('app.float.image_area_height')) + .width(Constants.FULL_PARENT) + .padding({ left: $r('app.float.image_area_left_padding'), right: $r('app.float.image_area_right_padding') }) - // button list, prompting the user to click the button to select the target image. - Column() { - // multi-threads sync call button - Button($r('app.string.sync_button_title')) - .width(Constants.FULL_PARENT) - .margin($r('app.float.button_common_margin')) - .onClick(() => { - this.imageName = Constants.SYNC_BUTTON_IMAGE; - this.imagePath = Constants.IMAGE_ROOT_PATH + testNapi.getImagePathSync(this.imageName); - hilog.info(0x0000, 'testTag', 'sync operate imagePath: %{public}s', this.imagePath); - }) + // button list, prompting the user to click the button to select the target image. + Column() { + // multi-threads sync call button + Button($r('app.string.sync_button_title')) + .width(Constants.FULL_PARENT) + .margin($r('app.float.button_common_margin')) + .onClick(() => { + this.imageName = Constants.SYNC_BUTTON_IMAGE; + this.imagePath = Constants.IMAGE_ROOT_PATH + testNapi.getImagePathSync(this.imageName); + hilog.info(0x0000, 'testTag', 'sync operate imagePath: %{public}s', this.imagePath); + }) - // multi-threads callback async button - Button($r('app.string.async_callback_button_title')) - .width(Constants.FULL_PARENT) - .margin($r('app.float.button_common_margin')) - .onClick(() => { - this.imageName = Constants.CALLBACK_BUTTON_IMAGE; - testNapi.getImagePathAsyncCallBack(this.imageName, (result: string) => { - this.imagePath = Constants.IMAGE_ROOT_PATH + result; - hilog.info(0x0000, 'testTag', 'async callback operate imagePath: %{public}s', this.imagePath); - }); - }) + // multi-threads callback async button + Button($r('app.string.async_callback_button_title')) + .width(Constants.FULL_PARENT) + .margin($r('app.float.button_common_margin')) + .onClick(() => { + this.imageName = Constants.CALLBACK_BUTTON_IMAGE; + testNapi.getImagePathAsyncCallBack(this.imageName, (result: string) => { + this.imagePath = Constants.IMAGE_ROOT_PATH + result; + hilog.info(0x0000, 'testTag', 'async callback operate imagePath: %{public}s', this.imagePath); + }); + }) - // multi-threads promise async button - Button($r('app.string.async_promise_button_title')) - .width(Constants.FULL_PARENT) - .margin($r('app.float.button_common_margin')) - .onClick(() => { - this.imageName = Constants.PROMISE_BUTTON_IMAGE; - let promiseObj = testNapi.getImagePathAsyncPromise(this.imageName); - promiseObj.then((result: string) => { - this.imagePath = Constants.IMAGE_ROOT_PATH + result; - hilog.info(0x0000, 'testTag', 'async promise operate imagePath: %{public}s', this.imagePath); + // multi-threads promise async button + Button($r('app.string.async_promise_button_title')) + .width(Constants.FULL_PARENT) + .margin($r('app.float.button_common_margin')) + .onClick(() => { + this.imageName = Constants.PROMISE_BUTTON_IMAGE; + let promiseObj = testNapi.getImagePathAsyncPromise(this.imageName); + promiseObj.then((result: string) => { + this.imagePath = Constants.IMAGE_ROOT_PATH + result; + hilog.info(0x0000, 'testTag', 'async promise operate imagePath: %{public}s', this.imagePath); + }) }) - }) - // multi-threads tsf async button - Button($r('app.string.async_tsf_button_title')) - .width(Constants.FULL_PARENT) - .margin($r('app.float.button_common_margin')) - .onClick(() => { - this.imageName = Constants.TSF_BUTTON_IMAGE; - testNapi.getImagePathAsyncTSF(this.imageName, (result: string) => { - this.imagePath = Constants.IMAGE_ROOT_PATH + result; - hilog.info(0x0000, 'testTag', 'async thread_safe_func operate imagePath: %{public}s', this.imagePath); - }); - }) + // multi-threads tsf async button + Button($r('app.string.async_tsf_button_title')) + .width(Constants.FULL_PARENT) + .margin($r('app.float.button_common_margin')) + .onClick(() => { + this.imageName = Constants.TSF_BUTTON_IMAGE; + testNapi.getImagePathAsyncTSF(this.imageName, (result: string) => { + this.imagePath = Constants.IMAGE_ROOT_PATH + result; + hilog.info(0x0000, 'testTag', 'async thread_safe_func operate imagePath: %{public}s', this.imagePath); + }); + }) - // error image button - Button($r('app.string.error_image_button_title')) - .width(Constants.FULL_PARENT) - .margin($r('app.float.button_common_margin')) - .onClick(() => { - this.imageName = Constants.ERROR_BUTTON_IMAGE; - this.imagePath = Constants.IMAGE_ROOT_PATH + testNapi.getImagePathSync(this.imageName); - hilog.info(0x0000, 'testTag', 'error operate imagePath: %{public}s', this.imagePath); - }) + // error image button + Button($r('app.string.error_image_button_title')) + .width(Constants.FULL_PARENT) + .margin($r('app.float.button_common_margin')) + .onClick(() => { + this.imageName = Constants.ERROR_BUTTON_IMAGE; + this.imagePath = Constants.IMAGE_ROOT_PATH + testNapi.getImagePathSync(this.imageName); + hilog.info(0x0000, 'testTag', 'error operate imagePath: %{public}s', this.imagePath); + }) + } + .width(Constants.FULL_PARENT) + .justifyContent(FlexAlign.End) + .layoutWeight(Constants.BUTTON_AREA_LAYOUT_WEIGHT) + .padding( + { + bottom: $r('app.float.button_area_bottom_padding'), + left: $r('app.float.button_area_left_padding'), + right: $r('app.float.button_area_right_padding') + } + ) } .width(Constants.FULL_PARENT) - .justifyContent(FlexAlign.End) - .layoutWeight(Constants.BUTTON_AREA_LAYOUT_WEIGHT) - .padding( - { - bottom: $r('app.float.button_area_bottom_padding'), - left: $r('app.float.button_area_left_padding'), - right: $r('app.float.button_area_right_padding') - } - ) + .height(Constants.FULL_PARENT) + .margin({ top: $r('app.float.image_margin_top') }) } - .width(Constants.FULL_PARENT) - .height(Constants.FULL_PARENT) - .backgroundColor($r('app.color.root_background_color')); + .title($r('app.string.sample_title')) + .backgroundColor($r('app.color.root_background_color')) } -} +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json index b607899..f01ca3c 100644 --- a/entry/src/main/resources/base/element/float.json +++ b/entry/src/main/resources/base/element/float.json @@ -51,6 +51,10 @@ { "name": "button_area_bottom_padding", "value": "18vp" + }, + { + "name": "image_margin_top", + "value": "16vp" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 648320f..210d32c 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -14,7 +14,7 @@ }, { "name": "sample_title", - "value": "Native MultiThreads Sample" + "value": "Native MultiThreads" }, { "name": "image_error_dialog_title", diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 648320f..210d32c 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -14,7 +14,7 @@ }, { "name": "sample_title", - "value": "Native MultiThreads Sample" + "value": "Native MultiThreads" }, { "name": "image_error_dialog_title", -- Gitee