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

134 lines
4.2 KiB
C++

#include "TjdUiAppSettingAdapter.h"
#include "NativeAbility.h"
#include "TjdUiImageIds.h"
#include "TjdUiMultiLanguageExt.h"
#include "common/image_cache_manager.h"
#include "style.h"
#include "components/ui_image_view.h"
#include "ui_view.h"
#include <stdio.h>
#include "TjdUiAppSettingView.h"
#include "TjdUiUtils.h"
#include "components/ui_label_button.h"
#include "components/ui_qrcode.h"
#include "components/ui_toggle_button.h"
#include "components/ui_view.h"
#include "components/ui_view_group.h"
using namespace OHOS;
#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 IMAGE_BIN_PATH TJD_IMAGE_PATH "img_setting.bin"
namespace TJD {
SettingListItemView::SettingListItemView(const SettingCaseInfo &info)
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(450, 128);
SetTouchable(true);
SetOnClickListener(TjdUiAppSettingPresenter::GetInstance());
SetViewIndex(info.index);
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
SetStyle(OHOS::STYLE_BORDER_RADIUS, 64);
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
icon_.SetPosition(16, 19, 90, 90);
if (info.imgInfo != nullptr) {
icon_.SetSrc(info.imgInfo);
}
name_.Resize(220, GetHeight());
name_.SetPosition(120, 0);
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 40);
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
Add(&icon_);
Add(&name_);
switch_.SetPosition(348, 45, 72, 38);
switch_.SetTouchable(false);
openRes_ = images.LoadOneInMultiRes(IMG_SETTING_OPEN, IMAGE_BIN_PATH);
closeRes_ = images.LoadOneInMultiRes(IMG_SETTING_COLSE, IMAGE_BIN_PATH);
Add(&switch_);
}
void SettingListItemView::RefreshItem(const SettingCaseInfo &info, int16_t index)
{
itemInfo_ = info;
name_.SetTextId(info.name);
auto viewIndex = GetViewIndex();
if (closeRes_ != nullptr && openRes_ != nullptr) {
if (viewIndex == SETTING_BLUETOOTH_INDEX) {
TjdUiAppSettingPresenter::GetInstance()->IsOpenBle() ? switch_.SetSrc(openRes_) : switch_.SetSrc(closeRes_);
} else {
if (viewIndex == SETTING_PINCH_TO_ANSWER_INDEX) {
SetSwitchSelected(TjdUiAppSettingPresenter::GetInstance()->IsPinchToAnswer());
} else if (viewIndex == SETTING_COVER_TO_TURN_OFF_SCREEN_INDEX) {
SetSwitchSelected(TjdUiAppSettingPresenter::GetInstance()->IsCoverToTurnOffScreen());
}
}
}
if (SETTING_USER_INDEX != info.index) {
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 40);
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
TjdUiUtils::AutoAlignHorizontalCenter(name_, GetWidth());
icon_.SetY(19);
} else {
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
name_.SetText(TjdUiAppSettingPresenter::GetInstance()->GetUserName().c_str());
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff000000);
icon_.SetY(13);
}
if (info.isCanSwitch) {
switch_.SetVisible(true);
switch_.Invalidate();
Invalidate();
} else {
switch_.SetVisible(false);
switch_.Invalidate();
Invalidate();
}
if (info.imgInfo) {
icon_.SetSrc(info.imgInfo);
icon_.Resize(info.imgInfo->header.width, info.imgInfo->header.height);
}
}
SettingListItemView::~SettingListItemView() { RemoveAll(); }
bool SettingListItemView::OnClickEvent(const OHOS::ClickEvent &event)
{
TjdUiAppSettingPresenter *persneter = TjdUiAppSettingPresenter::GetInstance();
if (persneter == nullptr) {
return false;
}
ToggleSwitch();
bool ret = persneter->OnClickSettingItem(itemInfo_, IsSwitchSelected());
if (!ret) {
ToggleSwitch();
}
return true;
}
} // namespace TJD