From: 罗正yun <1732036298@qq.com> Date: Thu, 28 Dec 2023 09:26:01 +0000 (+0800) Subject: 音乐视图完善,秒表视图解决添加list数据重复问题 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=beda999aa5f61a33e28db4f87d97959dfcbe3248;p=mirrors%2FFD230.git 音乐视图完善,秒表视图解决添加list数据重复问题 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp index 021940166..315e6cb9e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -315,7 +315,7 @@ void PullUpDownView::InitViewInfo(void) bool PullUpDownView::InitView( ) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView caller:%p", caller); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView caller:"); clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); InitViewImg(); 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 index 000000000..9b98ac4fc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h @@ -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 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h index 5f164355e..25fc414df 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h @@ -8,12 +8,19 @@ #ifndef PLAYERS_CASE_LIST_ADAPTER_H #define PLAYERS_CASE_LIST_ADAPTER_H +#include +#include #include "components/abstract_adapter.h" #include "components/ui_label.h" #include "components/ui_label_button.h" #include "UiConfig.h" namespace OHOS { +typedef struct +{ + int index; + const char *label; // 标签 +} PlayerListItem; class PlayersCaseListAdapter : public AbstractAdapter { public: PlayersCaseListAdapter() {} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h index 87344686a..bc9b0c171 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h @@ -25,14 +25,14 @@ #include "graphic_config.h" #include "components/ui_card_page.h" #include "PlayersPresenter.h" - +#include "components/ui_scroll_view.h" namespace OHOS { #define PLAY_PROGRESS_MIN 0 #define PLAY_PROGRESS_MAX 100 class JumpView; class PlayersPresenter; class PlayersCaseListAdapter; -class PlayersView : public UICardPage { +class PlayersView : public UICardPage{ public: PlayersView(); virtual ~PlayersView(); @@ -94,11 +94,12 @@ private: UIButton *optionsButton{nullptr}; //选项按钮 UIButton *preButton{nullptr}; //上一首按钮 UIButton *nextButton{nullptr}; //下一首按钮 - UIViewGroup *listGroup{nullptr}; //列表组:可能是歌单~暂定 + UIScrollView *listGroup{nullptr}; //列表组:可能是歌单~暂定 UIImageView *soundButton{nullptr}; //声音按钮 UIImageView *playerModelButton{nullptr}; //播放模式按钮 UICheckBox *playerButton{nullptr}; //播放按钮 UICircleProgress *playbackProgress{nullptr};//播放进度条 + UILabel *musicListTitle{nullptr}; //歌单列表名 int16_t volumeSet{0}; //声音值的大小设置 UIList *list{nullptr}; JumpView *jumpView{nullptr}; 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 index 000000000..fec268c9f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp @@ -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 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp index fcb169d89..5e6467ef3 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -11,7 +11,7 @@ #include "PlayersPresenter.h" #include "wearable_log.h" #include "PlayersModel.h" - +#include "PlayerListitemView.h" namespace OHOS { constexpr uint16_t TESTCASE_BUTTON_HEIGHT = 64; constexpr uint16_t STYLE_BORDER_WIDTH_VALUE = 4; @@ -38,10 +38,14 @@ public: private: void BtnOnListData(UIView& view); - char *sliceId_{nullptr}; - int16_t index_{0}; + char *sliceId_{nullptr};//歌名 + int16_t index_{0}; //歌曲索引 }; +/// @brief 这个函数是一个按钮点击事件监听器的回调函数 +/// @param view +/// @param event +/// @return bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtnOnClickListListener sliceId_: %s.", sliceId_); @@ -54,19 +58,21 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playersView null!"); return false; } + //BtnOnListData该函数的作用是从传入的视图中提取相关数据 BtnOnListData(view); // 标记当前播放歌曲index_ - PlayersModel::GetInstance()->SetCurrentIndex(index_); + PlayersModel::GetInstance()->SetCurrentIndex(index_); //当前正在播放的歌曲 // 本地播放文件路径和状态 - std::string strSrcMusic(APP_MUSIC_PATH); + std::string strSrcMusic(APP_MUSIC_PATH);//"/user/music" std::string tempStr("/"); std::string strName = sliceId_; - PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName); + PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", PlayersModel::GetInstance()->GetPlayerUri().c_str()); std::string strSongName = sliceId_; - std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); //获取纯粹歌曲名 + const char *songName = pureName.c_str(); - playersView->TitleSetText(songName); + //playersView->TitleSetText(songName); playersView->SetPlayerListGroupStatus(false); // 刷新UI RootView::GetInstance()->Invalidate(); @@ -105,7 +111,10 @@ void BtnOnClickListListener::BtnOnListData(UIView& view) for (uint16_t i = 0; i < index_; i++) { node = node->next_; } - sliceId_ = node->data_.sliceId; + if(node != nullptr) + { + sliceId_ = node->data_.sliceId; + } } void PlayersCaseListAdapter::LabelButtonSet() @@ -130,44 +139,39 @@ UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index) if ((index > playersCaseList.Size() - 1) || (index < 0)) { return nullptr; } - if (inView == nullptr) { - item = new UILabelButton(); - if (item == nullptr) { - return nullptr; - } - item->SetPosition(0, 0); - item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::RELEASED); - item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::PRESSED); - item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::INACTIVE); - item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::RELEASED); - item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::PRESSED); - item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::INACTIVE); - item->Resize(HORIZONTAL_RESOLUTION, TESTCASE_BUTTON_HEIGHT); - } else { - item = static_cast(inView); - } ListNode* node = playersCaseList.Begin(); for (uint16_t i = 0; i < index; i++) { node = node->next_; } - if (listener == nullptr) { + std::string strSongName = node->data_.sliceId; + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + const char *songName = pureName.c_str(); + //printf("%s\n",songName); + PlayerListItemView *listitem = nullptr; + PlayerListItem listitemData; + listitemData.index = index; + listitemData.label = songName; + if (inView == nullptr) { + listitem = new PlayerListItemView(); + } else { + listitem = static_cast(inView); + } + listitem->SetItemInfo(listitemData); + if(listener == nullptr) + { listener = new BtnOnClickListListener(); - if (listener == nullptr) { + if(listener == nullptr) + { + printf("%d listener == null\n",__LINE__); return nullptr; } - item->SetOnClickListener(listener); - } else { - item->SetOnClickListener(listener); + listitem->SetOnClickListener(listener); } - std::string strSongName = node->data_.sliceId; - std::string pureName = strSongName.substr(0, strSongName.rfind(".")); - const char *songName = pureName.c_str(); - item->SetText(songName); - item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: means font size - item->SetViewIndex(index); - item->SetAlign(TEXT_ALIGNMENT_CENTER); - item->SetLabelPosition(24, 0); // 24: lable x-coordinate - LabelButtonSet(); - return item; + else + { + listitem->SetOnClickListener(listener); + } + return listitem; + } } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp index 6744d6d73..c09de493b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -611,7 +611,7 @@ void ButtonOnClickListener::PlayerModelButtonOnClick() bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event) { - UNUSED(view); + UNUSED(event); PlayersView *playersView = PlayersView::GetInstance(); if (playersView == nullptr) { @@ -647,6 +647,10 @@ bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "optionsButton OnClick"); OptionsButtonOnClick(); } + if(strcmp(view.GetViewId(),"music_list_button") == 0) + { + PlayersPresenter::GetInstance()->ShowPlayerListGroup(); + } return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp index c704a5348..c8aa4f3b2 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp @@ -216,12 +216,30 @@ PlayersView* PlayersView::GetInstance(void) void PlayersView::ShowUpListView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView"); - listGroup = new UIViewGroup(); + listGroup = new UIScrollView(); if (listGroup == nullptr) { return; } listGroup->SetPosition(0, 0); listGroup->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + listGroup->SetScrollBlankSize(20); + listGroup->SetReboundSize(50); + listGroup->SetDirection(1); + + musicListTitle = new UILabel(); + if(musicListTitle ==nullptr) + { + return; + } + musicListTitle->SetPosition(173, 52,120,35); + musicListTitle->SetStyle(STYLE_TEXT_FONT, 30); + musicListTitle->SetStyle(STYLE_LINE_HEIGHT, 36); + musicListTitle->SetText("音乐列表"); + musicListTitle->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + musicListTitle->SetTextColor(Color::GetColorFromRGBA(0xff, 0xf3, 0xff, 0xff)); + musicListTitle->SetRollSpeed(0); + musicListTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + listGroup->Add(musicListTitle); // list type if (adapterText == nullptr) { @@ -237,7 +255,7 @@ void PlayersView::ShowUpListView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); return; } - list->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + list->SetPosition(67, 138, 332, 960); list->SetStartIndex(0); // 0 : list start index list->SetAdapter(adapterText); } @@ -453,6 +471,7 @@ int PlayersView::ShowUpMusicListbutton() SetUpButton(music_list_button, pointBtn, 60, 60, music_list_button_listener); // 75:width 76:height ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_LIST, PLAYER_IAMGES); music_list_button->SetImageSrc(image, image); + music_list_button->SetViewId("music_list_button"); music_list_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); music_list_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); music_list_button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); @@ -488,6 +507,7 @@ int PlayersView::ShowUpButtonOptions() pointBtn.y = 394; // 394:y SetUpButton(pullButton, pointBtn, 95, 48, nullptr); // 95:width 48:height pullButton->SetImageSrc(PNG_PULLBUTTON_FACE_IMAGE, PNG_PULLBUTTON_FACE_IMAGE); + pullButton->SetVisible(false); return OHOS_SUCCESS; } //显示播放进度条 @@ -616,11 +636,10 @@ void PlayersView::CreatePlayerMusicName() bool PlayersView::OnDragEvent(const DragEvent& event) { /* 300: y limit of drag start point */ - if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) { - PlayersPresenter::GetInstance()->ShowPlayerListGroup(); - return true; - } - + // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) { + // PlayersPresenter::GetInstance()->ShowPlayerListGroup(); + // return true; + // } return false; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index 18eda3c6b..307d090e1 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -127,12 +127,12 @@ namespace OHOS mainStopWatchView->SetViewIsVisible(m_list, true); mainStopWatchView->SetViewIsVisible(m_image, true); } - char PickerData[128] = {0}; + char *PickerData = (char *)malloc(128); sprintf(PickerData, "0%d %s %s", RecordCycleNumber, "00:08:09", "+00:08:09"); - m_listdata->PushBack(PickerData); + m_listdata->PushFront(static_cast(PickerData)); m_listadapter->SetData(m_listdata); m_list->SetAdapter(m_listadapter); - //m_list->SetStartIndex(RecordCycleNumber - 1); + m_list->SetStartIndex(RecordCycleNumber - 1); m_list->SetSelectPosition(RecordCycleNumber); m_list->RefreshList(); // m_list->Invalidate(); @@ -149,6 +149,11 @@ namespace OHOS mainStopWatchView->SetViewIsVisible(m_image, false); if (m_listdata != nullptr) { + for(int i=0;iSize();i++) + { + char *p = ( char*)( m_listdata->Tail()->data_); + free(p); + } m_listdata->Clear(); } mainStopWatchView->SetViewIsVisible(m_list, false);