132 lines
3.9 KiB
C++
132 lines
3.9 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: wuchangxin
|
|
*
|
|
* Create: 2024-6-14
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiAppMainPageMap.h"
|
|
#include "TjdUiAppMainPresenter.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "gfx_utils/mem_check.h"
|
|
#include "sys_config.h"
|
|
#include <string>
|
|
|
|
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
|
|
|
|
namespace TJD {
|
|
|
|
#define MAIN_MAP_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_main_map.bin"
|
|
|
|
static TjdUiAppMainPageMap *g_pMapPage = nullptr;
|
|
|
|
TjdUiAppMainPageMap::TjdUiAppMainPageMap()
|
|
{
|
|
SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
g_pMapPage = this;
|
|
}
|
|
|
|
TjdUiAppMainPageMap::~TjdUiAppMainPageMap()
|
|
{
|
|
UnLoad();
|
|
g_pMapPage = nullptr;
|
|
}
|
|
|
|
TjdUiAppMainPageMap *TjdUiAppMainPageMap::GetInstance(void) { return g_pMapPage; }
|
|
|
|
void TjdUiAppMainPageMap::PreLoad(void)
|
|
{
|
|
static_print_debug("TjdUiAppMainPageMap::PreLoad");
|
|
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(true);
|
|
if (!viewiInitStatus) {
|
|
InitView();
|
|
viewiInitStatus = true;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppMainPageMap::UnLoad(void)
|
|
{
|
|
static_print_debug("TjdUiAppMainPageMap::UnLoad");
|
|
if (viewiInitStatus) {
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(MAIN_MAP_IMAGE_BIN_PATH);
|
|
RemoveAll();
|
|
if (container_) {
|
|
container_->RemoveAll();
|
|
delete container_;
|
|
container_ = nullptr;
|
|
}
|
|
if (image_bg) {
|
|
delete image_bg;
|
|
image_bg = nullptr;
|
|
}
|
|
if (image_enter) {
|
|
delete image_enter;
|
|
image_enter = nullptr;
|
|
}
|
|
viewiInitStatus = false;
|
|
}
|
|
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(false); // 关闭内存泄露检测
|
|
}
|
|
|
|
class MapOnClickListener : public UIView::OnClickListener
|
|
{
|
|
public:
|
|
MapOnClickListener() {}
|
|
virtual ~MapOnClickListener() {}
|
|
virtual bool OnClick(UIView &view, const ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
if (viewId == "image_enter") {
|
|
NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN); // 目前点击enter后跳转回主界面
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
bool TjdUiAppMainPageMap::InitView(void)
|
|
{
|
|
ImageCacheManager::GetInstance().LoadAllInMultiRes(MAIN_MAP_IMAGE_BIN_PATH);
|
|
|
|
container_ = new UIViewGroup();
|
|
container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
|
|
|
image_bg = new UIImageView();
|
|
image_bg->SetPosition(0, 0, 466, 466);
|
|
auto *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_MAP_BJ, MAIN_MAP_IMAGE_BIN_PATH);
|
|
if (imgInfo == nullptr) {
|
|
static_print_debug("load image error");
|
|
}
|
|
image_bg->SetSrc(imgInfo);
|
|
container_->Add(image_bg);
|
|
|
|
image_enter = new UIImageView();
|
|
image_enter->SetPosition(76, 377, 312, 88);
|
|
image_enter->SetViewId("image_enter");
|
|
imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_MAP_ENTER, MAIN_MAP_IMAGE_BIN_PATH);
|
|
image_enter->SetSrc(imgInfo);
|
|
// image_enter->SetTouchable(true);
|
|
// image_enter->SetOnClickListener(new MapOnClickListener());
|
|
container_->Add(image_enter);
|
|
|
|
Add(container_);
|
|
return true;
|
|
}
|
|
} // namespace TJD
|