170 lines
5.9 KiB
C++
170 lines
5.9 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayerAdapter.cpp
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2025-01-02
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiAppPlayerAdapter.h"
|
|
#include "TjdUiAppPlayerBTImpl.h"
|
|
#include "TjdUiAppPlayerPresenter.h"
|
|
#include "TjdUiAppPlayerView.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "UiConfig.h"
|
|
#include "common/image_cache_manager.h"
|
|
|
|
namespace TJD {
|
|
#define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_music.bin"
|
|
#define IMAGE_SETTING_BIN_PATH TJD_IMAGE_PATH "img_setting.bin"
|
|
|
|
using namespace OHOS;
|
|
|
|
static constexpr int16_t DEVICE_ITEM_ALIGN_X = 221;
|
|
static constexpr int16_t ITEM_WIDTH = 230;
|
|
static constexpr int16_t ITEM_HEIGHT = 56;
|
|
|
|
static constexpr int16_t HEADSET_ITEM_ALIGN_X = 237;
|
|
DeviceSelectListItemView::DeviceSelectListItemView(const DeviceSelectListItemInfo &itemInfo)
|
|
{
|
|
Resize(450, 128);
|
|
SetTouchable(true);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
|
SetStyle(OHOS::STYLE_BORDER_RADIUS, 64);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
|
|
|
|
icon_.SetPosition(22, 22, 84, 84);
|
|
icon_.SetAutoEnable(false);
|
|
icon_.SetResizeMode(OHOS::UIImageView::COVER);
|
|
|
|
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 42);
|
|
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
|
|
|
|
state_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
state_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
|
|
state_.SetPosition(78, 76, 150, 100);
|
|
state_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_TOP);
|
|
|
|
Add(&icon_);
|
|
Add(&name_);
|
|
Add(&state_);
|
|
Add(&select_);
|
|
}
|
|
|
|
DeviceSelectListItemView::~DeviceSelectListItemView() { RemoveAll(); }
|
|
|
|
void DeviceSelectListItemView::RefreshItem(const DeviceSelectListItemInfo &info, int16_t index)
|
|
{
|
|
itemInfo_ = info;
|
|
selectRes_ = info.selectInfo;
|
|
unSelectRes_ = info.unSelectInfo;
|
|
name_.SetTextId(info.textId);
|
|
|
|
bool isBtItem = itemInfo_.deviceIndex == PlayerDeviceType::DEVICE_HEADSET;
|
|
RefreshPos(isBtItem);
|
|
state_.SetVisible(isBtItem);
|
|
icon_.SetVisible(!isBtItem);
|
|
|
|
if (isBtItem) {
|
|
state_.SetStyle(OHOS::STYLE_TEXT_OPA, info.state ? OHOS::OPA_OPAQUE * 0.7 : OHOS::OPA_OPAQUE * 0.3);
|
|
state_.SetTextId(info.state ? STR_ID_589 : STR_ID_590);
|
|
} else {
|
|
icon_.SetSrc(info.iconInfo);
|
|
}
|
|
select_.SetSrc(itemInfo_.state ? selectRes_ : unSelectRes_);
|
|
|
|
SetTouchable(itemInfo_.active);
|
|
SetStyle(OHOS::STYLE_IMAGE_OPA, info.active ? OHOS::OPA_OPAQUE : OHOS::OPA_OPAQUE * 0.3);
|
|
}
|
|
|
|
bool DeviceSelectListItemView::OnClickEvent(const OHOS::ClickEvent &event)
|
|
{
|
|
TjdUiAppPlayerPresenter *presenter = TjdUiAppPlayerPresenter::GetInstance();
|
|
if (itemInfo_.deviceIndex == PlayerDeviceType::DEVICE_HEADSET) {
|
|
if (!itemInfo_.state) {
|
|
presenter->HeadsetEnableOnClick();
|
|
} else {
|
|
presenter->HeadsetDisableOnClick();
|
|
}
|
|
} else if (itemInfo_.deviceIndex == PlayerDeviceType::DEVICE_PHONE)
|
|
presenter->SelectPhoneDeviceOnClick();
|
|
else {
|
|
presenter->SelectWatchDeviceOnClick();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void DeviceSelectListItemView::RefreshPos(bool isBtItem)
|
|
{
|
|
if (isBtItem) {
|
|
name_.SetPosition(78, 18, ITEM_WIDTH, ITEM_HEIGHT);
|
|
name_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_TOP);
|
|
select_.SetPosition(350, 45, 72, 38);
|
|
} else {
|
|
name_.SetPosition(DEVICE_ITEM_ALIGN_X - (ITEM_WIDTH >> 1), (GetHeight() >> 1) - (ITEM_HEIGHT >> 1), ITEM_WIDTH,
|
|
ITEM_HEIGHT);
|
|
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
select_.SetPosition(382, 44, 40, 40);
|
|
}
|
|
}
|
|
|
|
HeadsetListItemView::HeadsetListItemView(const HeadsetListItemInfo &itemInfo)
|
|
{
|
|
Resize(450, 128);
|
|
SetTouchable(true);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
|
SetStyle(OHOS::STYLE_BORDER_RADIUS, 64);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
|
|
|
|
icon_.SetPosition(16, 18, 92, 92);
|
|
icon_.SetAutoEnable(false);
|
|
icon_.SetResizeMode(OHOS::UIImageView::COVER);
|
|
|
|
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 42);
|
|
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
|
|
name_.SetPosition(HEADSET_ITEM_ALIGN_X - (ITEM_WIDTH >> 1), 16, ITEM_WIDTH, ITEM_HEIGHT);
|
|
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
|
|
state_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
state_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
|
|
state_.SetPosition(HEADSET_ITEM_ALIGN_X - (ITEM_WIDTH >> 1), 65, ITEM_WIDTH, ITEM_HEIGHT);
|
|
state_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
|
|
more_.SetPosition(401, 51, 15, 26);
|
|
more_.SetSrc(itemInfo.moreInfo);
|
|
|
|
Add(&icon_);
|
|
Add(&name_);
|
|
Add(&state_);
|
|
Add(&more_);
|
|
}
|
|
|
|
HeadsetListItemView::~HeadsetListItemView() { RemoveAll(); }
|
|
|
|
void HeadsetListItemView::RefreshItem(const HeadsetListItemInfo &info, int16_t index)
|
|
{
|
|
itemInfo_ = info;
|
|
icon_.SetSrc(info.iconInfo);
|
|
name_.SetText(info.headsetInfo->name.c_str());
|
|
state_.SetStyle(OHOS::STYLE_TEXT_OPA,
|
|
info.headsetInfo->isConnect ? OHOS::OPA_OPAQUE * 0.7 : OHOS::OPA_OPAQUE * 0.3);
|
|
if (info.headsetInfo->isConnect) {
|
|
state_.SetTextId(STR_ID_589);
|
|
} else if (info.headsetInfo->isPaired) {
|
|
state_.SetTextId(STR_ID_271);
|
|
} else {
|
|
state_.SetTextId(STR_ID_590);
|
|
}
|
|
}
|
|
|
|
bool HeadsetListItemView::OnClickEvent(const OHOS::ClickEvent &event)
|
|
{
|
|
TjdUiAppPlayerPresenter::GetInstance()->SetConnectDeviceAddr(itemInfo_.headsetInfo->bdAddr);
|
|
TjdUiAppPlayerPresenter::GetInstance()->HeadsetConnectOnClick();
|
|
return true;
|
|
}
|
|
|
|
} // namespace TJD
|