134 lines
4.9 KiB
C++
134 lines
4.9 KiB
C++
#include "NativeAbility.h"
|
|
#include "TjdUiAppLefunAiView.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "gfx_utils/color.h"
|
|
#include "style.h"
|
|
#include "sys_config.h"
|
|
#include "ui_checkbox.h"
|
|
#include "ui_view.h"
|
|
#include <TjdUiScreenManage.h>
|
|
#include <cstdlib>
|
|
#include "TjdUiImageIds.h"
|
|
#include "common/image_cache_manager.h"
|
|
|
|
#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
|
|
|
|
using namespace OHOS;
|
|
// clang-format off
|
|
|
|
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
|
|
|
|
static inline int16_t VerticalCenter(int16_t height, int16_t parentHeight) { return (parentHeight - height) / 2; }
|
|
|
|
static inline void InitLabel(OHOS::UILabel &label, uint8_t size, int16_t x, int16_t y, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
label.SetPosition(x, y);
|
|
}
|
|
|
|
static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
label.SetPosition(HorizontalCenter(label.GetWidth(), target), y);
|
|
}
|
|
|
|
static inline void InitLabelVerCenter(OHOS::UILabel &label, uint8_t size, int16_t x, int16_t target, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
label.SetPosition(x, VerticalCenter(label.GetHeight(), target));
|
|
}
|
|
|
|
static inline void InitLabelCenter(OHOS::UILabel &label, uint8_t size, int16_t parentWidth, int16_t parentHeight, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
label.SetPosition(HorizontalCenter(label.GetWidth(), parentWidth), VerticalCenter(label.GetHeight(), parentHeight));
|
|
}
|
|
// clang-format on
|
|
namespace TJD {
|
|
|
|
HistoryListItemView::HistoryListItemView()
|
|
{
|
|
SetPosition(0, 0, 450, 120);
|
|
SetStyle(OHOS::STYLE_MARGIN_TOP, 4);
|
|
SetStyle(OHOS::STYLE_MARGIN_BOTTOM, 4);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
|
SetStyle(STYLE_BORDER_RADIUS, 60);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
|
SetTouchable(true);
|
|
|
|
question_.SetFont(TJD_VECTOR_FONT_FILENAME, 33);
|
|
question_.SetText("问题描述");
|
|
question_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_OSCILLATION);
|
|
question_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_LEFT);
|
|
question_.SetPosition(49, 22, 349, 40);
|
|
|
|
answer_.SetFont(TJD_VECTOR_FONT_FILENAME, 27);
|
|
answer_.SetText("问题反馈");
|
|
answer_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_OSCILLATION);
|
|
answer_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_LEFT);
|
|
// answer_.setTextColor(OHOS::Color::GetColorFromRGB(0x80, 0x80, 0x80););
|
|
answer_.SetPosition(49, 73,346,32);
|
|
Add(&question_);
|
|
Add(&answer_);
|
|
}
|
|
|
|
void HistoryListItemView::UpdateInfo(HistoryItemInfo &info)
|
|
{
|
|
printf("cxin HistoryListItemView::%s===%s====%s\n", __func__, info.question.c_str(), info.answer.c_str());
|
|
question_.SetText(info.question.c_str());
|
|
answer_.SetText(info.answer.c_str());
|
|
answer_.SetTextColor(OHOS::Color::GetColorFromRGB(0x80, 0x80, 0x80));
|
|
}
|
|
|
|
TjdUiAppLefunAiAdapter::~TjdUiAppLefunAiAdapter()
|
|
{
|
|
printf("TjdUiAppLefunAiAdapter::%s\n", __func__);
|
|
}
|
|
|
|
uint16_t TjdUiAppLefunAiAdapter::GetCount() { return TjdUiAppLefunAiView::GetInstance()->historyItemList_->size();}
|
|
|
|
void TjdUiAppLefunAiAdapter::ClearItem(void) {}
|
|
|
|
UIView *TjdUiAppLefunAiAdapter::GetView(UIView *inView, int16_t index)
|
|
{
|
|
std::list<HistoryItemInfo> *historyList_ = TjdUiAppLefunAiView::GetInstance()->historyItemList_;
|
|
if (index >= historyList_->size() || index < 0) {
|
|
return nullptr;
|
|
}
|
|
|
|
std::list<HistoryItemInfo>::iterator curIt = historyList_->begin();
|
|
std::advance(curIt, index);
|
|
if (inView == nullptr) {
|
|
itemView_ = new HistoryListItemView();
|
|
} else {
|
|
itemView_ = static_cast<HistoryListItemView *>(inView);
|
|
}
|
|
|
|
itemView_->UpdateInfo(*curIt);
|
|
return itemView_;
|
|
}
|
|
|
|
} // namespace TJD
|