From bb1267d0993fde7bf8966bf3823464362f119e8c Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 7 Aug 2024 14:08:38 +0800 Subject: [PATCH] =?utf8?q?obu=20Slice=E6=B7=BB=E5=8A=A0list=E6=98=BE?= =?utf8?q?=E7=A4=BAMessage=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9C=AA=E6=B5=8B?= =?utf8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 2 + .../include/OBUMessageListAdapter.h | 41 +++++++++ .../obumessage/include/OBUMessageView.h | 9 +- .../obumessage/include/OBUMessageitemView.h | 27 ++++++ .../obumessage/include/OUBMessageItem.h | 23 +++++ .../obumessage/src/OBUMessageListAdapter.cpp | 86 +++++++++++++++++++ .../obumessage/src/OBUMessageView.cpp | 55 +++++++++++- .../obumessage/src/OBUMessageitemView.cpp | 36 ++++++++ 8 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageitemView.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index a0271c33f..4b0d88164 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -492,6 +492,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rotate/src/RotateView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rotate/src/RotatePresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/obumessage/src/OBUMessageitemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/obumessage/src/OBUMessageListAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/obumessage/src/OBUMessageModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/obumessage/src/OBUMessageView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/obumessage/src/OBUMessagePresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h new file mode 100644 index 000000000..7262f672f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h @@ -0,0 +1,41 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-07 11:04:21 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-07 11:52:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h + */ +#ifndef OBU_MESSAGE_LIST_ADAPTER_H +#define OBU_MESSAGE_LIST_ADAPTER_H + +#include "components/abstract_adapter.h" +#include "components/ui_list.h" +#include "obumessage/include/OBUMessageitemView.h" +#include "OUBMessageItem.h" +#include "iostream" +#include + +namespace OHOS +{ + + + class OBUMessageListAdapter : public AbstractAdapter + { + public: + OBUMessageListAdapter(); + ~OBUMessageListAdapter(); + + void SetData(std::list &data); + void ClearData(void); + std::list &GetChatContentItem(); + virtual uint16_t GetCount(void) override; + virtual UIView *GetView(UIView *inView, int16_t index) override; + void AddListItem(const OBUItem &item); + + private: + std::list listData; + int itemViewHeight{0}; + bool aiAnswerFlag{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h index 7677ee4b7..f2dd67569 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-27 10:58:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 12:02:16 + * @LastEditTime: 2024-08-07 11:37:56 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView..h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -16,6 +16,8 @@ #include "components/ui_label.h" #include "components/ui_button.h" #include "components/ui_view_group.h" +#include "components/ui_list.h" +#include "obumessage/include/OBUMessageListAdapter.h" namespace OHOS { class OBUMessagePresenter; @@ -42,6 +44,11 @@ namespace OHOS UILabel *title = nullptr; UILabel *displayTimeLabel = nullptr; UILabel *obuMessageLabel = nullptr; + + OBUMessageListAdapter *obuAdapter{nullptr}; + UIList *obuList{nullptr}; + + int count{0}; bool viewInitStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h new file mode 100644 index 000000000..b094966a7 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h @@ -0,0 +1,27 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-07 11:05:29 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-07 11:58:19 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h + */ +#ifndef OBU_MESSAGE_ITEM_VIEW_H +#define OBU_MESSAGE_ITEM_VIEW_H +#include "components/ui_label.h" +#include "OUBMessageItem.h" +#include "obumessage/include/OBUMessageListAdapter.h" +namespace OHOS +{ + + class OBUMessageitemView : public UIViewGroup + { + public: + OBUMessageitemView(); + ~OBUMessageitemView(); + void SetItemInfo(const OBUItem itemInfo); + void SetUpChild(); + UILabel label; + OBUItem sItemInfo = {0, ""}; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h new file mode 100644 index 000000000..64e96a2d4 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h @@ -0,0 +1,23 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-07 11:54:25 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-07 11:54:42 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#include "iostream" +#include "string" +#ifndef OBU_MESSAGE_ITEM_H +#define OBU_MESSAGE_ITEM_H + +namespace OHOS +{ + typedef struct + { + int index; + std::string text; + } OBUItem; + +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp new file mode 100644 index 000000000..cb9acaecc --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp @@ -0,0 +1,86 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-07 11:04:32 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-07 11:40:27 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp + */ +#include "obumessage/include/OBUMessageListAdapter.h" +#include "obumessage/include/OBUMessageitemView.h" + +namespace OHOS +{ + + OBUMessageListAdapter::OBUMessageListAdapter() {} + + OBUMessageListAdapter::~OBUMessageListAdapter() + { + listData.clear(); + } + + uint16_t OBUMessageListAdapter::GetCount(void) + { + return listData.size(); + } + + void OBUMessageListAdapter::ClearData(void) + { + if (!listData.empty()) + { + listData.clear(); + } + } + + void OBUMessageListAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } + } + + UIView *OBUMessageListAdapter::GetView(UIView *inView, int16_t index) + { + if (listData.empty()) + { + return nullptr; + } + if (index < 0) + { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } + + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + OBUItem itemData = *it; + OBUMessageitemView *item = nullptr; + if (inView == nullptr) + { + item = new OBUMessageitemView(); + } + else + { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + return item; + } + + void OBUMessageListAdapter::AddListItem(const OBUItem &item) + { + listData.push_back(item); + } +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp index a9b27d249..8c2647cfd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 14:06:08 + * @LastEditTime: 2024-08-07 12:11:00 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp */ #include "obumessage/include/OBUMessagePresenter.h" @@ -60,6 +60,16 @@ namespace OHOS delete obuMessageLabel; obuMessageLabel = nullptr; } + if (obuAdapter != nullptr) + { + delete obuAdapter; + obuAdapter = nullptr; + } + if (obuList != nullptr) + { + delete obuList; + obuList = nullptr; + } delete group; group = nullptr; } @@ -156,6 +166,36 @@ namespace OHOS obuMessageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); obuMessageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); group->Add(obuMessageLabel); + + /* + obuAdapter = new OBUMessageListAdapter(); + if (obuAdapter == nullptr) + { + return; + } + obuList = new UIList(UIList::VERTICAL); + if (obuList == nullptr) + { + return; + } + obuList->SetPosition(53, 30, 360, 250); + obuList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + obuList->EnableAutoAlign(true); + obuList->SetTouchable(true); + obuList->SetDraggable(true); + obuList->SetThrowDrag(true); + obuList->SetReboundSize(35); + obuList->SetMaxScrollDistance(1000); + obuList->SetSwipeACCLevel(800); // 800: compensation distance + obuList->SetDragACCLevel(5); // 5: drag acceleration + obuList->SetRotateFactor(2); + obuList->RequestFocus(); + obuList->SetIntercept(true); + obuList->SetAdapter(obuAdapter); + obuList->RefreshList(); + group->Add(obuList); + */ + viewInitStatus = true; } @@ -241,5 +281,18 @@ namespace OHOS } displayTimeLabel->SetText(labelTimeStr.c_str()); /*时间更新:时:分:秒*/ obuMessageLabel->SetText(rxdataStr.c_str()); /*数据更新*/ + /* + OBUItem item; + item.index = count++; + item.text = rxdataStr; + if (count >= 50) + { + count = 0; + obuAdapter->ClearData(); + } + obuAdapter->AddListItem(item); + obuList->RefreshList(); + obuList->SetStartIndex(count); + */ } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageitemView.cpp new file mode 100644 index 000000000..7df64c28a --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageitemView.cpp @@ -0,0 +1,36 @@ +#include "obumessage/include/OBUMessageitemView.h" + +namespace OHOS +{ + OBUMessageitemView::OBUMessageitemView() + { + SetPosition(0, 0, 360, 250); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, 0x00); + SetUpChild(); + Add(&label); + } + + OBUMessageitemView::~OBUMessageitemView() + { + Remove(&label); + } + + void OBUMessageitemView::SetItemInfo(const OBUItem itemInfo) + { + sItemInfo = itemInfo; + label.SetText(itemInfo.text.c_str()); + } + + void OBUMessageitemView::SetUpChild() + { + label.SetPosition(0, 0, 360, 250); + label.SetStyle(STYLE_BORDER_RADIUS, 33); + label.SetStyle(STYLE_TEXT_FONT, 40); + label.SetStyle(STYLE_LINE_HEIGHT, 45); + label.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + } + +} \ No newline at end of file -- 2.17.1