obu Slice添加list显示Message功能,未测试
authorluozheng <1732036298@qq.com>
Wed, 7 Aug 2024 06:08:38 +0000 (14:08 +0800)
committerluozheng <1732036298@qq.com>
Wed, 7 Aug 2024 06:08:38 +0000 (14:08 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageListAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h
code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageitemView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OUBMessageItem.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageListAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp
code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageitemView.cpp [new file with mode: 0644]

index a0271c3..4b0d881 100644 (file)
@@ -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 (file)
index 0000000..7262f67
--- /dev/null
@@ -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 <list>
+
+namespace OHOS
+{
+   
+
+    class OBUMessageListAdapter : public AbstractAdapter
+    {
+    public:
+        OBUMessageListAdapter();
+        ~OBUMessageListAdapter();
+
+        void SetData(std::list<OBUItem> &data);
+        void ClearData(void);
+        std::list<OBUItem> &GetChatContentItem();
+        virtual uint16_t GetCount(void) override;
+        virtual UIView *GetView(UIView *inView, int16_t index) override;
+        void AddListItem(const OBUItem &item);
+
+    private:
+        std::list<OBUItem> listData;
+        int itemViewHeight{0};
+        bool aiAnswerFlag{false};
+    };
+}
+#endif
\ No newline at end of file
index 7677ee4..f2dd675 100644 (file)
@@ -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 (file)
index 0000000..b094966
--- /dev/null
@@ -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 (file)
index 0000000..64e96a2
--- /dev/null
@@ -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 (file)
index 0000000..cb9acae
--- /dev/null
@@ -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<OBUItem> &data)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+        std::list<OBUItem>::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<OBUItem>::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<OBUMessageitemView *>(inView);
+        }
+        item->SetItemInfo(itemData);
+        return item;
+    }
+
+    void OBUMessageListAdapter::AddListItem(const OBUItem &item)
+    {
+        listData.push_back(item);
+    }
+} // namespace OHOS
index a9b27d2..8c2647c 100644 (file)
@@ -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 (file)
index 0000000..7df64c2
--- /dev/null
@@ -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