diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..48439ed68073b99be118d374d1ebd43d04d4c4eb --- /dev/null +++ b/.clang-format @@ -0,0 +1,64 @@ +Language: Cpp +# BasedOnStyle: LLVM +ColumnLimit: 120 +SortIncludes: CaseSensitive +TabWidth: 4 +IndentWidth: 4 +UseTab: Never +AccessModifierOffset: -4 +ContinuationIndentWidth: 4 +IndentCaseBlocks: false +IndentCaseLabels: false +IndentGotoLabels: true +IndentWrappedFunctionNames: false +SortUsingDeclarations: false +NamespaceIndentation: None +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +AlignTrailingComments: true +AlignAfterOpenBracket: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +InsertBraces: false +IndentExternBlock: NoIndent +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false +ReflowComments: true +MaxEmptyLinesToKeep: 2 \ No newline at end of file diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4278fb0641d84107c3c134047ac487368e..e891c02ac390388cd81806409d10c2004f5bbc08 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -20,8 +20,8 @@ }, "modules": [ { - "name": "entry", - "srcPath": "./entry", + "name": "verificationcodescenariosample", + "srcPath": "./verificationcodescenariosample", "targets": [ { "name": "default", @@ -30,6 +30,10 @@ ] } ] + }, + { + "name": "verificationcodescenariolibrary", + "srcPath": "./verificationcodescenariolibrary", } ] } \ No newline at end of file diff --git a/verificationcodescenariolibrary/.gitignore b/verificationcodescenariolibrary/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/verificationcodescenariolibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/verificationcodescenariolibrary/BuildProfile.ets b/verificationcodescenariolibrary/BuildProfile.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /dev/null +++ b/verificationcodescenariolibrary/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/verificationcodescenariolibrary/Index.ets b/verificationcodescenariolibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64a59f4c51ba62a373c350d1bd986d4911351a57 --- /dev/null +++ b/verificationcodescenariolibrary/Index.ets @@ -0,0 +1,2 @@ +export { VerificationCodeScenarioPage } from './src/main/ets/pages/VerificationCodeScenarioPage'; +export { WindowUtil } from './src/main/ets/common/utils/WindowUtil'; \ No newline at end of file diff --git a/verificationcodescenariolibrary/build-profile.json5 b/verificationcodescenariolibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..312d38eb08629793b3484c7373213f22840c8d82 --- /dev/null +++ b/verificationcodescenariolibrary/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/verificationcodescenariolibrary/consumer-rules.txt b/verificationcodescenariolibrary/consumer-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/verificationcodescenariolibrary/hvigorfile.ts b/verificationcodescenariolibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/verificationcodescenariolibrary/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/verificationcodescenariolibrary/obfuscation-rules.txt b/verificationcodescenariolibrary/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/verificationcodescenariolibrary/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/verificationcodescenariolibrary/oh-package.json5 similarity index 55% rename from entry/oh-package.json5 rename to verificationcodescenariolibrary/oh-package.json5 index 803b25293388deda7b9a05a21b5aeadeb716b4d5..7b64a65799faf31642a183efd2b2cbc0e6044a82 100644 --- a/entry/oh-package.json5 +++ b/verificationcodescenariolibrary/oh-package.json5 @@ -1,9 +1,9 @@ { - "name": "entry", + "name": "verificationcodescenariolibrary", "version": "1.0.0", "description": "Please describe the basic information.", - "main": "", + "main": "Index.ets", "author": "", - "license": "", + "license": "Apache-2.0", "dependencies": {} -} \ No newline at end of file +} diff --git a/entry/src/main/ets/common/Constants.ets b/verificationcodescenariolibrary/src/main/ets/common/Constants.ets similarity index 100% rename from entry/src/main/ets/common/Constants.ets rename to verificationcodescenariolibrary/src/main/ets/common/Constants.ets diff --git a/entry/src/main/ets/common/GlobalBuilderContext.ets b/verificationcodescenariolibrary/src/main/ets/common/GlobalBuilderContext.ets similarity index 100% rename from entry/src/main/ets/common/GlobalBuilderContext.ets rename to verificationcodescenariolibrary/src/main/ets/common/GlobalBuilderContext.ets diff --git a/verificationcodescenariolibrary/src/main/ets/common/utils/BreakpointSystem.ets b/verificationcodescenariolibrary/src/main/ets/common/utils/BreakpointSystem.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa7581b2047323eac83c8d9a031e21faabc55bd2 --- /dev/null +++ b/verificationcodescenariolibrary/src/main/ets/common/utils/BreakpointSystem.ets @@ -0,0 +1,118 @@ +/* + * 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. + */ + +import { window } from '@kit.ArkUI'; +import type { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[BreakpointSystem]'; + +export enum BreakpointTypeEnum { + XS = 'xs', + SM = 'sm', + MD = 'md', + LG = 'lg', + XL = 'xl', +} + +export interface BreakpointTypes { + xs?: T; + sm: T; + md: T; + lg: T; + xl?: T; +} + +export class BreakpointType { + private xs: T; + private sm: T; + private md: T; + private lg: T; + private xl: T; + + public constructor(param: BreakpointTypes) { + this.xs = param.xs || param.sm; + this.sm = param.sm; + this.md = param.md; + this.lg = param.lg; + this.xl = param.xl || param.lg; + } + + public getValue(currentBreakpoint: string): T { + if (currentBreakpoint === BreakpointTypeEnum.XS) { + return this.xs; + } + if (currentBreakpoint === BreakpointTypeEnum.SM) { + return this.sm; + } + if (currentBreakpoint === BreakpointTypeEnum.MD) { + return this.md; + } + if (currentBreakpoint === BreakpointTypeEnum.XL) { + return this.xl; + } + return this.lg; + } +} + +export class BreakpointSystem { + private static instance: BreakpointSystem; + private currentBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.MD; + + private constructor() { + } + + public static getInstance(): BreakpointSystem { + if (!BreakpointSystem.instance) { + BreakpointSystem.instance = new BreakpointSystem(); + } + return BreakpointSystem.instance; + } + + public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { + if (this.currentBreakpoint !== breakpoint) { + this.currentBreakpoint = breakpoint; + AppStorage.setOrCreate('currentBreakpoint', this.currentBreakpoint); + } + } + + public onWindowSizeChange(window: window.Window): void { + this.updateWidthBp(window); + } + + public updateWidthBp(window: window.Window): void { + try { + const mainWindow: window.WindowProperties = window.getWindowProperties(); + const windowWidth: number = mainWindow.windowRect.width; + const windowWidthVp = px2vp(windowWidth); + let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.MD; + if (windowWidthVp < 320) { + widthBp = BreakpointTypeEnum.XS; + } else if (windowWidthVp >= 320 && windowWidthVp < 600) { + widthBp = BreakpointTypeEnum.SM; + } else if (windowWidthVp >= 600 && windowWidthVp < 840) { + widthBp = BreakpointTypeEnum.MD; + } else if (windowWidthVp >= 840 && windowWidthVp < 1440) { + widthBp = BreakpointTypeEnum.LG; + } else { + widthBp = BreakpointTypeEnum.XL; + } + this.updateCurrentBreakpoint(widthBp); + } catch (error) { + const err: BusinessError = error as BusinessError; + hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + } + } +} \ No newline at end of file diff --git a/verificationcodescenariolibrary/src/main/ets/common/utils/WindowUtil.ets b/verificationcodescenariolibrary/src/main/ets/common/utils/WindowUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..c60b494dc867671bf4650835c2b23d6a2d43ce15 --- /dev/null +++ b/verificationcodescenariolibrary/src/main/ets/common/utils/WindowUtil.ets @@ -0,0 +1,70 @@ +/* + * 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. + */ + +import { window } from '@kit.ArkUI'; +import type { BusinessError } from '@kit.BasicServicesKit'; +import { BreakpointSystem } from './BreakpointSystem'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[WindowUtil]'; + +export class WindowUtil { + public static requestFullScreen(windowStage: window.WindowStage): void { + windowStage.getMainWindow((err: BusinessError, data: window.Window) => { + if (err.code) { + return; + } + const windowClass: window.Window = data; + // Realize the immersive effect. + try { + const promise: Promise = windowClass.setWindowLayoutFullScreen(true); + promise.then(() => { + hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + hilog.info(0x0000, TAG, + `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); + }); + } catch { + hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); + } + }); + } + + public static registerBreakPoint(windowStage: window.WindowStage) { + windowStage.getMainWindow((err: BusinessError, data: window.Window) => { + if (err.code) { + hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); + return; + } + AppStorage.setOrCreate('windowClass', data); + data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); + data.on('avoidAreaChange', (avoidAreaOption) => { + if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || + avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); + } + }); + }) + } + + // Get status bar height and indicator height. + public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + if (type === window.AvoidAreaType.TYPE_SYSTEM) { + AppStorage.setOrCreate('topRectHeight', px2vp(area.topRect.height)); + } else { + AppStorage.setOrCreate('bottomRectHeight', px2vp(area.bottomRect.height)); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/BackgroundColorChange.ets b/verificationcodescenariolibrary/src/main/ets/pages/BackgroundColorChange.ets similarity index 99% rename from entry/src/main/ets/pages/BackgroundColorChange.ets rename to verificationcodescenariolibrary/src/main/ets/pages/BackgroundColorChange.ets index dd844c291fbac0b12a47ed3b05abd0304cb711c5..54033fac347b2956556ebbf39bd4b5844c2c7faf 100644 --- a/entry/src/main/ets/pages/BackgroundColorChange.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/BackgroundColorChange.ets @@ -206,7 +206,7 @@ struct BackgroundColorChange { $r('sys.float.padding_level16')).GetValue(this.curBp), right: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), $r('sys.float.padding_level16')).GetValue(this.curBp), - top: px2vp(this.topRectHeight) + top: this.topRectHeight }) .height(Constants.ONE_HUNDRED_PERCENT) .width(Constants.ONE_HUNDRED_PERCENT) diff --git a/entry/src/main/ets/pages/BottomWithBar.ets b/verificationcodescenariolibrary/src/main/ets/pages/BottomWithBar.ets similarity index 99% rename from entry/src/main/ets/pages/BottomWithBar.ets rename to verificationcodescenariolibrary/src/main/ets/pages/BottomWithBar.ets index 1638cd76b056faee16412f55b87af27e29a5c9b3..ceb96b05dffa9d326157aec2bc2305e288d881d7 100644 --- a/entry/src/main/ets/pages/BottomWithBar.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/BottomWithBar.ets @@ -102,7 +102,7 @@ struct BottomWithBar { $r('sys.float.padding_level16')).GetValue(this.curBp), right: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), $r('sys.float.padding_level16')).GetValue(this.curBp), - top: px2vp(this.topRectHeight) + top: this.topRectHeight }) .height(Constants.ONE_HUNDRED_PERCENT) .width(Constants.ONE_HUNDRED_PERCENT) diff --git a/entry/src/main/ets/pages/SelectVerificationCode.ets b/verificationcodescenariolibrary/src/main/ets/pages/SelectVerificationCode.ets similarity index 97% rename from entry/src/main/ets/pages/SelectVerificationCode.ets rename to verificationcodescenariolibrary/src/main/ets/pages/SelectVerificationCode.ets index 230b16f7ac6245079d90a4a275fc5b61f83bff87..267a16b2e780679a0aca65f6c73dda1a7791ba91 100644 --- a/entry/src/main/ets/pages/SelectVerificationCode.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/SelectVerificationCode.ets @@ -171,7 +171,7 @@ struct SelectVerificationCode { .translate({ x: this.oneX - (this.curBp === 'sm' ? Constants.PADDING_SM : this.curBp === 'md' ? Constants.PADDING_MD : Constants.PADDING_LG), - y: this.oneY - px2vp(this.topRectHeight) - Constants.BAR_HEIGHT + y: this.oneY - this.topRectHeight - Constants.BAR_HEIGHT }) .visibility(this.showNumberIcon[0]) Text(Constants.TWO.toString()) @@ -179,7 +179,7 @@ struct SelectVerificationCode { .translate({ x: this.twoX - (this.curBp === 'sm' ? Constants.PADDING_SM : this.curBp === 'md' ? Constants.PADDING_MD : Constants.PADDING_LG), - y: this.twoY - px2vp(this.topRectHeight) - Constants.BAR_HEIGHT + y: this.twoY - this.topRectHeight - Constants.BAR_HEIGHT }) .visibility(this.showNumberIcon[1]) Text(Constants.THREE.toString()) @@ -187,7 +187,7 @@ struct SelectVerificationCode { .translate({ x: this.threeX - (this.curBp === 'sm' ? Constants.PADDING_SM : this.curBp === 'md' ? Constants.PADDING_MD : Constants.PADDING_LG), - y: this.threeY - px2vp(this.topRectHeight) - Constants.BAR_HEIGHT + y: this.threeY - this.topRectHeight - Constants.BAR_HEIGHT }) .visibility(this.showNumberIcon[2]) @@ -196,7 +196,7 @@ struct SelectVerificationCode { .translate({ x: this.fourX - (this.curBp === 'sm' ? Constants.PADDING_SM : this.curBp === 'md' ? Constants.PADDING_MD : Constants.PADDING_LG), - y: this.fourY - px2vp(this.topRectHeight) - Constants.BAR_HEIGHT + y: this.fourY - this.topRectHeight - Constants.BAR_HEIGHT }) .visibility(this.showNumberIcon[3]) @@ -342,7 +342,7 @@ struct SelectVerificationCode { $r('sys.float.padding_level16')).GetValue(this.curBp), right: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), $r('sys.float.padding_level16')).GetValue(this.curBp), - top: px2vp(this.topRectHeight) + top: this.topRectHeight }) .width(Constants.ONE_HUNDRED_PERCENT) .height(Constants.ONE_HUNDRED_PERCENT) diff --git a/entry/src/main/ets/pages/SliderVerificationCode.ets b/verificationcodescenariolibrary/src/main/ets/pages/SliderVerificationCode.ets similarity index 99% rename from entry/src/main/ets/pages/SliderVerificationCode.ets rename to verificationcodescenariolibrary/src/main/ets/pages/SliderVerificationCode.ets index f7858d375bf4aea00b46a95204d39028cfe4b7a8..c4e557cbce649fca20a16f07926138253eb272ff 100644 --- a/entry/src/main/ets/pages/SliderVerificationCode.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/SliderVerificationCode.ets @@ -150,7 +150,7 @@ struct SliderVerificationCode { }) } .padding({ - top: px2vp(this.topRectHeight) + top: this.topRectHeight }) .width(Constants.ONE_HUNDRED_PERCENT) .height(Constants.ONE_HUNDRED_PERCENT) diff --git a/entry/src/main/ets/pages/TextBoxShowCursor.ets b/verificationcodescenariolibrary/src/main/ets/pages/TextBoxShowCursor.ets similarity index 99% rename from entry/src/main/ets/pages/TextBoxShowCursor.ets rename to verificationcodescenariolibrary/src/main/ets/pages/TextBoxShowCursor.ets index f1cc4bedfbbd18fe39a0bcc03065901b04fbfa97..0aa7b1d90bd90376f0095acef58424a01abac013 100644 --- a/entry/src/main/ets/pages/TextBoxShowCursor.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/TextBoxShowCursor.ets @@ -296,7 +296,7 @@ struct TextBoxShowCursor { $r('sys.float.padding_level16')).GetValue(this.curBp), right: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), $r('sys.float.padding_level16')).GetValue(this.curBp), - top: px2vp(this.topRectHeight) + top: this.topRectHeight }) .height(Constants.ONE_HUNDRED_PERCENT) .width(Constants.ONE_HUNDRED_PERCENT) diff --git a/entry/src/main/ets/pages/Index.ets b/verificationcodescenariolibrary/src/main/ets/pages/VerificationCodeScenarioPage.ets similarity index 72% rename from entry/src/main/ets/pages/Index.ets rename to verificationcodescenariolibrary/src/main/ets/pages/VerificationCodeScenarioPage.ets index 9784443a828630ddf4b61c8d1a57430122a843b5..a3cad0ada7f2b42d232e56e1d1d742d79330b2b6 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/verificationcodescenariolibrary/src/main/ets/pages/VerificationCodeScenarioPage.ets @@ -1,25 +1,9 @@ -/* - * 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. - */ +import Constants from "../common/Constants"; +import { GlobalBuilderContext } from "../common/GlobalBuilderContext"; +import { NavDestinationItem } from "../viewmodel/NavDestinationItem"; -import Constants from '../common/Constants'; -import { NavDestinationItem } from '../viewmodel/NavDestinationItem'; -import { GlobalBuilderContext } from '../common/GlobalBuilderContext'; - -@Entry @Component -struct Index { +export struct VerificationCodeScenarioPage { private navDestinationData: NavDestinationItem[] = Constants.NAV_DESTINATION_DATA; @Provide('pathInfos') pathInfos: NavPathStack = new NavPathStack(); @StorageProp('currentBreakpoint') curBp: string = Constants.BREAKPOINTS[0]; @@ -78,12 +62,12 @@ struct Index { .padding({ left: $r('sys.float.padding_level8'), right: $r('sys.float.padding_level8'), - top: Constants.PADDING_TOP_INDEX + px2vp(this.topRectHeight), - bottom: Constants.PADDING_BOTTOM_INDEX + px2vp(this.bottomRectHeight) + top: Constants.PADDING_TOP_INDEX + this.topRectHeight, + bottom: Constants.PADDING_BOTTOM_INDEX + this.bottomRectHeight }) } .mode(NavigationMode.Stack) .hideTitleBar(true) .navDestination(this.PagesMap) } -} \ No newline at end of file +} diff --git a/entry/src/main/ets/viewmodel/NavDestinationItem.ets b/verificationcodescenariolibrary/src/main/ets/viewmodel/NavDestinationItem.ets similarity index 100% rename from entry/src/main/ets/viewmodel/NavDestinationItem.ets rename to verificationcodescenariolibrary/src/main/ets/viewmodel/NavDestinationItem.ets diff --git a/verificationcodescenariolibrary/src/main/module.json5 b/verificationcodescenariolibrary/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f319c26bbd34fbd652c9ec43d4b8fcb72ec647c7 --- /dev/null +++ b/verificationcodescenariolibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "verificationcodescenariolibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/entry/src/main/resources/base/element/color.json b/verificationcodescenariolibrary/src/main/resources/base/element/color.json similarity index 100% rename from entry/src/main/resources/base/element/color.json rename to verificationcodescenariolibrary/src/main/resources/base/element/color.json diff --git a/entry/src/main/resources/base/element/float.json b/verificationcodescenariolibrary/src/main/resources/base/element/float.json similarity index 100% rename from entry/src/main/resources/base/element/float.json rename to verificationcodescenariolibrary/src/main/resources/base/element/float.json diff --git a/entry/src/main/resources/base/element/string.json b/verificationcodescenariolibrary/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to verificationcodescenariolibrary/src/main/resources/base/element/string.json diff --git a/entry/src/main/resources/base/media/background.png b/verificationcodescenariolibrary/src/main/resources/base/media/background.png similarity index 100% rename from entry/src/main/resources/base/media/background.png rename to verificationcodescenariolibrary/src/main/resources/base/media/background.png diff --git a/entry/src/main/resources/base/media/button.png b/verificationcodescenariolibrary/src/main/resources/base/media/button.png similarity index 100% rename from entry/src/main/resources/base/media/button.png rename to verificationcodescenariolibrary/src/main/resources/base/media/button.png diff --git a/entry/src/main/resources/base/media/foreground.png b/verificationcodescenariolibrary/src/main/resources/base/media/foreground.png similarity index 100% rename from entry/src/main/resources/base/media/foreground.png rename to verificationcodescenariolibrary/src/main/resources/base/media/foreground.png diff --git a/entry/src/main/resources/base/media/img_1.png b/verificationcodescenariolibrary/src/main/resources/base/media/img_1.png similarity index 100% rename from entry/src/main/resources/base/media/img_1.png rename to verificationcodescenariolibrary/src/main/resources/base/media/img_1.png diff --git a/entry/src/main/resources/base/media/layered_image.json b/verificationcodescenariolibrary/src/main/resources/base/media/layered_image.json similarity index 100% rename from entry/src/main/resources/base/media/layered_image.json rename to verificationcodescenariolibrary/src/main/resources/base/media/layered_image.json diff --git a/entry/src/main/resources/base/media/slider.png b/verificationcodescenariolibrary/src/main/resources/base/media/slider.png similarity index 100% rename from entry/src/main/resources/base/media/slider.png rename to verificationcodescenariolibrary/src/main/resources/base/media/slider.png diff --git a/entry/src/main/resources/base/media/sliderBackground.png b/verificationcodescenariolibrary/src/main/resources/base/media/sliderBackground.png similarity index 100% rename from entry/src/main/resources/base/media/sliderBackground.png rename to verificationcodescenariolibrary/src/main/resources/base/media/sliderBackground.png diff --git a/entry/src/main/resources/base/media/startIcon.png b/verificationcodescenariolibrary/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to verificationcodescenariolibrary/src/main/resources/base/media/startIcon.png diff --git a/entry/src/main/resources/en_US/element/string.json b/verificationcodescenariolibrary/src/main/resources/en_US/element/string.json similarity index 100% rename from entry/src/main/resources/en_US/element/string.json rename to verificationcodescenariolibrary/src/main/resources/en_US/element/string.json diff --git a/entry/src/main/resources/zh_CN/element/string.json b/verificationcodescenariolibrary/src/main/resources/zh_CN/element/string.json similarity index 100% rename from entry/src/main/resources/zh_CN/element/string.json rename to verificationcodescenariolibrary/src/main/resources/zh_CN/element/string.json diff --git a/entry/build-profile.json5 b/verificationcodescenariosample/build-profile.json5 similarity index 100% rename from entry/build-profile.json5 rename to verificationcodescenariosample/build-profile.json5 diff --git a/entry/hvigorfile.ts b/verificationcodescenariosample/hvigorfile.ts similarity index 100% rename from entry/hvigorfile.ts rename to verificationcodescenariosample/hvigorfile.ts diff --git a/entry/obfuscation-rules.txt b/verificationcodescenariosample/obfuscation-rules.txt similarity index 100% rename from entry/obfuscation-rules.txt rename to verificationcodescenariosample/obfuscation-rules.txt diff --git a/verificationcodescenariosample/oh-package-lock.json5 b/verificationcodescenariosample/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a4eddf9931e267778e30206055eeaaeeb6e6d5a0 --- /dev/null +++ b/verificationcodescenariosample/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "verificationcodescenariolibrary@../verificationcodescenariolibrary": "verificationcodescenariolibrary@../verificationcodescenariolibrary" + }, + "packages": { + "verificationcodescenariolibrary@../verificationcodescenariolibrary": { + "name": "verificationcodescenariolibrary", + "version": "1.0.0", + "resolved": "../verificationcodescenariolibrary", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/verificationcodescenariosample/oh-package.json5 b/verificationcodescenariosample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..283d99fbbf513762f5c6c50818b21f545cbb25cc --- /dev/null +++ b/verificationcodescenariosample/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "verificationcodescenariosample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "verificationcodescenariolibrary": "file:../verificationcodescenariolibrary" + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/verificationcodescenariosample/src/main/ets/entryability/EntryAbility.ets similarity index 45% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to verificationcodescenariosample/src/main/ets/entryability/EntryAbility.ets index 703915b8d06c8a51f1320b6a7dd4774128345a78..e15bcb0add95ff10175a0e3f9f8bae358f4b29fc 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/verificationcodescenariosample/src/main/ets/entryability/EntryAbility.ets @@ -14,9 +14,10 @@ */ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { display, window } from '@kit.ArkUI'; +import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { WindowUtil } from 'verificationcodescenariolibrary'; + const TAG: string = '[EntryAbility]'; @@ -33,38 +34,8 @@ export default class EntryAbility extends UIAbility { } onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.getMainWindow().then((windowObj: window.Window) => { - try { - let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = windowObj.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }); - - windowObj.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause: %{public}s', - `the code is ${err.code}, the message is ${err.message}`); - }); - - AppStorage.setOrCreate('windowClass', windowObj); - } catch (error) { - const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, 'get window info catch err: Cause: %{public}s', - `the code is ${err.code}, the message is ${err.message}`); - } - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to get main window. Cause:`, err.message); - }); + WindowUtil.requestFullScreen(windowStage) + WindowUtil.registerBreakPoint(windowStage) windowStage.loadContent('pages/Index', (err, _data) => { if (err.code) { hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', @@ -89,26 +60,4 @@ export default class EntryAbility extends UIAbility { // Ability has back to background hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); } - - private updateBreakpoint(windowWidth: number): void { - try { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < 600) { - newBp = 'sm'; - } else if (windowWidthVp < 840) { - newBp = 'md'; - } else { - newBp = 'lg'; - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); - } - } catch (error) { - const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, '%{public}s', - `An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); - } - } } diff --git a/verificationcodescenariosample/src/main/ets/pages/Index.ets b/verificationcodescenariosample/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6aaa5002898a96ccc9e7ec7791a867c5f146f1cd --- /dev/null +++ b/verificationcodescenariosample/src/main/ets/pages/Index.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ + +import Constants from 'verificationcodescenariolibrary/src/main/ets/common/Constants'; +import { NavDestinationItem } from 'verificationcodescenariolibrary/src/main/ets/viewmodel/NavDestinationItem'; +import { GlobalBuilderContext } from 'verificationcodescenariolibrary/src/main/ets/common/GlobalBuilderContext'; +import { VerificationCodeScenarioPage } from 'verificationcodescenariolibrary'; + +@Entry +@Component +struct Index { + build() { + Stack() { + VerificationCodeScenarioPage() + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/verificationcodescenariosample/src/main/module.json5 similarity index 86% rename from entry/src/main/module.json5 rename to verificationcodescenariosample/src/main/module.json5 index b2b33b8607d3688403661c437df3b87ee32d03ab..e9397545980e9c8b1f8cc7b21c75f02b59cf3b95 100644 --- a/entry/src/main/module.json5 +++ b/verificationcodescenariosample/src/main/module.json5 @@ -1,6 +1,6 @@ { "module": { - "name": "entry", + "name": "verificationcodescenariosample", "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -14,14 +14,14 @@ "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "VerificationcodescenariosampleAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": false, + "exported": true, "skills": [ { "entities": [ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/verificationcodescenariosample/src/main/resources/base/profile/main_pages.json similarity index 100% rename from entry/src/main/resources/base/profile/main_pages.json rename to verificationcodescenariosample/src/main/resources/base/profile/main_pages.json