From: 罗正yun <1732036298@qq.com> Date: Tue, 2 Jan 2024 01:44:47 +0000 (+0800) Subject: 音乐播放器歌单功能基本完成,但歌单删除按钮点击无反应。 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f6bb76546b67f2b8bb4b3438835fd18a906bf332;p=mirrors%2FFD230.git 音乐播放器歌单功能基本完成,但歌单删除按钮点击无反应。 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h index 9b98ac4fc..171d36e01 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListitemView.h @@ -16,7 +16,14 @@ namespace OHOS virtual void SetItemInfo(const PlayerListItem itemInfo); virtual void SetUpChild(); int GetPlayerListIndex(); - + UILabel *GetLabel() + { + return &sLabel; + } + UIButton *GetButton() + { + return &sButton; + } private: PlayerListItemView(const PlayerListItemView &); UILabel sLabel; 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 25fc414df..9c15544ab 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h @@ -16,6 +16,28 @@ #include "UiConfig.h" namespace OHOS { +class PlayersCaseListAdapter; +class BtnOnClickListListener : public UIView::OnClickListener { +public: + BtnOnClickListListener(){} + ~BtnOnClickListListener(){} + bool OnClick(UIView& view, const ClickEvent& event) override; + void SetButtonAndLabel(UILabel *label,UIButton *button,int index,UIView::OnClickListener *listener) + { + m_label[index] = label; + m_button[index] = button; + //m_button[index]->SetOnClickListener(listener); + } + void SongClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index); + void SongNotClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index); +private: + void BtnOnListData(UIView& view); + UILabel * m_label[256]{nullptr}; + UIButton *m_button[256]{nullptr}; + int playOrDeleteStatus[256]{0}; + char *sliceId_{nullptr};//歌名 + int16_t index_{0}; //歌曲索引 +}; typedef struct { int index; @@ -23,14 +45,13 @@ typedef struct } PlayerListItem; class PlayersCaseListAdapter : public AbstractAdapter { public: - PlayersCaseListAdapter() {} + PlayersCaseListAdapter(); ~PlayersCaseListAdapter(); + static PlayersCaseListAdapter *GetInstance(void); UIView *GetView(UIView *inView, int16_t index) override; uint16_t GetCount() override; - + BtnOnClickListListener *p_BtnOnClickListListener{nullptr}; private: - void LabelButtonSet(); - UILabelButton *item{nullptr}; UIView::OnClickListener *listener{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h index 724c7394d..2df70c160 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h @@ -17,7 +17,7 @@ #include "audio_base_type.h" #include "PlayersPresenter.h" #include "bts_avrcp_controller.h" - +#include "PlayersCaseListAdapter.h" namespace OHOS { using OHOS::Media::Player; using OHOS::Media::Source; @@ -94,6 +94,7 @@ public: void ClearActivateAudioInterrupt(void); void GetDuration(int64_t &duration); private: + PlayersCaseListAdapter *m_PlayersCaseListAdapter{nullptr}; int64_t duration_{0}; bool audioInitStatus{false}; char *sliceId{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h index 6ff81250e..cffd0fc11 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h @@ -26,7 +26,7 @@ #include "TipsFailMessageView.h" #include "BluetoothDeviceListView.h" #include "BluetoothItemView.h" - +#include "PlayersCaseListAdapter.h" namespace OHOS { using OHOS::Media::Player; using namespace OHOS::Media; @@ -108,6 +108,7 @@ private: void SoundButtonOnClick(); void PlayerModelButtonOnClick(); void OptionsButtonOnClick(); + PlayersCaseListAdapter *m_PlayersCaseListAdapter{nullptr}; VolumeSettingView *volumeSetting{nullptr}; UIViewGroup *volumeSettingView{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 index fec268c9f..b8798a64e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListitemView.cpp @@ -1,5 +1,6 @@ #include "PlayerListitemView.h" - +#include "ui_resource_image.h" +#include "common/image_cache_manager.h" namespace OHOS { @@ -38,11 +39,12 @@ namespace OHOS sLabel.SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - sButton.SetPosition(292, 0, 40, 40); + sButton.SetPosition(292, 0, 78, 78); 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); + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_DELETE, PLAYER_IAMGES); + sButton.SetImageSrc(image, 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); 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 5e6467ef3..7b8d797b8 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -12,17 +12,38 @@ #include "wearable_log.h" #include "PlayersModel.h" #include "PlayerListitemView.h" +#include "ui_resource_image.h" +#include "common/image_cache_manager.h" namespace OHOS { constexpr uint16_t TESTCASE_BUTTON_HEIGHT = 64; constexpr uint16_t STYLE_BORDER_WIDTH_VALUE = 4; constexpr uint16_t STYLE_BORDER_RADIUS_VALUE = 12; static constexpr uint32 BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333; +static PlayersCaseListAdapter *g_PlayersCaseListAdapter{nullptr}; +PlayersCaseListAdapter::PlayersCaseListAdapter() +{ + g_PlayersCaseListAdapter = this; +} + PlayersCaseListAdapter::~PlayersCaseListAdapter() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersCaseListAdapter::~PlayersCaseListAdapter"); delete listener; listener = nullptr; + + g_PlayersCaseListAdapter = nullptr; + + if(p_BtnOnClickListListener != nullptr) + { + delete p_BtnOnClickListListener; + p_BtnOnClickListListener = nullptr; + } +} + +PlayersCaseListAdapter *PlayersCaseListAdapter::GetInstance(void) +{ + return g_PlayersCaseListAdapter; } uint16_t PlayersCaseListAdapter::GetCount() @@ -30,18 +51,24 @@ uint16_t PlayersCaseListAdapter::GetCount() return PlayersListGroup::GetInstance()->GetCase().Size(); } -class BtnOnClickListListener : public UIView::OnClickListener { -public: - BtnOnClickListListener() {} - ~BtnOnClickListListener() {} - bool OnClick(UIView& view, const ClickEvent& event) override; - -private: - void BtnOnListData(UIView& view); - char *sliceId_{nullptr};//歌名 - int16_t index_{0}; //歌曲索引 -}; +void BtnOnClickListListener::SongClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index) +{ + ImageInfo *imagePlaying = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAYING, PLAYER_IAMGES); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_label[index]->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index]->SetImageSrc(imagePlaying,nullptr); + //P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index]->SetViewId("playing"); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->playOrDeleteStatus[index] = 1; +} +void BtnOnClickListListener::SongNotClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index) +{ + ImageInfo *imageDeleye = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_DELETE, PLAYER_IAMGES); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_label[index]->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index]->SetImageSrc(imageDeleye,nullptr); + //std::string viewId = "delete"; + //P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index]->SetViewId(viewId.c_str()); + P_PlayersCaseListAdapter->p_BtnOnClickListListener->playOrDeleteStatus[index] = 0; +} /// @brief 这个函数是一个按钮点击事件监听器的回调函数 /// @param view /// @param event @@ -60,13 +87,21 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) } //BtnOnListData该函数的作用是从传入的视图中提取相关数据 BtnOnListData(view); + /* -------------------------------------------------------------------------- */ + PlayersCaseListAdapter *P_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); + // if((&view == P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index_]) && (P_PlayersCaseListAdapter->p_BtnOnClickListListener->playOrDeleteStatus[index_] == 0)) + // { + // printf("delete index = %d song,%s\n",index_,__func__); + // return false; + // } + /* -------------------------------------------------------------------------- */ // 标记当前播放歌曲index_ PlayersModel::GetInstance()->SetCurrentIndex(index_); //当前正在播放的歌曲 // 本地播放文件路径和状态 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(".")); //获取纯粹歌曲名 @@ -74,6 +109,17 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) const char *songName = pureName.c_str(); //playersView->TitleSetText(songName); playersView->SetPlayerListGroupStatus(false); + /* -------------------------------------------------------------------------- */ + //PlayersCaseListAdapter *P_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); + SongClick(P_PlayersCaseListAdapter,index_); + for(int i= 0;iGetCount();i++) + { + if(i != index_) + { + SongNotClick(P_PlayersCaseListAdapter,i); + } + } + /* -------------------------------------------------------------------------- */ // 刷新UI RootView::GetInstance()->Invalidate(); @@ -117,19 +163,6 @@ void BtnOnClickListListener::BtnOnListData(UIView& view) } } -void PlayersCaseListAdapter::LabelButtonSet() -{ - if (item == nullptr) { - return; - } - item->SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); - item->SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); - item->SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); - item->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED); - item->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED); - item->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE); -} - UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index) { List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); @@ -146,7 +179,6 @@ UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index) 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; @@ -160,16 +192,19 @@ UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index) if(listener == nullptr) { listener = new BtnOnClickListListener(); + p_BtnOnClickListListener = new BtnOnClickListListener(); if(listener == nullptr) { - printf("%d listener == null\n",__LINE__); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listener == nullptr"); return nullptr; } listitem->SetOnClickListener(listener); + p_BtnOnClickListListener->SetButtonAndLabel(listitem->GetLabel(),listitem->GetButton(),index,listener); } else { listitem->SetOnClickListener(listener); + p_BtnOnClickListListener->SetButtonAndLabel(listitem->GetLabel(),listitem->GetButton(),index,listener); } return listitem; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp index c4ae96dcc..ce172b326 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp @@ -170,6 +170,18 @@ int16_t PlayersModel::GetCurrentIndex(void) void PlayersModel::SetCurrentIndex(int16_t value) { currentIndex = value; + /* -------------------------------------------------------------------------- */ + m_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); + m_PlayersCaseListAdapter->p_BtnOnClickListListener->SongClick(m_PlayersCaseListAdapter,currentIndex); + for(int i= 0;iGetCount();i++) + { + if(i != currentIndex) + { + m_PlayersCaseListAdapter->p_BtnOnClickListListener->SongNotClick(m_PlayersCaseListAdapter,i); + } + } + PlayersView::GetInstance()->GetPlayerList(); + /* -------------------------------------------------------------------------- */ } int16_t PlayersModel::GetPlayerModel(void) 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 c09de493b..4bd5e659a 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -527,6 +527,19 @@ void ButtonOnClickListener::PlayerButtonOnClick() } else if (state == UICheckBox::UICheckBoxState::UNSELECTED) { PlayersModel::GetInstance()->ConnectBtAndLocalPause(connCtState, connTgState); } + /* -------------------------------------------------------------------------- */ + //点击播放音乐时,音乐列表当前歌曲名要变颜色 + m_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); + m_PlayersCaseListAdapter->p_BtnOnClickListListener->SongClick(m_PlayersCaseListAdapter,PlayersModel::GetInstance()->GetCurrentIndex()); + for(int i= 0;iGetCount();i++) + { + if(i != PlayersModel::GetInstance()->GetCurrentIndex()) + { + m_PlayersCaseListAdapter->p_BtnOnClickListListener->SongNotClick(m_PlayersCaseListAdapter,i); + } + } + PlayersView::GetInstance()->GetPlayerList(); + /* -------------------------------------------------------------------------- */ } void ButtonOnClickListener::SoundButtonOnClick() 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 c8aa4f3b2..0e31a000e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp @@ -255,7 +255,7 @@ void PlayersView::ShowUpListView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); return; } - list->SetPosition(67, 138, 332, 960); + list->SetPosition(67, 138, 332, 500); list->SetStartIndex(0); // 0 : list start index list->SetAdapter(adapterText); } diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/music/FolkSongToTheParty.mp3 b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/music/FolkSongToTheParty.mp3 new file mode 100644 index 000000000..6f88343c2 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/music/FolkSongToTheParty.mp3 differ