219 lines
7.5 KiB
C++
219 lines
7.5 KiB
C++
/*----------------------------------------------------------------------------
|
||
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
||
*
|
||
* Description:
|
||
*
|
||
* Author: huangshuyi
|
||
*
|
||
* Create: 2024-8
|
||
*--------------------------------------------------------------------------*/
|
||
|
||
#include "components/ui_label.h"
|
||
#include "wearable_log.h"
|
||
#include "common/image_cache_manager.h"
|
||
#include <time.h>
|
||
#include <unordered_map>
|
||
#include "gfx_utils/image_info.h"
|
||
#include "gfx_utils/heap_base.h"
|
||
#include "TjdUiImageIds.h"
|
||
#include "ui_label.h"
|
||
#include "TjdUiMultiLanguageExt.h"
|
||
#include "sys_config.h"
|
||
#include "components/ui_view.h"
|
||
#include "components/ui_view_group.h"
|
||
#include "components/root_view.h"
|
||
#include "components/ui_scroll_view.h"
|
||
#include "components/ui_image_view.h"
|
||
#include "components/ui_image_animator.h"
|
||
#include "ui_label_ext.h"
|
||
|
||
#include "notification_manager.h"
|
||
#include "msg_center.h"
|
||
#include "TjdUiMsgCenter.h"
|
||
#include "TjdUiMemManage.h"
|
||
#include "NativeAbility.h"
|
||
#include "TjdUiAppIds.h"
|
||
#include "TransitionType.h"
|
||
#include "animator/animator_manager.h"
|
||
#include "time.h"
|
||
#include "sys/time.h"
|
||
#include "graphic_timer.h"
|
||
|
||
using namespace OHOS;
|
||
using namespace TJD;
|
||
|
||
#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
|
||
|
||
#define FEMALE_IMAGE_BIN_PATH TJD_IMAGE_PATH"img_female.bin"
|
||
static const int ANIMATOR_COUNT = 9;
|
||
static OHOS::ImageAnimatorInfo g_pv_waitInfo_[ANIMATOR_COUNT];
|
||
|
||
class TjdUiFemaleNotifyPage : public OHOS::UIView::OnClickListener, public OHOS::UIView::OnDragListener
|
||
{
|
||
public:
|
||
TjdUiFemaleNotifyPage(){}
|
||
virtual ~TjdUiFemaleNotifyPage();
|
||
bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event) override
|
||
{
|
||
NotificationManager::GetInstance()->StopNotify();
|
||
|
||
return true;
|
||
}
|
||
bool OnDrag(OHOS::UIView& view, const OHOS::DragEvent& event)
|
||
{
|
||
dragCurrentX_ = event.GetCurrentPos().x;
|
||
dragDistance_ = dragCurrentX_ - dragStartX_;
|
||
if (dragDistance_ >= 100 && dragStartX_ < 80) {
|
||
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) {
|
||
dragDistance_ = 0;
|
||
NotificationManager::GetInstance()->StopNotify();
|
||
//OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
||
//printf("TjdUiMessageDetailsPage::OnDrag:dragDistance_:%d\n", dragDistance_);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
bool OnDragStart(OHOS::UIView& view, const OHOS::DragEvent& event)
|
||
{
|
||
// 如果在0-80的距离内开始滑动,并且拖动的距离大于200,则认为是退出标志
|
||
dragStartX_ = event.GetStartPoint().x;
|
||
//printf("dragStartX_ = %d\n", dragStartX_);
|
||
return true;
|
||
}
|
||
bool OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event)
|
||
{
|
||
return true;
|
||
}
|
||
UIViewGroup* PageInit(void);
|
||
UIViewGroup* Page{nullptr};
|
||
OHOS::UIImageAnimatorView* animator_{nullptr};
|
||
OHOS::GraphicTimer *waitTimer_{nullptr};
|
||
private:
|
||
|
||
static void TimerCallback(void*);
|
||
int16_t dragStartX_{0};
|
||
int16_t dragCurrentX_{0};
|
||
int32_t dragDistance_{0};
|
||
};
|
||
|
||
static TjdUiFemaleNotifyPage*FemaleNotifyPage = nullptr;
|
||
|
||
TjdUiFemaleNotifyPage::~TjdUiFemaleNotifyPage()
|
||
{
|
||
|
||
}
|
||
|
||
static void PageFree(void)
|
||
{
|
||
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST);
|
||
if (FemaleNotifyPage != nullptr) {
|
||
FemaleNotifyPage->waitTimer_->Stop();
|
||
FemaleNotifyPage->animator_->Stop();
|
||
RootView::GetInstance()->Remove(FemaleNotifyPage->Page);
|
||
TjdUiMemManage::DeleteChildren(FemaleNotifyPage->Page);
|
||
delete FemaleNotifyPage->waitTimer_;
|
||
FemaleNotifyPage->waitTimer_ = nullptr;
|
||
}
|
||
delete FemaleNotifyPage;
|
||
printf("PageFree\n");
|
||
RunPopOutPageCallback();
|
||
}
|
||
|
||
void TjdUiFemaleNotifyPage::TimerCallback(void* arg)
|
||
{
|
||
static_print_debug("TjdUiFemaleWaitDataPage::Timeout\n");
|
||
//NotificationManager::GetInstance()->StopNotify();
|
||
}
|
||
|
||
UIViewGroup* TjdUiFemaleNotifyPage::PageInit(void)
|
||
{
|
||
Page = new UIViewGroup();
|
||
if (Page == nullptr) {
|
||
static_print_error("CreateAlarmView g_alarmView null!");
|
||
return nullptr;
|
||
}
|
||
Page->SetDraggable(true);
|
||
Page->SetTouchable(true);
|
||
Page->SetOnDragListener(this);
|
||
Page->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
||
//Page->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
|
||
|
||
animator_ = new UIImageAnimatorView();
|
||
animator_->SetPosition(156, 78, 156, 73);
|
||
Page->Add(animator_);
|
||
const int WaitAnimatorId[ANIMATOR_COUNT] = {
|
||
IMG_FEMALE_RING0, IMG_FEMALE_RING1, IMG_FEMALE_RING2, IMG_FEMALE_RING3, IMG_FEMALE_RING4, IMG_FEMALE_RING5,
|
||
IMG_FEMALE_RING6, IMG_FEMALE_RING7, IMG_FEMALE_RING8
|
||
};
|
||
auto &imgManager = OHOS::ImageCacheManager::GetInstance();
|
||
|
||
for (int i = 0; i < ANIMATOR_COUNT; i++) {
|
||
g_pv_waitInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(WaitAnimatorId[i], FEMALE_IMAGE_BIN_PATH);
|
||
g_pv_waitInfo_[i].pos = {156, 78};
|
||
g_pv_waitInfo_[i].width = 185;
|
||
g_pv_waitInfo_[i].height = 180;
|
||
g_pv_waitInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
|
||
}
|
||
waitTimer_ = new OHOS::GraphicTimer(3000, TimerCallback, nullptr, false);
|
||
animator_->SetImageAnimatorSrc(g_pv_waitInfo_, ANIMATOR_COUNT, 100);
|
||
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(PageFree);
|
||
animator_->Start();
|
||
waitTimer_->Start();
|
||
|
||
UILabel *labelFemale = new UILabel();
|
||
Page->Add(labelFemale);
|
||
labelFemale->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
Page->Add(labelFemale);
|
||
char buf[50];
|
||
uint8_t day=1;
|
||
snprintf(buf, 50, "距离本月经期还有%d天", day);//需要根据实际数据显示
|
||
labelFemale->SetText(buf);
|
||
labelFemale->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
||
labelFemale->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
||
labelFemale->LayoutLeftOfParent((Page->GetWidth() - labelFemale->GetWidth()) / 2);
|
||
labelFemale->LayoutTopOfParent(298);
|
||
|
||
ImageInfo* imgInfo;
|
||
UIImageView *imageOk_ = new UIImageView();
|
||
imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FEMALE_CONFIRM, FEMALE_IMAGE_BIN_PATH);
|
||
Page->Add(imageOk_);
|
||
imageOk_->SetPosition(52, 380);
|
||
imageOk_->SetSrc(imgInfo);
|
||
imageOk_->SetOnClickListener(this);
|
||
imageOk_->SetTouchable(true);
|
||
|
||
return Page;
|
||
}
|
||
|
||
static UIViewGroup* TjdUiFemaleNotifyPageCreate(void)
|
||
{
|
||
FemaleNotifyPage = new TjdUiFemaleNotifyPage();
|
||
return FemaleNotifyPage->PageInit();
|
||
}
|
||
|
||
////////////////////////////下面两个是对外的接口////////////////////////////
|
||
void TjdUiMsgCenterFemaleProc(const Topic topic, Request* req)
|
||
{
|
||
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic));
|
||
NotificationManager::GetInstance()->ShowNotify(TjdUiFemaleNotifyPageCreate, static_cast<uint16_t>(topic), true);
|
||
}
|
||
|
||
//extern "C" {
|
||
void TjdUiMsgCenterFemaleNotifyTrigger(void)
|
||
{
|
||
GraphicService::GetInstance()->PostGraphicEvent(
|
||
std::bind(TjdUiMsgEventPublish, TJDUI_TOPIC_EVENT_FEMALE, nullptr, 0));
|
||
}
|
||
//}
|