return true;
}
-
/***
* @description:
* @param {UILabelButtonExt} *
bool InitButtonExt(UILabelButtonExt *&button, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, int fontSize)
{
// 创建新按钮(如果当前按钮为空)
- if (button == nullptr)
- {
- button = new UILabelButtonExt();
- }
+ button = new UILabelButtonExt();
if (button == nullptr)
{
return false; // 内存分配失败,返回false
button->Resize(width, height);
button->SetViewId(viewId);
button->SetTextId(id);
-
button->SetStyle(STYLE_TEXT_FONT, fontSize);
button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize);
-
button->SetStyle(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR);
button->SetStyleForState(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR, UIButton::PRESSED);
button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED);
button->SetVisible(true);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed");
return true;
}
-/* -------------------------------------------------------------------------- */
+ /* -------------------------------------------------------------------------- */
/*替换字符串中的变量*/
std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id)
{
// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed");
return true;
}
-
+
/***
* @description:
* @param {UIImageView} *
{
InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize);
}
-
+
/* -------------------------------------------------------------------------- */
/**
* 创建包含图片文件路径的数组
-/***
- * @Date: 2024-06-17 19:38:57
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-17 19:42:38
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h
- */
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-15 15:47:19
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h
- */
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-04-23 15:32:55
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h
- */
+
#ifndef MessageShow_VIEW_H
#define MessageShow_VIEW_H
namespace OHOS
{
+#define DELETEBUTTON "deletebutton"
+
class MessageModel;
class MessageShowPresenter;
class MessageShowView : public View<MessageShowPresenter>
void OnTearDownView() override;
void OnStop() override;
- void UpdateMessage(MessageData *data);
+ void InitializeLabel(UILabel *label, int posX, int posY, int width, int height, const char *viewId, int fontSize);
+ void InitializeButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId);
+
+ void UpdateMessage();
void InitView();
void DeInitView(void);
void PreLoad(void);
private:
UIScrollView *container_ = nullptr;
- UILabelExt *title{nullptr};
- UILabelExt *time{nullptr};
+ UILabel *title{nullptr};
+ UILabel *time{nullptr};
+ UILabel *message{nullptr};
- UILabelButtonExt *messageButton; // 消息
- UILabelButtonExt *deleteButton; // 清除按键
+ UILabelButton *messageButton; // 消息
+ UILabelButtonExt *deleteButton; // 清除按键
bool viewInitStatus{false};
};
+/***
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-18 17:26:05
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
+ */
/***
* @Date: 2024-04-15 10:55:58
* @LastEditors: Caisking 3449750381@qq.com
bool MessagePresenter::OnClick(UIView &view, const ClickEvent &event)
{
UNUSED(event);
-#if 0
- MessageItemView *messageItemView = static_cast<MessageItemView *>(&view);
- int index = messageItemView->GetMessageListIndex();
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index:%d", index);
- if (index >= p_MessageModel->GetMessageListNum())
+ if (MessageModel::GetInstance().GetPopupView())
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index");
- return false;
+ MessageItemView *p_MessageItemView = static_cast<MessageItemView *>(&view);
+ int index = p_MessageItemView->GetMessageListIndex();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+ // 读取json数据
+ std::vector<MessageData> messageDataVector = MessageModel::GetInstance().LoadMessageJson();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+ if (!messageDataVector.empty())
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+ // 选择点击按键的历史数据
+ int arraynum = messageDataVector.size() - 1;
+ MessageData messageData = messageDataVector[arraynum - index]; // 显示是倒序 id同理
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+ MessageModel::GetInstance().SetMessageData(&messageData);
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE_SHOW);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+ return true;
+ }
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the messageDataVector is error");
}
-#endif
return true;
}
#include "UiConfig.h"
#include "wearable_log.h"
#include "uicomponents/UIComponents.h"
+#include "string"
namespace OHOS
{
+ // 定义按键颜色宏
+#define DEFAULT_BACKGROUND_COLOR 0xff191919
+#define PRESSED_BACKGROUND_COLOR 0xff249115
+#define PRESSED_BORDER_COLOR 0xff0b1928
static MessageShowView *g_pMessageShowView{nullptr};
+ static constexpr const int kTitlePosX = 73;
+ static constexpr const int kTitlePosY = 60;
+ static constexpr const int kTitleWidth = 320;
+ static constexpr const int kTitleHeight = 35;
+ static constexpr const int kTitleFontSize = 30;
+ static constexpr const char *kTitleViewId = "title";
+ // static constexpr const Color kTitleTextColor = Color::White();
+
+ static constexpr const int kTimePosX = 73;
+ static constexpr const int kTimePosY = 104;
+ static constexpr const int kTimeWidth = 320;
+ static constexpr const int kTimeHeight = 33;
+ static constexpr const int kTimeFontSize = 28;
+ static constexpr const char *kTimeViewId = "time";
+ // static constexpr const Color kTimeTextColor = Color::Gray();
+
+ std::string titleStr = "12306中国高速铁路";
+ std::string timeStr = "2023.12.26 17:23";
+ std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/";
+
MessageShowView::MessageShowView()
{
g_pMessageShowView = this;
void MessageShowView::DeInitView()
{
container_->RemoveAll();
+ if (title != nullptr)
+ {
+ delete title;
+ title = nullptr;
+ }
+ if (time != nullptr)
+ {
+ delete time;
+ time = nullptr;
+ }
+ if (message != nullptr)
+ {
+ delete message;
+ message = nullptr;
+ }
+ if (messageButton != nullptr)
+ {
+ delete messageButton;
+ messageButton = nullptr;
+ }
+ if (deleteButton != nullptr)
+ {
+ delete deleteButton;
+ deleteButton = nullptr;
+ }
if (container_ != nullptr)
{
container_->RemoveAll();
// delete draglistener;
// draglistener = nullptr;
}
- void MessageShowView::InitView() {}
- void MessageShowView::UpdateMessage(MessageData *data) {}
+ void MessageShowView::InitializeLabel(UILabel *label, int posX, int posY, int width, int height, const char *viewId, int fontSize)
+ {
+ label = new UILabel();
+ if (label == nullptr)
+ {
+ return; // 内存分配失败,返回
+ }
+ label->SetPosition(posX, posY);
+ label->Resize(width, height);
+ label->SetViewId(viewId);
+ label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize);
+ label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label->SetVisible(true);
+ }
+ void MessageShowView::InitializeButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId)
+ {
+ button = new UILabelButton();
+ if (button == nullptr)
+ {
+ return; // 内存分配失败,返回
+ }
+ button->SetPosition(left, top);
+ button->Resize(width, height);
+ button->SetViewId(viewId);
+ button->SetStyle(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR);
+ button->SetStyleForState(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR, UIButton::PRESSED);
+ button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED);
+ button->SetVisible(true);
+ }
+ void MessageShowView::InitView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView");
+ /* -------------------------------------------------------------------------- */
+ title = new UILabel();
+ if (title == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title:: new UILabel fail");
+ return; // 内存分配失败,返回
+ }
+ title->SetPosition(83, 60, 300, 35);
+ title->SetText(titleStr.c_str());
+ title->SetStyle(STYLE_TEXT_FONT, 30);
+ title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ title->SetVisible(true);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title is ok!");
+ /* -------------------------------------------------------------------------- */
+ time = new UILabel();
+ if (time == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time:: new UILabel fail");
+ return; // 内存分配失败,返回
+ }
+ time->SetPosition(73, 104, 320, 33);
+ time->SetViewId("time");
+ time->SetText(timeStr.c_str());
+ time->SetTextColor(Color::Gray());
+ time->SetStyle(STYLE_TEXT_FONT, 28);
+ time->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);
+ time->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ time->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ time->SetVisible(true);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time is ok!");
+ /* -------------------------------------------------------------------------- */
+ /*初始化消息内容*/
+ InitializeButton(messageButton, 33, 157, 380, 350, "message");
+ messageButton->SetStyle(STYLE_BORDER_RADIUS, 30);
+ messageButton->SetText(messageStr.c_str());
+ //messageButton->SetAlign(TEXT_ALIGNMENT_LEFT);
+ messageButton->SetTextColor(Color::Gray());
+ messageButton->SetTouchable(false);
+ messageButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageButton");
+ /*加载清除按键*/
+ InitButtonExt(deleteButton, 43, 527, 380, 100, DELETEBUTTON, STR_CLOSE, 30);
+ deleteButton->SetOnClickListener(static_cast<UIView::OnClickListener *>(MessageShowPresenter::GetInstance()));
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton");
+ /* -------------------------------------------------------------------------- */
+ container_->Add(title);
+ container_->Add(time);
+ container_->Add(messageButton);
+ // container_->Add(message);
+ container_->Add(deleteButton);
+ /* -------------------------------------------------------------------------- */
+ // UpdateMessage();
+ }
+ void MessageShowView::UpdateMessage()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateMessage");
+ MessageData *data = MessageModel::GetInstance().GetMessageData();
+ if (data == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateMessage is error");
+ return;
+ }
+ titleStr = data->labeltitle;
+ timeStr = data->labeltime;
+ messageStr = data->labeldetails;
+ }
void MessageShowView::PreLoad(void)
{
if (!viewInitStatus)
{
+ UpdateMessage();
InitView();
viewInitStatus = true;
}
}
- /// @brief 页面启动时需要执行的代码逻辑
void MessageShowView::OnStart()
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnStart");
container_ = new UIScrollView();
if (container_ == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
return;
}
- container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ container_->SetScrollBlankSize(35);
+ container_->SetReboundSize(50);
+ container_->SetDirection(1);
// 创建 draglistener 实例并设置为拖动监听器
UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(MessageShowPresenter::GetInstance());
if (draglistener == nullptr)
container_->SetOnDragListener(draglistener);
container_->SetTouchable(true);
container_->SetDraggable(true);
- // container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
PreLoad();
RootView::GetInstance()->Add(container_);
}
- /// @brief 创建页面的视图
void MessageShowView::OnSetUpView()
{
View<MessageShowPresenter>::OnSetUpView();
Draw();
}
-
- /// @brief 销毁页面的视图
void MessageShowView::OnTearDownView()
{
View<MessageShowPresenter>::OnTearDownView();
return;
}
-
- /// @brief 页面结束时需要执行的销毁逻辑。
void MessageShowView::OnStop()
{
View<MessageShowPresenter>::OnStop();