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

84 lines
2.9 KiB
C++

#include "TjdUiAppBusinesscardAdapter.h"
#include "NativeAbility.h"
#include "TjdUiAppBusinesscardView.h"
#include "TjdUiMultiLanguageExt.h"
#include "sql_bt.h"
#include "style.h"
#include "sys_config.h"
#include "ui_checkbox.h"
#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 {
static int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; }
BusinessCardCaseItemView::BusinessCardCaseItemView(const BusinessCardCaseInfo &info)
{
Resize(450, 110);
SetStyle(OHOS::STYLE_MARGIN_TOP, 4);
SetStyle(OHOS::STYLE_MARGIN_BOTTOM, 4);
SetStyle(OHOS::STYLE_BORDER_RADIUS, 55);
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
name_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
icon_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
boundIcon_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
SetTouchable(true);
Add(&icon_);
Add(&name_);
Add(&boundIcon_);
}
BusinessCardCaseItemView::~BusinessCardCaseItemView() { RemoveAll(); }
bool BusinessCardCaseItemView::OnClickEvent(const OHOS::ClickEvent &event)
{
printf("OnClickEvent index = %d\n", itemInfo_.index);
BusinessCardListView::GetInstance()->ChooseBusinesscardItem(static_cast<BusinessCardItemIndex>(itemInfo_.index));
return OHOS::UIView::OnClickEvent(event);
}
void BusinessCardCaseItemView::RefreshItem(const BusinessCardCaseInfo &itemInfo, int16_t index)
{
itemInfo_ = itemInfo;
SetViewIndex(itemInfo.index);
icon_.SetPosition(16, 12, 84, 84);
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
name_.SetTextId(itemInfo.nameId);
icon_.SetSrc(itemInfo.imgInfo);
// name_.SetX(HorizontalCenter(name_.GetWidth()));
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
name_.SetPosition(HorizontalCenter(name_.GetWidth()), 30);
if (itemInfo.type == BusinessCardType::BUSINESSCARD_TYPE_HIDE) {
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0);
} else {
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
}
boundIcon_.SetPosition(391, 34, 42, 42);
boundIcon_.SetSrc(itemInfo.ifBoundsImgInfo);
if (sql_bt_get_qrcode_exist(itemInfo.ifBoundsImgIndex))
boundIcon_.SetVisible(true);
else
boundIcon_.SetVisible(false);
}
} // namespace TJD