From fce2fe6acc520b8fb559e1aa6f50ac683c01aa23 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Thu, 15 May 2025 19:55:12 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20ArkUI=20=E6=A0=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 4 +- .../EntryAbilityExtactScreenAdaption.ets | 71 +++++++++++ .../EntryAbilityGetWindowStageInstance.ets | 44 +++++++ .../EntryAbilityScreenRotation.ets | 67 ++++++++++ .../EntryAbilitySetWindowPrivacy.ets | 87 +++++++++++++ .../EntryAbilityStatusBarOverlayOne.ets | 74 +++++++++++ .../EntryAbilityStatusBarOverlayTwo.ets | 80 ++++++++++++ .../main/ets/pages/AddComponentInTabbar.ets | 4 +- .../src/main/ets/pages/AvoidAreaHeight.ets | 4 +- .../src/main/ets/pages/BottomNavBarHeight.ets | 4 +- .../pages/BottomPopsUpAsTheTopOfKeyboard.ets | 4 +- .../src/main/ets/pages/BottomSlideAndOut.ets | 4 +- .../ets/pages/ControlLevelOfCustomDialog.ets | 4 +- .../pages/CopyContentDirectlyClipboard.ets | 4 +- .../ets/pages/CustomDialogVariableToPage.ets | 98 +-------------- .../CustomDialogVariableToPageSecond.ets | 68 ++++++++++ .../pages/CustomDialogVariableToPageThird.ets | 62 +++++++++ .../ets/pages/ExcavationScreenAdaptation.ets | 25 +--- .../entry/src/main/ets/pages/FontSetting.ets | 6 +- .../ets/pages/FullNavigationSubcomponent.ets | 4 +- .../src/main/ets/pages/GetAppInformation.ets | 20 +-- .../ets/pages/GetAppInformationWithBundle.ets | 30 +++++ .../ets/pages/GetComponentRenderingTime.ets | 4 +- .../pages/GetCoordinatesFromTouchPoint.ets | 4 +- .../main/ets/pages/GetDarkModeColorSync.ets | 13 +- .../GetHorizontalAndVerticalScreenStatus.ets | 39 +----- ...lAndVerticalScreenStatusWindowRotation.ets | 53 ++++++++ .../src/main/ets/pages/GetRouterBackParam.ets | 7 +- .../entry/src/main/ets/pages/GetTextWidth.ets | 4 +- .../pages/GetWindowStageInstanceInPage.ets | 30 +---- .../ets/pages/HandleDrawNineMapPrinciple.ets | 32 +++++ ...HandleDrawNinePatchReplacementRegimen.ets} | 19 +-- .../pages/ImageCanNotUseBindContextMenu.ets | 4 +- .../main/ets/pages/InertialSlidingEffect.ets | 4 +- .../ets/pages/ListFoldAnimationEffect.ets | 4 +- .../ets/pages/ListenForScreenRotation.ets | 4 +- .../src/main/ets/pages/PrivacyDetailsPage.ets | 8 +- .../main/ets/pages/ReplaceDefaultTimeSet.ets | 6 +- .../src/main/ets/pages/ResourceNesting.ets | 4 +- .../src/main/ets/pages/ScreenRotation.ets | 8 +- .../pages/ScreenorizontalVerticalStatus.ets | 4 +- .../ets/pages/SetClickEventInCustomspan.ets | 4 +- .../main/ets/pages/SetOffsetInBindPopup.ets | 4 +- .../ets/pages/SetWindowPrivacyModeInPage.ets | 87 +------------ ...etWindowPrivacyModeRequestPermission.json5 | 26 ++++ .../ets/pages/SettingScreenBrightness.ets | 8 +- ArkUI/entry/src/main/ets/pages/SharePopup.ets | 17 +-- .../ets/pages/SideSlipEventInterception.ets | 4 +- .../main/ets/pages/SimilarKeyFramesEffect.ets | 4 +- .../ets/pages/StatusbarAndPageOverlap.ets | 119 +----------------- .../StatusbarAndPageOverlapAvoidStatusBar.ets | 79 ++++++++++++ .../main/ets/pages/SwipeActionToNotSlide.ets | 4 +- .../TextExpansionAndCollapseFunctions.ets | 4 +- .../ets/pages/TextSetMaxlinesIsHideText.ets | 4 +- .../src/main/ets/pages/TheHeaderTruncated.ets | 4 +- .../src/main/ets/pages/ToggleWithDelay.ets | 4 +- .../src/main/ets/pages/WindowProperties.ets | 4 +- .../main/resources/base/element/color.json | 4 + .../src/main/resources/rawfile/index.html | 14 +++ 59 files changed, 899 insertions(+), 514 deletions(-) create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityGetWindowStageInstance.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityScreenRotation.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets create mode 100644 ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets create mode 100644 ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageSecond.ets create mode 100644 ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageThird.ets create mode 100644 ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets create mode 100644 ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets create mode 100644 ArkUI/entry/src/main/ets/pages/HandleDrawNineMapPrinciple.ets rename ArkUI/entry/src/main/ets/pages/{HandleDraw9PatchReplacementRegimen.ets => HandleDrawNinePatchReplacementRegimen.ets} (86%) create mode 100644 ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeRequestPermission.json5 create mode 100644 ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets create mode 100644 ArkUI/entry/src/main/resources/rawfile/index.html diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbility.ets index 508880a..a42f8ab 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbility.ets @@ -17,13 +17,15 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - + AppStorage.setOrCreate('windowStage',windowStage); windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); return; } hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + const context = windowStage.getMainWindowSync().getUIContext(); + AppStorage.setOrCreate("context", context); }); } diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets new file mode 100644 index 0000000..2d056d4 --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何完成挖孔屏的适配 +*/ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + // [Start extract_screen_adaption] + onWindowStageCreate(windowStage: window.WindowStage): void { + AppStorage.setOrCreate('context', windowStage); + windowStage.getMainWindow((err: BusinessError, data) => { + let errCode: number = err.code; + // 设置窗口为全屏显示状态 + data.setWindowLayoutFullScreen(true); + // 设置顶部状态栏为隐藏状态 + let names: Array<'status' | 'navigation'> = []; + data.setWindowSystemBarEnable(names, (err: BusinessError) => { + if (err.code) { + console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the system bar to be visible.'); + }); + }) + // ... + } + // [End extract_screen_adaption] + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityGetWindowStageInstance.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityGetWindowStageInstance.ets new file mode 100644 index 0000000..0174fe1 --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityGetWindowStageInstance.ets @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何在Page中获取WindowStage实例 +*/ + +// [Start entry_ability_get_window_stage_instance] +import { UIAbility } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + // ... + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + 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.'); + }); + console.info('windowStage+++', JSON.stringify(windowStage)) + AppStorage.setAndLink('windowStage', windowStage) + } + + // ... +} +// [End entry_ability_get_window_stage_instance] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityScreenRotation.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityScreenRotation.ets new file mode 100644 index 0000000..4fffe23 --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityScreenRotation.ets @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何设置窗口旋转 +*/ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + // [Start window_rotation] + AppStorage.setOrCreate('windowStage',windowStage); + // [End window_rotation] + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + const context = windowStage.getMainWindowSync().getUIContext(); + AppStorage.setOrCreate("context", context); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets new file mode 100644 index 0000000..8e63014 --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现防截屏功能 +*/ + +// [Start set_window_privacy_mode] +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } 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): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + // 获取主窗口 + windowStage.getMainWindow((err: BusinessError, data) => { + let errCode: number = err.code; + if (errCode) { + console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + let windowClass: window.Window = data; + console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + // 设置窗口隐私模式 + let isPrivacyMode: boolean = true; + try { + windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the window to privacy mode.'); + }); + } catch (exception) { + console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); + } + }) + 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) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} +// [End set_window_privacy_mode] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets new file mode 100644 index 0000000..9e816ef --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:状态栏与页面内容发生重叠,如何解决 +*/ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + // [Start store_window_class] + // EntryAbility.ets + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/ImagePreview', (err) => { + 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.'); + + let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 + // 1. 设置窗口全屏 + let isLayoutFullScreen = true; + windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); + // 2. 缓存window窗口对象 + AppStorage.setOrCreate('windowClass', windowClass); + }); + } + // [End store_window_class] + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets new file mode 100644 index 0000000..7fbef4d --- /dev/null +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:状态栏与页面内容发生重叠,如何解决 +*/ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + // [Start get_window_avoid_area] + // EntryAbility.ets + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/AvoidStatusBar', (err) => { + 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.'); + + let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 + // 1. 设置窗口全屏 + let isLayoutFullScreen = true; + windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); + // 2. 缓存window窗口对象 + AppStorage.setOrCreate('windowClass', windowClass); + + // 3. 获取布局避让遮挡的区域 + let type = window.AvoidAreaType.TYPE_SYSTEM; + let avoidArea = windowClass.getWindowAvoidArea(type); + let statusBar = windowClass.getUIContext().px2vp( avoidArea.topRect.height); // 获取状态栏的高度 + AppStorage.setOrCreate('statusBar', statusBar); + }); + } + // [End get_window_avoid_area] + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets b/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets index 530f370..a818aa5 100644 --- a/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets +++ b/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets @@ -17,7 +17,7 @@ * FAQ:如何在Tabs的tabBar中添加其他组件 */ -// DocsCode 1 +// [Start tabs_demo] import { componentUtils } from '@kit.ArkUI'; @Entry @@ -194,4 +194,4 @@ struct TabsDemo { }) } } -// DocsCode 1 \ No newline at end of file +// [End tabs_demo] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets b/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets index 5e5b733..90befb4 100644 --- a/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets +++ b/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets @@ -17,7 +17,7 @@ * FAQ:如何获取屏幕顶部状态栏、底部导航栏和导航条的高度 */ -// DocsCode 1 +// [Start get_avoid_area_height] import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -53,4 +53,4 @@ struct GetAvoidAreaHeight { } } } -// DocsCode 1 \ No newline at end of file +// [End get_avoid_area_height] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets b/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets index 802349b..a609d9b 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets @@ -17,7 +17,7 @@ * FAQ:如何获取底部手势横条的高度 */ -// DocsCode 1 +// [Start get_bottom_nav_bar_height] import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -44,4 +44,4 @@ struct GetBottomNavBarHeight { } } } -// DocsCode 1 \ No newline at end of file +// [End get_bottom_nav_bar_height] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets b/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets index 3e51055..f983212 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets @@ -17,7 +17,7 @@ * FAQ:输入框拉起键盘时,如何将底部布局弹起到键盘顶部 */ -// DocsCode 1 +// [Start bottom_pops_up_as_the_top_of_keyboard] import { window } from '@kit.ArkUI'; @Entry @@ -95,4 +95,4 @@ struct BottomPopsUpAsTheTopOfKeyboard { .backgroundColor(0xDCDCDC) } } -// DocsCode 1 \ No newline at end of file +// [End bottom_pops_up_as_the_top_of_keyboard] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets b/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets index dffdc8b..78607f9 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets @@ -17,7 +17,7 @@ * FAQ:自定义组件间如何实现从底部滑入滑出的效果 */ -// DocsCode 1 +// [Start component_transition] @Entry @Component struct ComponentTransition { @@ -72,4 +72,4 @@ struct ComponentChild2 { } } } -// DocsCode 1 \ No newline at end of file +// [End component_transition] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets b/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets index fb27722..7ac984c 100644 --- a/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets +++ b/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets @@ -17,7 +17,7 @@ * FAQ:如何控制CustomDialog显示层级 */ -// DocsCode 1 +// [Start custom_dialog_display_level] @Component struct Test1 { @State message: string = 'Hello World'; @@ -173,4 +173,4 @@ struct CustomDialogDisplayLevel { .navDestination(this.pageMap) } } -// DocsCode 1 \ No newline at end of file +// [End custom_dialog_display_level] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets b/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets index 35d966b..7cb31c4 100644 --- a/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets +++ b/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets @@ -17,7 +17,7 @@ * FAQ:如何将内容直接复制到剪贴板 */ -// DocsCode 1 +// [Start copy_text] import { pasteboard } from '@kit.BasicServicesKit'; @Entry @@ -62,4 +62,4 @@ function copyText(text: string) { } }) } -// DocsCode 1 \ No newline at end of file +// [End copy_text] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPage.ets b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPage.ets index 15cc7de..4b8af93 100644 --- a/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPage.ets +++ b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPage.ets @@ -17,7 +17,7 @@ * FAQ:自定义弹窗中的变量如何传递给页面 */ -// DocsCode 1 +// [Start dialog_demo_first] @CustomDialog struct CustomDialog01 { @Link inputValue: string; @@ -60,98 +60,4 @@ struct DialogDemo01 { .margin({ top: 5 }) } } -// DocsCode 1 - -// DocsCode 2 -@CustomDialog -struct CustomDialog02 { - private inputValue: string = ''; - changeInputValue: (val: string) => void = () => { - }; - controller: CustomDialogController; - - build() { - Column() { - Text('Change text') - .fontSize(20) - .margin({ top: 10, bottom: 10 }) - TextInput({ placeholder: '', text: this.inputValue }) - .height(60) - .width('90%') - .onChange((value: string) => { - this.changeInputValue(value); - }) - } - } -} - -@Entry -@Component -struct DialogDemo02 { - @State inputValue: string = 'click me'; - dialogController: CustomDialogController = new CustomDialogController({ - builder: CustomDialog02({ - inputValue: this.inputValue, - changeInputValue: (val: string) => { - this.inputValue = val; - } - }) - }) - - build() { - Column() { - Button(this.inputValue) - .onClick(() => { - this.dialogController.open(); - }) - .backgroundColor(0x317aff) - } - .width('100%') - .margin({ top: 5 }) - } -} -// DocsCode 2 - -// DocsCode 3 -let storage = LocalStorage.getShared(); -@CustomDialog -struct CustomDialog03 { - @LocalStorageLink('inputVal') inputValue: string = ''; - controller: CustomDialogController; - - build() { - Column() { - Text('Change text') - .fontSize(20) - .margin({ top: 10, bottom: 10 }) - TextInput({ placeholder: '', text: this.inputValue }) - .height(60) - .width('90%') - .onChange((value: string) => { - this.inputValue = value; - }) - } - } -} - -@Entry(storage) -@Component -struct DialogDemo03 { - @LocalStorageLink('inputVal') inputValue: string = 'click me'; - dialogController: CustomDialogController = new CustomDialogController({ - builder: CustomDialog03() - }); - - build() { - Column() { - Button(this.inputValue) - .onClick(() => { - this.dialogController.open(); - }) - .backgroundColor(0x317aff) - } - .width('100%') - .margin({ top: 5 }) - } -} -// DocsCode 3 \ No newline at end of file +// [End dialog_demo_first] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageSecond.ets b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageSecond.ets new file mode 100644 index 0000000..769954a --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageSecond.ets @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:自定义弹窗中的变量如何传递给页面 +*/ + +// [Start dialog_demo_second] +@CustomDialog +struct CustomDialog02 { + private inputValue: string = ''; + changeInputValue: (val: string) => void = () => { + }; + controller: CustomDialogController; + + build() { + Column() { + Text('Change text') + .fontSize(20) + .margin({ top: 10, bottom: 10 }) + TextInput({ placeholder: '', text: this.inputValue }) + .height(60) + .width('90%') + .onChange((value: string) => { + this.changeInputValue(value); + }) + } + } +} + +@Entry +@Component +struct DialogDemo02 { + @State inputValue: string = 'click me'; + dialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialog02({ + inputValue: this.inputValue, + changeInputValue: (val: string) => { + this.inputValue = val; + } + }) + }) + + build() { + Column() { + Button(this.inputValue) + .onClick(() => { + this.dialogController.open(); + }) + .backgroundColor(0x317aff) + } + .width('100%') + .margin({ top: 5 }) + } +} +// [End dialog_demo_second] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageThird.ets b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageThird.ets new file mode 100644 index 0000000..8102c3a --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/CustomDialogVariableToPageThird.ets @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:自定义弹窗中的变量如何传递给页面 +*/ + +// [Start dialog_demo_third] +let storage = LocalStorage.getShared(); +@CustomDialog +struct CustomDialog03 { + @LocalStorageLink('inputVal') inputValue: string = ''; + controller: CustomDialogController; + + build() { + Column() { + Text('Change text') + .fontSize(20) + .margin({ top: 10, bottom: 10 }) + TextInput({ placeholder: '', text: this.inputValue }) + .height(60) + .width('90%') + .onChange((value: string) => { + this.inputValue = value; + }) + } + } +} + +@Entry(storage) +@Component +struct DialogDemo03 { + @LocalStorageLink('inputVal') inputValue: string = 'click me'; + dialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialog03() + }); + + build() { + Column() { + Button(this.inputValue) + .onClick(() => { + this.dialogController.open(); + }) + .backgroundColor(0x317aff) + } + .width('100%') + .margin({ top: 5 }) + } +} +// [End dialog_demo_third] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets index dd3c105..fb8140a 100644 --- a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets +++ b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets @@ -17,28 +17,7 @@ * FAQ:如何完成挖孔屏的适配 */ -// DocsCode 1 -onWindowStageCreate(windowStage: window.WindowStage): void { - AppStorage.setOrCreate('context', windowStage); - windowStage.getMainWindow((err: BusinessError, data) => { - let errCode: number = err.code; - // 设置窗口为全屏显示状态 - data.setWindowLayoutFullScreen(true); - // 设置顶部状态栏为隐藏状态 - let names: Array<'status' | 'navigation'> = []; - data.setWindowSystemBarEnable(names, (err: BusinessError) => { - if (err.code) { - console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar to be visible.'); - }); - }) - // ... -} -// DocsCode 1 - -// DocsCode 2 +// [Start extract_screen_adaption_page] import { display, window } from '@kit.ArkUI'; import { common } from '@kit.AbilityKit'; import { batteryInfo } from '@kit.BasicServicesKit'; @@ -155,4 +134,4 @@ struct Index { .alignContent(Alignment.TopStart) } } -// DocsCode 2 \ No newline at end of file +// [End extract_screen_adaption_page] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/FontSetting.ets b/ArkUI/entry/src/main/ets/pages/FontSetting.ets index 46af49f..0edb3df 100644 --- a/ArkUI/entry/src/main/ets/pages/FontSetting.ets +++ b/ArkUI/entry/src/main/ets/pages/FontSetting.ets @@ -17,10 +17,10 @@ * FAQ:如何设置Text的字体,可以不受系统设置里显示字体大小的影响 */ -// DocsCode 1 +// [Start custom_font_setting] @Entry @Component -struct CustomDialogDisplayLevel { +struct CustomFontSetting { @State message: string = 'hello world'; build() { @@ -41,4 +41,4 @@ struct CustomDialogDisplayLevel { } } } -// DocsCode 1 \ No newline at end of file +// [End custom_font_setting] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets b/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets index e19a6ff..54275cb 100644 --- a/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets +++ b/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets @@ -17,7 +17,7 @@ * FAQ:Navigation容器中,如何设置子组件的高度为100%,撑满父容器 */ -// DocsCode 1 +// [Start full_navigation_subcomponent] import { window } from '@kit.ArkUI'; @Entry @@ -46,4 +46,4 @@ struct FullNavigationSubcomponent { .backgroundColor(Color.Grey) } } -// DocsCode 1 \ No newline at end of file +// [End full_navigation_subcomponent] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets b/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets index 4ce18e9..1b6403f 100644 --- a/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets +++ b/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets @@ -17,23 +17,11 @@ * FAQ:如何获取App版本号,版本名,屏幕分辨率等信息 */ -// DocsCode 1 -import { BusinessError } from '@kit.BasicServicesKit'; -import { bundleManager } from '@kit.AbilityKit'; -// ... -bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{ - let versionName = bundleInfo.versionName;//应用版本名 - let versionNo = bundleInfo.versionCode;//应用版本号 -}).catch((error: BusinessError )=>{ - console.error("get bundleInfo failed,error is "+error) -}) -// DocsCode 1 - -// DocsCode 2 +// [Start screen_density] import { common } from '@kit.AbilityKit'; // ... -context = this.getUIContext(); +// 工具类中:在EntryAbility - onCreate 生命周期中获取Context后保存至AppStorage,然后在工具类中使用AppStorage获取 +let context = AppStorage.get("context") as common.UIAbilityContext; -let context = this.context.getHostContext() as common.UIAbilityContext; let screenDensity = context.config.screenDensity; -// DocsCode 2 +// [End screen_density] diff --git a/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets b/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets new file mode 100644 index 0000000..e1ae650 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何获取App版本号,版本名,屏幕分辨率等信息 +*/ + +// [Start get_bundle_info] +import { BusinessError } from '@kit.BasicServicesKit'; +import { bundleManager } from '@kit.AbilityKit'; +// ... +bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{ + let versionName = bundleInfo.versionName;//应用版本名 + let versionNo = bundleInfo.versionCode;//应用版本号 +}).catch((error: BusinessError )=>{ + console.error("get bundleInfo failed,error is "+error) +}) +// [End get_bundle_info] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets b/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets index 632ddf7..00fc50c 100644 --- a/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets +++ b/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets @@ -17,7 +17,7 @@ * FAQ:如何获取组件渲染完成时间 */ -// DocsCode 1 +// [Start get_component_render_time] import { inspector } from '@kit.ArkUI'; @Entry @@ -64,4 +64,4 @@ struct GetComponentRenderTime { }) } } -// DocsCode 1 \ No newline at end of file +// [End get_component_render_time] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets b/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets index d8540b1..98f4ab3 100644 --- a/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets +++ b/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets @@ -17,7 +17,7 @@ * FAQ:如何在长按手势回调方法里获取手指触摸点的坐标 */ -// DocsCode 1 +// [Start CoordinatesOfTheFingerTouchPoint] @Component struct CoordinatesOfTheFingerTouchPoint { @State count: number = 0; @@ -94,4 +94,4 @@ struct CoordinatesOfTheFingerTouchPoint { .backgroundColor('#F1F3F5') } } -// DocsCode 1 \ No newline at end of file +// [End CoordinatesOfTheFingerTouchPoint] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetDarkModeColorSync.ets b/ArkUI/entry/src/main/ets/pages/GetDarkModeColorSync.ets index 660648f..c2b4a18 100644 --- a/ArkUI/entry/src/main/ets/pages/GetDarkModeColorSync.ets +++ b/ArkUI/entry/src/main/ets/pages/GetDarkModeColorSync.ets @@ -17,15 +17,6 @@ * FAQ:如何在系统深色模式下使用getColorSync(resource)返回深色颜色值 */ -// DocsCode 1 +// [Start get_dark_mode_color_sync] this.getUIContext().getHostContext()!.resourceManager.getColorSync($r('app.color.xxx').id); -// DocsCode 1 - -// DocsCode 2 -"metadata": [ - { - "name": "ContextResourceConfigLoadFromParentTemp", - "value": "true" - } -] -// DocsCode 2 \ No newline at end of file +// [Start get_dark_mode_color_sync] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets index 540bb6d..3b823d8 100644 --- a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets +++ b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets @@ -17,7 +17,7 @@ * FAQ:如何获取设备屏幕横竖屏状态 */ -// DocsCode 1 +// [Start get_window_status] import { mediaquery, UIContext } from '@kit.ArkUI'; // 在 EntryAbility 中存储 context @@ -49,39 +49,4 @@ struct Index { .justifyContent(FlexAlign.End) } } -// DocsCode 1 - -// DocsCode 2 -import { display, window } from '@kit.ArkUI'; - -@Entry -@Component -struct windowRotation { - build() { - Text("Scroll Area") - .width("100%") - .height("100%") - .backgroundColor(0X330000FF) - .fontSize(16) - .textAlign(TextAlign.Center) - .onClick(() => { - window.getLastWindow(this.getUIContext().getHostContext(), (err, win) => { - let cutOutInfo = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE) - console.log(JSON.stringify(cutOutInfo)) - if (window.Orientation.AUTO_ROTATION) { - let rotation: number = display.getDefaultDisplaySync().orientation // 获取当前屏幕的枚举值 - console.log('' + rotation); - if (rotation == 0) { - console.log("CutOutInfo 竖屏数据: " + JSON.stringify(cutOutInfo)); - } else if (rotation == 1) { - console.log("CutOutInfo 横屏数据: " + JSON.stringify(cutOutInfo)); - } else if (rotation == 2) { - console.log("CutOutInfo 反向竖屏数据: " + JSON.stringify(cutOutInfo)); - } else { - console.log("CutOutInfo 反向横屏数据: " + JSON.stringify(cutOutInfo)); - } - } - }) - }) - }} -// DocsCode 2 \ No newline at end of file +// [End get_window_status] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets new file mode 100644 index 0000000..8df03bc --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何获取设备屏幕横竖屏状态 +*/ + +// [Start get_window_rotation] +import { display, window } from '@kit.ArkUI'; + +@Entry +@Component +struct windowRotation { + build() { + Text("Scroll Area") + .width("100%") + .height("100%") + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + .onClick(() => { + window.getLastWindow(this.getUIContext().getHostContext(), (err, win) => { + let cutOutInfo = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE) + console.log(JSON.stringify(cutOutInfo)) + if (window.Orientation.AUTO_ROTATION) { + let rotation: number = display.getDefaultDisplaySync().orientation // 获取当前屏幕的枚举值 + console.log('' + rotation); + if (rotation == 0) { + console.log("CutOutInfo 竖屏数据: " + JSON.stringify(cutOutInfo)); + } else if (rotation == 1) { + console.log("CutOutInfo 横屏数据: " + JSON.stringify(cutOutInfo)); + } else if (rotation == 2) { + console.log("CutOutInfo 反向竖屏数据: " + JSON.stringify(cutOutInfo)); + } else { + console.log("CutOutInfo 反向横屏数据: " + JSON.stringify(cutOutInfo)); + } + } + }) + }) + }} +// [End get_window_rotation] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets b/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets index 5ff4d98..e6958a5 100644 --- a/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets +++ b/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets @@ -17,7 +17,7 @@ * FAQ:如何获取router.back传递的参数 */ -// DocsCode 1 +// [Start get_router_back_params] class InfoTmp { age: number = 0 } @@ -28,7 +28,8 @@ class RouTmp { info: InfoTmp = new InfoTmp() } -const params: RouTmp = this.getUIContext().getRouter().getParams() as RouTmp; // 获取传递过来的参数对象 +const context = AppStorage.get("context") as UIContext; +const params: RouTmp = context.getRouter().getParams() as RouTmp; // 获取传递过来的参数对象 const id: object = params.id // 获取id属性的值 const age: number = params.info.age // 获取age属性的值 -// DocsCode 1 \ No newline at end of file +// [End get_router_back_params] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetTextWidth.ets b/ArkUI/entry/src/main/ets/pages/GetTextWidth.ets index b929b0e..5735693 100644 --- a/ArkUI/entry/src/main/ets/pages/GetTextWidth.ets +++ b/ArkUI/entry/src/main/ets/pages/GetTextWidth.ets @@ -17,7 +17,7 @@ * FAQ:如何获取Text组件中文字的宽度 */ -// DocsCode 1 +// [Start get_text_width] @Entry @Component struct Index { @@ -36,4 +36,4 @@ struct Index { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End get_text_width] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets b/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets index bfad6ed..ecd5d53 100644 --- a/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets +++ b/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets @@ -17,33 +17,7 @@ * FAQ:如何在Page中获取WindowStage实例 */ -// DocsCode 1 -import { UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -export default class EntryAbility extends UIAbility { - // ... - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - 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.'); - }); - console.info('windowStage+++', JSON.stringify(windowStage)) - AppStorage.setAndLink('windowStage', windowStage) - } - - // ... -} -// DocsCode 1 - -// DocsCode 2 +// [Start get_window_stage_instance_in_page] // Index.ets import common from '@ohos.app.ability.common'; @@ -68,4 +42,4 @@ struct Index { .height('100%') } } -// DocsCode 2 \ No newline at end of file +// [End get_window_stage_instance_in_page] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/HandleDrawNineMapPrinciple.ets b/ArkUI/entry/src/main/ets/pages/HandleDrawNineMapPrinciple.ets new file mode 100644 index 0000000..7c28b91 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/HandleDrawNineMapPrinciple.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:是否有处理"9图"(又称"draw9patch"、".9图"、"点9图"等)的平替方案 +*/ + +// [Start nine_map_principle] +@Entry +@Component +struct NineMapPrinciple { + build() { + Row() { + Image($r('app.media.startIcon')) + .resizable({ slice: { top: 10, left: 10, bottom: 50, right: 50 } }) + } + .height('50%') + } +} +// [End nine_map_principle] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/HandleDraw9PatchReplacementRegimen.ets b/ArkUI/entry/src/main/ets/pages/HandleDrawNinePatchReplacementRegimen.ets similarity index 86% rename from ArkUI/entry/src/main/ets/pages/HandleDraw9PatchReplacementRegimen.ets rename to ArkUI/entry/src/main/ets/pages/HandleDrawNinePatchReplacementRegimen.ets index b2c2afa..7dd3c36 100644 --- a/ArkUI/entry/src/main/ets/pages/HandleDraw9PatchReplacementRegimen.ets +++ b/ArkUI/entry/src/main/ets/pages/HandleDrawNinePatchReplacementRegimen.ets @@ -17,22 +17,7 @@ * FAQ:是否有处理"9图"(又称"draw9patch"、".9图"、"点9图"等)的平替方案 */ -// DocsCode 1 -@Entry -@Component -struct NineMapPrinciple { - build() { - Row() { - Image($r('app.media.startIcon')) - .resizable({ slice: { top: 10, left: 10, bottom: 50, right: 50 } }) - } - .height('50%') - } -} -// DocsCode 1 - - -// DocsCode 2 +// [Start chat_bubble_stretch_demo] @Entry @Component struct ChatBubbleStretchDemo { @@ -71,4 +56,4 @@ struct ChatBubbleStretchDemo { .width('100%') } } -// DocsCode 2 \ No newline at end of file +// [End chat_bubble_stretch_demo] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets b/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets index 9167128..b33265b 100644 --- a/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets +++ b/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets @@ -17,7 +17,7 @@ * FAQ:Image无法使用bindContextMenu */ -// DocsCode 1 +// [Start image_can_not_use_bind_context_menu] @Entry @Component struct Index { @@ -52,4 +52,4 @@ struct Index { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End image_can_not_use_bind_context_menu] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets b/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets index 81c2ee2..f8171b3 100644 --- a/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets +++ b/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets @@ -17,7 +17,7 @@ * FAQ:如何实现手指离开屏幕后的惯性滑动效果 */ -// DocsCode 1 +// [Start pan_gesture_example] @Entry @Component struct PanGestureExample { @@ -80,4 +80,4 @@ struct PanGestureExample { ) } } -// DocsCode 1 \ No newline at end of file +// [End pan_gesture_example] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets b/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets index 87efb50..f7175bf 100644 --- a/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets +++ b/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets @@ -17,7 +17,7 @@ * FAQ:如何实现List的折叠动画效果 */ -// DocsCode 1 +// [Start list_collapse_expand] @Entry @Component struct ListCollapseExpand { @@ -74,4 +74,4 @@ struct ListCollapseExpand { .padding(12) } } -// DocsCode 1 \ No newline at end of file +// [End list_collapse_expand] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets b/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets index 53a445b..4bcd626 100644 --- a/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets +++ b/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets @@ -17,7 +17,7 @@ * FAQ:如何监听屏幕旋转 */ -// DocsCode 1 +// [Start watch_screen_rotation] import { mediaquery, UIContext } from '@kit.ArkUI'; const context = AppStorage.get("context") as UIContext; let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); // 监听横屏事件 @@ -30,4 +30,4 @@ function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { } listener.on('change', onPortrait) // 注册回调 listener.off('change', onPortrait) // 取消注册回调 -// DocsCode 1 \ No newline at end of file +// [End watch_screen_rotation] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets b/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets index 63f2cab..142d2df 100644 --- a/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets +++ b/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets @@ -17,7 +17,7 @@ * FAQ:如何使当前页面弹窗在页面跳转返回之后还存在(隐私详情页场景) */ -// DocsCode 1 +// [Start dialog_jump_retained] @Component struct DialogJumpRetained { @State visible: Visibility = Visibility.None; @@ -126,9 +126,9 @@ struct DialogJumpRetained { } } } -// DocsCode 1 +// [End dialog_jump_retained] -// DocsCode 2 +// [Start second] @Entry @Component struct Second { @@ -150,4 +150,4 @@ struct Second { .height('100%') } } -// DocsCode 2 \ No newline at end of file +// [End second] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets b/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets index decf141..7887c89 100644 --- a/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets +++ b/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets @@ -17,12 +17,12 @@ * FAQ:Grid onItemDragStart默认时间设置替代方案、以及多列GridItem实现通用示例 */ -// DocsCode 1 +// [Start replace_default_time_set_page] import { curves } from '@kit.ArkUI'; @Entry @Component -struct Page { +struct ReplaceDefaultTimeSetPage { //元素数组 @State numbers: number[] = []; @State row: number = 4; @@ -331,4 +331,4 @@ struct Page { .padding({ top: 5 }) } } -// DocsCode 1 \ No newline at end of file +// [End replace_default_time_set_page] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets b/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets index f0bd07b..516f409 100644 --- a/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets +++ b/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets @@ -17,7 +17,7 @@ * FAQ:通过$r访问应用资源是否支持嵌套形式 */ -// DocsCode 1 +// [Start resource_nesting] @Entry @Component struct Page16 { @@ -36,4 +36,4 @@ struct Page16 { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End resource_nesting] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets b/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets index db56971..cc460c5 100644 --- a/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets +++ b/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets @@ -17,11 +17,7 @@ * FAQ:如何设置窗口旋转 */ -// DocsCode 1 -AppStorage.setOrCreate('windowStage',windowStage); -// DocsCode 1 - -// DocsCode 2 +// [Start screen_rotation] import { display, window } from '@kit.ArkUI'; @Component @@ -50,4 +46,4 @@ struct ScreenRotation { }.height('100%').backgroundColor(Color.White) } } -// DocsCode 2 \ No newline at end of file +// [End screen_rotation] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets b/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets index 1cfc999..4bb9922 100644 --- a/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets +++ b/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets @@ -17,7 +17,7 @@ * FAQ:如何监听当前屏幕的横竖屏状态?如何实现页面跟随屏幕横竖屏自动旋转 */ -// DocsCode 1 +// [Start screen_test] import { window, display } from '@kit.ArkUI'; const TAG = 'foo' @@ -84,4 +84,4 @@ struct ScreenTest { .height("100%") } } -// DocsCode 1 \ No newline at end of file +// [End screen_test] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets b/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets index 8075a5b..af87a99 100644 --- a/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets +++ b/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets @@ -17,7 +17,7 @@ * FAQ:如何设置customspan不同位置的点击事件 */ -// DocsCode 1 +// [Start custom_span] @Entry @Component struct Index { @@ -77,4 +77,4 @@ struct Index { } } } -// DocsCode 1 \ No newline at end of file +// [End custom_span] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets b/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets index dc4e33a..5c1c9e6 100644 --- a/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets +++ b/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets @@ -17,7 +17,7 @@ * FAQ:bindPopup适配Web组件长按菜单功能,如何设置offset控制弹窗的偏移 */ -// DocsCode 1 +// [Start bind_popup_offset] import { webview } from '@kit.ArkWeb'; @Entry @@ -97,4 +97,4 @@ struct BindPopupOffset { } } } -// DocsCode 1 \ No newline at end of file +// [End bind_popup_offset] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets index eba8e7a..d4d1cd6 100644 --- a/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets +++ b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets @@ -17,88 +17,7 @@ * FAQ:如何实现防截屏功能 */ -// DocsCode 1 -"requestPermissions": [ - {"name": "ohos.permission.PRIVACY_WINDOW"} -] -// DocsCode 1 - -// DocsCode 2 -import { AbilityConstant, ConfigurationConstant, UIAbility, Want } 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): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - // 获取主窗口 - windowStage.getMainWindow((err: BusinessError, data) => { - let errCode: number = err.code; - if (errCode) { - console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - return; - } - let windowClass: window.Window = data; - console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - // 设置窗口隐私模式 - let isPrivacyMode: boolean = true; - try { - windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to privacy mode.'); - }); - } catch (exception) { - console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); - } - }) - 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) ?? ''); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} -// DocsCode 2 - -// DocsCode 3 -"requestPermissions": [ - {"name": "ohos.permission.PRIVACY_WINDOW"} -] -// DocsCode 3 - -// DocsCode 4 +// [Start window_privacy_mode_page] import { BusinessError } from '@kit.BasicServicesKit'; import { common } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; @@ -120,7 +39,7 @@ class windowUtils { @Entry @Component -struct Index { +struct WindowPrivacyModePage { @State message: string = 'hello world'; @Provide('NavPathStack') pageStack: NavPathStack = new NavPathStack(); context = this.getUIContext(); @@ -172,4 +91,4 @@ struct PageOne { }) } } -// DocsCode 4 \ No newline at end of file +// [End window_privacy_mode_page] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeRequestPermission.json5 b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeRequestPermission.json5 new file mode 100644 index 0000000..fc296c8 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeRequestPermission.json5 @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现防截屏功能 +*/ + +{ + // [Start request_privacy_window] + "requestPermissions": [ + {"name": "ohos.permission.PRIVACY_WINDOW"} + ] + // [End request_privacy_window] +} diff --git a/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets b/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets index 7c3536c..0b6cd65 100644 --- a/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets +++ b/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets @@ -17,11 +17,11 @@ * FAQ:如何设置屏幕亮度 */ -// DocsCode 1 +// [Start store_window_stage] AppStorage.setOrCreate('windowStage',windowStage); -// DocsCode 1 +// [End store_window_stage] -// DocsCode 2 +// [Start set_screen_brightness] import { window } from '@kit.ArkUI' @Component @@ -64,4 +64,4 @@ struct SettingScreenBrightness { }.height('100%').backgroundColor(Color.White) } } -// DocsCode 2 \ No newline at end of file +// [End set_screen_brightness] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SharePopup.ets b/ArkUI/entry/src/main/ets/pages/SharePopup.ets index 99d5b92..b6447d3 100644 --- a/ArkUI/entry/src/main/ets/pages/SharePopup.ets +++ b/ArkUI/entry/src/main/ets/pages/SharePopup.ets @@ -17,7 +17,7 @@ * FAQ:如何使用自定义弹窗实现分享弹窗 */ -// DocsCode 1 +// [Start custom_share_dialog] import { ComponentContent } from '@kit.ArkUI'; let componentContent: ComponentContent | undefined = undefined; @@ -32,15 +32,17 @@ class Params { } } +const context = AppStorage.get("context") as UIContext + @Builder -function buildText($$: Params) { +function buildText($$: Params) { Column() { Text('share') Grid() { ForEach($$.applicationSharings, (item: string, index) => { GridItem() { Column() { - Image($r('app.media.app_icon')) + Image($r('app.media.startIcon')) .height(50) .width(50) Text(item) @@ -59,7 +61,7 @@ function buildText($$: Params) { ForEach($$.sharings, (item: string, index) => { GridItem() { Column() { - Image($r('app.media.app_icon')) + Image($r('app.media.startIcon')) .height(50) .width(50) Text(item) @@ -79,7 +81,7 @@ function buildText($$: Params) { .fontColor(Color.Black) .backgroundColor(Color.White) .onClick(() => { - this.getUIContext().getPromptAction()?.closeCustomDialog(componentContent); + context.getPromptAction().closeCustomDialog(componentContent); }) } .backgroundColor('#FFF0F0F0') @@ -95,12 +97,13 @@ struct CustomShareDialog { ['share1', 'share2', 'share3', 'share4', 'share5', 'share6', 'share7', 'share8']; @State sharings: string[] = ['share1', 'share2', 'share3', 'share4', 'share5', 'share6', 'share7', 'share8']; + build() { Row() { Column() { Button('click me') .onClick(() => { - let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), + let contentNode = new ComponentContent(this.getUIContext(), wrapBuilder(buildText), new Params(this.applicationSharings, this.sharings)); componentContent = contentNode; this.getUIContext().getPromptAction().openCustomDialog(contentNode); @@ -112,4 +115,4 @@ struct CustomShareDialog { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End custom_share_dialog] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets b/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets index 6f4f313..992ce0c 100644 --- a/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets +++ b/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets @@ -17,7 +17,7 @@ * FAQ:如何在Navigation页面中实现侧滑事件拦截 */ -// DocsCode 1 +// [Start sideslip_intercept] import { ShowDialogSuccessResponse } from '@kit.ArkUI'; @Entry @@ -85,4 +85,4 @@ struct SideslipIntercept { }) } } -// DocsCode 1 \ No newline at end of file +// [End sideslip_intercept] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SimilarKeyFramesEffect.ets b/ArkUI/entry/src/main/ets/pages/SimilarKeyFramesEffect.ets index 936c2ad..754c76b 100644 --- a/ArkUI/entry/src/main/ets/pages/SimilarKeyFramesEffect.ets +++ b/ArkUI/entry/src/main/ets/pages/SimilarKeyFramesEffect.ets @@ -17,7 +17,7 @@ * FAQ:如何实现类似keyframes的效果 */ -// DocsCode 1 +// [Start animate_to_example] @Entry @Component struct AnimateToExample { @@ -61,4 +61,4 @@ struct AnimateToExample { }.width('100%').margin({ top: 5 }) } } -// DocsCode 1 \ No newline at end of file +// [End animate_to_example] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets index 48230d7..81b0972 100644 --- a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets +++ b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets @@ -17,31 +17,7 @@ * FAQ:状态栏与页面内容发生重叠,如何解决 */ -// DocsCode 1 -// EntryAbility.ets - -onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/ImagePreview', (err) => { - 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.'); - - let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 - // 1. 设置窗口全屏 - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); - // 2. 缓存window窗口对象 - AppStorage.setOrCreate('windowClass', windowClass); - }); -} -// DocsCode 1 - -// DocsCode 2 +// [Start image_preview_example] import { window } from '@kit.ArkUI'; @Entry @@ -145,95 +121,4 @@ struct ImagePreviewExample { .width('100%') } } -// DocsCode 2 - -// DocsCode 3 -// EntryAbility.ets - -onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/AvoidStatusBar', (err) => { - 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.'); - - let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 - // 1. 设置窗口全屏 - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); - // 2. 缓存window窗口对象 - AppStorage.setOrCreate('windowClass', windowClass); - - // 3. 获取布局避让遮挡的区域 - let type = window.AvoidAreaType.TYPE_SYSTEM; - let avoidArea = windowClass.getWindowAvoidArea(type); - let statusBar = this.getUIContext().px2vp( avoidArea.topRect.height); // 获取状态栏的高度 - AppStorage.setOrCreate('statusBar', statusBar); - }); -} -// DocsCode 3 - -// DocsCode 4 -@Entry -@Component -struct AvoidStatusBar { - statusBar: number = AppStorage.get('statusBar') as number; - - build() { - - Column() { - Row() { - Text('ROW1') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - - Row() { - Text('ROW2') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - - Row() { - Text('ROW3') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - - Row() { - Text('ROW4') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - - Row() { - Text('ROW5') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - - Row() { - Text('ROW6') - .fontSize(40) - } - .backgroundColor(Color.Orange) - .padding(20) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.SpaceBetween) - .padding({ top: this.statusBar }) // 此处margin或padding具体数值在实际中应与状态栏区域高度保持一致 - .backgroundColor('#008000') - } -} -// DocsCode 4 \ No newline at end of file +// [End image_preview_example] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets new file mode 100644 index 0000000..1a0930a --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:状态栏与页面内容发生重叠,如何解决 +*/ + +// [Start avoid_status_bar] +@Entry +@Component +struct AvoidStatusBar { + statusBar: number = AppStorage.get('statusBar') as number; + + build() { + + Column() { + Row() { + Text('ROW1') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + + Row() { + Text('ROW2') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + + Row() { + Text('ROW3') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + + Row() { + Text('ROW4') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + + Row() { + Text('ROW5') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + + Row() { + Text('ROW6') + .fontSize(40) + } + .backgroundColor(Color.Orange) + .padding(20) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.SpaceBetween) + .padding({ top: this.statusBar }) // 此处margin或padding具体数值在实际中应与状态栏区域高度保持一致 + .backgroundColor('#008000') + } +} +// [End avoid_status_bar] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets b/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets index 45c79d1..3ccfa67 100644 --- a/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets +++ b/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets @@ -17,7 +17,7 @@ * FAQ:如何将ListItem的swipeAction滑动效果恢复至未滑动 */ -// DocsCode 1 +// [Start swiper_action_recover] @Component export struct SwiperActionRecover { @State arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; @@ -74,4 +74,4 @@ export struct SwiperActionRecover { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End swiper_action_recover] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets b/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets index da14102..cdb1323 100644 --- a/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets +++ b/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets @@ -17,7 +17,7 @@ * FAQ:如何实现文本展开收起功能 */ -// DocsCode 1 +// [Start text_collapse_test] // 文本行宽度 const TEXT_WIDTH: number = 350; // 收起文本显示行数 @@ -142,4 +142,4 @@ struct TextCollapseTest { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End text_collapse_test] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets b/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets index 61b9132..41143f4 100644 --- a/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets +++ b/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets @@ -17,7 +17,7 @@ * FAQ:Text组件设置maxLines后如何确定文本是否被隐藏 */ -// DocsCode 1 +// [Start text_input_example] @Entry @Component struct TextInputExample { @@ -75,4 +75,4 @@ struct TextInputExample { }.width('100%') } } -// DocsCode 1 \ No newline at end of file +// [End text_input_example] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets index 449a3b3..0b0dbb7 100644 --- a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets +++ b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets @@ -17,7 +17,7 @@ * FAQ:如何解决Web页面输入框拉起键盘后,页面头部被截断的问题 */ -// DocsCode 1 +// [Start sub_window_page] // 子窗口页面布局 import { webview } from '@kit.ArkWeb'; import { window } from '@kit.ArkUI'; @@ -72,4 +72,4 @@ export struct SubWindowPage { .alignContent(Alignment.Center) } } -// DocsCode 1 \ No newline at end of file +// [End sub_window_page] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets b/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets index d64e193..3650628 100644 --- a/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets +++ b/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets @@ -17,7 +17,7 @@ * FAQ:目前Toggle组件响应点击之后会立刻渲染且立刻回调,如何延迟改变Toggle状态且延时回调? */ -// DocsCode 1 +// [Start toggle_demo] @Entry @Component struct ToggleDemo { @@ -46,4 +46,4 @@ struct ToggleDemo { .padding(32) } } -// DocsCode 1 \ No newline at end of file +// [End toggle_demo] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/WindowProperties.ets b/ArkUI/entry/src/main/ets/pages/WindowProperties.ets index d30bc6d..87016af 100644 --- a/ArkUI/entry/src/main/ets/pages/WindowProperties.ets +++ b/ArkUI/entry/src/main/ets/pages/WindowProperties.ets @@ -17,7 +17,7 @@ * FAQ:如何获取窗口的宽度 */ -// DocsCode 1 +// [Start get_window_width] import { window } from '@kit.ArkUI'; @Entry @@ -43,4 +43,4 @@ struct WindowProperties { }) } } -// DocsCode 1 \ No newline at end of file +// [End get_window_width] \ No newline at end of file diff --git a/ArkUI/entry/src/main/resources/base/element/color.json b/ArkUI/entry/src/main/resources/base/element/color.json index 3c71296..a4a39f5 100644 --- a/ArkUI/entry/src/main/resources/base/element/color.json +++ b/ArkUI/entry/src/main/resources/base/element/color.json @@ -3,6 +3,10 @@ { "name": "start_window_background", "value": "#FFFFFF" + }, + { + "name": "xxx", + "value": "#FFFFFF" } ] } \ No newline at end of file diff --git a/ArkUI/entry/src/main/resources/rawfile/index.html b/ArkUI/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000..a421355 --- /dev/null +++ b/ArkUI/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,14 @@ + + + + + + + Document + + + + + + + \ No newline at end of file -- Gitee From d5709d88c0476645e10428d5e6fb2aea4ed02d68 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Fri, 16 May 2025 18:35:59 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20ArkUI=20=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E4=B8=AD=E6=96=87=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E6=88=90=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets | 8 ++++---- ArkUI/entry/src/main/ets/pages/FontSetting.ets | 8 ++++---- ArkUI/entry/src/main/ets/pages/GetAppInformation.ets | 2 +- .../src/main/ets/pages/GetComponentRenderingTime.ets | 10 +++++----- .../ets/pages/GetHorizontalAndVerticalScreenStatus.ets | 8 ++++---- ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets | 6 +++--- .../main/ets/pages/GetWindowStageInstanceInPage.ets | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets b/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets index f983212..1731002 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomPopsUpAsTheTopOfKeyboard.ets @@ -31,13 +31,13 @@ struct BottomPopsUpAsTheTopOfKeyboard { @State text: string = ''; aboutToAppear() { window.getLastWindow(this.context.getHostContext()).then(currentWindow => { - // 设置窗口的布局为沉浸式布局 + // Set the layout of the window to immersive layout currentWindow.setWindowLayoutFullScreen(true); let property = currentWindow.getWindowProperties(); - // 初始化窗口高度 + // Initialize window height let avoidArea = currentWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); this.scrollHeight = px2vp(property.windowRect.height - avoidArea.bottomRect.height); - // 监听软键盘的隐藏和显示 + // Monitor the hiding and showing of the soft keyboard currentWindow.on('avoidAreaChange', data => { if (data.type == window.AvoidAreaType.TYPE_KEYBOARD) { this.keyHeight = px2vp(data.area.bottomRect.height); @@ -80,7 +80,7 @@ struct BottomPopsUpAsTheTopOfKeyboard { .width('100%') .height(this.scrollHeight) .layoutWeight(1) - Text('这是一个测试文本') + Text('This is a test text') .width('100%') .height(50) .backgroundColor(Color.Red) diff --git a/ArkUI/entry/src/main/ets/pages/FontSetting.ets b/ArkUI/entry/src/main/ets/pages/FontSetting.ets index 0edb3df..9e26544 100644 --- a/ArkUI/entry/src/main/ets/pages/FontSetting.ets +++ b/ArkUI/entry/src/main/ets/pages/FontSetting.ets @@ -26,18 +26,18 @@ struct CustomFontSetting { build() { Column() { Text(this.message) - .fontSize(53) // 默认单位为fp,会跟随系统显示大小变化 + .fontSize(53) // Default unit is fp, which changes with system display size Text(this.message) - .fontSize(this.getUIContext().px2fp(160) + 'px') // 使用像素单位,不会跟随系统显示大小变化 + .fontSize(this.getUIContext().px2fp(160) + 'px') // Use pixel units, unaffected by system display size Blank() .color(0xff0000) .height(30) .width(226) - .margin({ bottom: 20 }) // 默认单位 vp会跟随系统显示大小变化 + .margin({ bottom: 20 }) // Default unit vp changes with system display size Blank() .color(0xff0000) .height(30 + 'px') - .width(this.getUIContext().px2vp(672) + 'px') // 使用像素单位,不会跟随系统显示大小变化 + .width(this.getUIContext().px2vp(672) + 'px') // Use pixel units, unaffected by system display size } } } diff --git a/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets b/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets index 1b6403f..a368123 100644 --- a/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets +++ b/ArkUI/entry/src/main/ets/pages/GetAppInformation.ets @@ -20,7 +20,7 @@ // [Start screen_density] import { common } from '@kit.AbilityKit'; // ... -// 工具类中:在EntryAbility - onCreate 生命周期中获取Context后保存至AppStorage,然后在工具类中使用AppStorage获取 +// In the utility class: Save the context to AppStorage in the EntryAbility - onCreate lifecycle, then use AppStorage to retrieve it in the utility class let context = AppStorage.get("context") as common.UIAbilityContext; let screenDensity = context.config.screenDensity; diff --git a/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets b/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets index 00fc50c..2369969 100644 --- a/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets +++ b/ArkUI/entry/src/main/ets/pages/GetComponentRenderingTime.ets @@ -26,22 +26,22 @@ struct GetComponentRenderTime { @State startTime: number = 0; private listener: inspector.ComponentObserver = this.getUIContext().getUIInspector().createComponentObserver('IMAGE_ID'); private onDrawComplete = () => { - // 2.图片组件绘制完成的时间 + // 2. Time when the image component finishes drawing console.info('onDrawComplete', new Date().getTime()); }; aboutToAppear() { - // 1.渲染开始的时间 + // 1. Time when rendering starts this.startTime = new Date().getTime(); console.info('aboutToAppear', this.startTime); - // layout: 组件布局完成 - // draw: 组件绘制完成 + // layout: Component layout completed + // draw: Component drawing completed this.listener.on('draw', this.onDrawComplete); } aboutToDisappear() { - // 销毁之前取消注册回调 + // Unregister callback before destruction this.listener.off('draw', this.onDrawComplete); } diff --git a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets index 3b823d8..f1d9a3d 100644 --- a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets +++ b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatus.ets @@ -20,9 +20,9 @@ // [Start get_window_status] import { mediaquery, UIContext } from '@kit.ArkUI'; -// 在 EntryAbility 中存储 context +// Store context in EntryAbility const context = AppStorage.get("context") as UIContext; -let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); //监听横屏事件 +let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); // Listen to landscape events function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { console.info('mediaQueryResult.matches:' + mediaQueryResult.matches) if (mediaQueryResult.matches) { @@ -31,8 +31,8 @@ function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { // do something here } } -listener.on('change', onPortrait) // 注册回调 -listener.off('change', onPortrait) // 取消注册回调 +listener.on('change', onPortrait) // Register callback +listener.off('change', onPortrait) // Unregister callback @Entry @Component diff --git a/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets b/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets index e6958a5..d43fe39 100644 --- a/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets +++ b/ArkUI/entry/src/main/ets/pages/GetRouterBackParam.ets @@ -29,7 +29,7 @@ class RouTmp { } const context = AppStorage.get("context") as UIContext; -const params: RouTmp = context.getRouter().getParams() as RouTmp; // 获取传递过来的参数对象 -const id: object = params.id // 获取id属性的值 -const age: number = params.info.age // 获取age属性的值 +const params: RouTmp = context.getRouter().getParams() as RouTmp; // Get the parameter object passed +const id: object = params.id // Get the value of the id property +const age: number = params.info.age // Get the value of the age property // [End get_router_back_params] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets b/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets index ecd5d53..51420dd 100644 --- a/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets +++ b/ArkUI/entry/src/main/ets/pages/GetWindowStageInstanceInPage.ets @@ -34,7 +34,7 @@ struct Index { .fontWeight(FontWeight.Bold) .onClick(() => { let context = this.getUIContext().getHostContext() as common.UIAbilityContext; - console.info('获取到的WindowStage实例:',JSON.stringify(context.windowStage)) + console.info('Obtained WindowStage instance:',JSON.stringify(context.windowStage)) }); } .width('100%') -- Gitee From e68183df0c8316d88b7f3b1c10e4e7f59c961036 Mon Sep 17 00:00:00 2001 From: Gorit Date: Fri, 16 May 2025 10:42:44 +0000 Subject: [PATCH 3/7] update ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets. Signed-off-by: Gorit --- .../ets/entryability/EntryAbilityExtactScreenAdaption.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets index 2d056d4..6838ace 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets @@ -38,9 +38,9 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('context', windowStage); windowStage.getMainWindow((err: BusinessError, data) => { let errCode: number = err.code; - // 设置窗口为全屏显示状态 + // The settings window is displayed in full screen data.setWindowLayoutFullScreen(true); - // 设置顶部状态栏为隐藏状态 + // Set the top status bar to be hidden let names: Array<'status' | 'navigation'> = []; data.setWindowSystemBarEnable(names, (err: BusinessError) => { if (err.code) { -- Gitee From 057dd1bdad6d4f67d2973c3ba5cd427bc423df38 Mon Sep 17 00:00:00 2001 From: Gorit Date: Fri, 16 May 2025 10:43:32 +0000 Subject: [PATCH 4/7] update ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets. Signed-off-by: Gorit --- .../main/ets/entryability/EntryAbilitySetWindowPrivacy.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets index 8e63014..53713e4 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilitySetWindowPrivacy.ets @@ -36,7 +36,7 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - // 获取主窗口 + // Get the main window windowStage.getMainWindow((err: BusinessError, data) => { let errCode: number = err.code; if (errCode) { @@ -45,7 +45,7 @@ export default class EntryAbility extends UIAbility { } let windowClass: window.Window = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - // 设置窗口隐私模式 + // Set the window privacy mode let isPrivacyMode: boolean = true; try { windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { -- Gitee From 42ed06cd5331d46914231e18477abe39b6522df4 Mon Sep 17 00:00:00 2001 From: Gorit Date: Fri, 16 May 2025 10:44:14 +0000 Subject: [PATCH 5/7] update ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets. Signed-off-by: Gorit --- .../ets/entryability/EntryAbilityStatusBarOverlayOne.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets index 9e816ef..551efa9 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayOne.ets @@ -47,11 +47,11 @@ export default class EntryAbility extends UIAbility { } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); - let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 - // 1. 设置窗口全屏 + let windowClass: window. Window = windowStage.getMainWindowSync(); Get the main app window + // 1. Set the window to full screen let isLayoutFullScreen = true; windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); - // 2. 缓存window窗口对象 + // 2. Cache the window object AppStorage.setOrCreate('windowClass', windowClass); }); } -- Gitee From 5626fe875f65c27f59b1b38e6da8cdb50ba1155e Mon Sep 17 00:00:00 2001 From: Gorit Date: Fri, 16 May 2025 10:45:12 +0000 Subject: [PATCH 6/7] update ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets. Signed-off-by: Gorit --- .../entryability/EntryAbilityStatusBarOverlayTwo.ets | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets index 7fbef4d..abcf80c 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityStatusBarOverlayTwo.ets @@ -47,17 +47,17 @@ export default class EntryAbility extends UIAbility { } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); - let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 - // 1. 设置窗口全屏 + let windowClass: window. Window = windowStage.getMainWindowSync(); Get the main app window + // 1. Set the window to full screen let isLayoutFullScreen = true; windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); - // 2. 缓存window窗口对象 + // 2. Caching the window object AppStorage.setOrCreate('windowClass', windowClass); - // 3. 获取布局避让遮挡的区域 + // 3. Gets the area that the layout avoids occlusion let type = window.AvoidAreaType.TYPE_SYSTEM; let avoidArea = windowClass.getWindowAvoidArea(type); - let statusBar = windowClass.getUIContext().px2vp( avoidArea.topRect.height); // 获取状态栏的高度 + let statusBar = windowClass.getUIContext().px2vp( avoidArea.topRect.height); // Get statusBar height AppStorage.setOrCreate('statusBar', statusBar); }); } -- Gitee From 9f6356cb2748a709f0ff2226083878ef8c874362 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Fri, 16 May 2025 20:01:18 +0800 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20ArkUI=20=E6=B3=A8=E9=87=8A=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=20-=20=E5=B0=86=E4=B8=AD=E6=96=87=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E8=BD=AC=E6=8D=A2=E4=B8=BA=E8=8B=B1=E6=96=87=EF=BC=88?= =?UTF-8?q?TabsDemo=E3=80=81AvoidAreaHeight=E3=80=81BottomNavBarHeight?= =?UTF-8?q?=E3=80=81ControlLevelOfCustomDialog=E7=AD=89=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/AddComponentInTabbar.ets | 28 ++++----- .../src/main/ets/pages/AvoidAreaHeight.ets | 10 ++-- .../src/main/ets/pages/BottomNavBarHeight.ets | 4 +- .../src/main/ets/pages/BottomSlideAndOut.ets | 4 +- .../ets/pages/ControlLevelOfCustomDialog.ets | 20 +++---- .../pages/CopyContentDirectlyClipboard.ets | 16 ++--- .../ets/pages/ExcavationScreenAdaptation.ets | 42 ++++++------- .../ets/pages/FullNavigationSubcomponent.ets | 2 +- .../ets/pages/GetAppInformationWithBundle.ets | 4 +- .../pages/GetCoordinatesFromTouchPoint.ets | 4 +- ...lAndVerticalScreenStatusWindowRotation.ets | 10 ++-- .../pages/ImageCanNotUseBindContextMenu.ets | 2 +- .../main/ets/pages/InertialSlidingEffect.ets | 4 +- .../ets/pages/ListFoldAnimationEffect.ets | 4 +- .../ets/pages/ListenForScreenRotation.ets | 6 +- .../src/main/ets/pages/PrivacyDetailsPage.ets | 12 ++-- .../main/ets/pages/ReplaceDefaultTimeSet.ets | 60 +++++++++---------- .../src/main/ets/pages/ResourceNesting.ets | 2 +- .../src/main/ets/pages/ScreenRotation.ets | 8 +-- .../pages/ScreenorizontalVerticalStatus.ets | 4 +- .../ets/pages/SetClickEventInCustomspan.ets | 2 +- .../main/ets/pages/SetOffsetInBindPopup.ets | 6 +- .../ets/pages/SetWindowPrivacyModeInPage.ets | 6 +- .../ets/pages/SettingScreenBrightness.ets | 10 ++-- ArkUI/entry/src/main/ets/pages/SharePopup.ets | 2 +- .../ets/pages/SideSlipEventInterception.ets | 22 +++---- .../ets/pages/StatusbarAndPageOverlap.ets | 2 +- .../StatusbarAndPageOverlapAvoidStatusBar.ets | 2 +- .../main/ets/pages/SwipeActionToNotSlide.ets | 2 +- .../TextExpansionAndCollapseFunctions.ets | 35 +++++------ .../ets/pages/TextSetMaxlinesIsHideText.ets | 10 ++-- .../src/main/ets/pages/TheHeaderTruncated.ets | 4 +- .../src/main/ets/pages/ToggleWithDelay.ets | 2 +- .../src/main/ets/pages/WindowProperties.ets | 4 +- 34 files changed, 178 insertions(+), 177 deletions(-) diff --git a/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets b/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets index a818aa5..e40dc29 100644 --- a/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets +++ b/ArkUI/entry/src/main/ets/pages/AddComponentInTabbar.ets @@ -32,7 +32,7 @@ struct TabsDemo { private controller: TabsController = new TabsController(); private tabsWidth: number = 0; - // 单独的页签 + // Single tab @Builder tab(tabName: string, tabItem: number, tabIndex: number) { Row({ space: 20 }) { @@ -66,12 +66,12 @@ struct TabsDemo { build() { Column() { - // 页签 + // Tab bar Stack({ alignContent: Alignment.TopStart }) { Scroll() { Row() { ForEach(this.tabArray, (item: number, index: number) => { - this.tab('页签' + item, item, index); + this.tab('Tab' + item, item, index); }) Text('+') .width(36) @@ -108,7 +108,7 @@ struct TabsDemo { Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { ForEach(this.tabArray, (item: number, index: number) => { TabContent() { - Text('我是页面' + item + '的内容') + Text('I am the content of page ' + item) .height(300) .width('100%') .fontSize(30) @@ -128,21 +128,21 @@ struct TabsDemo { .backgroundColor('#F1F3F5') .animationDuration(this.animationDuration) .onChange((index: number) => { - this.currentIndex = index; // 监听索引index的变化,实现页签内容的切换。 + this.currentIndex = index; // Listen for index changes to switch tab content. }) .onAnimationStart((index: number, targetIndex: number, event: TabsAnimationEvent) => { - // 切换动画开始时触发该回调。下划线跟着页面一起滑动,同时宽度渐变。 + // Callback when the switching animation starts. The underline slides with the page and the width changes. this.currentIndex = targetIndex; let targetIndexInfo = this.getTextInfo(targetIndex); this.startAnimateTo(this.animationDuration, targetIndexInfo.left, targetIndexInfo.width); }) .onAnimationEnd((index: number, event: TabsAnimationEvent) => { - // 切换动画结束时触发该回调。下划线动画停止。 + // Callback when the switching animation ends. The underline animation stops. let currentIndicatorInfo = this.getCurrentIndicatorInfo(index, event); this.startAnimateTo(0, currentIndicatorInfo.left, currentIndicatorInfo.width); }) .onGestureSwipe((index: number, event: TabsAnimationEvent) => { - // 在页面跟手滑动过程中,逐帧触发该回调。 + // Callback triggered frame by frame during page swipe. let currentIndicatorInfo = this.getCurrentIndicatorInfo(index, event); this.currentIndex = currentIndicatorInfo.index; this.indicatorLeftMargin = currentIndicatorInfo.left; @@ -152,7 +152,7 @@ struct TabsDemo { .height('100%') } - // 获取组件大小、位置、平移缩放旋转及仿射矩阵属性信息。 + // Get component size, position, translation, scaling, rotation, and affine matrix attribute information. private getTextInfo(index: number): Record { let modePosition: componentUtils.ComponentInfo = componentUtils.getRectangleById(index.toString()); return { 'left': this.getUIContext().px2vp(modePosition.windowOffset.x), 'width': this.getUIContext().px2vp(modePosition.size.width) }; @@ -168,7 +168,7 @@ struct TabsDemo { let indexInfo = this.getTextInfo(index); let nextIndexInfo = this.getTextInfo(nextIndex); let swipeRatio = Math.abs(event.currentOffset / this.tabsWidth); - // 页面滑动超过一半,tabBar切换到下一页。 + // When page sliding exceeds half, tabBar switches to the next page. let currentIndex = swipeRatio > 0.5 ? nextIndex : index; let currentLeft = indexInfo.left + (nextIndexInfo.left - indexInfo.left) * swipeRatio; let currentWidth = indexInfo.width + (nextIndexInfo.width - indexInfo.width) * swipeRatio; @@ -177,13 +177,13 @@ struct TabsDemo { private startAnimateTo(duration: number, leftMargin: number, width: number) { animateTo({ - // 动画时长 + // Animation duration duration: duration, - // 动画曲线 + // Animation curve curve: Curve.Linear, - // 播放次数 + // Number of iterations iterations: 1, - // 动画模式 + // Animation mode playMode: PlayMode.Normal, onFinish: () => { console.info('play end'); diff --git a/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets b/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets index 90befb4..2704853 100644 --- a/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets +++ b/ArkUI/entry/src/main/ets/pages/AvoidAreaHeight.ets @@ -33,15 +33,15 @@ struct GetAvoidAreaHeight { let type1 = window.AvoidAreaType.TYPE_SYSTEM; let type2 = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; window.getLastWindow(this.context.getHostContext()).then((data) => { - // 获取系统默认区域,一般包括状态栏、导航栏 + // Get the system default area, usually including the status bar and navigation bar let avoidArea1 = data.getWindowAvoidArea(type1); - // 顶部状态栏高度 + // Top status bar height let statusBarHeight = avoidArea1.topRect.height; - // 底部导航栏高度 + // Bottom navigation bar height let bottomNavHeight = avoidArea1.bottomRect.height; - // 获取导航条区域 + // Get the navigation bar area let avoidArea2 = data.getWindowAvoidArea(type2); - // 获取到导航条区域的高度 + // Get the height of the navigation bar area let indicatorHeight = avoidArea2.bottomRect.height; console.info(`statusBarHeight is ${statusBarHeight}`); console.info(`bottomNavHeight is ${bottomNavHeight}`); diff --git a/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets b/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets index a609d9b..7ff50fc 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomNavBarHeight.ets @@ -29,12 +29,12 @@ struct GetBottomNavBarHeight { build() { Column() { - Button('获取底部手势横条的高度') + Button('Get the height of the bottom gesture bar') .onClick(() => { let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; window.getLastWindow(this.context.getHostContext()).then((data) => { let avoidArea = data.getWindowAvoidArea(type); - // 获取到导航条区域的高度 + // Get the height of the navigation bar area let bottomRectHeight = avoidArea.bottomRect.height; console.info(`window bottomRectHeight is: ${bottomRectHeight}`); }).catch((err: BusinessError) => { diff --git a/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets b/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets index 78607f9..03c334f 100644 --- a/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets +++ b/ArkUI/entry/src/main/ets/pages/BottomSlideAndOut.ets @@ -43,7 +43,7 @@ struct ComponentChild1 { build() { Column() { - Image($r('app.media.ic_banner01'))//resources\base\media路径 + Image($r('app.media.ic_banner01'))// path: resources\base\media .width('100%') .height(200) .onClick(() => { @@ -61,7 +61,7 @@ struct ComponentChild2 { build() { Column() { - Image($r('app.media.ic_banner02'))//resources\base\media路径 + Image($r('app.media.ic_banner02'))// path: resources\base\media .width('100%') .height(200) .onClick(() => { diff --git a/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets b/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets index 7ac984c..394e5bf 100644 --- a/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets +++ b/ArkUI/entry/src/main/ets/pages/ControlLevelOfCustomDialog.ets @@ -45,8 +45,8 @@ struct Test1 { @Component struct CustomDialogDisplayLevel { @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack(); - @State textValue: string = '输入'; - // 显隐控制设置为不占用 + @State textValue: string = 'Input'; + // Visible and hidden control is set to not occupied @State visible: Visibility = Visibility.None; @Builder @@ -62,10 +62,10 @@ struct CustomDialogDisplayLevel { Stack() { Row() { Column() { - Text('我是第一个页面') + Text('I am the first page') .fontSize(30) .fontWeight(FontWeight.Bold) - Button('按钮') + Button('Button') .onClick(() => { console.info('hit me!'); if (this.visible === Visibility.Visible) { @@ -95,7 +95,7 @@ struct CustomDialogDisplayLevel { }) .width('100%') .height('100%') - // 透明度可以自己调节一下 + // set opacity .opacity(0.5) .backgroundColor(Color.Black) .visibility(this.visible) @@ -127,17 +127,17 @@ struct CustomDialogDisplayLevel { } }) { Column() { - Text('安全隐私') + Text('Privacy') .fontSize(20) .margin({ top: 10, bottom: 10 }) - Text('是否跳转到隐私详情页面?') + Text('Do you want to jump to the privacy details page?') .fontSize(16) .margin({ bottom: 10 }) Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('取消') + Button('Cancel') .onClick(() => { if (this.visible === Visibility.Visible) { this.visible = Visibility.None; @@ -147,7 +147,7 @@ struct CustomDialogDisplayLevel { }) .backgroundColor(0xffffff) .fontColor(Color.Black) - Button('确定') + Button('OK') .onClick(() => { this.pageInfos.pushPath({ name: 'pageOne' }); }) @@ -163,7 +163,7 @@ struct CustomDialogDisplayLevel { } } } - //设置弹窗宽度 + // set dialog width .width('100%') } } diff --git a/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets b/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets index 7cb31c4..bda17ff 100644 --- a/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets +++ b/ArkUI/entry/src/main/ets/pages/CopyContentDirectlyClipboard.ets @@ -23,7 +23,7 @@ import { pasteboard } from '@kit.BasicServicesKit'; @Entry @Component struct CopyText { - private textContent: string = '复制我'; + private textContent: string = 'Copy me'; build() { Column() { @@ -47,18 +47,18 @@ struct CopyText { } } -// 定义方法 +// Define method function copyText(text: string) { - // 创建剪贴板内容对象 + // Create clipboard content object const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text); - // 获取系统剪贴板对象 + // Get system clipboard object const systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.setData(pasteboardData); // 将数据放入剪贴板 - systemPasteboard.getData().then((data) => { // 读取剪贴板内容 + systemPasteboard.setData(pasteboardData); // Put data into clipboard + systemPasteboard.getData().then((data) => { // Read clipboard content if (data) { - this.getUIContext().getPromptAction().showToast({ message: '复制成功' }); + this.getUIContext().getPromptAction().showToast({ message: 'Copy succeeded' }); } else { - this.getUIContext().getPromptAction().showToast({ message: '复制失败' }); + this.getUIContext().getPromptAction().showToast({ message: 'Copy failed' }); } }) } diff --git a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets index fb8140a..e402c32 100644 --- a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets +++ b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets @@ -23,21 +23,21 @@ import { common } from '@kit.AbilityKit'; import { batteryInfo } from '@kit.BasicServicesKit'; class TextMargin { - left: number = 0; // 状态栏左偏移量 - right: number = 0; // 状态栏右偏移量 + left: number = 0; // Status bar left offset + right: number = 0; // Status bar right offset } @Entry @Component struct Index { @State date: Date = new Date(); - @State currentTime: string = ''; // 顶部状态栏时间 - @State boundingRect: display.Rect[] = []; // 不可用区域数据 - @State screenWidth: number = 0; // 屏幕宽度 + @State currentTime: string = ''; // Top status bar time + @State boundingRect: display.Rect[] = []; // Unavailable area data + @State screenWidth: number = 0; // Screen width @State displayClass: display.Display | null = null; - @State topTextMargin: TextMargin = { left: 0, right: 0 }; // 顶部状态栏偏移量 + @State topTextMargin: TextMargin = { left: 0, right: 0 }; // Top status bar offset @StorageLink('context') context: common.UIAbilityContext | undefined = - AppStorage.get('context'); // 获取UIAbilityContext + AppStorage.get('context'); // Get UIAbilityContext aboutToAppear(): void { this.displayClass = display.getDefaultDisplaySync(); @@ -49,15 +49,15 @@ struct Index { this.boundingRect = data.boundingRects; this.topTextMargin = this.getBoundingRectPosition(); }) - // 获取小时 + // Get hour let hours = this.date.getHours(); - // 获取分钟 + // Get minute let minutes = this.date.getMinutes(); - // 分钟小于10在前面加0 + // Add 0 before minute if less than 10 this.currentTime = hours.toString() + ':' + (minutes < 10 ? '0' + minutes : minutes.toString()); } - // 退出当前页面时将窗口重新设置成初始状态 + // Reset window to initial state when leaving the page aboutToDisappear() { if (this.context !== undefined) { window.getLastWindow(this.context, async (err, data) => { @@ -72,20 +72,20 @@ struct Index { getBoundingRectPosition(): TextMargin { if (this.boundingRect !== null && this.displayClass !== null && this.boundingRect[0] !== undefined) { - // 不可用区域右侧到屏幕右边界的距离:屏幕宽度减去左侧宽度和不可用区域宽度 + // Distance from the right of the unavailable area to the right edge of the screen: screen width minus left width and unavailable area width let boundingRectRight: number = this.displayClass.width - (this.boundingRect[0].left + this.boundingRect[0].width); - // 不可用区域左侧到屏幕左边界的距离:getCutoutInfo接口可以直接获取 + // Distance from the left of the unavailable area to the left edge of the screen: can be obtained directly by getCutoutInfo let boundingRectLeft: number = this.boundingRect[0].left; - // 部分设备不可用区域在中间时存在左右距离会有10像素以内的差距,获取到的左右距离差值绝对值小于10都按照不可用区域位于中间处理 + // For some devices, if the unavailable area is in the middle, the difference between the left and right distances is less than 10 pixels, treat it as being in the middle if (Math.abs(boundingRectLeft - boundingRectRight) <= 10) { return { left: 0, right: 0 }; } if (boundingRectLeft > boundingRectRight) { - // 不可用区域在右边 + // Unavailable area on the right return { left: 0, right: this.displayClass.width - boundingRectLeft }; } else if (boundingRectLeft < boundingRectRight) { - // 不可用区域在左边 + // Unavailable area on the left return { left: this.boundingRect[0].left + this.boundingRect[0].width, right: 0 }; } } @@ -100,13 +100,13 @@ struct Index { .height('100%') .onClick(() => { this.getUIContext().getPromptAction().showToast({ - message: '该功能暂未开发', + message: 'This function is not yet developed', duration: 2000 }) }) Column() { Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween }) { - Text(this.currentTime) // 时间 + Text(this.currentTime) // Time .fontSize(16) .fontColor(Color.Black) .fontWeight(FontWeight.Regular) @@ -114,8 +114,8 @@ struct Index { .margin({ left: this.getUIContext().px2vp(this.topTextMargin.left), top: 14 - }) // 获取的偏移量单位为px需要进行转换 - Text(batteryInfo.batterySOC.toString() + '%')// 电池电量 + }) // The obtained offset is in px and needs to be converted + Text(batteryInfo.batterySOC.toString() + '%')// Battery level .fontSize(16) .fontColor(Color.Black) .fontWeight(FontWeight.Regular) @@ -123,7 +123,7 @@ struct Index { .margin({ right: this.getUIContext().px2vp(this.topTextMargin.right), top: 14 - }) // 获取的偏移量单位为px需要进行转换 + }) // The obtained offset is in px and needs to be converted } .width('100%') } diff --git a/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets b/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets index 54275cb..d17e1ed 100644 --- a/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets +++ b/ArkUI/entry/src/main/ets/pages/FullNavigationSubcomponent.ets @@ -41,7 +41,7 @@ struct FullNavigationSubcomponent { } .width('100%') .height('100%') - .title('个性化设置') + .title('Personalization Settings') .titleMode(NavigationTitleMode.Mini) .backgroundColor(Color.Grey) } diff --git a/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets b/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets index e1ae650..e6e9d83 100644 --- a/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets +++ b/ArkUI/entry/src/main/ets/pages/GetAppInformationWithBundle.ets @@ -22,8 +22,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { bundleManager } from '@kit.AbilityKit'; // ... bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{ - let versionName = bundleInfo.versionName;//应用版本名 - let versionNo = bundleInfo.versionCode;//应用版本号 + let versionName = bundleInfo.versionName;//App version name + let versionNo = bundleInfo.versionCode;//App version code }).catch((error: BusinessError )=>{ console.error("get bundleInfo failed,error is "+error) }) diff --git a/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets b/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets index 98f4ab3..5345410 100644 --- a/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets +++ b/ArkUI/entry/src/main/ets/pages/GetCoordinatesFromTouchPoint.ets @@ -43,7 +43,7 @@ struct CoordinatesOfTheFingerTouchPoint { this.touchAreaBottom = newValue.height as number; }) .gesture( - // 以下组合手势为顺序识别,当长按手势事件未正常触发时则不会触发拖动手势事件 + // The following combined gestures are recognized sequentially. If the long press gesture event is not triggered normally, the drag gesture event will not be triggered. GestureGroup(GestureMode.Sequence, LongPressGesture({ repeat: true }) .onAction((event: GestureEvent) => { @@ -75,7 +75,7 @@ struct CoordinatesOfTheFingerTouchPoint { }) ) .onCancel(() => { - this.getUIContext().getPromptAction().showToast({ message: '取消', duration: 1000 }); + this.getUIContext().getPromptAction().showToast({ message: 'Cancel', duration: 1000 }); }) ) } diff --git a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets index 8df03bc..7b6af20 100644 --- a/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets +++ b/ArkUI/entry/src/main/ets/pages/GetHorizontalAndVerticalScreenStatusWindowRotation.ets @@ -35,16 +35,16 @@ struct windowRotation { let cutOutInfo = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE) console.log(JSON.stringify(cutOutInfo)) if (window.Orientation.AUTO_ROTATION) { - let rotation: number = display.getDefaultDisplaySync().orientation // 获取当前屏幕的枚举值 + let rotation: number = display.getDefaultDisplaySync().orientation // Get current screen orientation enum value console.log('' + rotation); if (rotation == 0) { - console.log("CutOutInfo 竖屏数据: " + JSON.stringify(cutOutInfo)); + console.log("CutOutInfo Portrait data: " + JSON.stringify(cutOutInfo)); } else if (rotation == 1) { - console.log("CutOutInfo 横屏数据: " + JSON.stringify(cutOutInfo)); + console.log("CutOutInfo Landscape data: " + JSON.stringify(cutOutInfo)); } else if (rotation == 2) { - console.log("CutOutInfo 反向竖屏数据: " + JSON.stringify(cutOutInfo)); + console.log("CutOutInfo Reverse portrait data: " + JSON.stringify(cutOutInfo)); } else { - console.log("CutOutInfo 反向横屏数据: " + JSON.stringify(cutOutInfo)); + console.log("CutOutInfo Reverse landscape data: " + JSON.stringify(cutOutInfo)); } } }) diff --git a/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets b/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets index b33265b..75fcf94 100644 --- a/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets +++ b/ArkUI/entry/src/main/ets/pages/ImageCanNotUseBindContextMenu.ets @@ -43,7 +43,7 @@ struct Index { } .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) .onDragStart(() => { - // 拖拽时关闭菜单 + // Close menu when dragging this.getUIContext().getContextMenuController().close() }) diff --git a/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets b/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets index f8171b3..a26385b 100644 --- a/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets +++ b/ArkUI/entry/src/main/ets/pages/InertialSlidingEffect.ets @@ -36,8 +36,8 @@ struct PanGestureExample { .padding(20) .border({ width: 3 }) .margin(30) - .translate({ x: this.offsetX, y: this.offsetY, z: 0 }) // 以组件左上角为坐标原点进行移动 - // 上下拖动触发该手势事件 + .translate({ x: this.offsetX, y: this.offsetY, z: 0 }) // Move using the component's top-left corner as the coordinate origin + // Trigger gesture event when dragging up and down .gesture( PanGesture(this.panOption) .onActionStart((event?: GestureEvent) => { diff --git a/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets b/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets index f7175bf..7bbae26 100644 --- a/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets +++ b/ArkUI/entry/src/main/ets/pages/ListFoldAnimationEffect.ets @@ -33,7 +33,7 @@ struct ListCollapseExpand { Column() { Row() { Text(item.toString()) - Button(this.isContentShow && this.selectItem === item ? '收起' : '展开') + Button(this.isContentShow && this.selectItem === item ? 'Collapse' : 'Expand') .onClick(() => { this.getUIContext().animateTo({ duration: 300, @@ -50,7 +50,7 @@ struct ListCollapseExpand { .justifyContent(FlexAlign.SpaceBetween) if (this.isContentShow && this.selectItem === item) { - Text('这是内容区域') + Text('This is the content area') .backgroundColor(Color.Gray) .width('100%') .height(100) diff --git a/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets b/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets index 4bcd626..20fcdea 100644 --- a/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets +++ b/ArkUI/entry/src/main/ets/pages/ListenForScreenRotation.ets @@ -20,7 +20,7 @@ // [Start watch_screen_rotation] import { mediaquery, UIContext } from '@kit.ArkUI'; const context = AppStorage.get("context") as UIContext; -let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); // 监听横屏事件 +let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); // Listen for landscape screen events function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { if (mediaQueryResult.matches) { // do something here @@ -28,6 +28,6 @@ function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { // do something here } } -listener.on('change', onPortrait) // 注册回调 -listener.off('change', onPortrait) // 取消注册回调 +listener.on('change', onPortrait) // Register callback +listener.off('change', onPortrait) // Unregister callback // [End watch_screen_rotation] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets b/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets index 142d2df..4243c53 100644 --- a/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets +++ b/ArkUI/entry/src/main/ets/pages/PrivacyDetailsPage.ets @@ -86,17 +86,17 @@ struct DialogJumpRetained { } }) { Column() { - Text('隐私弹窗') + Text('Privacy Dialog') .fontSize(20) .margin({ top: 10, bottom: 10 }) - Text('是否查看隐私详情') + Text('View privacy details?') .fontSize(16) .margin({ bottom: 10 }) Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('关闭弹窗') + Button('Close Dialog') .onClick(() => { if (this.visible === Visibility.Visible) { this.visible = Visibility.None; @@ -104,7 +104,7 @@ struct DialogJumpRetained { this.visible = Visibility.Visible; } }).backgroundColor(0xffffff).fontColor(Color.Black) - Button('跳转详情页') + Button('Go to Details') .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/Second' @@ -132,14 +132,14 @@ struct DialogJumpRetained { @Entry @Component struct Second { - @State message: string = '隐私详情页'; + @State message: string = 'Privacy Details Page'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) - Button('返回').onClick(() => { + Button('Back').onClick(() => { this.getUIContext().getRouter().back({ url: 'pages/DialogJumpRetained' }); diff --git a/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets b/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets index 7887c89..c9e58e6 100644 --- a/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets +++ b/ArkUI/entry/src/main/ets/pages/ReplaceDefaultTimeSet.ets @@ -23,17 +23,17 @@ import { curves } from '@kit.ArkUI'; @Entry @Component struct ReplaceDefaultTimeSetPage { - //元素数组 + // Element array @State numbers: number[] = []; @State row: number = 4; - //元素数组中最后一个元素的索引 + // Index of the last element in the array @State lastIndex: number = 0; @State dragItem: number = -1; @State scaleItem: number = -1; @State item: number = -1; @State offsetX: number = 0; @State offsetY: number = 0; - // row 设置网格列数 + // Set grid column count private str: string = ''; private dragRefOffsetx: number = 0; private dragRefOffsety: number = 0; @@ -46,7 +46,7 @@ struct ReplaceDefaultTimeSetPage { } this.lastIndex = this.numbers.length - 1; - // 多列 + // Multiple columns for (let i = 0; i < this.row; i++) { this.str = this.str + '1fr '; } @@ -60,19 +60,19 @@ struct ReplaceDefaultTimeSetPage { this.numbers.splice(newIndex, 0, tmp[0]); } - //向下滑 + // Slide down down(index: number): void { - // 指定固定GridItem不响应事件 + // Specify fixed GridItem does not respond to events if (!this.isDraggable(index + this.row)) { return; } this.offsetY -= this.FIX_VP_Y; this.dragRefOffsety += this.FIX_VP_Y; - // 多列 + // Multiple columns this.itemMove(index, index + this.row); } - //向下滑(右下角为空) + // Slide down (bottom right is empty) down2(index: number): void { if (!this.isDraggable(index + 3)) { return; @@ -82,7 +82,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index + 3); } - //向上滑 + // Slide up up(index: number): void { if (!this.isDraggable(index - this.row)) { return; @@ -92,7 +92,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index - this.row); } - //向左滑 + // Slide left left(index: number): void { if (!this.isDraggable(index - 1)) { return; @@ -102,7 +102,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index - 1); } - //向右滑 + // Slide right right(index: number): void { if (!this.isDraggable(index + 1)) { return; @@ -112,7 +112,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index + 1); } - //向右下滑 + // Slide bottom right lowerRight(index: number): void { if (!this.isDraggable(index + this.row + 1)) { return; @@ -124,7 +124,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index + this.row + 1); } - //向右上滑 + // Slide top right upperRight(index: number): void { if (!this.isDraggable(index - (this.row - 1))) { return; @@ -136,7 +136,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index - (this.row - 1)); } - //向左下滑 + // Slide bottom left lowerLeft(index: number): void { if (!this.isDraggable(index + (this.row - 1))) { return; @@ -148,7 +148,7 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index + (this.row - 1)); } - //向左上滑 + // Slide top left upperLeft(index: number): void { if (!this.isDraggable(index - (this.row + 1))) { return; @@ -160,9 +160,9 @@ struct ReplaceDefaultTimeSetPage { this.itemMove(index, index - (this.row + 1)); } - //通过元素的索引,控制对应元素是否能移动排序 + // Control whether the element can be moved and sorted by its index isDraggable(index: number): boolean { - return index > -1; //恒成立,所有元素均可移动排序 + return index > -1; // Always成立,所有元素均可移动排序 } build() { @@ -195,18 +195,18 @@ struct ReplaceDefaultTimeSetPage { }) } .onAreaChange((_oldVal, newVal) => { - // 多列 + // Multiple columns this.FIX_VP_X = Math.round(newVal.width as number); this.FIX_VP_Y = Math.round(newVal.height as number); }) - // 指定固定GridItem不响应事件 + // Specify fixed GridItem does not respond to events .hitTestBehavior(this.isDraggable(this.numbers.indexOf(item)) ? HitTestMode.Default : HitTestMode.None) .scale({ x: this.scaleItem === item ? 1.05 : 1, y: this.scaleItem === item ? 1.05 : 1 }) .zIndex(this.dragItem === item ? 1 : 0) .translate(this.dragItem === item ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 }) .padding(10) .gesture( - //以下组合手势为顺序识别,当长按手势事件未正常触发时则不会触发拖动手势事件 + //The following combined gestures are recognized sequentially. If the long press gesture event is not triggered normally, the drag gesture event will not be triggered. GestureGroup(GestureMode.Sequence, LongPressGesture({ repeat: true, @@ -248,44 +248,44 @@ struct ReplaceDefaultTimeSetPage { if (this.offsetY >= this.FIX_VP_Y / 2 && (this.offsetX <= this.FIX_VP_X / 2 && this.offsetX >= -this.FIX_VP_X / 2) && (index + this.row <= this.lastIndex)) { - //向下滑 + // Slide down this.down(index); } else if (this.offsetY <= -this.FIX_VP_Y / 2 && (this.offsetX <= this.FIX_VP_X / 2 && this.offsetX >= -this.FIX_VP_X / 2) && index - this.row >= 0) { - //向上滑 + // Slide up this.up(index); } else if (this.offsetX >= this.FIX_VP_X / 2 && (this.offsetY <= this.FIX_VP_Y / 2 && this.offsetY >= -this.FIX_VP_Y / 2) && !(((index - (this.row - 1)) % this.row === 0) || index === this.lastIndex)) { // ) { - //向右滑 + // Slide right this.right(index); } else if (this.offsetX <= -this.FIX_VP_X / 2 && (this.offsetY <= this.FIX_VP_Y / 2 && this.offsetY >= -this.FIX_VP_Y / 2) && !(index % this.row === 0)) { - //向左滑 + // Slide left this.left(index); } else if (this.offsetX >= this.FIX_VP_X / 2 && this.offsetY >= this.FIX_VP_Y / 2 && ((index + this.row + 1 <= this.lastIndex && !((index - (this.row - 1)) % this.row === 0)) || !((index - (this.row - 1)) % this.row === 0))) { - //向右下滑 + // Slide bottom right this.lowerRight(index); } else if (this.offsetX >= this.FIX_VP_X / 2 && this.offsetY <= -this.FIX_VP_Y / 2 && !((index - this.row < 0) || ((index - (this.row - 1)) % this.row === 0))) { - //向右上滑 + // Slide top right this.upperRight(index); } else if (this.offsetX <= -this.FIX_VP_X / 2 && this.offsetY >= this.FIX_VP_Y / 2 && (!(index % this.row === 0) && (index + (this.row - 1) <= this.lastIndex))) { - //向左下滑 + // Slide bottom left this.lowerLeft(index); } else if (this.offsetX <= -this.FIX_VP_X / 2 && this.offsetY <= -this.FIX_VP_Y / 2 && !((index <= this.row - 1) || (index % this.row === 0))) { - //向左上滑 + // Slide top left this.upperLeft(index); } else if (this.offsetX >= this.FIX_VP_X / 2 && this.offsetY >= this.FIX_VP_Y / 2 && (index === this.lastIndex)) { - //向右下滑(右下角为空) + // Slide right down (bottom right is empty) this.down2(index); } }); @@ -322,7 +322,7 @@ struct ReplaceDefaultTimeSetPage { .width('90%') .editMode(true) .scrollBar(BarState.Off) - // 多列 + // Multiple columns .columnsTemplate(this.str) } .width('100%') diff --git a/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets b/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets index 516f409..8a6fd32 100644 --- a/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets +++ b/ArkUI/entry/src/main/ets/pages/ResourceNesting.ets @@ -27,7 +27,7 @@ struct Page16 { Row() { Column() { Text($r('app.string.EntryAbility1_label2', - this.context.getHostContext()!.resourceManager.getStringSync($r('app.string.EntryAbility_label'))))//resources\base\element\string.json + this.context.getHostContext()!.resourceManager.getStringSync($r('app.string.EntryAbility_label'))))// path: resources\base\element\string.json .fontSize(50) .fontWeight(FontWeight.Bold) } diff --git a/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets b/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets index cc460c5..8672d57 100644 --- a/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets +++ b/ArkUI/entry/src/main/ets/pages/ScreenRotation.ets @@ -23,22 +23,22 @@ import { display, window } from '@kit.ArkUI'; @Component struct ScreenRotation { windowStage: window.WindowStage = AppStorage.get('windowStage') as window.WindowStage; - // 获取主窗口的方式 + // Method to get the main window mainWin: window.Window = this.windowStage.getMainWindowSync(); context = this.getUIContext(); onPageShow() { - // 获取最上层窗口的方式 + // Method to get the top window window.getLastWindow(this.context.getHostContext()); this.mainWin.setPreferredOrientation(window.Orientation.LANDSCAPE); - // 使用display接口获取当前旋转方向,可以放置在监听中持续获取 + // Use display interface to get current rotation direction, can be placed in listener for continuous updates display.getDefaultDisplaySync().rotation; } build() { Row() { Column({ space: 10 }) { - Text('屏幕旋转demo') + Text('Screen rotation demo') .fontSize(25) .margin(20) .fontColor(0x3399FF) diff --git a/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets b/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets index 4bb9922..501fb86 100644 --- a/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets +++ b/ArkUI/entry/src/main/ets/pages/ScreenorizontalVerticalStatus.ets @@ -21,7 +21,7 @@ import { window, display } from '@kit.ArkUI'; const TAG = 'foo' -const ORIENTATION: Array = ['垂直', '水平', '反向垂直', '反向水平'] +const ORIENTATION: Array = ['Portrait', 'Landscape', 'Reverse Portrait', 'Reverse Landscape'] @Entry @Component @@ -37,7 +37,7 @@ struct ScreenTest { // ... } try { - display.on("change", callback); // 监听屏幕状态改变 + display.on("change", callback); // Listen for screen state changes } catch (exception) { console.error(TAG, 'Failed to register callback. Code: ' + JSON.stringify(exception)); } diff --git a/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets b/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets index af87a99..56eaece 100644 --- a/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets +++ b/ArkUI/entry/src/main/ets/pages/SetClickEventInCustomspan.ets @@ -44,7 +44,7 @@ struct Index { .height(25) .onClick(() => { this.getUIContext().getPromptAction().showToast({ - message: '点我删除' + message: 'Click to delete' }) }) } diff --git a/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets b/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets index 5c1c9e6..21716e9 100644 --- a/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets +++ b/ArkUI/entry/src/main/ets/pages/SetOffsetInBindPopup.ets @@ -34,7 +34,7 @@ struct BindPopupOffset { MenuBuilder() { Menu() { MenuItem({ - content: '复制图片', + content: 'Copy image', }) .width(100) .height(50) @@ -43,7 +43,7 @@ struct BindPopupOffset { this.showMenu = false; }) MenuItem({ - content: '剪切' + content: 'Cut' }) .width(100) .height(50) @@ -84,7 +84,7 @@ struct BindPopupOffset { } }) - Web({ src: $rawfile('index.html'), controller: this.controller })//触发自定义弹窗 + Web({ src: $rawfile('index.html'), controller: this.controller })// Trigger custom popup .onContextMenuShow((event) => { if (event) { this.result = event.result; diff --git a/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets index d4d1cd6..7276fbf 100644 --- a/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets +++ b/ArkUI/entry/src/main/ets/pages/SetWindowPrivacyModeInPage.ets @@ -61,13 +61,13 @@ struct WindowPrivacyModePage { .height(40) .margin(20) .onClick(() => { - this.pageStack.pushPath({ name: 'PageOne' }) //将name指定的NavDestination页面信息入栈 + this.pageStack.pushPath({ name: 'PageOne' }) // Push the page info of specified NavDestination into the stack }) } } .navDestination(this.PagesMap) .onNavBarStateChange((isVisible: boolean) => { - // 导航栏显示状态切换时触发该回调 + // Callback triggered when navigation bar display state changes console.info('------>isVisible:' + isVisible) windowUtils.setWindowPrivacyModeInPage(this.context.getHostContext() as common.UIAbilityContext, isVisible); }) @@ -86,7 +86,7 @@ struct PageOne { } .title('pageOne') .onBackPressed(() => { - const popDestinationInfo = this.pageStack.pop(); // 弹出路由栈栈顶元素 + const popDestinationInfo = this.pageStack.pop(); // Pop the top element from the navigation stack return true; }) } diff --git a/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets b/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets index 0b6cd65..c43457a 100644 --- a/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets +++ b/ArkUI/entry/src/main/ets/pages/SettingScreenBrightness.ets @@ -29,16 +29,16 @@ struct SettingScreenBrightness { context = this.getUIContext(); windowStage: window.WindowStage = AppStorage.get('windowStage') as window.WindowStage; - // 获取主窗口的方式 + // Method to get the main window mainWin: window.Window = this.windowStage.getMainWindowSync(); aboutToAppear(): void { - // 修改brightness即可改变屏幕亮度 + // Change screen brightness by modifying brightness let brightness = 1; this.windowStage = AppStorage.get('windowStage') as window.WindowStage; - // 获取主窗口的方式 + // Method to get the main window this.mainWin = this.windowStage.getMainWindowSync(); - // 获取最上层窗口的方式 + // Method to get the top window window.getLastWindow(this.context.getHostContext()); try { this.mainWin.setWindowBrightness(brightness, (err) => { @@ -56,7 +56,7 @@ struct SettingScreenBrightness { build() { Row() { Column({ space: 10 }) { - Text('屏幕亮度设置demo') + Text('Screen brightness setting demo') .fontSize(25) .margin(20) .fontColor(0x3399FF) diff --git a/ArkUI/entry/src/main/ets/pages/SharePopup.ets b/ArkUI/entry/src/main/ets/pages/SharePopup.ets index b6447d3..8f67a06 100644 --- a/ArkUI/entry/src/main/ets/pages/SharePopup.ets +++ b/ArkUI/entry/src/main/ets/pages/SharePopup.ets @@ -76,7 +76,7 @@ function buildText($$: Params) { .scrollBar(BarState.Off) .rowsTemplate('1fr') - Button('取消') + Button('Cancel') .width('100%') .fontColor(Color.Black) .backgroundColor(Color.White) diff --git a/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets b/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets index 992ce0c..cd8af58 100644 --- a/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets +++ b/ArkUI/entry/src/main/ets/pages/SideSlipEventInterception.ets @@ -28,13 +28,13 @@ struct SideslipIntercept { @Provide pageStackForComponentSharedPages: NavPathStack = new NavPathStack(); build() { - // 应用主页用NavDestination承载,用于显示Navigation的内容区 + // Main page uses NavDestination as carrier to display Navigation content area Navigation(this.pageStackForComponentSharedPages) { } .onAppear(() => { this.pageStackForComponentSharedPages.pushPathByName('MainPage', null, false); }) - // 创建NavDestination组件,需使用此组件的onBackPressed回调拦截返回事件 + // Create NavDestination component, use its onBackPressed callback to intercept back event .navDestination(this.textArea) } @@ -56,29 +56,29 @@ struct SideslipIntercept { .height('100%') } .onBackPressed(() => { - // 此处可添加拦截处理逻辑,然后return true放行 + // Interception logic can be added here, then return true to proceed this.getUIContext().getPromptAction().showDialog({ - message: '是否保存', + message: 'Save?', alignment: DialogAlignment.Center, buttons: [ { - text: '不保存', + text: "Don't Save", color: '#0000FF' }, { - text: '保存', + text: 'Save', color: '#0000FF' } ] }).then((data: ShowDialogSuccessResponse) => { - // 操作菜单的响应结果,选中按钮在buttons数组中的索引,从0开始,第二个索引为1 - // 点击不保存按钮 + // When selecting button index in buttons array, starting from 0, second index is 1 + // Click Don't Save button if (data.index === 0) { - console.info('不保存') + console.info('Not saving') } - // 点击保存按钮 + // Click Save button if (data.index === 1) { - console.info('保存') + console.info('Saving') } }) return true ; diff --git a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets index 81b0972..4e8d397 100644 --- a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets +++ b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlap.ets @@ -68,7 +68,7 @@ struct ImagePreviewExample { }) .width('100%') .height('100%') - .opacity(0.16)// 透明度 + .opacity(0.16)// opacity .backgroundColor(Color.Black) .visibility(this.visible) diff --git a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets index 1a0930a..8575f70 100644 --- a/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets +++ b/ArkUI/entry/src/main/ets/pages/StatusbarAndPageOverlapAvoidStatusBar.ets @@ -72,7 +72,7 @@ struct AvoidStatusBar { .height('100%') .alignItems(HorizontalAlign.Center) .justifyContent(FlexAlign.SpaceBetween) - .padding({ top: this.statusBar }) // 此处margin或padding具体数值在实际中应与状态栏区域高度保持一致 + .padding({ top: this.statusBar }) // The specific value of margin or padding here should be consistent with the height of the status bar area in practice .backgroundColor('#008000') } } diff --git a/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets b/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets index 3ccfa67..e774ba5 100644 --- a/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets +++ b/ArkUI/entry/src/main/ets/pages/SwipeActionToNotSlide.ets @@ -29,7 +29,7 @@ export struct SwiperActionRecover { Button('Delete') Button('Set') .onClick(() => { - this.scrollerForList.closeAllSwipeActions(); // 重点是这行代码 + this.scrollerForList.closeAllSwipeActions(); // This is the key line of code }) } .justifyContent(FlexAlign.SpaceEvenly) diff --git a/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets b/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets index cdb1323..7d32071 100644 --- a/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets +++ b/ArkUI/entry/src/main/ets/pages/TextExpansionAndCollapseFunctions.ets @@ -18,18 +18,19 @@ */ // [Start text_collapse_test] -// 文本行宽度 +// Text line width const TEXT_WIDTH: number = 350; -// 收起文本显示行数 +// Number of lines to show when collapsed const COLLAPSE_LINES: number = 2; const ELLIPSIS: string = '...'; -const EXPAND_STR: string = '展开'; -const COLLAPSE_STR: string = '收起'; +const EXPAND_STR: string = 'Expand'; +const COLLAPSE_STR: string = 'Collapse'; const FULL_TEXT: string = - 'HarmonyOS提供了一套UI开发框架,即方舟开发框架(ArkUI框架)。方舟开发框架可为开发者提供应用UI开发' + - '所必需的能力,比如多种组件、布局计算、动画能力、UI交互、绘制等。\n' + - '方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于ArkTS的声明式开发范式(简称“声明式开发范式”)' + - '和兼容JS的类Web开发范式(简称“类Web开发范式”)。以下是两种开发范式的简单对比。' + 'HarmonyOS provides a UI development framework called the ArkUI Framework. The ArkUI Framework provides developers with ' + + 'essential capabilities for application UI development, such as multiple components, layout calculations, animation capabilities, UI interaction, drawing, etc.\n' + + 'The ArkUI Framework offers two development paradigms for developers with different purposes and technical backgrounds: ' + + 'the Declarative Development Paradigm based on ArkTS (referred to as the "Declarative Development Paradigm") ' + + 'and the JS-compatible Web Development Paradigm (referred to as the "Web Development Paradigm"). Here is a simple comparison of these two development paradigms.' @Entry @Component @@ -50,7 +51,7 @@ struct TextCollapseTest { } } - //展开文本 + // Expand text expandText(): void { if (this.needProcess) { this.suffixStr = COLLAPSE_STR; @@ -59,19 +60,19 @@ struct TextCollapseTest { } } - //收起文本 + // Collapse text collapseText(): void { if (!this.needProcess) { return; } - // 展开文本的size + // Size of expanded text let expandSize: SizeOptions = this.getUIContext().getMeasureUtils().measureTextSize({ textContent: FULL_TEXT, constraintWidth: TEXT_WIDTH, fontSize: 30 }); - // 将要收起的文本size + // Size of text to be collapsed let collapseSize: SizeOptions = this.getUIContext().getMeasureUtils().measureTextSize({ textContent: FULL_TEXT, constraintWidth: TEXT_WIDTH, @@ -79,7 +80,7 @@ struct TextCollapseTest { maxLines: COLLAPSE_LINES }); - //收起的文本高度和展开时的文本高度相等时,不进行处理 + // No processing needed when collapsed and expanded text heights are equal if ((expandSize.height as number) == (collapseSize.height as number)) { this.needProcess = false; return; @@ -87,7 +88,7 @@ struct TextCollapseTest { let clipTitle: string = FULL_TEXT this.suffixStr = EXPAND_STR; - // 使用二分法查找正好两行的长度的字符串 + // Use binary search to find string length that fits exactly two lines let leftCursor: number = 0; let rightCursor: number = this.title.length; let cursor: number = Math.floor(rightCursor / 2); @@ -102,16 +103,16 @@ struct TextCollapseTest { }); if ((currentLinesTextSize.height as number) > (collapseSize.height as number)) { - // 当前字符已超过两行,向左继续找 + // Current text exceeds two lines, continue searching left rightCursor = cursor; cursor = leftCursor + Math.floor((cursor - leftCursor) / 2); } else { - // 当前字符小于两行了,可能已经ok,但仍需向右查找 + // Current text less than two lines, might be ok but still need to search right leftCursor = cursor; cursor += Math.floor((rightCursor - cursor) / 2); } if (Math.abs(rightCursor - leftCursor) <= 1) { - // 两次指针基本重合了,代表已找到 + // Pointers almost overlap, meaning we found the position break; } } diff --git a/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets b/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets index 41143f4..fe24848 100644 --- a/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets +++ b/ArkUI/entry/src/main/ets/pages/TextSetMaxlinesIsHideText.ets @@ -22,7 +22,7 @@ @Component struct TextInputExample { @State text: string = ''; - @State truncatedHint: string = "文本未截断"; + @State truncatedHint: string = "Text not truncated"; controller: TextInputController = new TextInputController(); build() { @@ -56,11 +56,11 @@ struct TextInputExample { console.log("textSizeShow2.height=" + textSizeShow2.height); if (textSizeShow2 && textSizeShow1 && textSizeShow2?.height && textSizeShow1?.height && (textSizeShow2?.height > textSizeShow1?.height)) { - console.log("文本截断"); - this.truncatedHint = "文本截断"; + console.log("Text truncated"); + this.truncatedHint = "Text truncated"; } else { - console.log("文本未截断"); - this.truncatedHint = "文本未截断"; + console.log("Text not truncated"); + this.truncatedHint = "Text not truncated"; } }) Text(this.text) diff --git a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets index 0b0dbb7..3181b25 100644 --- a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets +++ b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets @@ -18,7 +18,7 @@ */ // [Start sub_window_page] -// 子窗口页面布局 +// Sub-window page layout import { webview } from '@kit.ArkWeb'; import { window } from '@kit.ArkUI'; @@ -34,7 +34,7 @@ export struct SubWindowPage { aboutToAppear() { window.getLastWindow(getContext(this)).then(currentWindow => { - // 监视软键盘的弹出和收起 + // Monitor keyboard pop-up and collapse currentWindow.on('avoidAreaChange', async data => { let property = currentWindow.getWindowProperties(); let avoidArea = currentWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); diff --git a/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets b/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets index 3650628..792d0f5 100644 --- a/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets +++ b/ArkUI/entry/src/main/ets/pages/ToggleWithDelay.ets @@ -33,7 +33,7 @@ struct ToggleDemo { this.getUIContext().getHostContext()!.getApplicationContext().setColorMode(this.isDarkMode ? 0 : 1); }) } - // 设置hitTestBehavior属性为HitTestMode.Block,阻塞Toggle组件响应事件。 + // Set hitTestBehavior property to HitTestMode.Block to block Toggle component's event response. .hitTestBehavior(HitTestMode.Block) .onClick(() => { setTimeout(() => { diff --git a/ArkUI/entry/src/main/ets/pages/WindowProperties.ets b/ArkUI/entry/src/main/ets/pages/WindowProperties.ets index 87016af..b5786f5 100644 --- a/ArkUI/entry/src/main/ets/pages/WindowProperties.ets +++ b/ArkUI/entry/src/main/ets/pages/WindowProperties.ets @@ -34,9 +34,9 @@ struct WindowProperties { .textAlign(TextAlign.Center) .onClick(() => { window.getLastWindow(this.context.getHostContext()).then((data) => { - // 获取窗口属性 + // get window attribute let properties = data?.getWindowProperties(); - // // 获取窗口宽高 + // Get window width and height console.log("windowClass width: " + properties.windowRect.width); console.log("windowClass height: " + properties.windowRect.height); }); -- Gitee