音乐视图完善,秒表视图解决添加list数据重复问题
author罗正yun <1732036298@qq.com>
Thu, 28 Dec 2023 09:26:01 +0000 (17:26 +0800)
committer罗正yun <1732036298@qq.com>
Thu, 28 Dec 2023 09:26:01 +0000 (17:26 +0800)
code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp
code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h
code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h
code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp
code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp

index 0219401..315e6cb 100755 (executable)
@@ -315,7 +315,7 @@ void PullUpDownView::InitViewInfo(void)
 \r
     bool PullUpDownView::InitView( )\r
     {\r
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView caller:%p", caller);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView caller:");\r
         clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance();\r
 \r
         InitViewImg();\r
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h
new file mode 100644 (file)
index 0000000..9b98ac4
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef PLAYER_LIST_ITEM_VIEW_H
+#define PLAYER_LIST_ITEM_VIEW_H
+
+#include "components/ui_label.h"
+#include "components/ui_view_group.h"
+#include "components/ui_button.h"
+#include "player/include/PlayersCaseListAdapter.h"
+#include "PlayersPresenter.h"
+namespace OHOS
+{
+    class PlayerListItemView : public UIViewGroup
+    {
+    public:
+        explicit PlayerListItemView();
+        virtual ~PlayerListItemView();
+        virtual void SetItemInfo(const PlayerListItem itemInfo);
+        virtual void SetUpChild();
+        int GetPlayerListIndex();
+
+    private:
+        PlayerListItemView(const PlayerListItemView &);
+        UILabel sLabel;
+        UIButton sButton;
+        PlayerListItem sItemInfo{0,nullptr};
+    };
+
+}
+#endif
\ No newline at end of file
index 5f16435..25fc414 100755 (executable)
@@ -8,12 +8,19 @@
 #ifndef PLAYERS_CASE_LIST_ADAPTER_H\r
 #define PLAYERS_CASE_LIST_ADAPTER_H\r
 \r
+#include <list>\r
+#include <string>\r
 #include "components/abstract_adapter.h"\r
 #include "components/ui_label.h"\r
 #include "components/ui_label_button.h"\r
 #include "UiConfig.h"\r
 \r
 namespace OHOS {\r
+typedef struct\r
+{\r
+    int index;\r
+    const char *label;    // 标签\r
+} PlayerListItem;\r
 class PlayersCaseListAdapter : public AbstractAdapter {\r
 public:\r
     PlayersCaseListAdapter() {}\r
index 8734468..bc9b0c1 100755 (executable)
 #include "graphic_config.h"\r
 #include "components/ui_card_page.h"\r
 #include "PlayersPresenter.h"\r
-\r
+#include "components/ui_scroll_view.h"\r
 namespace OHOS {\r
 #define PLAY_PROGRESS_MIN 0\r
 #define PLAY_PROGRESS_MAX 100\r
 class JumpView;\r
 class PlayersPresenter;\r
 class PlayersCaseListAdapter;\r
-class PlayersView : public UICardPage {\r
+class PlayersView : public UICardPage{\r
 public:\r
     PlayersView();\r
     virtual ~PlayersView();\r
@@ -94,11 +94,12 @@ private:
     UIButton *optionsButton{nullptr};           //选项按钮\r
     UIButton *preButton{nullptr};               //上一首按钮\r
     UIButton *nextButton{nullptr};              //下一首按钮\r
-    UIViewGroup *listGroup{nullptr};            //列表组:可能是歌单~暂定\r
+    UIScrollView *listGroup{nullptr};            //列表组:可能是歌单~暂定\r
     UIImageView *soundButton{nullptr};          //声音按钮\r
     UIImageView *playerModelButton{nullptr};    //播放模式按钮\r
     UICheckBox *playerButton{nullptr};          //播放按钮\r
     UICircleProgress *playbackProgress{nullptr};//播放进度条\r
+    UILabel *musicListTitle{nullptr};           //歌单列表名\r
     int16_t volumeSet{0};                       //声音值的大小设置\r
     UIList *list{nullptr};\r
     JumpView *jumpView{nullptr};\r
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp
new file mode 100644 (file)
index 0000000..fec268c
--- /dev/null
@@ -0,0 +1,58 @@
+#include "PlayerListitemView.h"
+
+namespace OHOS
+{
+
+    PlayerListItemView::PlayerListItemView()
+    {
+        SetPosition(0, 0, 332, 78); // 每一首歌曲的itemview宽高要配置好,因为每一首加到list歌曲都是以这个视图为基准
+        SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        SetStyle(STYLE_BACKGROUND_OPA, 255);
+        SetTouchable(true);
+        SetUpChild();
+        Add(&sLabel);
+        Add(&sButton);
+    }
+
+    PlayerListItemView::~PlayerListItemView()
+    {
+        Remove(&sLabel);
+        Remove(&sButton);
+    }
+
+    /// @brief 设置item的信息
+    /// @param itemInfo
+    void PlayerListItemView::SetItemInfo(const PlayerListItem itemInfo)
+    {
+        sItemInfo = itemInfo;
+        sLabel.SetText(itemInfo.label);
+    }
+
+    /// @brief 设置每一个itemview上的组件
+    void PlayerListItemView::SetUpChild()
+    {
+        sLabel.SetPosition(0, 0, 200, 40);
+        sLabel.SetStyle(STYLE_TEXT_FONT, 30);
+        sLabel.SetStyle(STYLE_LINE_HEIGHT, 36);
+        sLabel.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        sLabel.SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff));
+        sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+        sButton.SetPosition(292, 0, 40, 40);
+        sButton.SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+        sButton.SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+        sButton.SetStyle(STYLE_BORDER_RADIUS, 0);
+        sButton.SetImageSrc("/user/res/player/music_delete.bin", nullptr);
+        sButton.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff4fc34c, UIButton::PRESSED);
+        sButton.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+        sButton.SetStyleForState(STYLE_BORDER_RADIUS, 0, UIButton::PRESSED);
+    }
+
+    /// @brief 获取list歌单的中每首歌的在list的下标
+    /// @return 返回歌曲下标
+    int PlayerListItemView::GetPlayerListIndex()
+    {
+        return sItemInfo.index;
+    }
+
+}
\ No newline at end of file
index fcb169d..5e6467e 100755 (executable)
@@ -11,7 +11,7 @@
 #include "PlayersPresenter.h"\r
 #include "wearable_log.h"\r
 #include "PlayersModel.h"\r
-\r
+#include "PlayerListitemView.h"\r
 namespace OHOS {\r
 constexpr uint16_t TESTCASE_BUTTON_HEIGHT = 64;\r
 constexpr uint16_t STYLE_BORDER_WIDTH_VALUE = 4;\r
@@ -38,10 +38,14 @@ public:
 \r
 private:\r
     void BtnOnListData(UIView& view);\r
-    char *sliceId_{nullptr};\r
-    int16_t index_{0};\r
+    char *sliceId_{nullptr};//歌名\r
+    int16_t index_{0}; //歌曲索引\r
 };\r
 \r
+/// @brief 这个函数是一个按钮点击事件监听器的回调函数\r
+/// @param view \r
+/// @param event \r
+/// @return \r
 bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event)\r
 {\r
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtnOnClickListListener sliceId_: %s.", sliceId_);\r
@@ -54,19 +58,21 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event)
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playersView null!");\r
         return false;\r
     }\r
+    //BtnOnListData该函数的作用是从传入的视图中提取相关数据\r
     BtnOnListData(view);\r
     // 标记当前播放歌曲index_\r
-    PlayersModel::GetInstance()->SetCurrentIndex(index_);\r
+    PlayersModel::GetInstance()->SetCurrentIndex(index_); //当前正在播放的歌曲\r
     // 本地播放文件路径和状态\r
-    std::string strSrcMusic(APP_MUSIC_PATH);\r
+    std::string strSrcMusic(APP_MUSIC_PATH);//"/user/music"\r
     std::string tempStr("/");\r
     std::string strName = sliceId_;\r
-    PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName);\r
+     PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName);\r
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", PlayersModel::GetInstance()->GetPlayerUri().c_str());\r
     std::string strSongName = sliceId_;\r
-    std::string pureName = strSongName.substr(0, strSongName.rfind("."));\r
+    std::string pureName = strSongName.substr(0, strSongName.rfind(".")); //获取纯粹歌曲名\r
+\r
     const char *songName = pureName.c_str();\r
-    playersView->TitleSetText(songName);\r
+    //playersView->TitleSetText(songName);\r
     playersView->SetPlayerListGroupStatus(false);\r
     // 刷新UI\r
     RootView::GetInstance()->Invalidate();\r
@@ -105,7 +111,10 @@ void BtnOnClickListListener::BtnOnListData(UIView& view)
     for (uint16_t i = 0; i < index_; i++) {\r
         node = node->next_;\r
     }\r
-    sliceId_ = node->data_.sliceId;\r
+    if(node != nullptr)\r
+    {\r
+        sliceId_ = node->data_.sliceId;\r
+    }\r
 }\r
 \r
 void PlayersCaseListAdapter::LabelButtonSet()\r
@@ -130,44 +139,39 @@ UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index)
     if ((index > playersCaseList.Size() - 1) || (index < 0)) {\r
         return nullptr;\r
     }\r
-    if (inView == nullptr) {\r
-        item = new UILabelButton();\r
-        if (item == nullptr) {\r
-            return nullptr;\r
-        }\r
-        item->SetPosition(0, 0);\r
-        item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::RELEASED);\r
-        item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::PRESSED);\r
-        item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::INACTIVE);\r
-        item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::RELEASED);\r
-        item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::PRESSED);\r
-        item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::INACTIVE);\r
-        item->Resize(HORIZONTAL_RESOLUTION, TESTCASE_BUTTON_HEIGHT);\r
-    } else {\r
-        item = static_cast<UILabelButton*>(inView);\r
-    }\r
     ListNode<PlayerCaseInfo>* node = playersCaseList.Begin();\r
     for (uint16_t i = 0; i < index; i++) {\r
         node = node->next_;\r
     }\r
-    if (listener == nullptr) {\r
+    std::string strSongName = node->data_.sliceId;\r
+    std::string pureName = strSongName.substr(0, strSongName.rfind("."));\r
+    const char *songName = pureName.c_str();\r
+    //printf("%s\n",songName);\r
+    PlayerListItemView *listitem = nullptr;\r
+    PlayerListItem listitemData;\r
+    listitemData.index = index;\r
+    listitemData.label = songName;\r
+    if (inView == nullptr) {\r
+        listitem = new PlayerListItemView();\r
+    } else {\r
+        listitem = static_cast<PlayerListItemView*>(inView);\r
+    }\r
+    listitem->SetItemInfo(listitemData);\r
+    if(listener == nullptr)\r
+    {\r
         listener = new BtnOnClickListListener();\r
-        if (listener == nullptr) {\r
+        if(listener == nullptr)\r
+        {\r
+            printf("%d listener == null\n",__LINE__);\r
             return nullptr;\r
         }\r
-        item->SetOnClickListener(listener);\r
-    } else {\r
-        item->SetOnClickListener(listener);\r
+        listitem->SetOnClickListener(listener);\r
     }\r
-    std::string strSongName = node->data_.sliceId;\r
-    std::string pureName = strSongName.substr(0, strSongName.rfind("."));\r
-    const char *songName = pureName.c_str();\r
-    item->SetText(songName);\r
-    item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: means font size\r
-    item->SetViewIndex(index);\r
-    item->SetAlign(TEXT_ALIGNMENT_CENTER);\r
-    item->SetLabelPosition(24, 0); // 24: lable x-coordinate\r
-    LabelButtonSet();\r
-    return item;\r
+    else \r
+    {\r
+        listitem->SetOnClickListener(listener);\r
+    }\r
+    return listitem;\r
+    \r
 }\r
 } // namespace OHOS\r
index 6744d6d..c09de49 100755 (executable)
@@ -611,7 +611,7 @@ void ButtonOnClickListener::PlayerModelButtonOnClick()
 \r
 bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event)\r
 {\r
-    UNUSED(view);\r
+\r
     UNUSED(event);\r
     PlayersView *playersView = PlayersView::GetInstance();\r
     if (playersView == nullptr) {\r
@@ -647,6 +647,10 @@ bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event)
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "optionsButton OnClick");\r
         OptionsButtonOnClick();\r
     }\r
+    if(strcmp(view.GetViewId(),"music_list_button") == 0)\r
+    {\r
+        PlayersPresenter::GetInstance()->ShowPlayerListGroup();\r
+    }\r
     return true;\r
 }\r
 \r
index c704a53..c8aa4f3 100755 (executable)
@@ -216,12 +216,30 @@ PlayersView* PlayersView::GetInstance(void)
 void PlayersView::ShowUpListView()\r
 {\r
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView");\r
-    listGroup = new UIViewGroup();\r
+    listGroup = new UIScrollView();\r
     if (listGroup == nullptr) {\r
         return;\r
     }\r
     listGroup->SetPosition(0, 0);\r
     listGroup->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION);\r
+    listGroup->SetScrollBlankSize(20);\r
+    listGroup->SetReboundSize(50);\r
+    listGroup->SetDirection(1);\r
+\r
+    musicListTitle = new UILabel();\r
+    if(musicListTitle ==nullptr)\r
+    {\r
+        return;\r
+    }\r
+    musicListTitle->SetPosition(173, 52,120,35);        \r
+    musicListTitle->SetStyle(STYLE_TEXT_FONT, 30);\r
+    musicListTitle->SetStyle(STYLE_LINE_HEIGHT, 36);\r
+    musicListTitle->SetText("音乐列表");\r
+    musicListTitle->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);\r
+    musicListTitle->SetTextColor(Color::GetColorFromRGBA(0xff, 0xf3, 0xff, 0xff));\r
+    musicListTitle->SetRollSpeed(0);\r
+    musicListTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+    listGroup->Add(musicListTitle);\r
 \r
     // list type\r
     if (adapterText == nullptr) {\r
@@ -237,7 +255,7 @@ void PlayersView::ShowUpListView()
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail");\r
             return;\r
         }\r
-        list->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);\r
+        list->SetPosition(67, 138, 332, 960);\r
         list->SetStartIndex(0); // 0 : list start index\r
         list->SetAdapter(adapterText);\r
     }\r
@@ -453,6 +471,7 @@ int PlayersView::ShowUpMusicListbutton()
     SetUpButton(music_list_button, pointBtn, 60, 60, music_list_button_listener); // 75:width 76:height\r
     ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_LIST, PLAYER_IAMGES);\r
     music_list_button->SetImageSrc(image, image);\r
+    music_list_button->SetViewId("music_list_button");\r
     music_list_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
     music_list_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
     music_list_button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED);\r
@@ -488,6 +507,7 @@ int PlayersView::ShowUpButtonOptions()
     pointBtn.y = 394; // 394:y\r
     SetUpButton(pullButton, pointBtn, 95, 48, nullptr); // 95:width 48:height\r
     pullButton->SetImageSrc(PNG_PULLBUTTON_FACE_IMAGE, PNG_PULLBUTTON_FACE_IMAGE);\r
+    pullButton->SetVisible(false);\r
     return OHOS_SUCCESS;\r
 }\r
 //显示播放进度条\r
@@ -616,11 +636,10 @@ void PlayersView::CreatePlayerMusicName()
 bool PlayersView::OnDragEvent(const DragEvent& event)\r
 {\r
     /* 300: y limit of drag start point */\r
-    if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) {\r
-        PlayersPresenter::GetInstance()->ShowPlayerListGroup();\r
-        return true;\r
-    }\r
-\r
+    // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) {\r
+    //     PlayersPresenter::GetInstance()->ShowPlayerListGroup();\r
+    //     return true;\r
+    // }\r
     return false;\r
 }\r
 \r
index 18eda3c..307d090 100755 (executable)
@@ -127,12 +127,12 @@ namespace OHOS
                 mainStopWatchView->SetViewIsVisible(m_list, true);\r
                 mainStopWatchView->SetViewIsVisible(m_image, true);\r
             }\r
-            char PickerData[128] = {0};\r
+            char  *PickerData = (char *)malloc(128);\r
             sprintf(PickerData, "0%d    %s    %s", RecordCycleNumber, "00:08:09", "+00:08:09");\r
-            m_listdata->PushBack(PickerData);\r
+            m_listdata->PushFront(static_cast<char *>(PickerData));\r
             m_listadapter->SetData(m_listdata);\r
             m_list->SetAdapter(m_listadapter);\r
-            //m_list->SetStartIndex(RecordCycleNumber - 1);\r
+            m_list->SetStartIndex(RecordCycleNumber - 1);\r
             m_list->SetSelectPosition(RecordCycleNumber);\r
             m_list->RefreshList();\r
             // m_list->Invalidate();\r
@@ -149,6 +149,11 @@ namespace OHOS
             mainStopWatchView->SetViewIsVisible(m_image, false);\r
             if (m_listdata != nullptr)\r
             {\r
+                for(int i=0;i<m_listdata->Size();i++)\r
+                {\r
+                    char *p = ( char*)( m_listdata->Tail()->data_);\r
+                    free(p);\r
+                }\r
                 m_listdata->Clear();\r
             }\r
             mainStopWatchView->SetViewIsVisible(m_list, false);\r