信息通知Slice测试
authorCaisking <3449750381@qq.com>
Tue, 23 Jan 2024 09:32:45 +0000 (17:32 +0800)
committerCaisking <3449750381@qq.com>
Tue, 23 Jan 2024 09:32:45 +0000 (17:32 +0800)
15 files changed:
code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h
code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h
code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageAdapter.h
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageItem.h [deleted file]
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageItemView.h
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageModel.h
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessagePresenter.h
code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageView.h
code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageAdapter.cpp
code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageItemView.cpp
code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageModel.cpp
code/sdk/application/wearable/nativeapp/nativeui/message/src/MessagePresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageView.cpp

index 8cdaf6c..b15bc42 100755 (executable)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (c) 2020-2021 CompanyNameMagicTag.
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +25,7 @@
  */
 typedef enum : uint16_t
 {
-    VIEW_INVALID = 0,            // 无效视图
+    VIEW_INVALID = 0, // 无效视图
     /* ----------------------------- 每一个id对应一个slice ----------------------------- */
     VIEW_MAIN = 1,               // 主界面
     VIEW_SETTING,                // 设置
@@ -51,14 +52,16 @@ typedef enum : uint16_t
     VIEW_SYSTEM_REBOOT,          // 系统:重新启动
     VIEW_SYSTEM_SHOUTDOWN,       // 系统:关机
     VIEW_SYSTEM_FACTORY_RESET,   // 系统:恢复出厂设置
+    /* ---------------------------------- 测试界面 ---------------------------------- */
+    VIEW_MESSAGE, // 信息通知
     /* -------------------------------------------------------------------------- */
-    VIEW_MAIN_TEMP,              // 体温界面(暂时不用)
-    VIEW_OFFLINEVOICE,           // 语音助手界面(暂时不用)
-    VIEW_MAIN_ACTIVITY,          // 记录步数界面(暂时不用)
-    VIEW_UISAMPLE,               // 示例(暂时不用)
+    VIEW_MAIN_TEMP,     // 体温界面(暂时不用)
+    VIEW_OFFLINEVOICE,  // 语音助手界面(暂时不用)
+    VIEW_MAIN_ACTIVITY, // 记录步数界面(暂时不用)
+    VIEW_UISAMPLE,      // 示例(暂时不用)
     /* -------------------------------------------------------------------------- */
-    VIEW_MAX_INTER_APP,          // 在此之前添加native应用ID.
-    VIEW_EXTERN_APP = 0xFFFE,    // 三方应用
+    VIEW_MAX_INTER_APP,       // 在此之前添加native应用ID.
+    VIEW_EXTERN_APP = 0xFFFE, // 三方应用
     VIEW_INVALIDE_APP = 0xFFFF,
 } AppViewId;
 
index 7b1b4f7..c562ef3 100755 (executable)
@@ -1,15 +1,15 @@
-/*** 
+
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2023-12-13 19:33:14
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-01-22 16:32:42
  * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h
- * @Description: 
+ * @Description:
  * @
- * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
  */
 
-
 #ifndef NATIVE_LAUNCHER_H
 #define NATIVE_LAUNCHER_H
 #include "AppViewIDs.h"
@@ -43,17 +43,20 @@ namespace OHOS
         void InitDialSlice(void);
         /* ----------------------------------- 天气 ----------------------------------- */
         void InitWeatherSlice(void);
-        void InitWeatherReportSlice(void); 
-        void InitFutureWeatherSlice(void);  
+        void InitWeatherReportSlice(void);
+        void InitFutureWeatherSlice(void);
         void InitGetWeatherDataErrorSlice(void);
         /* -------------------------------------------------------------------------- */
-        void InitSystemSlice(void);                  
-        void InitSystemAboutWatchSlice(void);       
-        void InitSystemSuperviseSlice(void);        
-        void InitSystemLanguageSlice(void);         
-        void InitSystemRebootSlice(void);           
-        void InitSystemShoutDownSlice(void);        
-        void InitSystemFactoryResetSlice(void);      
+        void InitSystemSlice(void);
+        void InitSystemAboutWatchSlice(void);
+        void InitSystemSuperviseSlice(void);
+        void InitSystemLanguageSlice(void);
+        void InitSystemRebootSlice(void);
+        void InitSystemShoutDownSlice(void);
+        void InitSystemFactoryResetSlice(void);
+        /* -------------------------------------------------------------------------- */
+        void InitMessageSlice(void);
+
     private:
         void InitAllNativeSlices(void);
 
index 7763c66..753c2be 100755 (executable)
 #include "system/include/SystemFactoryResetPresenter.h"
 #include "system/include/SystemFactoryResetView.h"
 
+#include "message/include/MessageAdapter.h"
+#include "message/include/MessageView.h"
+#include "message/include/MessageItemView.h"
+#include "message/include/MessageModel.h"
+#include "message/include/MessagePresenter.h"
+
 #include "BluetoothHeadsetEvent.h"
 #include "graphic_hardware_config.h"
 #include "graphic_service.h"
@@ -129,10 +135,15 @@ namespace OHOS
         {VIEW_SYSTEM_REBOOT, &NativeLauncher::InitSystemRebootSlice},                 // 系统:重启实例化地址
         {VIEW_SYSTEM_SHOUTDOWN, &NativeLauncher::InitSystemShoutDownSlice},           // 系统:关机实例化地址
         {VIEW_SYSTEM_FACTORY_RESET, &NativeLauncher::InitSystemFactoryResetSlice},    // 系统:恢复出厂设置实例化地址
-        //{VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice},
-        //{VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice},
-        //{VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice},
-        //{VIEW_UISAMPLE, &NativeLauncher::InitUISampleSlice}
+
+        {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice},
+
+#if 0
+        {VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice},
+        {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice},
+        {VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice},
+        {VIEW_UISAMPLE, &NativeLauncher::InitUISampleSlice}
+#endif
     };
 
     static const ViewIdToString VIEW_MAPPER[] = {
@@ -517,4 +528,17 @@ namespace OHOS
         }
         NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_FACTORY_RESET, systemfactoryreset);
     }
+
+    /* -------------------------------------------------------------------------- */
+    void NativeLauncher::InitMessageSlice(void) // 系统:恢复出厂设置
+    {
+        SliceProxy *messageview = new AbilitySliceProxy<MessageView, MessagePresenter>;
+        if (messageview == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageView is nullptr");
+            return;
+        }
+        NativeAbility::GetInstance().AddSliceProxy(VIEW_MESSAGE, messageview);
+    }
+    /* -------------------------------------------------------------------------- */
 }
index 8708e29..0c3f8a3 100755 (executable)
@@ -26,6 +26,7 @@ namespace OHOS
         {VIEW_INDOORWALK, PNG_APPLIST_WALK_IMAGE, PNG_APPLIST_WALK_IMAGE, "室内步行", nullptr},
         {VIEW_WEATHER, PNG_APPLIST_WEATHER_IMAGE, PNG_APPLIST_WEATHER_IMAGE, "天气", nullptr},
         {VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "设置", nullptr},
+        {VIEW_MESSAGE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "信息通知", nullptr},
 #if 0
         {VIEW_MAIN_TEMP, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "体温", nullptr},
         {VIEW_CALLER_LOG, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "通话记录", nullptr},
index 2fbe1e1..04ed8d4 100644 (file)
@@ -1,10 +1,72 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-01-22 16:46:45
  * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-01-23 14:32:57
+ * @LastEditTime: 2024-01-23 16:33:12
  * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageAdapter.h
- * @Description: 
+ * @Description:
  * @
- * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
  */
+#ifndef Message_ADAPTER_H
+#define Message_ADAPTER_H
+#include <list>
+#include <string>
+#include "components/ui_list.h"
+#include "components/abstract_adapter.h"
+#include "components/ui_label.h"
+#include "components/ui_checkbox.h"
+
+// 音乐列表的适配器
+namespace OHOS
+{
+
+    typedef struct
+    {
+        int index;
+        const char *label;       // 标签
+        const char *icon;        // 图标
+        const char *labelbutton; // 未读
+
+    } MessageListItem;
+
+    class MessageListAdapter : public AbstractAdapter
+    {
+    public:
+        explicit MessageListAdapter();
+        virtual ~MessageListAdapter();
+
+        /* *
+         * @brief Sets the UIView adapter data, which is a MessageListItem linked list.
+         *
+         * @param data Indicates the MessageListItem linked list data.
+         * @since 1.0
+         * @version 1.0
+         */
+        void SetData(std::list<MessageListItem> &data);
+
+        /* *
+         * @brief Obtains the <b>data</b> size of the UILabel adapter.
+         *
+         * @return Returns the <b>data</b> size of the UILabel adapter.
+         * @since 1.0
+         * @version 1.0
+         */
+        virtual uint16_t GetCount(void) override;
+
+        virtual UIView *GetView(UIView *inView, int16_t index) override;
+
+        virtual void AddListItem(const MessageListItem &item);
+
+        void SetItemClickListener(UIView::OnClickListener *itemclicklistener)
+        {
+            itemClickListener = itemclicklistener;
+        }
+
+    private:
+        std::list<MessageListItem> listData;
+        UIView::OnClickListener *itemClickListener{nullptr};
+    };
+}
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageItem.h b/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageItem.h
deleted file mode 100644 (file)
index e69de29..0000000
index e69de29..e85c24a 100644 (file)
@@ -0,0 +1,42 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 16:33:48
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageItemView.h
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+#ifndef Message_ITEM_VIEW_H
+#define Message_ITEM_VIEW_H
+
+#include "components/ui_label.h"
+#include "components/ui_view_group.h"
+#include "components/ui_checkbox.h"
+#include "components/ui_image_view.h"
+#include "message/include/MessageAdapter.h"
+#include "components/ui_label_button.h"
+
+namespace OHOS
+{
+    class MessageItemView : public UIViewGroup
+    {
+    public:
+        explicit MessageItemView();
+        virtual ~MessageItemView();
+        virtual void SetItemInfo(const MessageListItem itemInfo);
+        virtual void SetUpChild();
+        int GetMessageListIndex();
+
+    private:
+        MessageItemView(const MessageItemView &);
+        UIImageView sbackground; // 背景
+        UILabel sLabel;          // 标签
+        UIImageView sIcon;       // 图标
+        UILabelButton sLabelButton;   // 未读
+        MessageListItem sItemInfo = {0, nullptr};
+    };
+
+}
+#endif
\ No newline at end of file
index e69de29..ecc4107 100644 (file)
@@ -0,0 +1,44 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 17:22:49
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageModel.h
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
+#ifndef Message_MODEL_H
+#define Message_MODEL_H
+
+#include <cstdint>
+#include <map>
+#include "AppViewIDs.h"
+#include "UiConfig.h"
+#include "MessagePresenter.h"
+#include "message/include/MessageAdapter.h"
+
+namespace OHOS
+{
+    class MessageModel
+    {
+    public:
+        static MessageModel &GetInstance(void);
+        void InitMessageListItem();
+        const MessageListItem *GetMessagelistItems() const;
+        uint8_t GetMessageListNum() const;
+        //const std::map<MessageIndex, AppViewId> &GetMessageIdToViewId() const;
+
+    private:
+        MessageModel();
+        MessageModel(const MessageModel &);
+        MessageModel &operator=(const MessageModel &);
+        virtual ~MessageModel();
+        static const uint16_t MessageListMaxNum = 6;
+        MessageListItem Messages[MessageListMaxNum] = {0, nullptr};
+        //std::map<int, AppViewId> MessageIdToViewId;
+        bool btConnectStatus{false};
+    };
+}
+
+#endif
\ No newline at end of file
index e69de29..533f9b9 100644 (file)
@@ -0,0 +1,44 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 16:37:19
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessagePresenter.h
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+#ifndef Message_PRESENTER_H
+#define Message_PRESENTER_H
+
+#include "Presenter.h"
+#include "MessageView.h"
+#include "message/include/MessageModel.h"
+namespace OHOS
+{
+    class MessageView;
+    class MessageModel;
+    class MessagePresenter : public Presenter<MessageView>,
+                             public UIView::OnClickListener,
+                             public UIView::OnDragListener
+    {
+    public:
+        MessagePresenter();
+        virtual ~MessagePresenter();
+
+        void OnStart() override;
+        void OnPause() override;
+        void OnResume() override;
+        void OnStop() override;
+
+        static MessagePresenter *GetInstance();
+
+    private:
+        // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        MessageModel *p_MessageModel{nullptr};
+    };
+} // namespace OHOS
+
+#endif
\ No newline at end of file
index e69de29..bbb288f 100644 (file)
@@ -0,0 +1,51 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 17:21:52
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/include/MessageView.h
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
+#ifndef Message_VIEW_H
+#define Message_VIEW_H
+
+#include "BaseView.h"
+#include "View.h"
+#include "components/ui_view_group.h"
+#include "components/ui_scroll_view.h"
+#include "components/ui_list.h"
+#include "message/include/MessageAdapter.h"
+namespace OHOS
+{
+    class MessagePresenter;
+    class MessageView : public View<MessagePresenter>
+    {
+
+    public:
+        MessageView();
+        virtual ~MessageView();
+        static MessageView *GetInstance(void);
+
+        void OnStart() override;
+        void OnSetUpView() override;
+        void OnTearDownView() override;
+        void OnStop() override;
+        void AddMessageToList(const MessageListItem &item);
+
+    private:
+        void InitView(void);
+        void DeInitView(void);
+        void PreLoad(void);
+
+    private:
+        UIScrollView *scrollView = nullptr;
+        UILabel *title{nullptr};
+        MessageListAdapter *p_MessageListAdapter{nullptr};
+        UIList *MessageList = nullptr; // 音乐列表
+        UIView::OnDragListener *draglistener{nullptr};
+        bool viewInitStatus{false};
+    };
+} // namespace OHOS
+#endif
\ No newline at end of file
index e69de29..0335334 100644 (file)
@@ -0,0 +1,89 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 17:27:19
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageAdapter.cpp
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
+#include "message/include/MessageAdapter.h"
+#include "message/include/MessageItemView.h"
+
+namespace OHOS
+{
+    MessageListAdapter::MessageListAdapter() {}
+
+    MessageListAdapter::~MessageListAdapter()
+    {
+        listData.clear();
+    }
+
+    uint16_t MessageListAdapter::GetCount(void)
+    {
+        return listData.size();
+    }
+
+    void MessageListAdapter::SetData(std::list<MessageListItem> &data)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+        std::list<MessageListItem>::iterator it;
+        for (it = data.begin(); it != data.end(); it++)
+        {
+            listData.push_back(*it);
+        }
+    }
+
+    /// @brief 为音乐列表的每一项创建一个视图
+    /// @param inView 一个指向已存在的视图对象的指
+    /// @param index 要创建的视图在列表中的索引l。
+    /// @return 返回该视图对象
+    UIView *MessageListAdapter::GetView(UIView *inView, int16_t index)
+    {
+        //1.先检查列表数据是否为空,若为空则返回空指针
+        if (listData.empty())
+        {
+            return nullptr;
+        }
+        //2.接着检查索引是否小于0,若小于0则返回空指针
+        if (index < 0)
+        {
+            return nullptr;
+        }
+        //3.检查是否超出列表数据大小,若超出则返回空指针
+        size_t uindex = index;
+        if (uindex >= listData.size())
+        {
+            return nullptr;
+        }
+        //4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量
+        std::list<MessageListItem>::iterator it = listData.begin();
+        for (int i = 0; i < index; i++)
+        {
+            it++;
+        }
+        MessageListItem itemData = *it;
+        MessageItemView *item = nullptr;
+        //5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的MessageItemView对象,否则将inView转换成MessageItemView类型的指针
+        if (inView == nullptr)
+        {
+            item = new MessageItemView();
+        }
+        else
+        {
+            item = static_cast<MessageItemView *>(inView);
+        }
+        item->SetItemInfo(itemData);
+        item->SetOnClickListener(itemClickListener);
+        return item;
+    }
+
+    void MessageListAdapter::AddListItem(const MessageListItem &item)
+    {
+        listData.push_back(item);
+    }
+} // namespace OHOS
index e69de29..98c9471 100644 (file)
@@ -0,0 +1,76 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 16:39:02
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageItemView.cpp
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+#include "message/include/MessageItemView.h"
+
+namespace OHOS
+{
+
+    MessageItemView::MessageItemView()
+    {
+        SetPosition(0, 0, 380, 120); // 每一itemview宽高要配置好,因为每一首加到list歌曲都是以这个视图为基准
+        SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        SetStyle(STYLE_BACKGROUND_OPA, 255);
+        SetTouchable(true);
+        SetUpChild();
+        Add(&sbackground);
+        Add(&sLabel);
+        Add(&sIcon);
+        Add(&sLabelButton);
+    }
+
+    MessageItemView::~MessageItemView()
+    {
+        Remove(&sbackground);
+        Remove(&sLabel);
+        Remove(&sIcon);
+        Remove(&sLabelButton);
+    }
+
+    /// @brief 设置item的信息
+    /// @param itemInfo
+    void MessageItemView::SetItemInfo(const MessageListItem itemInfo)
+    {
+        sItemInfo = itemInfo;
+        sIcon.SetSrc(itemInfo.icon);
+        sLabel.SetText(itemInfo.label);
+        sLabelButton.SetText(itemInfo.labelbutton);
+    }
+
+    /// @brief 设置每一个itemview上的组件
+    void MessageItemView::SetUpChild()
+    {
+        sbackground.SetSrc("/user/res/SETTING_BACKGROUND.bin");
+
+        sIcon.SetPosition(19, 19);
+        sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
+
+        sLabel.SetPosition(115, 33, 200, 40);
+        sLabel.SetStyle(STYLE_TEXT_FONT, 30);
+        sLabel.SetStyle(STYLE_LINE_HEIGHT, 36);
+        sLabel.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        sLabel.SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
+        sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+        sLabelButton.SetPosition(215, 25, 140, 50);
+        sLabelButton.SetStyle(STYLE_BACKGROUND_COLOR, 0xff303030);
+        sLabelButton.SetTextColor(Color::White());
+        sLabelButton.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
+        sLabelButton.SetTouchable(true);
+    }
+
+    /// @brief 获取list歌单的中每首歌的在list的下标
+    /// @return 返回歌曲下标
+    int MessageItemView::GetMessageListIndex()
+    {
+        return sItemInfo.index;
+    }
+
+}
\ No newline at end of file
index e69de29..e81bc1b 100644 (file)
@@ -0,0 +1,42 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-23 16:03:34
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 17:07:59
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageModel.cpp
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+#include "message/include/MessageModel.h"
+
+namespace OHOS
+{
+
+    MessageModel::MessageModel() {}
+
+    MessageModel::~MessageModel() {}
+
+    MessageModel &MessageModel::GetInstance()
+    {
+        static MessageModel instance;
+        return instance;
+    }
+
+    void MessageModel::InitMessageListItem()
+    {
+        Messages[0] = {0, "/user/res/message/system-icon.bin", "系统", "暂无信息"};
+        Messages[1] = {1, "/user/res/message/message-icon.bin", "信息", "暂无信息"};
+        Messages[2] = {2, "/user/res/message/WeChat-icon.bin", "微信", "暂无信息"};
+        Messages[3] = {3, "/user/res/message/QQ-icon.bin", "QQ", "暂无信息"};
+    }
+
+    const MessageListItem *MessageModel::GetMessagelistItems() const
+    {
+        return Messages;
+    }
+    uint8_t MessageModel::GetMessageListNum() const
+    {
+        return MessageListMaxNum;
+    }
+}
\ No newline at end of file
index e69de29..7c92fa0 100644 (file)
@@ -0,0 +1,95 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-22 16:22:26
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-23 17:31:05
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/src/MessagePresenter.cpp
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "message/include/MessagePresenter.h"
+#include "message/include/MessageAdapter.h"
+#include "message/include/MessageItemView.h"
+namespace OHOS
+{
+
+    // 当前Presenter属性实例化的内存指针
+    static MessagePresenter *g_pMessagePresenter = nullptr;
+
+    MessagePresenter::MessagePresenter()
+    {
+        p_MessageModel = &MessageModel::GetInstance();
+        g_pMessagePresenter = this;
+    }
+
+    MessagePresenter::~MessagePresenter()
+    {
+        g_pMessagePresenter = nullptr;
+    }
+
+    MessagePresenter *MessagePresenter::GetInstance()
+    {
+        return g_pMessagePresenter;
+    }
+
+    void MessagePresenter::OnStart()
+    {
+        // 初始化歌曲信息
+        p_MessageModel->InitMessageListItem();
+        Presenter<MessageView>::OnStart();
+    }
+
+    void MessagePresenter::OnPause(void)
+    {
+
+        Presenter<MessageView>::OnPause();
+    }
+
+    void MessagePresenter::OnResume(void)
+    {
+        // 把歌曲信息数据拿到存储到list中
+        if (view_ == nullptr)
+        {
+            return;
+        }
+        const MessageListItem *itemInfo = p_MessageModel->GetMessagelistItems();
+        for (int i = 0; i < p_MessageModel->GetMessageListNum(); i++)
+        {
+            view_->AddMessageToList(itemInfo[i]);
+        }
+        Presenter<MessageView>::OnResume();
+    }
+
+    void MessagePresenter::OnStop(void)
+    {
+        Presenter<MessageView>::OnStop();
+    }
+
+    bool MessagePresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
+        {
+            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+        }
+        return true;
+    }
+
+    bool MessagePresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        UNUSED(event);
+        MessageItemView *messageItemView = static_cast<MessageItemView *>(&view);
+        int index = messageItemView->GetMessageListIndex();
+        printf("%d\n",index);//测试点击是否有效
+        if (index >= p_MessageModel->GetMessageListNum())
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index");
+            return false;
+        }
+        return true;
+    }
+}
\ No newline at end of file
index dda2c91..c698b4d 100644 (file)
@@ -2,9 +2,142 @@
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-01-22 16:20:34
  * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-01-23 14:30:37
+ * @LastEditTime: 2024-01-23 17:12:40
  * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/message/src/MessageView.cpp
  * @Description: 
  * @
  * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
  */
+#include "message/include/MessageView.h"
+#include "message/include/MessagePresenter.h"
+
+#include "UiConfig.h"
+
+namespace OHOS
+{
+
+    static MessageView *g_pMessageView{nullptr};
+
+    MessageView::MessageView()
+    {
+
+        g_pMessageView = this;
+    }
+
+    MessageView::~MessageView()
+    {
+        if (viewInitStatus == true)
+        {
+            DeInitView();
+        }
+        g_pMessageView = nullptr;
+    }
+
+    MessageView *MessageView::GetInstance()
+    {
+        return g_pMessageView;
+    }
+
+    void MessageView::InitView()
+    {
+        if (scrollView == nullptr)
+        {
+            scrollView = new UIScrollView();
+        }
+        scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        scrollView->SetScrollBlankSize(20);
+        scrollView->SetReboundSize(50);
+        scrollView->SetTouchable(true);
+        scrollView->SetDraggable(true);
+        draglistener = static_cast<UIView::OnDragListener *>(MessagePresenter::GetInstance());
+        scrollView->SetOnDragListener(draglistener);
+        /* -------------------------------------------------------------------------- */
+        if (title == nullptr)
+        {
+            title = new UILabel();
+        }
+        title->SetPosition(173, 52, 120, 35);
+        title->Resize(120, 35);
+        title->SetStyle(STYLE_TEXT_FONT, 30);
+        title->SetStyle(STYLE_LINE_HEIGHT, 36);
+        title->SetText("信息通知");
+        title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        title->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
+        title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        /* -------------------------------------------------------------------------- */
+        //UIList 的适配器
+        p_MessageListAdapter = new MessageListAdapter();
+        p_MessageListAdapter->SetItemClickListener(presenter_);
+        if (MessageList == nullptr)
+        {
+            MessageList = new UIList();
+        }
+        MessageList->SetPosition(43, 120, 380, 600);
+        MessageList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+    }
+
+    void MessageView::DeInitView()
+    {
+        scrollView->RemoveAll();
+        delete title;
+        title = nullptr;
+
+        delete MessageList;
+        MessageList = nullptr;
+
+        delete scrollView;
+        scrollView = nullptr;
+
+        delete draglistener;
+        draglistener = nullptr;
+    }
+
+    void MessageView::PreLoad(void)
+    {
+        if (!viewInitStatus)
+        {
+            InitView();
+            viewInitStatus = true;
+        }
+    }
+
+    /// @brief 添加歌曲到list
+    /// @param item
+    void MessageView::AddMessageToList(const MessageListItem &item)
+    {
+        p_MessageListAdapter->AddListItem(item);
+    }
+
+    /// @brief 页面启动时需要执行的代码逻辑
+    void MessageView::OnStart()
+    {
+        PreLoad();
+    }
+
+    /// @brief 创建页面的视图。
+    void MessageView::OnSetUpView()
+    {
+        View<MessagePresenter>::OnSetUpView();
+        scrollView->Add(title);
+        scrollView->Add(MessageList);
+        RootView::GetInstance()->Add(scrollView);
+        MessageList->SetAdapter(p_MessageListAdapter);
+        Draw();
+    }
+
+    /// @brief 销毁页面的视图。
+    void MessageView::OnTearDownView()
+    {
+        View<MessagePresenter>::OnTearDownView();
+        return;
+    }
+
+    /// @brief 页面结束时需要执行的销毁逻辑。
+    void MessageView::OnStop()
+    {
+        View<MessagePresenter>::OnStop();
+        RootView::GetInstance()->RemoveAll();
+        return;
+    }
+}
\ No newline at end of file