mcu_hi3321_watch/tjd/ui/app/startup/TjdUiAppStartUpItemView.cpp
2025-05-26 20:15:20 +08:00

85 lines
2.8 KiB
C++

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
*
* Description:
*
* Author: liangjianfei
*
* Create: 2024-5
*--------------------------------------------------------------------------*/
#include "TjdUiAppStartUpItemView.h"
#include "TjdUiAppStartUpView.h"
#include "TjdUiImageIds.h"
#include "TjdUiMultiLanguageExt.h"
#include "common/image_cache_manager.h"
namespace TJD {
#define STARTUP_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_startup.bin"
// timer = new GraphicTimer(300, TimerCallback, nullptr);
// GraphicService::GetInstance()->PostGraphicEvent(
// std::bind([](void *arg) { TjdStartUpView::GetInstance()->ChangedView(DETAIL_VIEW, SELECT_VIEW); }, arg));
StartUpItemView::StartUpItemView(const StartUpItemInfo &itemInfo)
{
SetPosition(8, 0, 450, 128);
SetTouchable(true);
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
SetStyle(OHOS::STYLE_BORDER_RADIUS, 64);
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
SetViewIndex(itemInfo.index);
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
name_.SetText(itemInfo.name.c_str());
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_STRETCH);
name_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
name_.SetHeight(GetHeight());
name_.SetX(42);
selectIcon_.SetPosition(382, 44, 40, 40);
selectRes_ =
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STARTUP_ICON_SELECT, STARTUP_IMAGE_BIN_PATH);
unSelectRes_ =
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STARTUP_ICON_NO, STARTUP_IMAGE_BIN_PATH);
Add(&name_);
Add(&selectIcon_);
}
void StartUpItemView::RefreshItem(const StartUpItemInfo &itemInfo, int16_t index)
{
name_.SetText(itemInfo.name.c_str());
if (itemInfo.index == TjdStartUpPresenter::GetInstance()->GetLanguageSelect()) {
selectIcon_.SetSrc(selectRes_);
} else {
selectIcon_.SetSrc(unSelectRes_);
}
}
bool StartUpItemView::OnClickEvent(const OHOS::ClickEvent &event)
{
OHOS::UIView *childView = static_cast<OHOS::UITransformList *>(GetParent())->GetChildrenHead();
while (childView != nullptr) {
static_cast<StartUpItemView *>(childView)->selectIcon_.SetSrc(unSelectRes_);
childView = childView->GetNextSibling();
}
if (selectIcon_.GetImageInfo()->resId == selectRes_->resId) {
selectIcon_.SetSrc(unSelectRes_);
} else {
selectIcon_.SetSrc(selectRes_);
}
selectIcon_.Invalidate();
TjdStartUpPresenter *presenter = TjdStartUpPresenter::GetInstance();
if (presenter == nullptr) {
return false;
}
presenter->SetLanguageSelect(static_cast<language_enum>(GetViewIndex()));
presenter->StartJumpTimer(StartUpView::DETAIL_VIEW);
return true;
}
} // namespace TJD