Merge #341 into sdk602patch0521 from refs/changes/341/head 342/target/1 343/target/1
author袁清梦 <3449750381@qq.com>
Fri, 21 Jun 2024 03:06:07 +0000 (03:06 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Fri, 21 Jun 2024 03:06:07 +0000 (03:06 +0000)
开启主界面循环卡片显示

* refs/changes/341/head: (2 commits squashed)

  - 开启主界面循环卡片显示

  - 同步消息弹窗

Signed-off-by: Caisking <3449750381@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/341
code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp
code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c
code/sdk/application/wearable/service/msg_center/CMakeLists.txt
code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h [new file with mode: 0644]
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp [new file with mode: 0644]

index 4c0c317..3a1d5cb 100644 (file)
@@ -200,7 +200,7 @@ namespace OHOS
         VertViewLoad();
         mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
         mainSwipeGroup->SetAnimatorTime(50); // 50: animator drag time(ms);
-        mainSwipeGroup->SetLoopState(false); // 关闭主界面循环
+        mainSwipeGroup->SetLoopState(true); // 关闭主界面循环
         mainSwipeGroup->EnableScreenCap(true);
         mainSwipeGroup->RegisterSwipeCallback(callback);
         if (presenter_->IsFromSetCardView())
index c043138..3d84156 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-20 10:02:36
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h
+ */
 #ifndef MESSAGE_MODEL_H
 #define MESSAGE_MODEL_H
 
@@ -41,6 +47,7 @@ namespace OHOS
         void SetCurrentMessageData(MessageData *data); // 设置当前消息数据
         bool ClearAllData();                           // 清除所有数据
         bool DeleteSingleItem();                       // 删除单个项
+        MessageData *GetNewestData();                  // 获取最新信息项
 
     private:
         MessageModel();
index 87b8699..0ec8dcb 100644 (file)
@@ -196,5 +196,13 @@ namespace OHOS
     {
         return true;
     }
+    // 获取最新消息项
+    MessageData *MessageModel::GetNewestData()
+    {
+        std::vector<MessageData> messageVector = LoadMessageData();
+        numberOfItems = messageVector.size();
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the numberOfItems is %d", numberOfItems);
 
+        return &messageVector[numberOfItems - 1];
+    }
 }
index 1c94cd4..7f0757d 100644 (file)
@@ -87,6 +87,7 @@ typedef enum {
     TOPIC_EVENT_FIND_WATCH, //查找手表
     TOPIC_EVENT_CANCEL_FIND_WATCH,//取消查找
     TOPIC_EVENT_DRINKREMINDER,//喝水提醒
+    TOPIC_EVENT_MESSAGENOTE, //消息通知
     TOPIC_END_NUM = 20000,
 } TopicNum;
 
index a9e5925..c8194eb 100644 (file)
@@ -65,6 +65,7 @@ static const TopicToCore topicToCoreArray[] = {
     {TOPIC_EVENT_FIND_WATCH,A_CORE_MASK, 1},//查找手表
     {TOPIC_EVENT_CANCEL_FIND_WATCH,A_CORE_MASK, 1},
     {TOPIC_EVENT_DRINKREMINDER,A_CORE_MASK, 1},
+    {TOPIC_EVENT_MESSAGENOTE,A_CORE_MASK, 1},
 #ifdef SUPPORT_CAT1_MODEM
     {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1},
     {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1},
index a58b970..0fe23e2 100644 (file)
@@ -166,6 +166,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp
 )
 else()
 set(SOURCES
@@ -180,6 +181,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp
 )
 endif()
 
diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h
new file mode 100644 (file)
index 0000000..977cc2c
--- /dev/null
@@ -0,0 +1,35 @@
+/*** 
+ * @Date: 2024-06-20 09:43:23
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-20 09:47:45
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h
+ */
+#ifndef MESSAGE_NOTIFICATION
+#define MESSAGE_NOTIFICATION
+
+#include "BaseView.h"
+namespace OHOS
+{
+    UIViewGroup *CreateMessageView(void);
+    void FreeMessageView(void);
+
+    class MessageViewEventListener : public UIView::OnTouchListener,public UIView::OnDragListener
+    {
+    public:
+        static MessageViewEventListener &GetInstance();
+        bool OnRelease(UIView &view, const ReleaseEvent &event) override;
+        bool OnDrag(UIView& view, const DragEvent& event) override;
+        bool OnDragEnd(UIView& view, const DragEvent& event) override;
+
+    private:
+        MessageViewEventListener();
+        ~MessageViewEventListener();
+        MessageViewEventListener(const MessageViewEventListener &) = delete;
+        const MessageViewEventListener &operator=(const MessageViewEventListener &) = delete;
+        bool X_DRAG_FLAG{false};
+
+    };
+
+}
+
+#endif
\ No newline at end of file
index 5a65e5f..10d7600 100644 (file)
@@ -29,6 +29,7 @@
 #include "power_display_service.h"
 #include "cat1_server.h"
 #include "testchanging.h"
+#include "message_notification.h"
 #include "testcat1.h" 
 #include "testold.h"
 #include "testhrsenson.h" 
@@ -77,7 +78,6 @@ const PriorityMapper PRI_MAPPER[] = {
     {TOPIC_EVENT_HFP_WATCH_ACTIVE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_WATCH_TO_PHONE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE},
-
 #ifdef SUPPORT_CAT1_MODEM
     {TOPIC_EVENT_CAT1_INCOMMING, PRIORITY_ONE},
     {TOPIC_EVENT_CAT1_CALLCONNTED, PRIORITY_ONE},
@@ -105,6 +105,7 @@ const PriorityMapper PRI_MAPPER[] = {
     {TOPIC_EVENT_FIND_WATCH,PRIORITY_TWO},
     {TOPIC_EVENT_CANCEL_FIND_WATCH,PRIORITY_TWO},
     {TOPIC_EVENT_DRINKREMINDER,PRIORITY_TWO},
+    {TOPIC_EVENT_MESSAGENOTE,PRIORITY_TWO},
 };
 
 static bool CheckPriority(const Topic topic)
@@ -177,6 +178,7 @@ void MsgCenterSubscribe()
     MsgCenterSubscribeTopic(TOPIC_EVENT_FIND_WATCH);
     MsgCenterSubscribeTopic(TOPIC_EVENT_CANCEL_FIND_WATCH);
     MsgCenterSubscribeTopic(TOPIC_EVENT_DRINKREMINDER);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_MESSAGENOTE);
 }
 
 static OHOS::UIViewGroup* ShowAlarmNotify(void)
@@ -252,6 +254,12 @@ static OHOS::UIViewGroup* showtransmitNotify(void)
     return OHOS::transmittingShow();
 }
 
+/*显示消息提醒*/
+static OHOS::UIViewGroup* showMessageNotify(void)
+{
+    return OHOS::CreateMessageView();
+}
+
 void MsgCenterNotifyAlarmProc(const Topic topic, Request* req)
 {
     unused(req);
@@ -908,6 +916,15 @@ void MsgCenterNotifyDrinkReminderProc(const Topic topic, Request* req)
     NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
     NotificationManager::GetInstance()->ShowNotify(showDrinkReminderNotify, (uint16_t)topic, true);
 }
+//消息通知
+void MsgCenterNotifyMessageProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+    WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyMessageProc !");
+    NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+    NotificationManager::GetInstance()->ShowNotify(showMessageNotify, (uint16_t)topic, true);
+}
 void MsgCenterNotifyActivityProc(const Topic topic, Request* req)
 {
     unused(topic);
@@ -1092,6 +1109,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = {
     {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc},
     {TOPIC_EVENT_CANCEL_FIND_WATCH,MsgCenterNotifyCanCelFindWatchProc},
     {TOPIC_EVENT_DRINKREMINDER,MsgCenterNotifyDrinkReminderProc},
+    {TOPIC_EVENT_MESSAGENOTE,MsgCenterNotifyMessageProc},
 };
 
 static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx)
diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp
new file mode 100644 (file)
index 0000000..b2ff7d1
--- /dev/null
@@ -0,0 +1,198 @@
+#include "notification_manager.h"
+#include "wearable_log.h"
+#include "components/ui_button.h"
+#include <iostream>
+#include "ui_service.h"
+#include <graphic_service.h>
+#include "bleEvent.h"
+#include "components/ui_label_ext.h"
+#include "uicomponents/UIComponents.h"
+#include "message/include/MessageModel.h"
+#include "message_notification.h"
+#include "string"
+namespace OHOS
+{
+
+    UIViewGroup *MessageGroupView{nullptr};
+
+    UILabel *titleLabel{nullptr};            // 标题
+    UILabel *timeLabel{nullptr};             // 时间
+    UILabel *messageLabel{nullptr};          // 详细label
+    UILabelButtonExt *deleteButton{nullptr}; // 删除按键
+
+    static std::string titleStr, timeStr, messageStr;
+
+#define DELETEBUTTON "delete_button"
+
+    MessageViewEventListener::MessageViewEventListener()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::MessageViewEventListener");
+    }
+
+    MessageViewEventListener::~MessageViewEventListener()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::~MessageViewEventListener");
+    }
+
+    MessageViewEventListener &MessageViewEventListener::GetInstance()
+    {
+        static MessageViewEventListener instance;
+        return instance;
+    }
+    bool MessageViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease");
+        UNUSED(event);
+        if (strcmp(view.GetViewId(), DELETEBUTTON) == 0)
+        {
+            NotificationManager::GetInstance()->StopNotify();
+        }
+
+        return true;
+    }
+    bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag");
+        UNUSED(view);
+        return true;
+    }
+
+    bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd");
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        {
+            NotificationManager::GetInstance()->StopNotify();
+        }
+        return true;
+    }
+
+    /*创建信息弹窗*/
+    UIViewGroup *CreateMessageView(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateMessageView");
+        MessageGroupView = new UIViewGroup();
+        if (MessageGroupView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] MessageGroupView new fail!!");
+            return nullptr;
+        }
+        MessageGroupView->SetPosition(0, 0, 466, 466);
+        MessageGroupView->SetViewId("messagenotify");
+        MessageGroupView->SetTouchable(true);
+        MessageGroupView->SetDraggable(true);
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&MessageViewEventListener::GetInstance());
+        if (dragListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] dragListener new fail!!");
+            return nullptr;
+        }
+        MessageGroupView->SetOnDragListener(dragListener);
+        /*获取最新message*/
+        MessageData *data = MessageModel::GetInstance().GetNewestData();
+        if (data != nullptr)
+        {
+            titleStr = data->labelTitle;
+            timeStr = data->labelTime;
+            messageStr = data->labelDetails;
+        }
+        /*初始化label*/
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView");
+        /* -------------------------------------------------------------------------- */
+        titleLabel = new UILabel();
+        if (titleLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel fail");
+            return nullptr; // 内存分配失败,返回
+        }
+        titleLabel->SetPosition(83, 60, 300, 35);
+        titleLabel->SetText(titleStr.c_str());
+        titleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+        titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        titleLabel->SetVisible(true);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel is ok!");
+        /* -------------------------------------------------------------------------- */
+        timeLabel = new UILabel();
+        if (timeLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel fail");
+            return nullptr; // 内存分配失败,返回
+        }
+        timeLabel->SetPosition(73, 104, 320, 33);
+        timeLabel->SetViewId("timeLabel");
+        timeLabel->SetText(timeStr.c_str());
+        timeLabel->SetTextColor(Color::Gray());
+        timeLabel->SetStyle(STYLE_TEXT_FONT, 28);
+        timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);
+        timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        timeLabel->SetVisible(true);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel is ok!");
+        /* -------------------------------------------------------------------------- */
+        /*初始化消息内容*/
+        messageLabel = new UILabel();
+        if (messageLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel fail");
+            return nullptr; // 内存分配失败,返回
+        }
+        messageLabel->SetPosition(53, 170, 360, 144);
+        messageLabel->SetViewId("messageLabel");
+        messageLabel->SetText(messageStr.c_str());
+        messageLabel->SetTextColor(Color::Gray());
+        messageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel is ok");
+
+        /*加载清除按键*/
+        InitButtonExt(deleteButton, 0, 366, 466, 100, DELETEBUTTON, STR_CLOSE, 30);
+        const char *buttonImgSrc = "/user/res/466x100button.bin";
+        deleteButton->SetImageSrc(buttonImgSrc, buttonImgSrc);
+        UIView::OnTouchListener *TouchListener = static_cast<UIView::OnTouchListener *>(&MessageViewEventListener::GetInstance());
+        if (TouchListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] TouchListener new fail!!");
+            return nullptr;
+        }
+        deleteButton->SetOnTouchListener(TouchListener);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton");
+        /* -------------------------------------------------------------------------- */
+        MessageGroupView->Add(titleLabel);
+        MessageGroupView->Add(timeLabel);
+        MessageGroupView->Add(messageLabel);
+        MessageGroupView->Add(deleteButton);
+
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!");
+
+        return MessageGroupView;
+    }
+    /*释放消息弹窗视图*/
+    void FreeMessageView(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)");
+        if (MessageGroupView != nullptr)
+        {
+            MessageGroupView->RemoveAll();
+
+            delete titleLabel;
+            titleLabel = nullptr;
+
+            delete timeLabel;
+            timeLabel = nullptr;
+
+            delete messageLabel;
+            messageLabel = nullptr;
+
+            delete deleteButton;
+            deleteButton = nullptr;
+
+            RootView::GetInstance()->Remove(MessageGroupView);
+            delete MessageGroupView;
+            MessageGroupView = nullptr;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!");
+        }
+        return;
+    }
+}
\ No newline at end of file