236 lines
8.0 KiB
C++
236 lines
8.0 KiB
C++
#include "TjdUiAppAlarmPopUpPage.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "TjdUiMsgCenter.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "TjdUiScreenManage.h"
|
|
#include "TjdUiUtils.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "motor.h"
|
|
#include "msg_center.h"
|
|
#include "notification_manager.h"
|
|
#include "power_display_service.h"
|
|
#include "service_alarm.h"
|
|
#include "sql_setting.h"
|
|
#include "sys_config.h"
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
using namespace OHOS;
|
|
#define ALARM_CONFIRM_CANCEL_BIN_PATH TJD_IMAGE_PATH "img_confirm_cancel.bin"
|
|
#define ENABLE_PRINT_INFO 1
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
|
|
namespace TJD {
|
|
#define SCREEN_AUTO_OFF_TIME (1000 * 60 * 60)
|
|
#define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_alarm.bin"
|
|
|
|
static struct alarm_time time_data;
|
|
static TjdUiAppAlarmPopUpPage *AlarmNotifyPage = nullptr;
|
|
static const int ANIMATOR_COUNT = 4;
|
|
static OHOS::ImageAnimatorInfo g_pv_waitInfo_[ANIMATOR_COUNT];
|
|
|
|
static std::string formatTime(int hours, int minutes)
|
|
{
|
|
std::ostringstream oss;
|
|
oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0') << std::setw(2) << minutes;
|
|
return oss.str();
|
|
}
|
|
|
|
alarm_time add_ten_minutes(const alarm_time &time)
|
|
{
|
|
alarm_time result = time;
|
|
result.minute += 10;
|
|
|
|
if (result.minute >= 60) {
|
|
result.minute -= 60;
|
|
result.hour++;
|
|
|
|
if (result.hour >= 24) {
|
|
result.hour = 0;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static void PageFree(void)
|
|
{
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST);
|
|
if (AlarmNotifyPage != nullptr) {
|
|
delete AlarmNotifyPage;
|
|
AlarmNotifyPage = nullptr;
|
|
}
|
|
// printf("PageFree\n");
|
|
RunPopOutPageCallback();
|
|
}
|
|
|
|
static UIViewGroup *TjdUiAlarmNotifyPageCreate(void)
|
|
{
|
|
|
|
AlarmNotifyPage = new TjdUiAppAlarmPopUpPage();
|
|
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(PageFree);
|
|
return AlarmNotifyPage;
|
|
}
|
|
|
|
static void TjdUiAlarmNotifyPageDelete(void)
|
|
{
|
|
// printf("TjdUiAlarmNotifyPageDelete\n");
|
|
NotificationManager::GetInstance()->StopNotify();
|
|
}
|
|
|
|
static void TimerCallback(void *arg)
|
|
{
|
|
// printf("TjdUiAppAlarmPopUpPage::TimerCallback\n");
|
|
TjdUiAlarmNotifyPageDelete();
|
|
}
|
|
|
|
TjdUiAppAlarmPopUpPage::TjdUiAppAlarmPopUpPage()
|
|
{
|
|
// printf("TjdUiAppAlarmPopUpPage::TjdUiAppAlarmPopUpPage\n");
|
|
auto &imgManager = OHOS::ImageCacheManager::GetInstance();
|
|
|
|
SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
|
|
delayLabel_.SetPosition(88, 192, 289, 50);
|
|
delayLabel_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
|
|
delayLabel_.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
|
|
delayLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34);
|
|
// delayLabel_.SetText("闹钟将\n延时10分钟提醒");
|
|
delayLabel_.SetTextId(STR_ID_562);
|
|
delayLabel_.SetVisible(false);
|
|
|
|
cancelButton_.SetPosition(103, 326, 92, 92);
|
|
cancelButton_.SetStyle(STYLE_BORDER_RADIUS, 0);
|
|
cancelButton_.SetStyle(STYLE_BACKGROUND_OPA, 0);
|
|
cancelButton_.SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::INACTIVE);
|
|
ImageInfo *imageinfo = imgManager.LoadOneInMultiRes(IMG_CONFIRM_CANCEL_CANCEL, ALARM_CONFIRM_CANCEL_BIN_PATH);
|
|
cancelButton_.SetImageSrc(imageinfo, imageinfo);
|
|
cancelButton_.SetOnClickListener(this);
|
|
|
|
delayButton_.SetPosition(271, 326, 92, 92);
|
|
delayButton_.SetStyle(STYLE_BORDER_RADIUS, 0);
|
|
delayButton_.SetStyle(STYLE_BACKGROUND_OPA, 0);
|
|
delayButton_.SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::INACTIVE);
|
|
imageinfo = imgManager.LoadOneInMultiRes(IMG_ALARM_DELAY, IMAGE_BIN_PATH);
|
|
delayButton_.SetImageSrc(imageinfo, imageinfo);
|
|
delayButton_.SetOnClickListener(this);
|
|
|
|
for (int i = 0; i < ANIMATOR_COUNT; i++) {
|
|
g_pv_waitInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(IMG_ALARM_ALARM + i, IMAGE_BIN_PATH);
|
|
g_pv_waitInfo_[i].pos = {153, 72};
|
|
g_pv_waitInfo_[i].width = 153;
|
|
g_pv_waitInfo_[i].height = 145;
|
|
g_pv_waitInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
|
|
}
|
|
animator_.SetPosition(153, 72, 153, 145);
|
|
animator_.SetImageAnimatorSrc(g_pv_waitInfo_, ANIMATOR_COUNT, 100);
|
|
animator_.Start();
|
|
|
|
timeLabel_.SetPosition(166, 250, HORIZONTAL_RESOLUTION, 78);
|
|
timeLabel_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
|
|
timeLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
timeLabel_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, TJD_FONT_SIZE_70);
|
|
timeLabel_.SetText(formatTime(time_data.hour, time_data.minute).c_str());
|
|
TjdUiUtils::AdjustViewOffset(timeLabel_, animator_, 11, TjdUiUtils::OffsetDirection::OFFSET_BOTTOM);
|
|
TjdUiUtils::AutoAlignHorizontalCenter(timeLabel_);
|
|
|
|
Add(&timeLabel_);
|
|
Add(&delayLabel_);
|
|
Add(&cancelButton_);
|
|
Add(&delayButton_);
|
|
Add(&animator_);
|
|
|
|
waitTimer_ = new GraphicTimer(10 * 1000, TimerCallback, nullptr, false);
|
|
waitTimer_->Start();
|
|
|
|
motor_param_t motorParam = {.cycle1_on = 500, .cycle1_off = 500, .cycle1_cnt = 10, .duty = 100};
|
|
tjd_driver_motor_user_start(&motorParam);
|
|
|
|
TjdUiScreenManage::SetScreenKeepOnTimeout(SCREEN_AUTO_OFF_TIME);
|
|
}
|
|
|
|
TjdUiAppAlarmPopUpPage::~TjdUiAppAlarmPopUpPage()
|
|
{
|
|
// printf("TjdUiAppAlarmPopUpPage::~TjdUiAppAlarmPopUpPage\n");
|
|
tjd_driver_motor_user_stop();
|
|
|
|
TjdUiScreenManage::ResetScreenKeepOnTimeout();
|
|
|
|
if (isDeley_) {
|
|
alarm_time time = add_ten_minutes(time_data);
|
|
tjd_service_alarm_set_delay_alarm(time.hour, time.minute);
|
|
}
|
|
if (waitTimer_ != nullptr) {
|
|
waitTimer_->Stop();
|
|
delete waitTimer_;
|
|
waitTimer_ = nullptr;
|
|
}
|
|
animator_.Stop();
|
|
RemoveAll();
|
|
}
|
|
|
|
bool TjdUiAppAlarmPopUpPage::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
// printf("TjdUiAppAlarmPopUpPage::OnClick\n");
|
|
if (&view == &cancelButton_) {
|
|
isDeley_ = false; // 关闭延时触发
|
|
TjdUiAlarmNotifyPageDelete();
|
|
} else if (&view == &delayButton_) {
|
|
OnDelayButtonCallback();
|
|
}
|
|
tjd_driver_motor_user_stop();
|
|
return true;
|
|
}
|
|
|
|
void TjdUiAppAlarmPopUpPage::OnDelayButtonCallback()
|
|
{
|
|
timeLabel_.SetVisible(false);
|
|
cancelButton_.SetVisible(false);
|
|
delayButton_.SetVisible(false);
|
|
animator_.SetVisible(false);
|
|
|
|
delayLabel_.SetVisible(true);
|
|
waitTimer_->Stop();
|
|
delete waitTimer_;
|
|
waitTimer_ = new GraphicTimer(3 * 1000, TimerCallback, nullptr, false);
|
|
waitTimer_->Start();
|
|
}
|
|
|
|
////////////////////////////下面两个是对外的接口////////////////////////////
|
|
void TjdUiMsgCenterAlarmProc(const Topic topic, Request *req)
|
|
{
|
|
struct alarm_time *data = static_cast<struct alarm_time *>(req->data);
|
|
if (data == nullptr) {
|
|
// printf("TjdUiMsgCenterAlarmProc data is nullptr");
|
|
return;
|
|
}
|
|
time_data.hour = data->hour;
|
|
time_data.minute = data->minute;
|
|
|
|
if (AlarmNotifyPage == nullptr) {
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic));
|
|
NotificationManager::GetInstance()->ShowNotify(TjdUiAlarmNotifyPageCreate, static_cast<uint16_t>(topic), true);
|
|
}
|
|
}
|
|
|
|
// 当前不需要
|
|
// void TjdUiMsgCenterAlarmNotifyTrigger(void)
|
|
// {
|
|
// GraphicService::GetInstance()->PostGraphicEvent(
|
|
// std::bind(TjdUiMsgEventPublish, TJDUI_TOPIC_EVENT_ALARM, nullptr, 0));
|
|
// }
|
|
|
|
} // namespace TJD
|