331 lines
11 KiB
C++
331 lines
11 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: liangjianfei
|
|
*
|
|
* Create: 2024-5
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiAppStartUpView.h"
|
|
#include "TjdUiAppStartUpItemView.h"
|
|
#include "TjdUiAppStartUpPresenter.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "sys_config.h"
|
|
#include <cctype>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
|
|
using namespace OHOS;
|
|
|
|
// clang-format off
|
|
#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 STARTUP_IMAGE_BIN_PATH TJD_IMAGE_PATH"img_startup.bin"
|
|
static const char url[] = {"http://dw.ss-tjd.com/download/index4.html?name=Lefun&mac="};
|
|
// clang-format on
|
|
|
|
namespace TJD {
|
|
|
|
static TjdStartUpView *g_startUpView = nullptr;
|
|
|
|
static std::string reformatString(const std::string &input)
|
|
{
|
|
static std::string output;
|
|
char upperChar;
|
|
for (size_t i = 0; i < input.length(); i++) {
|
|
if (islower(input[i]))
|
|
upperChar = toupper(input[i]);
|
|
else
|
|
upperChar = input[i];
|
|
output += upperChar;
|
|
// 在每两个字符后(除了最后一个或倒数第二个字符后)插入冒号
|
|
if ((i + 1) % 2 == 0 && i != input.length() - 1) {
|
|
output += ':';
|
|
}
|
|
}
|
|
return output;
|
|
}
|
|
|
|
TjdStartUpView::TjdStartUpView() { g_startUpView = this; }
|
|
|
|
TjdStartUpView::~TjdStartUpView() { g_startUpView = nullptr; }
|
|
|
|
TjdStartUpView *TjdStartUpView::GetInstance() { return g_startUpView; };
|
|
|
|
void TjdStartUpView::OnStart()
|
|
{
|
|
static_print_info("TjdStartUpView::OnStart ");
|
|
allContainer_ = new UIViewGroup();
|
|
allContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
|
|
groupList_[SELECT_VIEW] = SelectContainerInit();
|
|
groupList_[DETAIL_VIEW] = DetailContainerInit();
|
|
groupList_[LINKOK_VIEW] = LinkOKContainerInit();
|
|
|
|
allContainer_->Add(groupList_[SELECT_VIEW]);
|
|
allContainer_->Add(groupList_[DETAIL_VIEW]);
|
|
allContainer_->Add(groupList_[LINKOK_VIEW]);
|
|
|
|
AddViewToRootContainer(allContainer_);
|
|
}
|
|
|
|
void TjdStartUpView::OnStop()
|
|
{
|
|
static_print_info("TjdStartUpView::OnStop");
|
|
if (allContainer_ != nullptr) {
|
|
allContainer_->RemoveAll();
|
|
delete allContainer_;
|
|
allContainer_ = nullptr;
|
|
}
|
|
|
|
if (selectContainer_ != nullptr) {
|
|
selectContainer_->RemoveAll();
|
|
delete selectContainer_;
|
|
selectContainer_ = nullptr;
|
|
}
|
|
if (languageAdapter_) {
|
|
delete languageAdapter_;
|
|
languageAdapter_ = nullptr;
|
|
}
|
|
|
|
if (languageList_) {
|
|
languageList_->RemoveAll();
|
|
delete languageList_;
|
|
languageList_ = nullptr;
|
|
}
|
|
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(STARTUP_IMAGE_BIN_PATH);
|
|
TjdUiMemManage::DeleteChildren(detailContainer_);
|
|
TjdUiMemManage::DeleteChildren(linkOKContainer_);
|
|
}
|
|
|
|
UIViewGroup *TjdStartUpView::SelectContainerInit(void)
|
|
{
|
|
selectContainer_ = new UIViewGroup();
|
|
selectContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
selectContainer_->SetViewId("selectContainer_");
|
|
|
|
languageInfoList_.clear();
|
|
for (uint16_t i = 0; i < language_enum::LANGUAGE_TYPE_MAX; ++i) {
|
|
languageInfoList_.push_back({static_cast<uint8_t>(i), get_language_name(static_cast<language_enum>(i))});
|
|
}
|
|
|
|
languageAdapter_ = new TjdUITransformListGroupAdapter<StartUpItemInfo, StartUpItemView, std::list<StartUpItemInfo>>(
|
|
languageInfoList_);
|
|
languageList_ = new TjdUITransformListGroup(languageAdapter_, "语言");
|
|
languageList_->RequestFocus();
|
|
|
|
selectContainer_->Add(languageList_);
|
|
return selectContainer_;
|
|
}
|
|
|
|
UIViewGroup *TjdStartUpView::DetailContainerInit(void)
|
|
{
|
|
detailContainer_ = new UISwipeView(UISwipeView::VERTICAL);
|
|
detailContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
detailContainer_->SetVisible(false);
|
|
detailContainer_->SetOnDragListener(presenter_);
|
|
detailContainer_->SetOnSwipeListener(presenter_);
|
|
|
|
UIViewGroup *container1_ = new UIViewGroup();
|
|
container1_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
container1_->SetViewId("container1_");
|
|
detailContainer_->Add(container1_);
|
|
|
|
UIViewGroup *container2_ = new UIViewGroup();
|
|
container2_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
container2_->SetViewId("container2_");
|
|
detailContainer_->Add(container2_);
|
|
|
|
qrcode_ = new UIQrcode();
|
|
qrcode_->SetViewId("StartUpQrcode");
|
|
qrcode_->SetPosition(107, 91, 252, 252);
|
|
qrcode_->SetStyle(STYLE_PADDING_LEFT, 10);
|
|
qrcode_->SetStyle(STYLE_PADDING_RIGHT, 10);
|
|
qrcode_->SetStyle(STYLE_PADDING_TOP, 10);
|
|
qrcode_->SetStyle(STYLE_PADDING_BOTTOM, 10);
|
|
qrcode_->SetAutoEnable(false);
|
|
qrcode_->SetResizeMode(UIImageView::ImageResizeMode::FILL);
|
|
qrcode_->SetECCLevel(QrCode::Ecc::QUARTILE);
|
|
qrcode_->SetTouchable(true);
|
|
qrcode_->SetOnClickListener(presenter_);
|
|
container1_->Add(qrcode_);
|
|
|
|
UILabel *label1 = new UILabel();
|
|
label1->SetViewId("label1");
|
|
label1->SetPosition(192, 26, 100, 26);
|
|
label1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
label1->SetText("二维码");
|
|
label1->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
container1_->Add(label1);
|
|
|
|
UILabel *label2 = new UILabel();
|
|
label2->SetViewId("label2");
|
|
label2->SetPosition(108, 364, 249, 71);
|
|
label2->SetText("扫描二维码下载APP或连接手表");
|
|
label2->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
label2->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
|
|
label2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
container1_->Add(label2);
|
|
|
|
UILabel *label3 = new UILabel();
|
|
label3->SetViewId("label3");
|
|
label3->SetPosition(156, 127, 200, 60);
|
|
label3->SetText("扫描MAC连接");
|
|
label3->SetFont(TJD_VECTOR_FONT_FILENAME, 25);
|
|
label3->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
label3->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
container2_->Add(label3);
|
|
|
|
UILabel *label4 = new UILabel();
|
|
label4->SetViewId("label4");
|
|
label4->SetPosition(31, 212, 200, 60);
|
|
label4->SetText("MAC:");
|
|
label4->SetFont(TJD_VECTOR_FONT_FILENAME, 32);
|
|
label4->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
label4->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
container2_->Add(label4);
|
|
|
|
labelMac_ = new UILabel();
|
|
labelMac_->SetViewId("labelMac_");
|
|
labelMac_->SetPosition(156, 212, 300, 60);
|
|
labelMac_->SetFont(TJD_VECTOR_FONT_FILENAME, 32);
|
|
labelMac_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelMac_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
container2_->Add(labelMac_);
|
|
|
|
return detailContainer_;
|
|
}
|
|
|
|
UIViewGroup *TjdStartUpView::LinkOKContainerInit(void)
|
|
{
|
|
linkOKContainer_ = new UISwipeView(UISwipeView::VERTICAL);
|
|
linkOKContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
linkOKContainer_->SetViewId("linkOKContainer_");
|
|
linkOKContainer_->SetVisible(false);
|
|
|
|
UIImageView *image1_ = new UIImageView();
|
|
image1_->SetPosition(66, 150, 330, 144);
|
|
ImageInfo *imageInfo =
|
|
ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STARTUP_LINK_SUCC, STARTUP_IMAGE_BIN_PATH);
|
|
image1_->SetSrc(imageInfo);
|
|
linkOKContainer_->Add(image1_);
|
|
|
|
UILabel *label1 = new UILabel();
|
|
label1->SetViewId("label1");
|
|
label1->SetPosition(166, 305);
|
|
label1->SetText("已连接APP");
|
|
label1->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
label1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
label1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
linkOKContainer_->Add(label1);
|
|
|
|
return linkOKContainer_;
|
|
}
|
|
|
|
void TjdStartUpView::ChangedView(StartUpView view, StartUpView hideView)
|
|
{
|
|
if (view >= STARTUPVIEW_MAX || viewMapper_[view] == nullptr) {
|
|
return;
|
|
}
|
|
|
|
if (hideView == SELECT_VIEW) {
|
|
languageList_->ClearFocus();
|
|
} else if (hideView == DETAIL_VIEW) {
|
|
detailContainer_->ClearFocus();
|
|
presenter_->HideQrcodeViewEvent();
|
|
}
|
|
|
|
(this->*viewMapper_[view])(hideView);
|
|
|
|
if (view == SELECT_VIEW) {
|
|
languageList_->RequestFocus();
|
|
} else if (view == DETAIL_VIEW) {
|
|
detailContainer_->RequestFocus();
|
|
presenter_->ShowQrcodeViewEvent();
|
|
}
|
|
}
|
|
|
|
bool TjdStartUpView::ShowSelectView(StartUpView hideView)
|
|
{
|
|
if (groupList_[hideView] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[hideView]->SetVisible(false);
|
|
|
|
if (groupList_[StartUpView::SELECT_VIEW] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[StartUpView::SELECT_VIEW]->SetVisible(true);
|
|
groupList_[StartUpView::SELECT_VIEW]->Invalidate();
|
|
currentPage = SELECT_VIEW;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TjdStartUpView::ShowDetailView(StartUpView hideView)
|
|
{
|
|
if (groupList_[hideView] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[hideView]->SetVisible(false);
|
|
|
|
if (groupList_[StartUpView::DETAIL_VIEW] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[StartUpView::DETAIL_VIEW]->SetVisible(true);
|
|
groupList_[StartUpView::DETAIL_VIEW]->Invalidate();
|
|
currentPage = DETAIL_VIEW;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TjdStartUpView::ShowlinkOKView(StartUpView hideView)
|
|
{
|
|
if (groupList_[hideView] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[hideView]->SetVisible(false);
|
|
|
|
if (groupList_[StartUpView::LINKOK_VIEW] == nullptr) {
|
|
static_print_error("%s: groupList_ is nullptr", __func__);
|
|
return false;
|
|
}
|
|
groupList_[StartUpView::LINKOK_VIEW]->SetVisible(true);
|
|
groupList_[StartUpView::LINKOK_VIEW]->Invalidate();
|
|
currentPage = LINKOK_VIEW;
|
|
|
|
return true;
|
|
}
|
|
|
|
void TjdStartUpView::InitViewData(void)
|
|
{
|
|
std::string str = url + presenter_->GetMacAddr();
|
|
qrcode_->SetQrcodeInfo(str.c_str());
|
|
str = reformatString(presenter_->GetMacAddr());
|
|
labelMac_->SetText(str.c_str());
|
|
}
|
|
|
|
} // namespace TJD
|