From: luozheng <1732036298@qq.com> Date: Sun, 3 Mar 2024 07:45:40 +0000 (+0800) Subject: 添加录音列表功能,能够查看录得音 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~35^2^2~3 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=eccb698287b789976b6f754b0e86a46f1a1fcc7f;p=mirrors%2FFD230.git 添加录音列表功能,能够查看录得音 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 6057fa583..e1502b3fb 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -310,10 +310,12 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordDeleteView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordGoingPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordGoingView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordListPresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingPlayerPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingPlayerView.cpp + + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingListAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingListitemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingModel.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 41701ddee..838d87268 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -58,7 +58,6 @@ typedef enum : uint16_t VIEW_FAST_TRAINING_ATTENTION, // 快速训练项目选择超出提示 /* ----------------------------------- 录音 ----------------------------------- */ VIEW_RECORD, - VIEW_RECORD_LIST, VIEW_RECORD_PLAY, VIEW_RECORD_DELETE, VIEW_RECORD_GOING, diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 538454cce..067ac99ff 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -32,7 +32,6 @@ namespace OHOS void InitUISampleSlice(void); /* ----------------------------------- 录音 ----------------------------------- */ void InitRecordingSlice(void); - void InitRecordingListSlice(void); void InitRecordingPlaySlice(void); void InitRecordingDeleteSlice(void); void InitRecordingGoingSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index d5cef167b..b33f26160 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -98,8 +98,6 @@ #include "record/include/RecordingPresenter.h" #include "record/include/RecordingView.h" -#include "record/include/RecordListPresenter.h" -#include "record/include/RecordListView.h" #include "record/include/RecordingPlayerPresenter.h" #include "record/include/RecordingPlayerView.h" #include "record/include/RecordDeletePresenter.h" @@ -168,7 +166,6 @@ namespace OHOS {VIEW_FAST_TRAINING_ATTENTION, &NativeLauncher::InitFastTrainingAttentionSlice}, {VIEW_RECORD, &NativeLauncher::InitRecordingSlice}, // 录音实例化地址 - {VIEW_RECORD_LIST, &NativeLauncher::InitRecordingListSlice}, {VIEW_RECORD_PLAY, &NativeLauncher::InitRecordingPlaySlice}, {VIEW_RECORD_DELETE, &NativeLauncher::InitRecordingDeleteSlice}, {VIEW_RECORD_DELETE, &NativeLauncher::InitRecordingDeleteSlice}, @@ -648,16 +645,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_RECORD, record); } - void NativeLauncher::InitRecordingListSlice(void) - { - SliceProxy *recordlist = new AbilitySliceProxy; - if (recordlist == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_RECORD_LIST, recordlist); - } - void NativeLauncher::InitRecordingPlaySlice(void) { SliceProxy *recordplay = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListPresenter.h deleted file mode 100644 index ca33ea864..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListPresenter.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef RECORD_LIST_PRESENTER_H -#define RECORD_LIST_PRESENTER_H - -#include "Presenter.h" - -#include "RecordListView.h" - -namespace OHOS -{ - class RecordListView; - - class RecordListPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener, - public UIView::OnLongPressListener - { - public: - RecordListPresenter(); - virtual ~RecordListPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static RecordListPresenter *GetInstance(); - - private: - //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - bool OnLongPress(UIView& view, const LongPressEvent& event) override; - }; -} //namespace OHOS - - - - - - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListView.h index 1869c7f78..610055b3b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordListView.h @@ -9,47 +9,46 @@ #include "components/ui_label.h" #include "components/ui_image_view.h" #include "components/ui_button.h" +#include "components/ui_list.h" +#include "record/include/RecordingListAdapter.h" namespace OHOS { - class RecordListPresenter; - class RecordListView : public View + + class RecordListView { public: + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + const char *text; // 文本 + uint8_t lineBreakMode; // 断行模式。 + }; RecordListView(); virtual ~RecordListView(); static RecordListView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; + UIScrollView *RecordListViewInit(void); + void ClearAll(void); + void IsVisibleLabel(bool value); private: - UIView::OnDragListener *draglistener{nullptr}; - - void InitView(void); - void DeInitView(void); - - UIViewGroup *container_ = nullptr; - UIScrollView *RecordListScrollView = nullptr; - UILabel *RecordListlabel1 = nullptr; - UIImageView *RecordImage = nullptr; - UIButton *RecordButton = nullptr; - - UIImageView *image6_ = nullptr; - UIButton *button3 = nullptr; - UIButton *button1 = nullptr; - UILabel *label3 = nullptr; - UILabel *label2 = nullptr; - UILabel *label1 = nullptr; - UIButton *button2 = nullptr; - UILabel *label9 = nullptr; - UILabel *label6 = nullptr; - UILabel *label8 = nullptr; - UILabel *label5 = nullptr; - UILabel *label7 = nullptr; - UILabel *label4 = nullptr; + bool SetUpScrollView(void); + UILabel *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + bool SetUpRecordListViewLabel(void); + bool SetUpRecordingList(void); + void AddRecordingToList(const RecordingListItem &item); + void InitRecordingInfo(void); + UIScrollView *RecordListScrollView{nullptr}; + UILabel *RecordListViewTitleLabel{nullptr}; // "录音列表" + UILabel *RecordListViewAttentionLabel{nullptr}; //"当前录音列表为空" + UIList *recordList{nullptr}; // 录音列表 + RecordingListAdapter *p_RecordingListAdapter{nullptr}; // 录音列表适配器 + bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListAdapter.h new file mode 100644 index 000000000..923e3c064 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListAdapter.h @@ -0,0 +1,58 @@ +#ifndef RECORDING_LIST_ADAPTER_H +#define RECORDING_LIST_ADAPTER_H + +#include "components/abstract_adapter.h" +#include "components/ui_list.h" +#include "list.h" +#include +namespace OHOS +{ + typedef struct + { + int index; + const char *recordId; // 录音编号 + const char *recordTotalTime; // 录音总时长 + const char *recordTime; // 录音时间 + } RecordingListItem; + + class RecordingListAdapter : public AbstractAdapter + { + public: + explicit RecordingListAdapter(); + virtual ~RecordingListAdapter(); + + /* * + * @brief Sets the UIView adapter data, which is a RecordingListItem linked list. + * + * @param data Indicates the RecordingListItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + virtual uint16_t GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16_t index) override; + + virtual void AddListItem(const RecordingListItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } + + private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; + }; + +} + +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListitemView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListitemView.h new file mode 100644 index 000000000..6cba24d2c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingListitemView.h @@ -0,0 +1,32 @@ +#ifndef RECORDING_LIST_ITEM_VIEW +#define RECORDING_LIST_ITEM_VIEW + +#include "components/ui_view_group.h" +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "record/include/RecordingListAdapter.h" + +namespace OHOS +{ + class RecordingListitemView : public UIViewGroup + { + public: + RecordingListitemView(); + virtual ~RecordingListitemView(); + virtual void SetItemInfo(const RecordingListItem itemInfo); + virtual void SetUpChild(); + int GetRecordingListIndex(); + + private: + RecordingListitemView(const RecordingListitemView &); + void SetLabelStyle(UILabel &label, int x, int y, int width, int height, OHOS::ColorType textColor, int fontSize); + UIButton m_button; + UILabel m_recordId; // 录音编号 + UILabel m_recordTotalTime; // 录音总时长 + UILabel m_recordTime; // 录音时间 + RecordingListItem m_ItemInfo{0, nullptr,nullptr,nullptr}; + }; + +} + +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingModel.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingModel.h index 0534663bb..8eda2b773 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingModel.h @@ -9,6 +9,13 @@ #include "audio_manager.h" #include "audio_base_type.h" #include "record/include/RecordingPresenter.h" +#include "record/include/RecordingListAdapter.h" + +#include +#include +#include +#include +#include namespace OHOS { using OHOS::Media::Player; @@ -18,34 +25,35 @@ namespace OHOS using Audio::AudioManager; // 播放器 -class RecordingPlayerInterruptListener : public InterruptListener { -public: - RecordingPlayerInterruptListener(){} - ~RecordingPlayerInterruptListener(){} + class RecordingPlayerInterruptListener : public InterruptListener + { + public: + RecordingPlayerInterruptListener() {} + ~RecordingPlayerInterruptListener() {} - void SetOwner(std::shared_ptr 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 GetPlayer(); + void SetOwner(std::shared_ptr 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 GetPlayer(); -private: - std::shared_ptr player_{nullptr}; - bool isPaused_{false}; - bool isDelayed_{false}; - bool isResumed_{false}; - bool isBeginStopped_{false}; - bool isEndStopped_{false}; -}; + private: + std::shared_ptr player_{nullptr}; + bool isPaused_{false}; + bool isDelayed_{false}; + bool isResumed_{false}; + bool isBeginStopped_{false}; + bool isEndStopped_{false}; + }; class RecordingModel { @@ -55,13 +63,17 @@ private: void SetRecordingPlayerUri(std::string src); void SetRecordingPlayButtonState(bool state); int RecordingPlayerStat(); - + /* -------------------------------------------------------------------------- */ + void InitRecordingListItem(); + const RecordingListItem *GetRecordinglistItems() const; + uint8_t GetRecordingListNum() const; + std::string GetCleanFileName(const std::string &filePath); + void SearchFiles(const std::string &directory, std::vector &fileNames, int &mp3FileCount); private: RecordingModel(); RecordingModel(const RecordingModel &) = delete; RecordingModel &operator=(const RecordingModel &) = delete; virtual ~RecordingModel(); - private: int64_t DurationTime{0}; // 播放时长,单位ms bool PlayButtonState{false}; // 播放按钮状态 @@ -74,6 +86,11 @@ private: std::string Uri; // 唯一标识一个资源的字符串。 std::map Header; std::shared_ptr Resource{nullptr}; + /* -------------------------------------------------------------------------- */ + std::vector fileNames; // 文件名 + int RecordingMp3FileCount = 0; // 录音MP3数量 + const std::string directory = "/user/res/record/recording/"; + RecordingListItem *Recordings = nullptr; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h index 59841a32e..e16a37d79 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h @@ -3,14 +3,20 @@ #include "Presenter.h" #include "RecordingView.h" - #include "KeyInputListener.h" #include "common/key_code.h" namespace OHOS { - class RecordingView; + typedef enum + { + RECORDINGVIEW = 0, // 录音视图(slice) + RECORDINGLISTVIEW, // 录音列表视图(subView) + MAX_RECORDINGVIEWID, + } RECORDINGVIEWID; + + class RecordingView; class RecordingPresenter : public Presenter, public UIView::OnClickListener, public RootView::OnKeyActListener, @@ -31,7 +37,8 @@ namespace OHOS // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; - bool OnKeyAct(UIView &view, const KeyEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h index 3ca9e4216..12d82208c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h @@ -11,6 +11,7 @@ #include "components/ui_button.h" #include "components/ui_image_animator.h" +#include "record/include/RecordListView.h" namespace OHOS { static const char *RECORD_BUTTON = "RecordButton"; //录音按钮 @@ -32,18 +33,28 @@ namespace OHOS virtual ~RecordingView(); static RecordingView *GetInstance(void); + bool ChangeRecordingView(int16_t thisView); // 切换到“录音”视图 + bool ChangeRecordListView(int16_t thisView);//切换到"录音列表"视图 + bool ClickFunc(int16_t interface); + void ChangeView(int16_t hideView, int16_t showView); + UIScrollView *GetRecordingViewScrollView(int i); + + public: void OnStart() override; void OnSetUpView() override; void OnTearDownView() override; void OnStop() override; + private: + RecordListView *p_RecordListView{nullptr}; + private: void RecordingViewInit(void); void ClearAll(void); bool SetUpScrollView(void); bool SetTheTitle(void); UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); - UIScrollView *RecordingViewScrollView{nullptr}; + UIScrollView *RecordingViewScrollView[2]{nullptr}; UILabel *RecordingViewTitleLabel{nullptr}; UIButton *RecordingViewButton{nullptr}; UILabel *AttentionLabel{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListPresenter.cpp deleted file mode 100644 index a009e80d0..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListPresenter.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "record/include/RecordListPresenter.h" - -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static RecordListPresenter *g_pRecordListPresenter = nullptr; - - RecordListPresenter::RecordListPresenter() - { - - g_pRecordListPresenter = this; - } - - RecordListPresenter::~RecordListPresenter() - { - - g_pRecordListPresenter = nullptr; - } - - RecordListPresenter *RecordListPresenter::GetInstance() - { - - return g_pRecordListPresenter; - } - - void RecordListPresenter::OnStart() - { - - Presenter::OnStart(); - } - - void RecordListPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void RecordListPresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void RecordListPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool RecordListPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM && - (event.GetDeltaY() > 30) && (event.GetDeltaY() > (2 * MATH_ABS(event.GetDeltaX())))) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD); - } - return true; - } - - bool RecordListPresenter::OnLongPress(UIView &view, const LongPressEvent &event) - { - - return false; - } - - bool RecordListPresenter::OnClick(UIView &view, const ClickEvent &event) - { - if (strcmp(view.GetViewId(), "button1") == 0) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_PLAY); - return true; - } - else if(strcmp(view.GetViewId(), "button2") == 0) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_PLAY); - return true; - } - else if(strcmp(view.GetViewId(), "button3") == 0) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_PLAY); - return true; - } - return true; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp index 1eb2c5cdd..39492d1a6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp @@ -1,8 +1,7 @@ #include "record/include/RecordListView.h" -#include "record/include/RecordListPresenter.h" - -#include "UiConfig.h" - +#include "record/include/RecordingPresenter.h" +#include "wearable_log.h" +#include "record/include/RecordingModel.h" namespace OHOS { @@ -10,12 +9,14 @@ namespace OHOS RecordListView::RecordListView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListView::RecordListView"); g_pRecordListView = this; } RecordListView::~RecordListView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListView::~RecordListView"); + ClearAll(); g_pRecordListView = nullptr; } @@ -25,502 +26,198 @@ namespace OHOS return g_pRecordListView; } - void RecordListView::InitView() + void RecordListView::ClearAll() { - if (container_ == nullptr) + if (initViewStatus == true) { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); - draglistener = static_cast(RecordListPresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); - } + RecordListScrollView->RemoveAll(); - // Add ScrollView to App - if (RecordListScrollView == nullptr) - { - RecordListScrollView = new UIScrollView(); - } - RecordListScrollView->SetPosition(0, 0); - RecordListScrollView->Resize(466, 466); - RecordListScrollView->SetViewId("RecordListScrollView"); - RecordListScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - // Add to rootView - container_->Add(RecordListScrollView); - RecordListScrollView->SetVisible(true); + delete RecordListViewAttentionLabel; + RecordListViewAttentionLabel = nullptr; - // Add Label to App - if (RecordListlabel1 == nullptr) - { - RecordListlabel1 = new UILabel(); - } - RecordListlabel1->SetPosition(188, 52); - RecordListlabel1->Resize(90, 35); - RecordListlabel1->SetViewId("RecordListlabel1"); - RecordListlabel1->SetStyle(STYLE_TEXT_FONT, 30); - RecordListlabel1->SetStyle(STYLE_LINE_HEIGHT, 35); + delete RecordListViewTitleLabel; + RecordListViewTitleLabel = nullptr; - // Set additional property - RecordListlabel1->SetText("录音机"); - RecordListlabel1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - RecordListlabel1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - RecordListlabel1->SetRollSpeed(0); - RecordListlabel1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + delete p_RecordingListAdapter; + p_RecordingListAdapter = nullptr; - // Add to scrollView1 - RecordListScrollView->Add(RecordListlabel1); - RecordListlabel1->SetVisible(true); - /********************************************************************************************************/ - // Add ImageView to App - if (RecordImage == nullptr) - { - RecordImage = new UIImageView(); - } - RecordImage->SetPosition(158, 129); - RecordImage->Resize(150, 150); - RecordImage->SetViewId("RecordImage"); - RecordImage->SetStyle(STYLE_BORDER_RADIUS, 10); - RecordImage->SetSrc(PNG_RECORD1_IMAGE); + delete recordList; + recordList = nullptr; - // Add to scrollView1 - RecordListScrollView->Add(RecordImage); - RecordImage->SetVisible(true); - /********************************************************************************************************/ - // Add Button to App - if (RecordButton == nullptr) - { - RecordButton = new UIButton(); - } - RecordButton->SetPosition(178, 150); - RecordButton->Resize(120, 120); - RecordButton->SetViewId("RecordButton"); - RecordButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36); - RecordButton->SetStyle(STYLE_BORDER_RADIUS, 100); - - // Set additional property - RecordButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff5a36, UIButton::PRESSED); - RecordButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - RecordButton->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); - - // Add the CallBack about events - UIView::OnClickListener *button4Click = static_cast(RecordListPresenter::GetInstance()); - RecordButton->SetOnClickListener(button4Click); - // Add to scrollView1 - RecordListScrollView->Add(RecordButton); - RecordButton->SetVisible(true); - /********************************************************************************************************/ - // Add Button to App - if (button1 == nullptr) - { - button1 = new UIButton(); - } - button1->SetPosition(43, 323); - button1->Resize(380, 100); - button1->SetViewId("button1"); - button1->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - button1->SetStyle(STYLE_BORDER_RADIUS, 50); - button1->SetImageSrc(PNG_SETTING_BACKGROUND_IMAGE, nullptr); - button1->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); - button1->SetStyleForState(STYLE_BACKGROUND_OPA, 0x82, UIButton::PRESSED); - button1->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - button1->SetStyleForState(STYLE_BORDER_RADIUS, 50, UIButton::PRESSED); - - // Add the CallBack about events - UIView::OnClickListener *button1Click = static_cast(RecordListPresenter::GetInstance()); - button1->SetOnClickListener(button1Click); - UIView::OnLongPressListener *button1LongPress = static_cast(RecordListPresenter::GetInstance()); - button1->SetOnLongPressListener(button1LongPress); - // Add to scrollView1 - RecordListScrollView->Add(button1); - button1->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label1 == nullptr) - { - label1 = new UILabel(); - } - label1->SetPosition(88, 356); - label1->Resize(200, 60); - label1->SetViewId("label1"); - label1->SetStyle(STYLE_TEXT_FONT, 30); - label1->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - label1->SetText("录音 3"); - label1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1->SetRollSpeed(0); - label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - RecordListScrollView->Add(label1); - label1->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label2 == nullptr) - { - label2 = new UILabel(); + delete RecordListScrollView; + RecordListScrollView = nullptr; } - label2->SetPosition(301, 342); // widget's left position and top position - label2->Resize(200, 60); // widget's width and height - label2->SetViewId("label2"); // Set style - label2->SetStyle(STYLE_TEXT_FONT, 30); - label2->SetStyle(STYLE_LINE_HEIGHT, 35); + } - // Set additional property - label2->SetText("20:57"); - label2->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label2->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label2->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - label2->SetRollSpeed(0); - label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - RecordListScrollView->Add(label2); - label2->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label3 == nullptr) + // 亮屏时长视图“scrollView”初始化 + bool RecordListView::SetUpScrollView(void) + { + RecordListScrollView = new UIScrollView(); + if (RecordListScrollView == nullptr) { - label3 = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::RecordListScrollView new fail!"); + return false; } - label3->SetPosition(280, 380); // widget's left position and top position - label3->Resize(200, 60); // widget's width and height - label3->SetViewId("label3"); // Set style - label3->SetStyle(STYLE_TEXT_FONT, 20); - label3->SetStyle(STYLE_LINE_HEIGHT, 23); - - // Set additional property - label3->SetText("2022.04.21"); - label3->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label3->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); - label3->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label3->SetRollSpeed(0); - label3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); - - // Add to scrollView1 - RecordListScrollView->Add(label3); - label3->SetVisible(true); - - /********************************************************************************************************/ - // Add Button to App - if (button2 == nullptr) + RecordListScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + RecordListScrollView->SetScrollBlankSize(35); + RecordListScrollView->SetReboundSize(50); + RecordListScrollView->SetDirection(1); + UIView::OnDragListener *draglistener = static_cast(RecordingPresenter::GetInstance()); + if (draglistener == nullptr) { - button2 = new UIButton(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::draglistener can not be nullptr!"); + return false; } - button2->SetPosition(43, 443); // widget's left position and top position - button2->Resize(380, 100); // widget's width and height - button2->SetViewId("button2"); // Set style - button2->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - button2->SetImageSrc(PNG_SETTING_BACKGROUND_IMAGE, nullptr); - button2->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); - button2->SetStyleForState(STYLE_BACKGROUND_OPA, 0x82, UIButton::PRESSED); - button2->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + RecordListScrollView->SetOnDragListener(draglistener); + RecordListScrollView->SetTouchable(true); + RecordListScrollView->SetDraggable(true); + return true; + } - // Add the CallBack about events - UIView::OnClickListener *button2Click = static_cast(RecordListPresenter::GetInstance()); - button2->SetOnClickListener(button2Click); - UIView::OnLongPressListener *button2LongPress = static_cast(RecordListPresenter::GetInstance()); - button2->SetOnLongPressListener(button2LongPress); - // Add to scrollView1 - RecordListScrollView->Add(button2); - button2->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label4 == nullptr) - { - label4 = new UILabel(); - } - label4->SetPosition(88, 480); - label4->Resize(200, 60); - label4->SetViewId("label4"); - label4->SetStyle(STYLE_TEXT_FONT, 30); - label4->SetStyle(STYLE_LINE_HEIGHT, 35); + // 设置标签 + UILabel *RecordListView::SetUpLabel(LabelConfig &labelconfig) + { + UILabel *label = new UILabel(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 + label->SetText(labelconfig.text); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } - // Set additional property - label4->SetText("录音 2"); - label4->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label4->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label4->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label4->SetRollSpeed(0); - label4->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - RecordListScrollView->Add(label4); - label4->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label5 == nullptr) - { - label5 = new UILabel(); - } - label5->SetPosition(301, 462); - label5->Resize(200, 60); - label5->SetViewId("label5"); - label5->SetStyle(STYLE_TEXT_FONT, 30); - label5->SetStyle(STYLE_LINE_HEIGHT, 35); + bool RecordListView::SetUpRecordListViewLabel(void) + { + // 创建ScreenDurationTitleLabel + LabelConfig labelconfig = { + .left = 173, + .top = 52, + .width = 120, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .text = "音乐列表", + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + + RecordListViewTitleLabel = SetUpLabel(labelconfig); + if (nullptr == RecordListViewTitleLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListView::RecordListViewTitleLabel is nullptr!"); + return false; + } + + labelconfig = { + .left = 33, + .top = 273, + .width = 400, + .height = 124, + .fontSize = 26, + .lineHeigh = 30, + .text = "当前音乐列表为空", + .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, + }; + RecordListViewAttentionLabel = SetUpLabel(labelconfig); + if (nullptr == RecordListViewAttentionLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListView::RecordListViewAttentionLabel is nullptr!"); + return false; + } + RecordListViewAttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + + RecordListScrollView->Add(RecordListViewTitleLabel); + RecordListScrollView->Add(RecordListViewAttentionLabel); + + return true; + } - // Set additional property - label5->SetText("09:51"); - label5->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label5->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label5->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label5->SetRollSpeed(0); - label5->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + bool RecordListView::SetUpRecordingList(void) + { + // UIList 的适配器 + p_RecordingListAdapter = new RecordingListAdapter(); + p_RecordingListAdapter->SetItemClickListener(RecordingPresenter::GetInstance()); + recordList = new UIList(); + if (recordList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListView::recordList is nullptr!"); + return false; + } + recordList->SetPosition(43, 120, 380, 120 + 120 * RecordingModel::GetInstance()->GetRecordingListNum()); + recordList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + recordList->SetAdapter(p_RecordingListAdapter); + InitRecordingInfo(); + recordList->RefreshList(); + RecordListScrollView->Add(recordList); + return true; + } - // Add to scrollView1 - RecordListScrollView->Add(label5); - label5->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label6 == nullptr) - { - label6 = new UILabel(); - } - label6->SetPosition(280, 500); - label6->Resize(200, 60); - label6->SetViewId("label6"); - label6->SetStyle(STYLE_TEXT_FONT, 20); - label6->SetStyle(STYLE_LINE_HEIGHT, 23); + /// @brief 添加录音到list + /// @param item + void RecordListView::AddRecordingToList(const RecordingListItem &item) + { + p_RecordingListAdapter->AddListItem(item); + } - // Set additional property - label6->SetText("2023.05.20"); - label6->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label6->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); - label6->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label6->SetRollSpeed(0); - label6->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); - // Add to scrollView1 - RecordListScrollView->Add(label6); - label6->SetVisible(true); - /********************************************************************************************************/ - // Add Button to App - if (button3 == nullptr) - { - button3 = new UIButton(); - } - button3->SetPosition(43, 563); // widget's left position and top position - button3->Resize(380, 100); // widget's width and height - button3->SetViewId("button3"); // Set style - button3->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - button3->SetImageSrc(PNG_SETTING_BACKGROUND_IMAGE, nullptr); - button3->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); - button3->SetStyleForState(STYLE_BACKGROUND_OPA, 0x82, UIButton::PRESSED); - button3->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events - UIView::OnClickListener *button3Click = static_cast(RecordListPresenter::GetInstance()); - button3->SetOnClickListener(button3Click); - UIView::OnLongPressListener *button3LongPress = static_cast(RecordListPresenter::GetInstance()); - button3->SetOnLongPressListener(button3LongPress); - // Add to scrollView1 - RecordListScrollView->Add(button3); - button3->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label7 == nullptr) - { - label7 = new UILabel(); - } - label7->SetPosition(88, 596); // widget's left position and top position - label7->Resize(200, 60); // widget's width and height - label7->SetViewId("label7"); // Set style - label7->SetStyle(STYLE_TEXT_FONT, 30); - label7->SetStyle(STYLE_LINE_HEIGHT, 35); - label7->SetText("录音 1"); - label7->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label7->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label7->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label7->SetRollSpeed(0); - label7->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - RecordListScrollView->Add(label7); - label7->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label8 == nullptr) + // 把录音信息数据拿到存储到list中 + void RecordListView::InitRecordingInfo(void) + { + const RecordingListItem *itemInfo = RecordingModel::GetInstance()->GetRecordinglistItems(); + for (int i = 0; i < RecordingModel::GetInstance()->GetRecordingListNum(); i++) { - label8 = new UILabel(); + AddRecordingToList(itemInfo[i]); } - label8->SetPosition(301, 582); // widget's left position and top position - label8->Resize(200, 60); // widget's width and height - label8->SetViewId("label8"); // Set style - label8->SetStyle(STYLE_TEXT_FONT, 30); - label8->SetStyle(STYLE_LINE_HEIGHT, 35); + } - // Set additional property - label8->SetText("12:33"); - label8->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label8->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); - label8->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label8->SetRollSpeed(0); - label8->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - RecordListScrollView->Add(label8); - label8->SetVisible(true); - /********************************************************************************************************/ - // Add Label to App - if (label9 == nullptr) + // 设置提醒标签是否可见 + void RecordListView::IsVisibleLabel(bool value) + { + if (value == true) { - label9 = new UILabel(); + RecordListViewAttentionLabel->SetVisible(true); + recordList->SetVisible(false); // 列表设置不可见 + RecordListScrollView->SetVerticalScrollState(false); } - label9->SetPosition(280, 620); // widget's left position and top position - label9->Resize(200, 60); // widget's width and height - label9->SetViewId("label9"); // Set style - label9->SetStyle(STYLE_TEXT_FONT, 20); - label9->SetStyle(STYLE_LINE_HEIGHT, 23); - // Set additional property - label9->SetText("2022.04.21"); - label9->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label9->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); - label9->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label9->SetRollSpeed(0); - label9->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); - // Add to scrollView1 - RecordListScrollView->Add(label9); - label9->SetVisible(true); - /********************************************************************************************************/ - // Add ImageView to App - if (image6_ == nullptr) + else { - image6_ = new UIImageView(); + RecordListViewAttentionLabel->SetVisible(false); + recordList->SetVisible(true); // 列表设置可见 + RecordListScrollView->SetVerticalScrollState(true); } - image6_->SetPosition(183, 632); // widget's left position and top position - image6_->Resize(100, 100); // widget's width and height - image6_->SetViewId("image6"); // Set style - - // Set additional property - - // Add to scrollView1 - RecordListScrollView->Add(image6_); - image6_->SetVisible(true); } - void RecordListView::DeInitView() + UIScrollView *RecordListView::RecordListViewInit() { - if (container_ != nullptr) + if (!SetUpScrollView()) { - container_->RemoveAll(); + return nullptr; } - if (RecordListScrollView != nullptr) - { - delete RecordListScrollView; - RecordListScrollView = nullptr; - } - if (RecordListlabel1 != nullptr) - { - delete RecordListlabel1; - RecordListlabel1 = nullptr; - } - if (RecordImage != nullptr) - { - delete RecordImage; - RecordImage = nullptr; - } - if (RecordButton != nullptr) - { - delete RecordButton; - RecordButton = nullptr; - } - if (image6_ != nullptr) - { - delete image6_; - image6_ = nullptr; - } - if (button3 != nullptr) - { - delete button3; - button3 = nullptr; - } - if (button1 != nullptr) - { - delete button1; - button1 = nullptr; - } - if (label3 != nullptr) - { - delete label3; - label3 = nullptr; - } - if (label2 != nullptr) - { - delete label2; - label2 = nullptr; - } - if (label1 != nullptr) - { - delete label1; - label1 = nullptr; - } - if (button2 != nullptr) - { - delete button2; - button2 = nullptr; - } - if (label9 != nullptr) - { - delete label9; - label9 = nullptr; - } - if (label6 != nullptr) - { - delete label6; - label6 = nullptr; - } - if (label8 != nullptr) + + if (!SetUpRecordingList()) { - delete label8; - label8 = nullptr; + return nullptr; } - if (label5 != nullptr) + + if (!SetUpRecordListViewLabel()) { - delete label5; - label5 = nullptr; + return nullptr; } - if (label7 != nullptr) + if (RecordingModel::GetInstance()->GetRecordingListNum() == 0) { - delete label7; - label7 = nullptr; + IsVisibleLabel(true); } - if (label4 != nullptr) + else { - delete label4; - label4 = nullptr; + IsVisibleLabel(false); } - delete container_; - container_ = nullptr; - } - void RecordListView::OnStart() - { - View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); - } - - void RecordListView::OnSetUpView() - { - - View::OnSetUpView(); - Draw(); - } - - void RecordListView::OnTearDownView() - { - - View::OnTearDownView(); - return; + initViewStatus = true; + return RecordListScrollView; } - void RecordListView::OnStop() - { - - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListAdapter.cpp new file mode 100644 index 000000000..05841ae8c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListAdapter.cpp @@ -0,0 +1,78 @@ +#include "record/include/RecordingListAdapter.h" +#include "record/include/RecordingListitemView.h" +namespace OHOS +{ + + RecordingListAdapter::RecordingListAdapter() + { + } + + RecordingListAdapter::~RecordingListAdapter() + { + listData.clear(); + } + + uint16_t RecordingListAdapter::GetCount(void) + { + return listData.size(); + } + + void RecordingListAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } + } + + UIView *RecordingListAdapter::GetView(UIView *inView, int16_t index) + { + // 1.先检查列表数据是否为空,若为空则返回空指针 + if (listData.empty()) + { + return nullptr; + } + // 2.接着检查索引是否小于0,若小于0则返回空指针 + if (index < 0) + { + return nullptr; + } + // 3.检查是否超出列表数据大小,若超出则返回空指针 + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + RecordingListItem itemData = *it; + RecordingListitemView *item = nullptr; + // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的RecordingListItemView对象,否则将inView转换成RecordingListItemView类型的指针 + if (inView == nullptr) + { + item = new RecordingListitemView(); + + } + else + { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; + } + + void RecordingListAdapter::AddListItem(const RecordingListItem &item) + { + listData.push_front(item); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp new file mode 100644 index 000000000..6486bed9d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp @@ -0,0 +1,69 @@ +#include "record/include/RecordingListitemView.h" +#include "wearable_log.h" + +namespace OHOS +{ + + RecordingListitemView::RecordingListitemView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingListitemView::RecordingListitemView"); + SetPosition(43, 100, 380, 120); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, 255); + SetTouchable(true); + SetUpChild(); + Add(&m_button); + Add(&m_recordId); + Add(&m_recordTotalTime); + Add(&m_recordTime); + } + + RecordingListitemView::~RecordingListitemView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingListitemView::~RecordingListitemView"); + Remove(&m_button); + Remove(&m_recordId); + Remove(&m_recordTotalTime); + Remove(&m_recordTime); + } + + void RecordingListitemView::SetItemInfo(const RecordingListItem itemInfo) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingListitemView::SetItemInfo"); + m_ItemInfo = itemInfo; + m_recordId.SetText(itemInfo.recordId); + m_recordTotalTime.SetText(itemInfo.recordTotalTime); + m_recordTime.SetText(itemInfo.recordTime); + } + + void RecordingListitemView::SetUpChild() + { + OHOS::ColorType textColor = Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xcc); + OHOS::ColorType subTextColor = Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff); + + m_button.SetPosition(0, 0, 380, 100); + m_button.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + m_button.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff4FC34C, UIButton::PRESSED); + + SetLabelStyle(m_recordId, 45, 33, 96, 35, textColor, 30); + SetLabelStyle(m_recordTotalTime, 258, 19, 73, 35, textColor, 30); + SetLabelStyle(m_recordTime, 237, 57, 94, 23, subTextColor, 20); + } + + void RecordingListitemView::SetLabelStyle(UILabel &label, int x, int y, int width, int height, OHOS::ColorType textColor, int fontSize) + { + label.SetPosition(x, y, width, height); + label.SetTextColor(textColor); + label.SetStyle(STYLE_TEXT_FONT, fontSize); + label.SetStyle(STYLE_LINE_HEIGHT, height); + label.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label.SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize); + } + + int RecordingListitemView::GetRecordingListIndex() + { + return m_ItemInfo.index; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp index df6da910f..956135360 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp @@ -46,8 +46,7 @@ namespace OHOS { PlayButtonState = state; } - - //播放器状态的控制 + // 播放器状态的控制 int RecordingModel::RecordingPlayerStat() { /* ------------------------------ 1.设置播放器的回调函数。 ----------------------------- */ @@ -132,4 +131,105 @@ namespace OHOS player_ = player; } + std::string RecordingModel::GetCleanFileName(const std::string &filePath) + { + size_t found = filePath.find_last_of("/\\"); + + std::string fileName = (found != std::string::npos) ? filePath.substr(found + 1) : filePath; + + if (fileName.size() >= 4 && fileName.substr(fileName.size() - 4) == ".mp3") + { + // 去除文件名的 .mp3 后缀 + return fileName.substr(0, fileName.size() - 4); + } + return ""; // 返回空字符串表示不是 .mp3 文件 + } + + void RecordingModel::SearchFiles(const std::string &directory, std::vector &fileNames, int &mp3FileCount) + { + DIR *dir; + struct dirent *ent; + if ((dir = opendir(directory.c_str())) != NULL) + { + while ((ent = readdir(dir)) != NULL) + { + std::string fileName = ent->d_name; + if (fileName != "." && fileName != "..") + { + std::string filePath = directory + fileName; + if (ent->d_type == DT_REG || ent->d_type == DT_UNKNOWN) // 普通文件 + { + std::string cleanFileName = GetCleanFileName(filePath); + if (!cleanFileName.empty()) + { + mp3FileCount++; + fileNames.push_back(cleanFileName); + } + } + else if (ent->d_type == DT_DIR) // 目录 + { + std::string subDirectory = directory + fileName + "/"; + SearchFiles(subDirectory, fileNames, mp3FileCount); // 递归搜索子目录 + } + } + } + closedir(dir); + } + } + + /// @brief 初始化录音列表数据 + void RecordingModel::InitRecordingListItem() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingModel::InitRecordingListItem"); + RecordingMp3FileCount = 0; + if (!fileNames.empty()) + { + fileNames.clear(); + } + SearchFiles(directory, fileNames, RecordingMp3FileCount); + if (RecordingMp3FileCount != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Total .mp3 Files Count:%d\n", RecordingMp3FileCount); + for (const auto &filename : fileNames) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File Name::%s\n", filename.c_str()); + } + Recordings = new RecordingListItem[RecordingMp3FileCount]; + if (Recordings == NULL) + { + // 内存分配失败处理 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Recordings new fail!\n"); + } + else + { + int cnt = 1; + // 对 Recordings 数组进行操作 + for (int i = 0; i < RecordingMp3FileCount; i++) + { + Recordings[i] = {i,fileNames[i].c_str(),"09:51", "2022.04.21"}; + //std::string Id = "recording" + std::to_string(cnt++); + //Recordings[i] = {i, Id.c_str(), "09:51", "2022.04.21"}; + } + // 记得在不需要使用 Recordings 后释放内存 + // free(Recordings); + } + } + } + + /// @brief 获取存放录音的基本信息数组 + /// @return + const RecordingListItem *RecordingModel::GetRecordinglistItems() const + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingModel::GetRecordinglistItems"); + return Recordings; + } + + /// @brief 获取录音数量 + /// @return + uint8_t RecordingModel::GetRecordingListNum() const + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingModel::GetRecordingListNum"); + return RecordingMp3FileCount; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPlayerPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPlayerPresenter.cpp index f0cc86036..3a5f7a7f1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPlayerPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPlayerPresenter.cpp @@ -58,7 +58,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && (event.GetDeltaX() > 30) && (event.GetDeltaX() > (3 * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_LIST); + return true; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp index 0b4d3fbb8..ff460be22 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp @@ -3,6 +3,8 @@ #include "graphic_math.h" #include "string.h" #include "record/include/RecordingPresenter.h" +#include "record/include/RecordingModel.h" +#include namespace OHOS { @@ -11,7 +13,6 @@ namespace OHOS RecordingPresenter::RecordingPresenter() { - g_pRecordPresenter = this; } @@ -29,13 +30,13 @@ namespace OHOS void RecordingPresenter::OnStart() { - + // 初始化录音信息 + RecordingModel::GetInstance()->InitRecordingListItem(); Presenter::OnStart(); } void RecordingPresenter::OnPause(void) { - Presenter::OnPause(); } @@ -53,16 +54,40 @@ namespace OHOS bool RecordingPresenter::OnDrag(UIView &view, const DragEvent &event) { + return true; + } - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + bool RecordingPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + for (int i = 0; i < MAX_RECORDINGVIEWID; i++) + { + if (p_RecordingView->GetRecordingViewScrollView(i) != nullptr && + p_RecordingView->GetRecordingViewScrollView(i)->IsVisible() == true) + { + if (i == RECORDINGVIEW) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + else + { + p_RecordingView->ChangeView(i, RECORDINGVIEW); + } + break; + } + } return true; } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_LIST); + p_RecordingView->ChangeView(RECORDINGVIEW, RECORDINGLISTVIEW); return true; } return false; @@ -82,7 +107,7 @@ namespace OHOS { // 将参数保存到数组中 - const char *args[] = {"01", "mp3", "16000", "1", "16", "/user/res/record/recording/record_test.mp3"}; + const char *args[] = {"01", "mp3", "16000", "1", "16", "/user/res/record/recording/record.mp3"}; int argc = sizeof(args) / sizeof(args[0]); // 根据控件id查找是哪个控件触发了点击回调 diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp index 3782b6555..c819088df 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp @@ -33,51 +33,54 @@ namespace OHOS { if (initViewStatus == true) { - RecordingViewScrollView->RemoveAll(); + RecordingViewScrollView[RECORDINGVIEW]->RemoveAll(); RecordingViewImageAnimator->Stop(); delete RecordingViewImageAnimator; - RecordingViewImageAnimator =nullptr; + RecordingViewImageAnimator = nullptr; delete RecordingViewTitleLabel; - RecordingViewTitleLabel =nullptr; + RecordingViewTitleLabel = nullptr; delete RecordingViewButton; - RecordingViewButton =nullptr; + RecordingViewButton = nullptr; delete AttentionLabel; - AttentionLabel =nullptr; + AttentionLabel = nullptr; delete RECORD1_Image; - RECORD1_Image =nullptr; + RECORD1_Image = nullptr; - delete RecordingViewScrollView; - RecordingViewScrollView =nullptr; + delete p_RecordListView; + p_RecordListView = nullptr; + + delete RecordingViewScrollView[RECORDINGVIEW]; + RecordingViewScrollView[RECORDINGVIEW] = nullptr; } } // 录音视图scrollView初始化 bool RecordingView::SetUpScrollView(void) { - RecordingViewScrollView = new UIScrollView(); - if (RecordingViewScrollView == nullptr) + RecordingViewScrollView[RECORDINGVIEW] = new UIScrollView(); + if (RecordingViewScrollView[RECORDINGVIEW] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingViewScrollView new fail!"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingViewScrollView[RECORDINGVIEW] new fail!"); return false; } - RecordingViewScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - RecordingViewScrollView->SetScrollBlankSize(35); - RecordingViewScrollView->SetReboundSize(50); - RecordingViewScrollView->SetDirection(1); + RecordingViewScrollView[RECORDINGVIEW]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + RecordingViewScrollView[RECORDINGVIEW]->SetScrollBlankSize(35); + RecordingViewScrollView[RECORDINGVIEW]->SetReboundSize(50); + RecordingViewScrollView[RECORDINGVIEW]->SetDirection(1); UIView::OnDragListener *draglistener = static_cast(RecordingPresenter::GetInstance()); if (draglistener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::draglistener can not be nullptr!"); return false; } - RecordingViewScrollView->SetOnDragListener(draglistener); - RecordingViewScrollView->SetTouchable(true); - RecordingViewScrollView->SetDraggable(true); + RecordingViewScrollView[RECORDINGVIEW]->SetOnDragListener(draglistener); + RecordingViewScrollView[RECORDINGVIEW]->SetTouchable(true); + RecordingViewScrollView[RECORDINGVIEW]->SetDraggable(true); return true; } @@ -105,7 +108,7 @@ namespace OHOS UIButton *button = new UIButton(); if (button == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " DisplayBrightnessView::SetTheButton: button new fail!"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " RecordingView::SetTheButton: button new fail!"); return nullptr; } button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); @@ -183,6 +186,88 @@ namespace OHOS initViewStatus = true; } + UIScrollView *RecordingView::GetRecordingViewScrollView(int i) + { + return RecordingViewScrollView[i]; + } + + // 切换到“录音”视图 + bool RecordingView::ChangeRecordingView(int16_t thisView) + { + if (RecordingViewScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::ChangeRecordingView"); + RootView::GetInstance()->Add(RecordingViewScrollView[thisView]); + } + return true; + } + + // 切换到录音列表视图 + bool RecordingView::ChangeRecordListView(int16_t thisView) + { + if (RecordingViewScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::ChangeRecordListView"); + p_RecordListView = new RecordListView(); + if (p_RecordListView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView:: new scrollView[%d] fail", thisView); + return false; + } + RecordingViewScrollView[thisView] = p_RecordListView->RecordListViewInit(); + RootView::GetInstance()->Add(RecordingViewScrollView[thisView]); + } + return true; + } + + /* -------------------------------------------------------------------------- */ + // 1.RecordingViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 + struct RecordingViewMapper + { + const int16_t viewId; + bool (RecordingView::*func)(int16_t thisView); + }; + + // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与RecordingViewMapper类中的特定成员函数指针进行了绑定。 + static const RecordingViewMapper ViewMapper[] = { + {RECORDINGVIEW, &RecordingView::ChangeRecordingView}, + {RECORDINGLISTVIEW, &RecordingView::ChangeRecordListView}, + }; + + // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 + bool RecordingView::ClickFunc(int16_t interface) + { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) + { + if (interface == ViewMapper[i].viewId) + { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (jug == false) + { + return false; + } + return true; + } + } + return false; + } + + // 4.切换视图 + void RecordingView::ChangeView(int16_t hideView, int16_t showView) + { + if (hideView > MAX_RECORDINGVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView:: RecordingViewID Overstep ones bounds"); + return; + } + RecordingViewScrollView[hideView]->SetVisible(false); + ClickFunc(showView); + RecordingViewScrollView[showView]->SetVisible(true); + Draw(); + } + /* -------------------------------------------------------------------------- */ + void RecordingView::OnStart() { View::OnStart(); @@ -192,12 +277,12 @@ namespace OHOS void RecordingView::OnSetUpView() { View::OnSetUpView(); - RecordingViewScrollView->Add(RecordingViewTitleLabel); - RecordingViewScrollView->Add(RECORD1_Image); - RecordingViewScrollView->Add(RecordingViewButton); - RecordingViewScrollView->Add(AttentionLabel); - RecordingViewScrollView->Add(RecordingViewImageAnimator); - RootView::GetInstance()->Add(RecordingViewScrollView); + RecordingViewScrollView[RECORDINGVIEW]->Add(RecordingViewTitleLabel); + RecordingViewScrollView[RECORDINGVIEW]->Add(RECORD1_Image); + RecordingViewScrollView[RECORDINGVIEW]->Add(RecordingViewButton); + RecordingViewScrollView[RECORDINGVIEW]->Add(AttentionLabel); + RecordingViewScrollView[RECORDINGVIEW]->Add(RecordingViewImageAnimator); + RootView::GetInstance()->Add(RecordingViewScrollView[RECORDINGVIEW]); Draw(); } diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/record/recording/animator1.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/record/recording/animator1.bin deleted file mode 100644 index 96f896968..000000000 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/record/recording/animator1.bin and /dev/null differ