消息详细显示
authorCaisking <3449750381@qq.com>
Tue, 18 Jun 2024 10:43:46 +0000 (18:43 +0800)
committerCaisking <3449750381@qq.com>
Tue, 18 Jun 2024 10:43:46 +0000 (18:43 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp

index 0f5ea04..5d7d0da 100644 (file)
@@ -103,7 +103,6 @@ namespace OHOS
         return true;
     }
 
-    
     /***
      * @description:
      * @param {UILabelButtonExt} *
@@ -120,10 +119,7 @@ namespace OHOS
     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
@@ -132,18 +128,16 @@ namespace OHOS
         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)
     {
@@ -254,7 +248,7 @@ namespace OHOS
         // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed");
         return true;
     }
-    
+
     /***
      * @description:
      * @param {UIImageView} *
@@ -291,7 +285,7 @@ namespace OHOS
     {
         InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize);
     }
-    
+
     /* -------------------------------------------------------------------------- */
     /**
      * 创建包含图片文件路径的数组
index 283ee99..cf85011 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-18 11:22:29
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h
+ */
 /***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
@@ -61,6 +67,10 @@ namespace OHOS
         bool GetPopupView();
         // 打印函数
         void PrintfData(MessageData messagedata);
+        // 获取目前的message
+        MessageData *GetMessageData();
+        // 设置目前的message
+        void SetMessageData(MessageData *data);
 
     private:
         MessageModel();
index 908a2e6..2205141 100644 (file)
@@ -1,21 +1,4 @@
-/***
- * @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
@@ -34,6 +17,8 @@
 
 namespace OHOS
 {
+#define DELETEBUTTON "deletebutton"
+
     class MessageModel;
     class MessageShowPresenter;
     class MessageShowView : public View<MessageShowPresenter>
@@ -49,7 +34,10 @@ namespace OHOS
         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);
@@ -57,11 +45,12 @@ namespace OHOS
     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};
     };
index 82be4c3..7336d00 100644 (file)
@@ -28,7 +28,7 @@
 extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char separator, bool include_seconds);
 namespace OHOS
 {
-
+    MessageData message_;
     MessageModel::MessageModel()
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageModel");
@@ -172,4 +172,22 @@ namespace OHOS
     {
         return popupStatus;
     }
+
+    // 获取目前的message
+    MessageData *MessageModel::GetMessageData()
+    {
+        return &message_;
+    }
+    // 设置目前的message
+    void MessageModel::SetMessageData(MessageData *data)
+    {
+        if (data != nullptr)
+        {
+            message_.labeldetails = data->labeldetails;
+            message_.labeltime = data->labeltime;
+            message_.labeltitle = data->labeltitle;
+            message_.read = data->read;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetMessageData is ok");
+        }
+    }
 }
index 66061a3..71490c6 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @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
@@ -98,16 +104,28 @@ namespace OHOS
     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;
     }
 
index 0c61bc2..cecca33 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-06-17 19:39:36
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-18 11:30:10
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowPresenter.cpp
+ */
 /***
  * @Date: 2024-06-17 19:39:36
  * @LastEditors: Caisking 3449750381@qq.com
@@ -61,7 +67,7 @@ namespace OHOS
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
             (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
-            NativeAbility::GetInstance().Back();
+            NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE);
         }
         return true;
     }
@@ -69,16 +75,10 @@ namespace OHOS
     bool MessageShowPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
         UNUSED(event);
-#if 0
-        MessageShowItemView *messageItemView = static_cast<MessageShowItemView *>(&view);
-        int index = messageItemView->GetMessageShowListIndex();
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index:%d", index);
-        if (index >= p_MessageShowModel->GetMessageShowListNum())
+        if (strcmp(view.GetViewId(), DELETEBUTTON) == 0)
         {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index");
-            return false;
+            NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE);
         }
-#endif
         return true;
     }
 
index f7a3e92..012b1f4 100644 (file)
 #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;
@@ -37,6 +62,31 @@ namespace OHOS
     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();
@@ -46,29 +96,132 @@ namespace OHOS
         // 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)
@@ -78,27 +231,21 @@ namespace OHOS
         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();