327 lines
9.3 KiB
C++
327 lines
9.3 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayDialAdapter.h
|
|
*
|
|
* Author: liuguanwu
|
|
*
|
|
* Create: 2024-10
|
|
*--------------------------------------------------------------------------*/
|
|
#ifndef TJDUI_APP_PLAY_DIAL_ADAPTOR_H
|
|
#define TJDUI_APP_PLAY_DIAL_ADAPTOR_H
|
|
|
|
#include "components/abstract_adapter.h"
|
|
#include "components/ui_image_view.h"
|
|
#include "components/ui_label_button.h"
|
|
#include "components/ui_label.h"
|
|
#include "components/ui_list.h"
|
|
#include "components/ui_label_ext.h"
|
|
#include "components/ui_scroll_view.h"
|
|
#include "components/ui_view_group.h"
|
|
#include "common/screen.h"
|
|
#include <list>
|
|
|
|
namespace TJD {
|
|
|
|
enum TjdAiStyleIndex : uint8_t {
|
|
AI_STYLE_INVALID = 0,
|
|
AI_STYLE_JAPANESE_ANIME = 1,
|
|
AI_STYLE_OIL_PAINTING = 2,
|
|
AI_STYLE_ANTIQUITIES = 3,
|
|
AI_STYLE_ABSTRACT_ART = 4,
|
|
AI_STYLE_DARK_ART = 5,
|
|
AI_STYLE_INK_AND_WASH = 6,
|
|
AI_STYLE_3D_RENDERING = 7,
|
|
AI_STYLE_VANGOGH_WIND = 8,
|
|
AI_STYLE_ILLUSTRATION = 9,
|
|
AI_STYLE_HAYAO_MIYAZAKI = 10,
|
|
AI_STYLE_MONET = 11,
|
|
AI_STYLE_MACHINERY = 12,
|
|
AI_STYLE_CERAMIC_WORLD = 13,
|
|
AI_STYLE_PAPER_CUT = 14,
|
|
AI_STYLE_BLACK_WHITE_SKETCH = 15,
|
|
AI_STYLE_THICK_COATING_WIND = 16,
|
|
AI_STYLE_5D_PORTRAIT = 17,
|
|
AI_STYLE_SCIENCE_FICTION = 18,
|
|
AI_STYLE_MAX_ID,
|
|
}; // TjdUiTextId
|
|
|
|
typedef struct {
|
|
int resId;
|
|
uint8_t styleId;
|
|
// char* pText;
|
|
uint16_t styleINamed;
|
|
}AiStyleItem;
|
|
|
|
class listContainerStyle : public OHOS::UIViewGroup {
|
|
public:
|
|
listContainerStyle() : imageBg_(nullptr), image_(nullptr), label_(nullptr) {}
|
|
~listContainerStyle() override
|
|
{
|
|
// printf("delete image text......\n");
|
|
RemoveAll();
|
|
if (imageBg_ != nullptr) {
|
|
delete imageBg_;
|
|
imageBg_ = nullptr;
|
|
}
|
|
if (image_ != nullptr) {
|
|
delete image_;
|
|
image_ = nullptr;
|
|
}
|
|
if (label_ != nullptr) {
|
|
delete label_;
|
|
label_ = nullptr;
|
|
}
|
|
}
|
|
listContainerStyle(const listContainerStyle &) = delete;
|
|
listContainerStyle &operator=(const listContainerStyle &) = delete;
|
|
|
|
bool InitContainer();
|
|
|
|
OHOS::UIImageView* GetImageBgView()
|
|
{
|
|
return imageBg_;
|
|
}
|
|
|
|
OHOS::UIImageView* GetImageView()
|
|
{
|
|
return image_;
|
|
}
|
|
|
|
OHOS::UILabelExt* GetLabelView()
|
|
{
|
|
return label_;
|
|
}
|
|
|
|
private:
|
|
OHOS::UIImageView* imageBg_;
|
|
OHOS::UIImageView* image_;
|
|
OHOS::UILabelExt* label_;
|
|
};
|
|
|
|
class TjdPlayDialAdapter : public OHOS::AbstractAdapter
|
|
{
|
|
public:
|
|
explicit TjdPlayDialAdapter() {}
|
|
~TjdPlayDialAdapter() {}
|
|
|
|
uint16_t GetCount(void);
|
|
OHOS::UIView *GetView(OHOS::UIView *inView, int16_t index) override;
|
|
class StyleList : public OHOS::UIList {
|
|
public:
|
|
void ReMeasure() override;
|
|
|
|
};
|
|
};
|
|
|
|
class TjdHistoryScrollView : public OHOS::UIScrollView
|
|
{
|
|
public:
|
|
TjdHistoryScrollView()
|
|
{}
|
|
~TjdHistoryScrollView()
|
|
{}
|
|
bool OnDragStartEvent(const OHOS::DragEvent &event) override
|
|
{
|
|
if(tjdScrollDir_ == TJD_BOTH_DIR_FIRST) {
|
|
tjdIntercept_ = IsIntercept();
|
|
uint8_t direction = event.GetDragDirection();
|
|
if (direction == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT || direction == OHOS::DragEvent::DIRECTION_RIGHT_TO_LEFT) {
|
|
SetIntercept(true);
|
|
}
|
|
if (IsIntercept() == true){
|
|
UIScrollView::OnDragStartEvent(event);
|
|
} else {
|
|
UIView::OnDragStartEvent(event);
|
|
}
|
|
}else{
|
|
return UIScrollView::OnDragStartEvent(event);
|
|
}
|
|
return IsIntercept();
|
|
}
|
|
bool OnDragEvent(const OHOS::DragEvent &event) override
|
|
{
|
|
if(tjdScrollDir_ == TJD_BOTH_DIR_FIRST) {
|
|
if (IsIntercept() == true){
|
|
UIScrollView::OnDragEvent(event);
|
|
} else {
|
|
UIView::OnDragEvent(event);
|
|
}
|
|
}else{
|
|
return UIScrollView::OnDragEvent(event);
|
|
}
|
|
return IsIntercept();
|
|
}
|
|
bool OnDragEndEvent(const OHOS::DragEvent& event) override
|
|
{
|
|
bool tempIntercept = IsIntercept();
|
|
if(tjdScrollDir_ == TJD_BOTH_DIR_FIRST) {
|
|
if (IsIntercept() == true){
|
|
UIScrollView::OnDragEndEvent(event);
|
|
} else {
|
|
UIView::OnDragEndEvent(event);
|
|
}
|
|
SetIntercept(tjdIntercept_);
|
|
}else{
|
|
return UIScrollView::OnDragEndEvent(event);
|
|
}
|
|
return tempIntercept;
|
|
}
|
|
|
|
void StartAnimatorOnDragEnd()
|
|
{
|
|
int16_t startValueX = GetChildrenHead()->GetX();
|
|
int16_t endValueX = GetChildrenTail()->GetX() + GetChildrenTail()->GetRelativeRect().GetWidth();
|
|
int16_t widthValueX = GetWidth();
|
|
int16_t tempDistanceX = 0;
|
|
if(abs(startValueX) < abs(endValueX - widthValueX)) {
|
|
tempDistanceX = abs(startValueX);
|
|
} else {
|
|
tempDistanceX = -abs(endValueX - widthValueX);
|
|
}
|
|
if(tempDistanceX == 0) {return;}
|
|
StartAnimator(tempDistanceX, 0);
|
|
//uint32_t timeTemp = 360*abs(tempDistanceX)/Screen::GetInstance().GetWidth();
|
|
//Animator_->SetTime((timeTemp > 100)? timeTemp : 100);
|
|
uint32_t timesTemp = 360/16.7*abs(tempDistanceX)/OHOS::Screen::GetInstance().GetWidth();
|
|
animatorCallback_.SetDragTimes((timesTemp > 5)? timesTemp : 5);
|
|
}
|
|
void StartAnimatorViewback()
|
|
{
|
|
int16_t startValueX = GetChildrenHead()->GetX();
|
|
int16_t endValueX = GetChildrenTail()->GetX() + GetChildrenTail()->GetRelativeRect().GetWidth();
|
|
int16_t widthValueX = GetWidth();
|
|
int16_t tempDistanceX = abs(startValueX);
|
|
if(tempDistanceX == 0) {return;}
|
|
StartAnimator(tempDistanceX, 0);
|
|
//uint32_t timeTemp = 360*abs(tempDistanceX)/Screen::GetInstance().GetWidth();
|
|
//Animator_->SetTime((timeTemp > 100)? timeTemp : 100);
|
|
uint32_t timesTemp = 360/16.7*abs(tempDistanceX)/OHOS::Screen::GetInstance().GetWidth();
|
|
animatorCallback_.SetDragTimes((timesTemp > 5)? timesTemp : 5);
|
|
}
|
|
|
|
#if 0
|
|
//TjdAnimatorViewback animatorViewback_;
|
|
//OHOS::Animator scrollAnimator_;
|
|
#endif
|
|
void SetScrollDirSameToFirst(bool en)
|
|
{
|
|
if(en) {
|
|
tjdScrollDir_ = TJD_BOTH_DIR_FIRST;
|
|
} else {
|
|
tjdScrollDir_ = TJD_BOTH_DIR;
|
|
}
|
|
}
|
|
static constexpr uint8_t TJD_BOTH_DIR = 0;
|
|
static constexpr uint8_t TJD_BOTH_DIR_FIRST = 1;
|
|
private:
|
|
uint8_t tjdScrollDir_{TJD_BOTH_DIR_FIRST};//
|
|
//uint8_t tjdScrollDir_{TJD_BOTH_DIR};//
|
|
bool tjdIntercept_{false};//SetIntercept()
|
|
};
|
|
|
|
class listContainerHistory : public OHOS::UIViewGroup {
|
|
public:
|
|
listContainerHistory() : ItemBg_(nullptr), imageBg_(nullptr), image_(nullptr), deleteView_(nullptr), startView_(nullptr)
|
|
{}
|
|
~listContainerHistory() override
|
|
{
|
|
// printf("delete image text......\n");
|
|
RemoveAll();
|
|
ItemBg_->RemoveAll();
|
|
if (ItemBg_ != nullptr) {
|
|
delete ItemBg_;
|
|
ItemBg_ = nullptr;
|
|
}
|
|
if (imageBg_ != nullptr) {
|
|
delete imageBg_;
|
|
imageBg_ = nullptr;
|
|
}
|
|
if (image_ != nullptr) {
|
|
delete image_;
|
|
image_ = nullptr;
|
|
}
|
|
if (deleteView_ != nullptr) {
|
|
delete deleteView_;
|
|
deleteView_ = nullptr;
|
|
}
|
|
if (startView_ != nullptr) {
|
|
delete startView_;
|
|
startView_ = nullptr;
|
|
}
|
|
}
|
|
listContainerHistory(const listContainerHistory &) = delete;
|
|
listContainerHistory &operator=(const listContainerHistory &) = delete;
|
|
|
|
bool InitContainer();
|
|
|
|
TjdHistoryScrollView* GetItemBgView()
|
|
{
|
|
return ItemBg_;
|
|
}
|
|
|
|
OHOS::UIImageView* GetImageBgView()
|
|
{
|
|
return imageBg_;
|
|
}
|
|
|
|
OHOS::UIImageView* GetImageView()
|
|
{
|
|
return image_;
|
|
}
|
|
|
|
OHOS::UIImageView* GetDeleteView()
|
|
{
|
|
return deleteView_;
|
|
}
|
|
|
|
OHOS::UIImageView* GetStartView()
|
|
{
|
|
return startView_;
|
|
}
|
|
private:
|
|
TjdHistoryScrollView* ItemBg_;
|
|
OHOS::UIImageView* imageBg_;
|
|
OHOS::UIImageView* image_;
|
|
OHOS::UIImageView* deleteView_;
|
|
OHOS::UIImageView* startView_;
|
|
};
|
|
class PlayDialHistoryAdapter : public OHOS::AbstractAdapter
|
|
{
|
|
public:
|
|
explicit PlayDialHistoryAdapter() {}
|
|
~PlayDialHistoryAdapter() {}
|
|
|
|
uint16_t GetCount(void);
|
|
OHOS::UIView *GetView(OHOS::UIView *inView, int16_t index) override;
|
|
class HistoryList : public OHOS::UIList {
|
|
public:
|
|
void ItemViewbackButOne(int16_t index)
|
|
{
|
|
OHOS::UIView *node = childrenHead_;
|
|
OHOS::UIView *tmp = nullptr;
|
|
while (node != nullptr) {
|
|
tmp = node;
|
|
node = node->GetNextSibling();
|
|
|
|
if(tmp->GetViewIndex() != index)
|
|
{
|
|
UIViewGroup *castView1 = dynamic_cast<UIViewGroup *>(tmp);
|
|
TjdHistoryScrollView *castView = dynamic_cast<TjdHistoryScrollView *>(castView1->GetChildrenHead());
|
|
castView->StartAnimatorViewback();
|
|
}
|
|
}
|
|
}
|
|
void ItemViewbackAll(void)
|
|
{
|
|
ItemViewbackButOne(0xffff);
|
|
}
|
|
//void ReMeasure() override;
|
|
};
|
|
|
|
};
|
|
|
|
} // namespace TJD
|
|
|
|
#endif
|