Application Profile
This article is an application introduction written by participating in the "[Creative Demo Challenge] HarmonyOS Sports and Health Practice—Waiting for you!" activity address:
https://developer.huawei.com/consumer/cn/forum/topic/0202116956892085528?fid=0101562279236410779
This document is familiar with common control usage and some development skills by studying healthy life cases, and makes a simple sports and health program, which is mainly divided into three pages: task, sports and me. The task page contains some check-in tasks, and the completion progress will be displayed with a circular progress bar. The sports page contains six sports content, mainly breathing, walking, running, fitness, yoga and rope skipping, and different sports will have corresponding operations.
Effect preview
brief introduction
Before the welcome page, first judge whether the user has accepted the "User Privacy Policy" through the preferences. The privacy policy is a user-defined pop-up window.
After the welcome interface, you will enter the main page, which is divided into three tabs at the bottom, tasks, sports and mine.
Task page:
Sports page:
The training consists of inhalation and exhalation exercises,
my page:
code analysis
The application welcome page records the user's last action through simple storage of preferences.
let preferences = data_preferences.getPreferences(this.context, SPORT_PREF);
preferences.then((res) => {
res.put(IS_ACCEPT, false);
res.get(IS_ACCEPT, false).then((isAccept) => {
if (isAccept === true) {
this.waitToMainPage();
} else {
this.dialogController.open();
}
});
});
copy
Breathing training in an exercise program where the start button triggers a timer.
startBreathing() {
var that = this
this.intervalID = setInterval(function() {
that.currentCount = that.currentCount + 1
if(that.currentCount == (that.select + 1) * 60) {
clearInterval(that.intervalID);
that.breathing = false
that.loopnum = 0
that.currentCount = 0
that.countdown = 0
AlertDialog.show(
{
title: '',
message: '\n恭喜训练完成\n',
confirm: {
value: '关闭',
action: () => {
console.info('Button-clicking callback')
}
},
cancel: () => {
console.info('Closed callbacks')
}
}
)
}
if((that.currentCount - 1) % 6 == 0) {
that.loopnum += 1
}
if(that.loopnum % 2 == 1) {
that.countdown = that.countdown + 1
that.prepare_tips = "第 " + Math.floor(that.loopnum / 2 + 1).toString() + " 次"+ "吸气..."
} else {
that.countdown = that.countdown - 1
that.prepare_tips = "第 " + (that.loopnum / 2).toString() + " 次"+ "呼气..."
}
}, 1000);
}
copy
After the training is completed, the training time will be recorded.
putLatestRecord() {
let preferences = data_preferences.getPreferences(this.context, commonConst.RECORD_PREF);
var that = this
preferences.then((res) => {
// res.put(IS_ACCEPT, false);
let date = new Date();
let currentTime = date.getFullYear() + "/" + (date.getMonth() + 1).toString().padStart(2, '0') + "/" + date.getDate().toString().padStart(2, '0') + " " + date.getHours() + ":" + date.getMinutes().toString().padStart(2, '0') + ":" + date.getSeconds().toString().padStart(2, '0')
console.log("currentTime", currentTime)
res.put("breath", currentTime);
that.lastRecord = "上次运动: " + currentTime
});
}
copy
project summary
Through this simple exercise, I learned a lot of commonly used knowledge. AppStorage is a singleton object in an application that provides central storage for application-wide mutable state properties. Flex is a powerful container component that supports horizontal layout, vertical layout, equal distribution of sub-components and fluid wrapping layout. Preferences provide applications with Key-Value key-value data processing capabilities, and support applications to persist lightweight data, and modify and query it.