mcu_hi3321_watch/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h
2025-05-26 20:15:20 +08:00

246 lines
8.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
* Description: Player view
* Author:
* Create: 2021-07-26
*/
#ifndef PLAYERS_PRESENTER_H
#define PLAYERS_PRESENTER_H
#include "gfx_utils/list.h"
#include "ohos_types.h"
#include "components/ui_view.h"
#include "player.h"
#include "audio_manager.h"
#include "audio_base_type.h"
#include "BluetoothView.h"
#include "VolumeSettingView.h"
#include "VolumeSettingPresenter.h"
#include "BluetoothModel.h"
#include "BluetoothEarPhoneView.h"
#include "BluetoothEarListView.h"
#include "BluetoothOptionsView.h"
#include "BluetoothReconnectView.h"
#include "TipsSuccMessageView.h"
#include "TipsConnFailMessageView.h"
#include "TipsFailMessageView.h"
#include "BluetoothDeviceListView.h"
#include "BluetoothItemView.h"
namespace OHOS {
using OHOS::Media::Player;
using namespace OHOS::Media;
using namespace::Audio;
using Audio::AudioManager;
class VolumeSettingView;
#define DEC_NUM_256 256
// 点击按钮视图ID
#define BLUETOOTH_RESCAN_BUTTON "rescanButton"
#define BLUETOOTH_NEWEQUIPMENT_BUTTON "newEquipmentButton"
#define BLUETOOTH_CANCELCONNEDREQUEST_BUTTON "cancelConnedRequestButton"
#define BLUETOOTH_UNPAIR_BUTTON "unpairButton"
#define BLUETOOTH_OPTIONONE_BUTTON "optionsOneButton"
#define BLUETOOTH_SETTING_BUTTON "settingButton"
#define BLUETOOTH_DELETE_BUTTON "deleteButton"
#define BLUETOOTH_SUCC_BACK_BUTTON "succBackButton"
#define BLUETOOTH_FAIL_BACK_BUTTON "failBackButton" // 重试按钮
#define BLUETOOTH_CONN_FAIL_BACK_BUTTON "connfailBackButton"
// 视图滑动事件ID
#define BLUETOOTH_EARLIST_VIEW "BluetoothEarListView"
#define BLUETOOTH_DEVICE_LIST_VIEW "BluetoothDeviceListView"
#define BLUETOOTH_EAR_PHONE_VIEW "BluetoothEarPhoneView"
#define BLUETOOTH_OPTIONS_VIEW "BluetoothOptionsView"
#define BLUETOOTH_RECONNECT_VIEW "BluetoothReconnectView"
#define BLUETOOTH_VIEW "BluetoothView"
#define TIPS_SUCC_MESSAGE_VIEW "TipsSuccMessageView"
#define TIPS_FAIL_MESSAGE_VIEW "TipsFailMessageView"
#define TIPS_CONN_FAIL_MESSAGE_VIEW "TipsConnFailMessageView"
static constexpr uint8_t FONT_THIRTY_SIZE = 30; // 30字体大小
static constexpr uint8_t FONT_FORTY_SIZE = 40; // 40字体大小
struct PlayerCaseInfo {
char sliceId[DEC_NUM_256];
int16_t index;
};
class PlayersListGroup {
public:
PlayersListGroup() {}
~PlayersListGroup();
static PlayersListGroup *GetInstance()
{
static PlayersListGroup instance;
return &instance;
}
void SetUpListCase();
List<PlayerCaseInfo>& GetCase();
char *GetCase(int16_t index);
void AddCase(PlayerCaseInfo testCaseInfo);
private:
List<PlayerCaseInfo> *playersCaseList_{nullptr};
int GetAllFiles(List<PlayerCaseInfo> *playersCaseList);
};
// Button OnClick
class ButtonOnClickListener : public UIView::OnClickListener {
public:
enum VolumeSetState : uint8_t {
MUTE,
LOW,
MEDIUM,
LOUD,
};
ButtonOnClickListener() {}
ButtonOnClickListener(UIView *view) : view_(view) {}
~ButtonOnClickListener();
static ButtonOnClickListener *GetInstance()
{
static ButtonOnClickListener instance;
return &instance;
}
bool OnClick(UIView& view, const ClickEvent& event) override;
private:
UIView *view_{nullptr};
void PlayerButtonOnClick();
void SoundButtonOnClick();
void PlayerModelButtonOnClick();
void OptionsButtonOnClick();
VolumeSettingView *volumeSettingView{nullptr};
};
// 播放器回调
class PlayerCallbackImpl : public OHOS::Media::PlayerCallback {
public:
PlayerCallbackImpl();
~PlayerCallbackImpl();
void OnPlaybackComplete();
void OnError(int32_t errorType, int32_t errorCode);
void OnInfo(int type, int extra);
void OnRewindToComplete();
private:
};
// 播放器
class PlayerInterruptListener : public InterruptListener {
public:
PlayerInterruptListener();
~PlayerInterruptListener();
void SetOwner(std::shared_ptr<Player> player);
void SetPaused(bool value);
void SetResumed(bool value);
void RestFlag();
bool IsPaused();
bool IsDelayed();
bool IsResumed();
bool IsBeginStopped();
bool IsEndStopped();
void OnInterrupt(int32_t type, int32_t hint) override;
void PausePlayer(void);
void ResumePlayer(void);
void StopPlayer(void);
std::shared_ptr<Player> GetPlayer();
private:
std::shared_ptr<Player> player_{nullptr};
bool isPaused_{false};
bool isDelayed_{false};
bool isResumed_{false};
bool isBeginStopped_{false};
bool isEndStopped_{false};
};
// 滑动手势
class PlayerOnDragListener : public UIView::OnDragListener {
public:
PlayerOnDragListener();
~PlayerOnDragListener();
bool OnDragEnd(UIView& view, const DragEvent& event) override;
bool OnDrag(UIView& view, const DragEvent& event) override;
static PlayerOnDragListener *GetInstance();
private:
void OnDragChangView(const DragEvent& event, int16_t hideView, int16_t showView, bool isStopScan);
void OnDragChangBluetoothView(const DragEvent& event);
void DropEarPhoneView(const DragEvent& event);
void DropEarListView(const DragEvent& event);
void CorrespondingJump(const DragEvent& event, int16_t hideView);
};
// Bluetooth View redirection
class BluetoothEarListView;
class BluetoothOptionsView;
class BluetoothDeviceListView;
class JumpView {
public:
enum BluetoothJumpViewNum : uint8_t {
BLUETOOTHEARPHONEVIEW = 0, // 扫描
BLUETOOTHEARLISTVIEW, // 扫描列表
BLUETOOTHDEVICELISTVIEW, // 已配对设备列表
BLUETOOTHEOPTIONSVIEW, // 选择界面
BLUETOOTHRECONNECTVIEW,
TIPSSUCCMESSAGEVIEW, // 连接成功
TIPSCONNFAILMESSAGEVIEW, // 连接失败
TIPSFAILMESSAGEVIEW,
BLUETOOTHEVIEW, // 设置界面
BLUETOOTHEJUMP_MAX,
};
JumpView();
~JumpView();
static JumpView *GetInstance();
void ChangeView(int16_t hideView, int16_t showView);
private:
bool ChangeTipsFailMessageView(int16_t hideView, int16_t thisView);
bool ChangeTipsConnFailMessageView(int16_t hideView, int16_t thisView);
bool ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothEarListView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView);
bool ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView);
bool CheckViewParam(int16_t hideView, int16_t showView);
void ResetEarListView(int16_t hideView);
UIViewGroup *container[BLUETOOTHEJUMP_MAX]{nullptr}; // CONTAINER_NUM 蓝牙耳机连接的9个界面容器
BluetoothEarPhoneView *bluetoothEarPhoneView{nullptr};
BluetoothEarListView *bluetoothEarListView{nullptr};
BluetoothView *bluetoothView{nullptr};
BluetoothOptionsView *bluetoothOptionsView{nullptr};
BluetoothDeviceListView *bluetoothDeviceListView{nullptr};
BluetoothReconnectView *bluetoothReconnectView{nullptr};
TipsSuccMessageView *tipsSuccMessageView{nullptr};
TipsConnFailMessageView *tipsConnFailMessageView{nullptr};
TipsFailMessageView *tipsFailMessageView{nullptr};
typedef bool (JumpView::*PreprosssChangeView)(int16_t hideView, int16_t thisView);
PreprosssChangeView preProcessView[BLUETOOTHEJUMP_MAX];
};
class PlayersPresenter : public UIView::OnClickListener {
public:
PlayersPresenter();
~PlayersPresenter();
static PlayersPresenter *GetInstance();
void OnClickRescanButton(void);
void OnClickNewEquipmentButton(void);
void OnClickCancelConnedRequestButton(void);
void OnClickButtonUnpair(void);
void OnClickButtonOptionOne(void);
void OnClickSetting(void);
void OnClickDelete(void);
void OnClickSuccBack(void);
void OnClickConnFailBack(void);
void OnClickFailBack(void);
void SetTitleSetText(const char *text);
void SetPlaybackProgress(int64_t value);
void SetPlayerState(bool value);
void PlayerbackReset(void);
void PlayerHeadsetReset(void);
void ShowPlayerListGroup(void);
private:
bool OnClick(UIView& view, const ClickEvent& event) override;
};
} // namespace OHOS
#endif