#include "components/ui_button.h"
#include "traing/include/TraingWinView.h"
#include "components/ui_view_group.h"
-#include "components/ui_label.h"
-#include "components/ui_image_view.h"
-#include "components/ui_button.h"
-#include "components/ui_image_animator.h"
#include "components/ui_label_button_ext.h"
#include "components/ui_chart.h"
#include "components/ui_list.h"
virtual void Callback(UIView *view) override
{
// 获取电池电压值
- // float voltage = 0.0F;
- // uint8_t value = 0;
- // value = battery_get_voltage(&voltage);
+ float voltage = 0.0F;
+ uint8_t value = 0;
+ value = battery_get_voltage(&voltage);
// 设置种子
- srand(static_cast<unsigned int>(time(0)));
+ // srand(static_cast<unsigned int>(time(0)));
// 生成随机数
- int value = rand() % 101; // 取余操作可以将随机数限制在0到100之间
+ // int value = rand() % 101; // 取余操作可以将随机数限制在0到100之间
printf("value:%d\n", value);
// 根据电池电量值选择相应的进度条前景图片
char *progress1ForeImageSrc = nullptr;
UIImageView *hour2{nullptr}; // 时钟小时第二位图像控件指针
UIImageView *minute1{nullptr}; // 时钟分钟第一位图像控件指针
UIImageView *minute2{nullptr}; // 时钟分钟第二位图像控件指针
- std::string stringtime = "14:56";
+ std::string stringtime;
+ std::string imageFolderPath;
public:
- explicit mytimeimageCallback(UIImageView *hour1, UIImageView *hour2, UIImageView *minute1, UIImageView *minute2) : hour1(hour1), hour2(hour2), minute1(minute1), minute2(minute2) {}
+ explicit mytimeimageCallback(UIImageView *hour1, UIImageView *hour2, UIImageView *minute1, UIImageView *minute2, std::string imageFolderPath, std::string stringtime)
+ : hour1(hour1), hour2(hour2), minute1(minute1), minute2(minute2), imageFolderPath(imageFolderPath), stringtime(stringtime) {}
~mytimeimageCallback() {}
// 时钟图片更新的回调函数
// 将小时和分钟转换为字符串,并更新 stringtime
stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
printf("Before updating images\n");
- std::string imageFolderPath = "/user/res/clocks/flowerbud/";
- updateImage(hour1, imageFolderPath, stringtime.substr(0, 1));
- updateImage(hour2, imageFolderPath, stringtime.substr(1, 1));
- updateImage(minute1, imageFolderPath, stringtime.substr(3, 1));
- updateImage(minute2, imageFolderPath, stringtime.substr(4, 1));
+ printf("--%s:%s--\n", imageFolderPath.c_str(), stringtime.c_str());
+ updateImage(hour1, imageFolderPath.c_str(), stringtime.substr(0, 1));
+ updateImage(hour2, imageFolderPath.c_str(), stringtime.substr(1, 1));
+ updateImage(minute1, imageFolderPath.c_str(), stringtime.substr(3, 1));
+ updateImage(minute2, imageFolderPath.c_str(), stringtime.substr(4, 1));
printf("After updating images\n");
}
{
printf("File exists: %s\n", imagePath.c_str());
imageControl->SetSrc(imagePath.c_str());
+ printf("File set!\n");
}
else
{
Animator *sweepClock1animator_ = nullptr;
bool viewiInitStatus{false};
const char **imagePaths;
+ std::string digitspath;
std::string stringtime;
- std::string JosnfilePath = "/user/res/clocks/maomao.json";
+ std::string JosnfilePath = "/user/res/clocks/KUMI.json";
};
} // namespace OHOS
#endif // Digital_clock_PRESENTER_H
#include <sys/stat.h>
#include "cJSON.h"
#include <dirent.h>
-
+#include <regex>
+#include <iomanip> // 用于格式化输出
+#include <stdexcept> //异常处理
#define PRINT_DEBUG_INFO printf("Function: %s, Line: %d\n", __PRETTY_FUNCTION__, __LINE__);
// Add code to set the background as a video
}
}
+ // 增加背景
+ container_->Add(background);
+ background->SetVisible(true);
PRINT_DEBUG_INFO
}
/*初始化表盘时钟*/
}
void Digital_clockView ::Initdigit()
{
- container_->Add(background);
- background->SetVisible(true);
cJSON *background_cjson = cJSON_GetObjectItem(cjson_json, "background");
std::string backgroundimagesPath = cJSON_GetObjectItem(background_cjson, "backgroundimagesPath")->valuestring;
if (isDirectory(backgroundimagesPath))
{
cJSON *picturesdisplay = cJSON_GetObjectItem(digits, "picturesdisplay");
cJSON *coordinates = cJSON_GetObjectItem(picturesdisplay, "coordinates");
- const char *digitspath = cJSON_GetObjectItem(cjson_json, "digitspath")->valuestring;
+ digitspath = cJSON_GetObjectItem(cjson_json, "digitspath")->valuestring;
int hour1_left = cJSON_GetObjectItem(coordinates, "left")->valueint;
int hour1_top = cJSON_GetObjectItem(coordinates, "top")->valueint;
int digitsize = cJSON_GetObjectItem(digits, "digitsize")->valueint;
- addImageView(hour1_left, hour1_top, (std::string(digitspath) + stringtime.substr(0, 1) + ".bin").c_str(), "hour1", 0, 0);
- addImageView(hour1_left, hour1_top, (std::string(digitspath) + stringtime.substr(1, 1) + ".bin").c_str(), "hour1", digitsize, 0);
- addImageView(hour1_left, hour1_top, (std::string(digitspath) + "point.bin").c_str(), "colon", digitsize * 2 + 10, 20);
- addImageView(hour1_left, hour1_top, (std::string(digitspath) + stringtime.substr(3, 1) + ".bin").c_str(), "minute1", digitsize * 3, 0);
- addImageView(hour1_left, hour1_top, (std::string(digitspath) + stringtime.substr(4, 1) + ".bin").c_str(), "minute2", digitsize * 4, 0);
- mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2);
- timeimageanimator_ = new Animator(mytimeimageCallback_, hour1, 10000, true);
+ addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(0, 1) + ".bin").c_str(), "hour1", 0, 0);
+ addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(1, 1) + ".bin").c_str(), "hour1", digitsize, 0);
+ addImageView(hour1_left, hour1_top, (digitspath + "point.bin").c_str(), "colon", digitsize * 2 + 10, 20);
+ addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(3, 1) + ".bin").c_str(), "minute1", digitsize * 3, 0);
+ addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(4, 1) + ".bin").c_str(), "minute2", digitsize * 4, 0);
+ printf("--%s--\n", digitspath.c_str());
+ mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2, digitspath, stringtime);
+ timeimageanimator_ = new Animator(mytimeimageCallback_, container_, 10000, true);
// callback.mytimeimageCallback("14:57");
// timeimageanimator_->Start();
}
timeLable->SetVisible(true);
timeLableCallback_ = new timeLableCallback(timeLable, stringtime);
- timeLableanimator_ = new Animator(timeLableCallback_, timeLable, 10000, true);
+ timeLableanimator_ = new Animator(timeLableCallback_, timeLable, 1000, true);
timeLableanimator_->Start();
}
}
sweepClock1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
sweepClock1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
- // 增加背景
- sweepClock1_->Add(background);
- background->SetVisible(true);
-
// Set additional property
sweepClock1_->SetWorkMode(UISweepClock::WorkMode::NORMAL);
Image *sweepClock1HourImage = new Image();
container_->Add(sweepClock1_);
sweepClock1_->SetVisible(true);
}
+
+ std::string FormatDate(const std::string &dateStr, const std::string &displayformat)
+ {
+ // 定义默认返回值
+ std::string formattedDate = "Invalid format";
+ // 输出日期字符串和子字符串
+ std::cout << "--date: " << dateStr << "--" << dateStr.substr(0, 4) << "--" << dateStr.substr(5, 2) << "--" << dateStr.substr(8, 2) << std::endl;
+ int year = std::stoi(dateStr.substr(0, 4)); // 从第0个字符开始,提取4个字符作为年份
+ int month = std::stoi(dateStr.substr(5, 2)); // 从第5个字符开始,提取2个字符作为月份
+ int day = std::stoi(dateStr.substr(8, 2)); // 从第8个字符开始,提取2个字符作为日期
+ if (displayformat == "yyyy-mm-dd")
+ {
+ formattedDate = std::to_string(year) + "-" + (month < 10 ? "0" : "") + std::to_string(month) + "-" + (day < 10 ? "0" : "") + std::to_string(day);
+ }
+ else if (displayformat == "mm月dd日")
+ {
+ formattedDate = std::to_string(month) + "月" + (day < 10 ? "0" : "") + std::to_string(day) + "号";
+ }
+ else if (displayformat == "dd")
+ {
+ formattedDate = (day < 10 ? "0" : "") + std::to_string(day);
+ }
+ PRINT_DEBUG_INFO
+ // 添加其他显示格式的处理逻辑
+
+ return formattedDate;
+ }
void Digital_clockView ::Initdata()
{
// loadJsonData(JosnfilePath);
cJSON *date = cJSON_GetObjectItem(cjson_json, "date");
cJSON *textdisplay = cJSON_GetObjectItem(date, "textdisplay");
- cJSON *displayformat = cJSON_GetObjectItem(textdisplay, "displayformat");
cJSON *coordinates = cJSON_GetObjectItem(textdisplay, "coordinates");
+ PRINT_DEBUG_INFO
// const char *font = cJSON_GetObjectItem(textdisplay, "font")->valuestring;
int fontsize = cJSON_GetObjectItem(textdisplay, "fontsize")->valueint;
int date_left = cJSON_GetObjectItem(coordinates, "left")->valueint;
int date_top = cJSON_GetObjectItem(coordinates, "top")->valueint;
+ PRINT_DEBUG_INFO
// Add Label to App
if (dateLable == nullptr)
{
dateLable->SetPosition(date_left, date_top); // widget's left position and top position
dateLable->SetViewId("label1"); // Set style
dateLable->SetStyle(STYLE_TEXT_FONT, fontsize);
+ PRINT_DEBUG_INFO
+ std::string dateStr = "2024-02-09";
- // Set additional property
- dateLable->SetText("1月8号");
+ std::string displayformat = cJSON_GetObjectItem(textdisplay, "displayformat")->valuestring;
+ // 调用日期格式化函数
+ std::string formattedDate = FormatDate(dateStr, displayformat);
+ PRINT_DEBUG_INFO
+ dateLable->SetText(formattedDate.c_str());
dateLable->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
dateLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
dateLable->SetRollSpeed(0);
// Add to rootView
container_->Add(dateLable);
dateLable->SetVisible(true);
+ PRINT_DEBUG_INFO
};
void Digital_clockView ::Initweek()
{
weekLable->SetStyle(STYLE_TEXT_FONT, fontsize);
// Set additional property
- weekLable->SetText("星期一");
+ cJSON *weekformat = cJSON_GetObjectItem(displayformat, "weekformat");
+ std ::string weekStr;
+ if (weekformat != nullptr && cJSON_IsArray(weekformat))
+ {
+ cJSON *weekformat1 = cJSON_GetArrayItem(weekformat, 1);
+ if (weekformat1 != nullptr && cJSON_IsString(weekformat1))
+ {
+ weekStr = weekformat1->valuestring;
+ }
+ }
+ weekLable->SetText(weekStr.c_str());
weekLable->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
weekLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
weekLable->SetRollSpeed(0);
{
std::string Dialtype = cJSON_GetObjectItem(cjson_json, "Dialtype")->valuestring;
Initbackground();
+ PRINT_DEBUG_INFO
if (Dialtype == "pointer")
{
Initpointer();
{
Initdigit();
}
+ PRINT_DEBUG_INFO
Initdata();
+ PRINT_DEBUG_INFO
Initweek();
+ PRINT_DEBUG_INFO
Initbattery();
+ PRINT_DEBUG_INFO
cJSON_Delete(cjson_json);
}
}
}
delete tempView;
}
- // FreeImagePathsArray(imagePaths);
+ /********************************************/
if (timeLableanimator_ != nullptr)
{
timeLableanimator_->Stop();
delete timeLableanimator_;
timeLableanimator_ = nullptr;
}
+ if (timeLableCallback_ != nullptr)
+ {
+ delete timeLableCallback_;
+ timeLableCallback_ = nullptr;
+ }
+ /********************************************/
+ if (mytimeimageCallback_ != nullptr)
+ {
+ delete mytimeimageCallback_;
+ mytimeimageCallback_ = nullptr;
+ }
if (timeimageanimator_ != nullptr)
{
timeimageanimator_->Stop();
delete timeimageanimator_;
timeimageanimator_ = nullptr;
}
+ /********************************************/
+ if (progress1callback_ != nullptr)
+ {
+ delete progress1callback_;
+ progress1callback_ = nullptr;
+ }
if (progress1animator_ != nullptr)
{
progress1animator_->Stop();
delete progress1animator_;
progress1animator_ = nullptr;
}
+ /********************************************/
+ if (sweepClock1callback_ != nullptr)
+ {
+ delete sweepClock1callback_;
+ sweepClock1callback_ = nullptr;
+ }
if (sweepClock1animator_ != nullptr)
{
- PRINT_DEBUG_INFO
- sweepClock1_->RemoveAll();
-
- delete sweepClock1_;
- sweepClock1_ = nullptr;
sweepClock1animator_->Stop();
- PRINT_DEBUG_INFO
delete sweepClock1animator_;
sweepClock1animator_ = nullptr;
}
- backgroundAnimator->Stop();
+ /********************************************/
+ if (backgroundAnimator != nullptr)
+ {
+ backgroundAnimator->Stop();
+ delete backgroundAnimator;
+ backgroundAnimator = nullptr;
+ }
delete container_;
container_ = nullptr;
+ PRINT_DEBUG_INFO
}
void Digital_clockView::PreLoad(void)
if (!viewiInitStatus)
{
-
InitView();
viewiInitStatus = true;
}