初次提交,截止到 基础课程:3、<HarmonyOS第一课>ArkTS语法介绍

This commit is contained in:
huangge1199 2024-10-25 09:18:47 +08:00
parent af5b43303f
commit 02fea1b4a8
55 changed files with 1614 additions and 0 deletions

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
/.appanalyzer

10
AppScope/app.json5 Normal file
View File

@ -0,0 +1,10 @@
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

41
build-profile.json5 Normal file
View File

@ -0,0 +1,41 @@
{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}

20
code-linter.json5 Normal file
View File

@ -0,0 +1,20 @@
{
"files": [
"**/*.ets"
],
"ignore": [
"**/src/ohosTest/**/*",
"**/src/test/**/*",
"**/src/mock/**/*",
"**/node_modules/**/*",
"**/oh_modules/**/*",
"**/build/**/*",
"**/.preview/**/*"
],
"ruleSet": [
"plugin:@performance/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
}
}

6
entry/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test

28
entry/build-profile.json5 Normal file
View File

@ -0,0 +1,28 @@
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}

6
entry/hvigorfile.ts Normal file
View File

@ -0,0 +1,6 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}

View File

@ -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

10
entry/oh-package.json5 Normal file
View File

@ -0,0 +1,10 @@
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {}
}

View File

@ -0,0 +1,144 @@
/*
* 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 { Link } from './Link'
/**
* Common constants for all features.
*/
export class CommonConstants {
/**
* String for input content.
*/
static readonly OFFSET_X: number = 0;
/**
* String for input content.
*/
static readonly OFFSET_Y: number = -25;
/**
* Number for zip level.
*/
static readonly PERCENT_NINETY: string = '90%';
/**
* Number for zip level.
*/
static readonly PERCENT_FULL: string = '100%';
/**
* Number for zip level.
*/
static readonly FONT_WEIGHT_SEVEN_HUNDRED: number = 700;
/**
* Number for zip level.
*/
static readonly LEAP_YEAR_INPUT: string = '请输入一个年份';
/**
* Number for zip level.
*/
static readonly LEAP_YEAR_YES: string = '该年份是闰年';
/**
* Number for zip level.
*/
static readonly LEAP_YEAR_NO: string = '该年份不是闰年';
/**
* Number for zip level.
*/
static readonly STRING_INPUT: string = '请输入一个字符串';
/**
* Number for zip level.
*/
static readonly PALINDROMIC_STRING_YES: string = '该字符串是回文字符串';
/**
* Number for zip level.
*/
static readonly PALINDROMIC_STRING_NO: string = '该字符串不是回文字符串';
/**
* Number for zip level.
*/
static readonly STRING_PRE: string = '反转结果为:';
/**
* The time of toast
*/
static readonly TOAST_TIME: number = 2000;
/**
* Full width or height.
*/
static readonly FULL_LENGTH: string = '100%';
/**
* Title height.
*/
static readonly TITLE_WIDTH: string = '80%';
/**
* List default width.
*/
static readonly LIST_DEFAULT_WIDTH: string = '93.3%';
/**
* Opacity of default.
*/
static readonly OPACITY_DEFAULT: number = 1;
/**
* Opacity of default.
*/
static readonly OPACITY_COMPLETED: number = 0.4;
/**
* BorderRadius of list item.
*/
static readonly BORDER_RADIUS: number = 24;
/**
* BorderRadius of list item.
*/
static readonly FONT_WEIGHT: number = 500;
/**
* Space of column.
*/
static readonly COLUMN_SPACE: number = 16;
/**
* agents data.
*/
static readonly TODO_DATA: Array<string> = [
"早起晨练",
"准备早餐",
"阅读名著",
"学习ArkTS",
"看剧放松"
];
/**
* 跳转路由
*/
static readonly LINK_DATA: Link[] = [
new Link("第二页","pages/Second"),
new Link("方法页","pages/Method"),
new Link("待办页","pages/ToDoListPage")
];
}

View File

@ -0,0 +1,9 @@
export class Link {
name: string = ''
path: string = ''
constructor(name: string, path: string) {
this.name = name;
this.path = path;
}
}

View File

@ -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.
*/
import { promptAction } from '@kit.ArkUI';
import { CommonConstants } from '../constants/Constants';
export class CommonUtils {
showToast(message: string) {
promptAction.showToast({
message: message,
duration: CommonConstants.TOAST_TIME
});
}
}
let commonUtils = new CommonUtils();
export default commonUtils as CommonUtils;

View File

@ -0,0 +1,55 @@
/*
* 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 { hilog } from '@kit.PerformanceAnalysisKit';
const LOGGER_PREFIX: string = 'ArkTSAlgorithm';
class Logger {
private domain: number;
private prefix: string;
// format Indicates the log format string.
private format: string = '%{public}s, %{public}s';
/**
* constructor.
*
* @param prefix Identifies the log tag.
* @param domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF
* @param args Indicates the log parameters.
*/
constructor(prefix: string = '', domain: number = 0xFF00) {
this.prefix = prefix;
this.domain = domain;
}
debug(...args: string[]): void {
hilog.debug(this.domain, this.prefix, this.format, args);
}
info(...args: string[]): void {
hilog.info(this.domain, this.prefix, this.format, args);
}
warn(...args: string[]): void {
hilog.warn(this.domain, this.prefix, this.format, args);
}
error(...args: string[]): void {
hilog.error(this.domain, this.prefix, this.format, args);
}
}
export default new Logger(LOGGER_PREFIX, 0xFF02);

View File

@ -0,0 +1,66 @@
// Method.ets
// 水仙花数
export function daffodilsNumber(): number[] {
let result: number[] = [];
for (let i = 100; i < 1000; i++) {
let unitsDigit: number = i % 10;
let tenthsDigit: number = Math.floor(i / 10) - Math.floor(i / 100) * 10;
let hundredthsDigit: number = Math.floor(i / 100);
if (i === unitsDigit * unitsDigit * unitsDigit + tenthsDigit * tenthsDigit * tenthsDigit +
hundredthsDigit * hundredthsDigit * hundredthsDigit) {
result.push(i);
}
}
return result;
}
// 九九乘法表
export function multiplicationTable(): string[][] {
let result: string[][] = [];
for (let i = 1; i <= 9; i++) {
let index: string[] = [];
for (let j = 1; j <= i; j++) {
let temp: string = j + ' * ' + i + ' = ' + i * j;
index.push(temp);
}
result.push(index);
}
return result;
}
// 回文字符串判断
export function IsPalindromicString(content: string): boolean {
let result: boolean = true;
let i: number = 0;
let j: number = content.length - 1;
while (i <= j) {
if (content.charAt(i) !== content.charAt(j)) {
result = false;
break;
}
i++;
j--;
}
return result;
}
// 字符串反转
export function StringReversal(content: string): string {
let result: string = '';
for (let index = content.length - 1; index >= 0; index--) {
result += content.charAt(index);
}
return result;
}
// 闰年判断
export function isLeapYear(year: number): boolean {
let result: boolean = false;
if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
result = true;
} else {
result = false;
}
return result;
}

View File

@ -0,0 +1,41 @@
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
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.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.');
});
}
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');
}
}

View File

@ -0,0 +1,12 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
export default class EntryBackupAbility extends BackupExtensionAbility {
async onBackup() {
hilog.info(0x0000, 'testTag', 'onBackup ok');
}
async onRestore(bundleVersion: BundleVersion) {
hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
}
}

View File

@ -0,0 +1,55 @@
// Index.ets
// 导入页面路由模块
import { router } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
import { Link } from '../common/constants/Link';
import DataModel from '../viewmodel/DataModel';
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
private linkData: Link[] = [];
aboutToAppear() {
this.linkData = DataModel.getLinkData();
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
// 添加按钮,以响应用户点击
ForEach(this.linkData, (link: Link) => {
Button() {
Text(link.name)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
.onClick(() => {
console.info(`Succeeded in clicking the 'Next' button.`)
router.pushUrl({ url: link.path }).then(() => {
console.info('Succeeded in jumping to the second page.')
}).catch((err: BusinessError) => {
console.error(`Failed to jump to the second page. Code is ${err.code}, message is ${err.message}`)
})
})
}, (link: Link) => JSON.stringify(link))
}
.width('100%')
}
.height('100%')
}
}

View File

@ -0,0 +1,101 @@
import { CommonConstants } from '../common/constants/Constants';
import Logger from '../common/utils/Logger';
import { multiplicationTable } from '../common/utils/Method';
import { DaffodilsNumberCustomDialog } from '../view/DaffodilsNumberCustomDialog';
import { IsLeapYearCustomDialog } from '../view/IsLeapYearCustomDialog';
import { IsPalindromicStringCustomDialog } from '../view/IsPalindromicStringCustomDialog';
import { MultiplicationTableCustomDialog } from '../view/MultiplicationTableCustomDialog';
import { StringReversalCustomDialog } from '../view/StringReversalCustomDialog';
import BackView from '../view/BackView';
@Entry
@Component
struct Method {
daffodilsNumberCustomDialogController: CustomDialogController | null = new CustomDialogController({
builder: DaffodilsNumberCustomDialog(),
alignment: DialogAlignment.Center,
offset: { dx: CommonConstants.OFFSET_X, dy: CommonConstants.OFFSET_Y }
});
multiplicationTableCustomDialogController: CustomDialogController | null = new CustomDialogController({
builder: MultiplicationTableCustomDialog(),
alignment: DialogAlignment.Center,
offset: { dx: CommonConstants.OFFSET_X, dy: CommonConstants.OFFSET_Y }
});
isPalindromicStringCustomDialogController: CustomDialogController | null = new CustomDialogController({
builder: IsPalindromicStringCustomDialog(),
alignment: DialogAlignment.Center,
offset: { dx: CommonConstants.OFFSET_X, dy: CommonConstants.OFFSET_Y }
});
stringReversalCustomDialogController: CustomDialogController | null = new CustomDialogController({
builder: StringReversalCustomDialog(),
alignment: DialogAlignment.Center,
offset: { dx: CommonConstants.OFFSET_X, dy: CommonConstants.OFFSET_Y }
});
isLeapYearCustomDialogController: CustomDialogController | null = new CustomDialogController({
builder: IsLeapYearCustomDialog(),
alignment: DialogAlignment.Center,
offset: { dx: CommonConstants.OFFSET_X, dy: CommonConstants.OFFSET_Y }
});
build() {
Row() {
Column() {
Text("方法")
.fontSize($r('app.float.title_font_size'))
.fontWeight(FontWeight.Bold)
.lineHeight($r('app.float.title_font_height'))
.width(CommonConstants.TITLE_WIDTH)
.margin({
top: $r('app.float.title_margin_top'),
bottom: $r('app.float.title_margin_bottom')
})
.textAlign(TextAlign.Start)
Button($r('app.string.DaffodilsNumber'))
.width($r('app.float.button_width'))
.height($r('app.float.button_height'))
.margin({ top: $r('app.float.button_margin_top') })
.onClick(() => {
this.daffodilsNumberCustomDialogController?.open();
})
Button($r('app.string.MultiplicationTable'))
.width($r('app.float.button_width'))
.height($r('app.float.button_height'))
.margin({ top: $r('app.float.button_margin_top') })
.onClick(() => {
this.multiplicationTableCustomDialogController?.open();
let result = multiplicationTable();
for (let index = 0; index < result.length; index++) {
Logger.info(result[index].toString());
}
})
Button($r('app.string.IsPalindromicString'))
.width($r('app.float.button_width'))
.height($r('app.float.button_height'))
.margin({ top: $r('app.float.button_margin_top') })
.onClick(() => {
this.isPalindromicStringCustomDialogController?.open();
})
Button($r('app.string.StringReversal'))
.width($r('app.float.button_width'))
.height($r('app.float.button_height'))
.margin({ top: $r('app.float.button_margin_top') })
.onClick(() => {
this.stringReversalCustomDialogController?.open();
})
Button($r('app.string.IsLeapYear'))
.width($r('app.float.button_width'))
.height($r('app.float.button_height'))
.margin({
top: $r('app.float.button_margin_top'),
bottom: $r('app.float.button_margin_bottom')
})
.onClick(() => {
this.isLeapYearCustomDialogController?.open();
})
BackView();
}
.width('100%')
}
}
}

View File

@ -0,0 +1,23 @@
// Second.ets
// 导入页面路由模块
import BackView from '../view/BackView';
@Entry
@Component
struct Second {
@State message: string = 'Hi there'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
BackView();
}
.width('100%')
}
.height('100%')
}
}

View File

@ -0,0 +1,39 @@
// ToDoListPage.ets
import { CommonConstants } from '../common/constants/Constants';
import ToDoItem from '../view/ToDoItem';
import DataModel from '../viewmodel/DataModel';
import BackView from '../view/BackView';
@Entry
@Component
struct ToDoListPage {
private totalTasks: Array<string> = [];
aboutToAppear() {
this.totalTasks = DataModel.getData();
}
build() {
Column({ space: CommonConstants.COLUMN_SPACE }) {
Text($r('app.string.page_title'))
.fontSize($r('app.float.title_font_size'))
.fontWeight(FontWeight.Bold)
.lineHeight($r('app.float.title_font_height'))
.width(CommonConstants.TITLE_WIDTH)
.margin({
top: $r('app.float.title_margin_top'),
bottom: $r('app.float.title_margin_bottom')
})
.textAlign(TextAlign.Start)
ForEach(this.totalTasks, (item: string) => {
ToDoItem({ content: item })
}, (item: string) => JSON.stringify(item))
BackView();
}
.width(CommonConstants.FULL_LENGTH)
.height(CommonConstants.FULL_LENGTH)
.backgroundColor($r('app.color.page_background'))
}
}

View File

@ -0,0 +1,36 @@
import { router } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
@Component
export default struct BackView{
build() {
Row() {
Column() {
Button() {
Text('Back')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
// 返回按钮绑定onClick事件点击按钮时返回到第一页
.onClick(() => {
console.info(`Succeeded in clicking the 'Back' button.`)
try {
router.back()
console.info('Succeeded in returning to the first page.')
} catch (err) {
let code = (err as BusinessError).code;
let message = (err as BusinessError).message;
console.error(`Failed to return to the first page. Code is ${code}, message is ${message}`)
}
})
}
}
}
}

View File

@ -0,0 +1,38 @@
// DaffodilsNumberCustomDialog.ets
import { CommonConstants } from '../common/constants/Constants';
import { daffodilsNumber } from '../common/utils/Method';
@CustomDialog
export struct DaffodilsNumberCustomDialog {
IsPalindromicStringCustomDialogController?: CustomDialogController;
build() {
Column() {
Column() {
Text($r('app.string.ArkTS_Development_Case'))
.height($r('app.float.button_height'))
.font({ size: $r('sys.float.ohos_id_text_size_headline8') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_text_margin_top') })
Text($r('app.string.DaffodilsNumberTitle'))
.font({ size: $r('sys.float.ohos_id_text_size_body2') })
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ left: $r('app.float.dialog_text_margin_left') })
}
.alignItems(HorizontalAlign.Center)
.width(CommonConstants.PERCENT_FULL)
.height($r('app.float.dialog_text_height'))
Text(daffodilsNumber().toString())
.font({ size: $r('sys.float.ohos_id_text_size_body1') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_padding') })
}
.alignItems(HorizontalAlign.Center)
.padding({
left: $r('app.float.dialog_padding'),
right: $r('app.float.dialog_padding'),
bottom: $r('app.float.dialog_padding')
})
}
}

View File

@ -0,0 +1,58 @@
// IsLeapYearCustomDialog.ets
import { CommonConstants } from '../common/constants/Constants';
import CommonUtils from '../common/utils/CommonUtils';
import { isLeapYear } from '../common/utils/Method';
@CustomDialog
@Component
export struct IsLeapYearCustomDialog {
@State content: string = '';
@State result: boolean = false;
IsPalindromicStringCustomDialogController?: CustomDialogController;
build() {
Column() {
Column() {
Text($r('app.string.ArkTS_Development_Case'))
.height($r('app.float.button_height'))
.font({ size: $r('sys.float.ohos_id_text_size_headline8') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_text_margin_top') })
Text($r('app.string.Judgment_of_leap_year'))
.font({ size: $r('sys.float.ohos_id_text_size_body2') })
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ left: $r('app.float.dialog_text_margin_left') })
}
.alignItems(HorizontalAlign.Center)
.width(CommonConstants.PERCENT_FULL)
.height($r('app.float.dialog_text_height'))
TextInput({ placeholder: CommonConstants.LEAP_YEAR_INPUT })
.margin({ top: $r('app.float.dialog_padding') })
.height($r('app.float.dialog_textInput_height'))
.showUnderline(true)
.onChange((value: string) => {
this.content = value;
})
Button($r('app.string.IsLeapYear'))
.width($r('app.float.dialog_button_width'))
.margin({
top: $r('app.float.button_margin_bottom'),
bottom: $r('app.float.dialog_padding')
})
.onClick(() => {
this.result = isLeapYear(Number.parseInt(this.content));
if (this.result) {
CommonUtils.showToast(CommonConstants.LEAP_YEAR_YES);
} else {
CommonUtils.showToast(CommonConstants.LEAP_YEAR_NO);
}
})
}
.alignItems(HorizontalAlign.Center)
.padding({
left: $r('app.float.dialog_padding'),
right: $r('app.float.dialog_padding')
})
}
}

View File

@ -0,0 +1,58 @@
// IsPalindromicStringCustomDialog.ets
import { CommonConstants } from '../common/constants/Constants';
import CommonUtils from '../common/utils/CommonUtils';
import { IsPalindromicString } from '../common/utils/Method';
@CustomDialog
@Component
export struct IsPalindromicStringCustomDialog {
@State content: string = '';
@State result: boolean = false;
IsPalindromicStringCustomDialogController?: CustomDialogController;
build() {
Column() {
Column() {
Text($r('app.string.ArkTS_Development_Case'))
.height($r('app.float.button_height'))
.font({ size: $r('sys.float.ohos_id_text_size_headline8') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_text_margin_top') })
Text($r('app.string.Judgment_of_palindromic_string'))
.font({ size: $r('sys.float.ohos_id_text_size_body2') })
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ left: $r('app.float.dialog_text_margin_left') })
}
.alignItems(HorizontalAlign.Center)
.width(CommonConstants.PERCENT_FULL)
.height($r('app.float.dialog_text_height'))
TextInput({ placeholder: CommonConstants.STRING_INPUT })
.margin({ top: $r('app.float.dialog_padding') })
.height($r('app.float.dialog_textInput_height'))
.showUnderline(true)
.onChange((value: string) => {
this.content = value;
})
Button($r('app.string.IsPalindromicString'))
.width($r('app.float.dialog_button_width'))
.margin({
top: $r('app.float.button_margin_bottom'),
bottom: $r('app.float.dialog_padding')
})
.onClick(() => {
this.result = IsPalindromicString(this.content);
if (this.result) {
CommonUtils.showToast(CommonConstants.PALINDROMIC_STRING_YES);
} else {
CommonUtils.showToast(CommonConstants.PALINDROMIC_STRING_NO);
}
})
}
.alignItems(HorizontalAlign.Center)
.padding({
left: $r('app.float.dialog_padding'),
right: $r('app.float.dialog_padding')
})
}
}

View File

@ -0,0 +1,37 @@
// MultiplicationTableCustomDialog.ets
import { CommonConstants } from '../common/constants/Constants'
@CustomDialog
export struct MultiplicationTableCustomDialog {
IsPalindromicStringCustomDialogController?: CustomDialogController;
build() {
Column() {
Column() {
Text($r('app.string.ArkTS_Development_Case'))
.height($r('app.float.button_height'))
.font({ size: $r('sys.float.ohos_id_text_size_headline8') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_text_margin_top') })
Text($r('app.string.Multiplication_Table_Title'))
.font({ size: $r('sys.float.ohos_id_text_size_body2') })
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ left: $r('app.float.dialog_text_margin_left') })
}
.alignItems(HorizontalAlign.Center)
.width(CommonConstants.PERCENT_FULL)
.height($r('app.float.dialog_text_height'))
Text($r('app.string.check_info_in_log'))
.font({ size: $r('sys.float.ohos_id_text_size_body1') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_padding') })
}
.alignItems(HorizontalAlign.Center)
.padding({
left: $r('app.float.dialog_padding'),
right: $r('app.float.dialog_padding'),
bottom: $r('app.float.dialog_padding')
})
}
}

View File

@ -0,0 +1,54 @@
// StringReversalCustomDialog.ets
import { CommonConstants } from '../common/constants/Constants';
import CommonUtils from '../common/utils/CommonUtils';
import { StringReversal } from '../common/utils/Method';
@CustomDialog
@Component
export struct StringReversalCustomDialog {
@State content: string = '';
@State result: string = '';
IsPalindromicStringCustomDialogController?: CustomDialogController;
build() {
Column() {
Column() {
Text($r('app.string.ArkTS_Development_Case'))
.height($r('app.float.button_height'))
.font({ size: $r('sys.float.ohos_id_text_size_headline8') })
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.margin({ top: $r('app.float.dialog_text_margin_top') })
Text($r('app.string.StringReversal'))
.font({ size: $r('sys.float.ohos_id_text_size_body2') })
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ left: $r('app.float.dialog_text_margin_left') })
}
.alignItems(HorizontalAlign.Center)
.width(CommonConstants.PERCENT_FULL)
.height($r('app.float.dialog_text_height'))
TextInput({ placeholder: CommonConstants.STRING_INPUT })
.margin({ top: $r('app.float.dialog_padding') })
.height($r('app.float.dialog_textInput_height'))
.showUnderline(true)
.onChange((value: string) => {
this.content = value;
})
Button($r('app.string.StringReversal'))
.width($r('app.float.dialog_button_width'))
.margin({
top: $r('app.float.button_margin_bottom'),
bottom: $r('app.float.dialog_padding')
})
.onClick(() => {
this.result = StringReversal(this.content);
CommonUtils.showToast(CommonConstants.STRING_PRE + this.result);
})
}
.alignItems(HorizontalAlign.Center)
.padding({
left: $r('app.float.dialog_padding'),
right: $r('app.float.dialog_padding')
})
}
}

View File

@ -0,0 +1,39 @@
import { CommonConstants } from "../common/constants/Constants";
// ToDoItem.ets
@Component
export default struct ToDoItem {
private content?: string;
@State isComplete: boolean = false;
@Builder labelIcon(icon: Resource) {
Image(icon)
.objectFit(ImageFit.Contain)
.width($r('app.float.checkbox_width'))
.height($r('app.float.checkbox_width'))
.margin($r('app.float.checkbox_margin'))
}
build() {
Row() {
if (this.isComplete) {
this.labelIcon($r('app.media.ic_ok'));
} else {
this.labelIcon($r('app.media.ic_default'));
}
Text(this.content)
.fontSize($r('app.float.item_font_size'))
.fontWeight(CommonConstants.FONT_WEIGHT)
.opacity(this.isComplete ? CommonConstants.OPACITY_COMPLETED : CommonConstants.OPACITY_DEFAULT)
.decoration({ type: this.isComplete ? TextDecorationType.LineThrough : TextDecorationType.None })
}
.borderRadius(CommonConstants.BORDER_RADIUS)
.backgroundColor($r('app.color.start_window_background'))
.width(CommonConstants.LIST_DEFAULT_WIDTH)
.height($r('app.float.list_item_height'))
.onClick(() => {
this.isComplete = !this.isComplete;
})
}
}

View File

@ -0,0 +1,27 @@
import { CommonConstants } from "../common/constants/Constants";
import { Link } from '../common/constants/Link';
/**
* Saving and manipulating data displayed on the page.
*/
export class DataModel {
/**
* Saved Data.
*/
private tasks: Array<string> = CommonConstants.TODO_DATA;
private links: Link[] = CommonConstants.LINK_DATA;
/**
* Get the data.
*/
getData(): Array<string> {
return this.tasks;
}
getLinkData(): Link[] {
return this.links;
}
}
export default new DataModel();

View File

@ -0,0 +1,52 @@
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"phone",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"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": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "EntryBackupAbility",
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
"type": "backup",
"exported": false,
"metadata": [
{
"name": "ohos.extension.backup",
"resource": "$profile:backup_config"
}
],
}
]
}
}

View File

@ -0,0 +1,12 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
},
{
"name": "page_background",
"value": "#F1F3F5"
}
]
}

View File

@ -0,0 +1,96 @@
{
"float": [
{
"name": "text_margin_top",
"value": "64vp"
},
{
"name": "text_margin_bottom",
"value": "8vp"
},
{
"name": "text_margin_left",
"value": "12vp"
},
{
"name": "text_margin_right",
"value": "20vp"
},
{
"name": "text_font_size",
"value": "30fp"
},
{
"name": "button_width",
"value": "288vp"
},
{
"name": "button_height",
"value": "40vp"
},
{
"name": "button_margin_top",
"value": "12vp"
},
{
"name": "button_margin_bottom",
"value": "16vp"
},
{
"name": "dialog_text_margin_left",
"value": "10vp"
},
{
"name": "dialog_text_height",
"value": "72vp"
},
{
"name": "dialog_text_margin_top",
"value": "8vp"
},
{
"name": "dialog_padding",
"value": "24vp"
},
{
"name": "dialog_button_width",
"value": "296vp"
},
{
"name": "dialog_textInput_height",
"value": "48vp"
},
{
"name": "checkbox_width",
"value": "28vp"
},
{
"name": "checkbox_margin",
"value": "20vp"
},
{
"name": "item_font_size",
"value": "20fp"
},
{
"name": "title_font_size",
"value": "28fp"
},
{
"name": "title_font_height",
"value": "33vp"
},
{
"name": "title_margin_top",
"value": "24vp"
},
{
"name": "title_margin_bottom",
"value": "12vp"
},
{
"name": "list_item_height",
"value": "64vp"
}
]
}

View File

@ -0,0 +1,64 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "Development Case"
},
{
"name": "ArkTS_Development_Case",
"value": "ArkTS Development Case"
},
{
"name": "DaffodilsNumber",
"value": "Print the number of daffodils within 1000"
},
{
"name": "MultiplicationTable",
"value": "Print Multiplication Tables"
},
{
"name": "IsPalindromicString",
"value": "Determines whether a string is a palindromic string"
},
{
"name": "StringReversal",
"value": "String reversal"
},
{
"name": "IsLeapYear",
"value": "Determine whether it is a leap year"
},
{
"name": "DaffodilsNumberTitle",
"value": "Daffodils Number"
},
{
"name": "Judgment_of_leap_year",
"value": "Judgment of leap year"
},
{
"name": "Judgment_of_palindromic_string",
"value": "Judgment of palindromic string"
},
{
"name": "Multiplication_Table_Title",
"value": "Multiplication Tables"
},
{
"name": "check_info_in_log",
"value": "Please check in the log print"
},
{
"name": "page_title",
"value": "待办"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,7 @@
{
"layered-image":
{
"background" : "$media:background",
"foreground" : "$media:foreground"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,3 @@
{
"allowToBackupRestore": true
}

View File

@ -0,0 +1,8 @@
{
"src": [
"pages/Index",
"pages/Second",
"pages/Method",
"pages/ToDoListPage"
]
}

View File

@ -0,0 +1,64 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "ArkTS Development Case"
},
{
"name": "ArkTS_Development_Case",
"value": "Development Case"
},
{
"name": "DaffodilsNumber",
"value": "Print the number of daffodils within 1000"
},
{
"name": "MultiplicationTable",
"value": "Print Multiplication Tables"
},
{
"name": "IsPalindromicString",
"value": "Determines whether a string is a palindromic string"
},
{
"name": "StringReversal",
"value": "String reversal"
},
{
"name": "IsLeapYear",
"value": "Determine whether it is a leap year"
},
{
"name": "DaffodilsNumberTitle",
"value": "Daffodils Number"
},
{
"name": "Judgment_of_leap_year",
"value": "Judgment of leap year"
},
{
"name": "Judgment_of_palindromic_string",
"value": "Judgment of palindromic string"
},
{
"name": "Multiplication_Table_Title",
"value": "Multiplication Tables"
},
{
"name": "check_info_in_log",
"value": "Please check in the log print"
},
{
"name": "page_title",
"value": "ToDo"
}
]
}

View File

@ -0,0 +1,64 @@
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "ArkTS开发案例"
},
{
"name": "ArkTS_Development_Case",
"value": "开发案例"
},
{
"name": "DaffodilsNumber",
"value": "打印水仙花数"
},
{
"name": "MultiplicationTable",
"value": "打印九九乘法表"
},
{
"name": "IsPalindromicString",
"value": "判断字符串是否为回文字符串"
},
{
"name": "StringReversal",
"value": "字符串反转"
},
{
"name": "IsLeapYear",
"value": "判断是否为闰年"
},
{
"name": "DaffodilsNumberTitle",
"value": "水仙花数"
},
{
"name": "Judgment_of_leap_year",
"value": "闰年判断"
},
{
"name": "Judgment_of_palindromic_string",
"value": "回文字符串判断"
},
{
"name": "Multiplication_Table_Title",
"value": "九九乘法表"
},
{
"name": "check_info_in_log",
"value": "请在日志打印中查看"
},
{
"name": "page_title",
"value": "待办"
}
]
}

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,35 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function abilityTest() {
describe('ActsAbilityTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
})
})
}

View File

@ -0,0 +1,5 @@
import abilityTest from './Ability.test';
export default function testsuite() {
abilityTest();
}

View File

@ -0,0 +1,13 @@
{
"module": {
"name": "entry_test",
"type": "feature",
"deviceTypes": [
"phone",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"installationFree": false
}
}

View File

@ -0,0 +1,5 @@
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}

View File

@ -0,0 +1,33 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}

View File

@ -0,0 +1,22 @@
{
"modelVersion": "5.0.0",
"dependencies": {
},
"execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
},
"logging": {
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
},
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
},
"nodeOptions": {
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
}
}

6
hvigorfile.ts Normal file
View File

@ -0,0 +1,6 @@
import { appTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}

27
oh-package-lock.json5 Normal file
View File

@ -0,0 +1,27 @@
{
"meta": {
"stableOrder": true
},
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
"@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19"
},
"packages": {
"@ohos/hamock@1.0.0": {
"name": "@ohos/hamock",
"version": "1.0.0",
"integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har",
"registryType": "ohpm"
},
"@ohos/hypium@1.0.19": {
"name": "@ohos/hypium",
"version": "1.0.19",
"integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har",
"registryType": "ohpm"
}
}
}

10
oh-package.json5 Normal file
View File

@ -0,0 +1,10 @@
{
"modelVersion": "5.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
"@ohos/hypium": "1.0.19",
"@ohos/hamock": "1.0.0"
}
}