196 lines
7.0 KiB
C++
196 lines
7.0 KiB
C++
#include "TjdUiAppDrainView.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "gfx_utils/mem_check.h"
|
|
#include "graphic_service.h"
|
|
#include "motor.h"
|
|
|
|
namespace TJD {
|
|
|
|
using namespace OHOS;
|
|
#define IF_MEM_CHECK 0
|
|
#define REFUSEHAND_ANIMATOR_COUNT 4
|
|
#define DRAIN_ANIMATOR_COUNT 5
|
|
|
|
int RefuseHandAnimatorId[REFUSEHAND_ANIMATOR_COUNT] = {IMG_DRAIN_REFUSEHAND_01, IMG_DRAIN_REFUSEHAND_02,
|
|
IMG_DRAIN_REFUSEHAND_03, IMG_DRAIN_REFUSEHAND_04};
|
|
|
|
int DrainAnimatorId[DRAIN_ANIMATOR_COUNT] = {IMG_DRAIN_DRAIN_01, IMG_DRAIN_DRAIN_02, IMG_DRAIN_DRAIN_03,
|
|
IMG_DRAIN_DRAIN_04, IMG_DRAIN_DRAIN_05};
|
|
|
|
#define Drain_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_drain.bin"
|
|
|
|
static OHOS::ImageInfo *g_pv_drainimageInfo[DrainViewIndex::Drain_VIEW_COUNT]{nullptr};
|
|
static OHOS::ImageAnimatorInfo g_pv_animatorInfo_[REFUSEHAND_ANIMATOR_COUNT];
|
|
static OHOS::ImageAnimatorInfo g_pv_animatorInfo_1[DRAIN_ANIMATOR_COUNT];
|
|
static TjdUiAppDrainView *g_pv_AppDrainView = nullptr;
|
|
TjdUiAppDrainView::TjdUiAppDrainView()
|
|
{
|
|
if (IF_MEM_CHECK)
|
|
OHOS::MemCheck::GetInstance()->EnableLeakCheck(true);
|
|
g_pv_AppDrainView = this;
|
|
}
|
|
TjdUiAppDrainView::~TjdUiAppDrainView()
|
|
{
|
|
g_pv_AppDrainView = nullptr;
|
|
if (IF_MEM_CHECK)
|
|
OHOS::MemCheck::GetInstance()->EnableLeakCheck(false);
|
|
}
|
|
TjdUiAppDrainView *TjdUiAppDrainView::GetInstance(void) { return g_pv_AppDrainView; }
|
|
|
|
void TjdUiAppDrainView::OnStart()
|
|
{
|
|
View<TjdUiAppDrainPresenter>::OnStart();
|
|
InitDrainImage();
|
|
if (containerAll_ == nullptr) {
|
|
containerAll_ = new UIScrollView();
|
|
}
|
|
containerAll_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
containerAll_->SetOnDragListener(TjdUiAppDrainPresenter::GetInstance());
|
|
drainView[DrainViewIndex::Refuse_Hand_VIEW] = InitRefuseHandView();
|
|
containerAll_->Add(drainView[DrainViewIndex::Refuse_Hand_VIEW]);
|
|
AddViewToRootContainer(containerAll_);
|
|
}
|
|
|
|
void TjdUiAppDrainView::OnStop()
|
|
{
|
|
tjd_driver_motor_user_stop();
|
|
if (timerdrain1_ != nullptr) {
|
|
timerdrain1_->Stop();
|
|
delete timerdrain1_;
|
|
timerdrain1_ = nullptr;
|
|
}
|
|
if (timerdrain2_ != nullptr) {
|
|
timerdrain2_->Stop();
|
|
delete timerdrain2_;
|
|
timerdrain2_ = nullptr;
|
|
}
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(Drain_IMAGE_BIN_PATH);
|
|
TjdUiMemManage::DeleteChildren(containerAll_);
|
|
}
|
|
|
|
void TjdUiAppDrainView::ShowView(DrainViewIndex hideView, DrainViewIndex showView)
|
|
{
|
|
if (drainView[hideView] != nullptr) {
|
|
drainView[hideView]->SetVisible(false);
|
|
}
|
|
if (drainView[showView] != nullptr) {
|
|
drainView[showView]->SetVisible(true);
|
|
currentView_ = showView;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppDrainView::InitDrainImage()
|
|
{
|
|
ImageCacheManager &imgManager = ImageCacheManager::GetInstance();
|
|
for (int i = 0; i < REFUSEHAND_ANIMATOR_COUNT; i++) {
|
|
g_pv_animatorInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(RefuseHandAnimatorId[i], Drain_IMAGE_BIN_PATH);
|
|
g_pv_animatorInfo_[i].pos = {111, 69};
|
|
g_pv_animatorInfo_[i].width = 267;
|
|
g_pv_animatorInfo_[i].height = 239;
|
|
g_pv_animatorInfo_[i].imageType = IMG_SRC_IMAGE_INFO;
|
|
}
|
|
|
|
for (int j = 0; j < DRAIN_ANIMATOR_COUNT; j++) {
|
|
g_pv_animatorInfo_1[j].imageInfo = imgManager.LoadOneInMultiRes(DrainAnimatorId[j], Drain_IMAGE_BIN_PATH);
|
|
g_pv_animatorInfo_1[j].pos = {314, 214};
|
|
g_pv_animatorInfo_1[j].width = 152;
|
|
g_pv_animatorInfo_1[j].height = 114;
|
|
g_pv_animatorInfo_1[j].imageType = IMG_SRC_IMAGE_INFO;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppDrainView::Changestatus1()
|
|
{
|
|
tjd_driver_motor_user_stop();
|
|
TjdUiAppDrainPresenter::GetInstance()->PlayerStop();
|
|
imageAnimatordrain_->SetVisible(false);
|
|
lblDrain_->SetVisible(false);
|
|
imageAnimatorwatch_->SetVisible(true);
|
|
lblRefuseHand_->SetVisible(true);
|
|
bool redo = true;
|
|
// TjdUiAppProductionModel::GetInstance()->ProductionItem(PRODUCTION_OPEN, PRODUCTION_ITEM_MOTOR, &redo);
|
|
}
|
|
|
|
void TjdUiAppDrainView::Changestatus2()
|
|
{
|
|
// TjdUiAppProductionModel::GetInstance()->ProductionItem(PRODUCTION_CLOSE, PRODUCTION_ITEM_MOTOR, NULL);
|
|
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);
|
|
}
|
|
|
|
void TimerCallback_Drain1(void *param)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent([]() { TjdUiAppDrainView::GetInstance()->Changestatus1(); });
|
|
}
|
|
|
|
void TimerCallback_Drain2(void *param)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent([]() { TjdUiAppDrainView::GetInstance()->Changestatus2(); });
|
|
}
|
|
|
|
OHOS::UIViewGroup *TjdUiAppDrainView::InitRefuseHandView()
|
|
{
|
|
OHOS::UIViewGroup *refuseHandView = new OHOS::UIViewGroup();
|
|
refuseHandView->SetPosition(0, 0, 466, 466);
|
|
|
|
motor_param_t motorParam = {.cycle1_on = 200, .cycle1_off = 100, .cycle1_cnt = 0xffff, .duty = 100};
|
|
tjd_driver_motor_user_start(&motorParam);
|
|
|
|
TjdUiAppDrainPresenter::GetInstance()->PlayerStart();
|
|
osDelay(100);
|
|
TjdUiAppDrainPresenter::GetInstance()->LoopPlayerStart();
|
|
|
|
if (lblDrain_ == nullptr) {
|
|
lblDrain_ = new UILabelExt();
|
|
}
|
|
lblDrain_->SetFont(TJD_VECTOR_FONT_FILENAME, 30);
|
|
// lblDrain_->SetText("正在自动排水...");
|
|
lblDrain_->SetTextId(STR_ID_72);
|
|
lblDrain_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
|
|
lblDrain_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lblDrain_->SetPosition(66, 353,334,42);
|
|
lblDrain_->SetVisible(true);
|
|
|
|
imageAnimatorwatch_ = new OHOS::UIImageAnimatorView();
|
|
imageAnimatorwatch_->SetPosition(111, 69, 267, 239);
|
|
imageAnimatorwatch_->SetImageAnimatorSrc(g_pv_animatorInfo_, REFUSEHAND_ANIMATOR_COUNT, 100);
|
|
imageAnimatorwatch_->Start();
|
|
imageAnimatorwatch_->SetVisible(false);
|
|
|
|
if (lblRefuseHand_ == nullptr) {
|
|
lblRefuseHand_ = new UILabelExt();
|
|
}
|
|
lblRefuseHand_->SetFont(TJD_VECTOR_FONT_FILENAME, 30);
|
|
// lblRefuseHand_->SetText("甩甩手表...");
|
|
lblRefuseHand_->SetTextId(STR_ID_73);
|
|
lblRefuseHand_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
|
|
lblRefuseHand_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lblRefuseHand_->SetPosition(66, 340,334,42);
|
|
lblRefuseHand_->SetVisible(false);
|
|
|
|
imageAnimatordrain_ = new OHOS::UIImageAnimatorView();
|
|
imageAnimatordrain_->SetPosition(111, 69, 267, 239);
|
|
imageAnimatordrain_->SetImageAnimatorSrc(g_pv_animatorInfo_1, DRAIN_ANIMATOR_COUNT, 100);
|
|
imageAnimatordrain_->Start();
|
|
imageAnimatordrain_->SetVisible(true);
|
|
|
|
if (timerdrain1_ == nullptr) {
|
|
timerdrain1_ = new OHOS::GraphicTimer(5000, TimerCallback_Drain1, nullptr, false);
|
|
timerdrain1_->Start();
|
|
}
|
|
if (timerdrain2_ == nullptr) {
|
|
timerdrain2_ = new OHOS::GraphicTimer(8000, TimerCallback_Drain2, nullptr, false);
|
|
timerdrain2_->Start();
|
|
}
|
|
|
|
refuseHandView->Add(lblDrain_);
|
|
refuseHandView->Add(imageAnimatordrain_);
|
|
refuseHandView->Add(lblRefuseHand_);
|
|
refuseHandView->Add(imageAnimatorwatch_);
|
|
refuseHandView->SetVisible(true);
|
|
|
|
return refuseHandView;
|
|
}
|
|
|
|
} // namespace TJD
|