From: luozheng <1732036298@qq.com> Date: Tue, 5 Mar 2024 01:40:28 +0000 (+0800) Subject: 将正在录音(slice)修改为录音视图的subview X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~32 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=903adbb978c754a0525cb2833e47806b563c94a7;p=mirrors%2FFD230.git 将正在录音(slice)修改为录音视图的subview --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 7c64f8ac1..97dc252ae 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -310,7 +310,6 @@ set(SOURCES #录音 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordDeletePresenter.cpp ${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/RecordingPlayerPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingPlayerView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 96f08e4cd..1ae060174 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -59,7 +59,6 @@ typedef enum : uint16_t VIEW_RECORD, VIEW_RECORD_PLAY, VIEW_RECORD_DELETE, - VIEW_RECORD_GOING, /* ---------------------------------- 界面 ---------------------------------- */ VIEW_DIAL, // 切换表盘 VIEW_MESSAGE, // 信息通知 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 067ac99ff..a19f849b2 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -34,7 +34,6 @@ namespace OHOS void InitRecordingSlice(void); void InitRecordingPlaySlice(void); void InitRecordingDeleteSlice(void); - void InitRecordingGoingSlice(void); /* ----------------------------------- 天气 ----------------------------------- */ void InitWeatherSlice(void); void InitWeatherReportSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 7fdca6729..f02c367f8 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -102,8 +102,6 @@ #include "record/include/RecordingPlayerView.h" #include "record/include/RecordDeletePresenter.h" #include "record/include/RecordDeleteView.h" -#include "record/include/RecordGoingPresenter.h" -#include "record/include/RecordGoingView.h" #include "BluetoothHeadsetEvent.h" #include "graphic_hardware_config.h" @@ -168,8 +166,6 @@ namespace OHOS {VIEW_RECORD, &NativeLauncher::InitRecordingSlice}, // 录音实例化地址 {VIEW_RECORD_PLAY, &NativeLauncher::InitRecordingPlaySlice}, {VIEW_RECORD_DELETE, &NativeLauncher::InitRecordingDeleteSlice}, - {VIEW_RECORD_DELETE, &NativeLauncher::InitRecordingDeleteSlice}, - {VIEW_RECORD_GOING, &NativeLauncher::InitRecordingGoingSlice}, {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice}, {VIEW_ROTATE, &NativeLauncher::InitRotateSlice}, @@ -664,13 +660,5 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_RECORD_DELETE, recorddelete); } - void NativeLauncher::InitRecordingGoingSlice(void) // 正在录音 - { - SliceProxy *recordgoing = new AbilitySliceProxy; - if (recordgoing == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_RECORD_GOING, recordgoing); - } + } diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingPresenter.h deleted file mode 100644 index dd4f941f5..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingPresenter.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RECORD_GOING_PRESENTER_H -#define RECORD_GOING_PRESENTER_H - -#include "Presenter.h" - -#include "RecordGoingView.h" -#include "animator/animator.h" -namespace OHOS -{ - class RecordGoingView; - - class RecordGoingPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - RecordGoingPresenter(); - virtual ~RecordGoingPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static RecordGoingPresenter *GetInstance(); - private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} // namespace OHOS - -#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingView.h index c88a19015..abfc4a7fd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordGoingView.h @@ -4,60 +4,49 @@ #include "BaseView.h" #include "View.h" -#include "components/ui_view_group.h" #include "components/ui_label.h" #include "components/ui_image_view.h" #include "components/ui_button.h" #include "components/ui_scroll_view.h" -#include "animator/animator.h" -#include "sys/time.h" namespace OHOS { - static constexpr int16_t TIME_CONVERT = 60; // sec to min, and min to hor - static constexpr int16_t TEXT_BUFFER_SIEZ = 20; - class TimerAnimatorCallback : public AnimatorCallback - { - public: - explicit TimerAnimatorCallback(UILabel *label) : label_(label) {} - ~TimerAnimatorCallback() override {} - void Callback(UIView *view) override; - - private: - UILabel *label_ = nullptr; - }; - static const char *RECORD_GOING_BUTTON_VIEWID = "RECORD_GOING_BUTTON"; // 点击按钮后停止录音 - class RecordGoingPresenter; - class RecordGoingView : public View + + class RecordGoingView { - 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; // 断行模式。 + }; RecordGoingView(); virtual ~RecordGoingView(); static RecordGoingView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; + UIScrollView *RecordGoingViewInit(void); + void ClearAll(void); private: - UIView::OnClickListener *RECORD_GOING_BUTTON_CLICK{nullptr}; - - void InitView(void); - void DeInitView(void); - - //有bug - TimerAnimatorCallback *callBack_ = nullptr; - Animator *animator_ = nullptr; - - UIViewGroup *container_ = nullptr; - UIScrollView *scrollView = nullptr; - UILabel *RECORD_GOING_LABEL1 = nullptr; - UIImageView *RECORD_GOING_IMAGE = nullptr; - UIButton *RECORD_GOING_BUTTON = nullptr; - UILabel *RECORD_GOING_LABEL2 = nullptr; - UILabel *RECORD_GOING_LABEL3 = nullptr; + bool SetUpScrollView(void); + UILabel *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + bool SetRecordGoingViewLabel(void); + bool SetUpImageView(void); + bool SetUpButton(void); + UIScrollView *RecordGoingViewScrollView{nullptr}; + UILabel *TitleLabel{nullptr}; // 标题 + UILabel *RecordGoingLabel{nullptr}; // “录音中” + UILabel *Timer{nullptr}; // 显示录音时长 + UIImageView *RECORD_GOING_IMAGE{nullptr}; + UIButton *RECORD_GOING_BUTTON{nullptr}; + + + bool initViewStatus{false}; }; } // namespace OHOS #endif \ No newline at end of file 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 15d07eba5..05a615496 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h @@ -12,10 +12,10 @@ namespace OHOS { RECORDINGVIEW = 0, // 录音视图(slice) RECORDINGLISTVIEW, // 录音列表视图(subView) - + RECORDGOINGVIEW, // 正在录音视图 MAX_RECORDINGVIEWID, } RECORDINGVIEWID; - + static const char *RECORD_GOING_BUTTON_VIEWID = "RECORD_GOING_BUTTON"; // 点击按钮后停止录音 class RecordListViewOnClickListener : public UIView::OnClickListener { public: @@ -43,6 +43,7 @@ namespace OHOS static RecordingPresenter *GetInstance(); int convertNumericDateTime(const char *numericDateTime, char *formattedDateTime); + private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &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 025a2e0d8..eb7fb84ee 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h @@ -36,6 +36,7 @@ namespace OHOS bool ChangeRecordingView(int16_t thisView); // 切换到“录音”视图 bool ChangeRecordListView(int16_t thisView);//切换到"录音列表"视图 + bool ChangeRecordGoingView(int16_t thisView);//切换到“正在录音”视图 bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); UIScrollView *GetRecordingViewScrollView(int i); @@ -55,7 +56,7 @@ namespace OHOS bool SetUpScrollView(void); bool SetTheTitle(void); UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); - UIScrollView *RecordingViewScrollView[2]{nullptr}; + UIScrollView *RecordingViewScrollView[3]{nullptr}; UILabel *RecordingViewTitleLabel{nullptr}; UIButton *RecordingViewButton{nullptr}; UILabel *AttentionLabel{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingPresenter.cpp deleted file mode 100644 index 3c198c33e..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingPresenter.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "string.h" -#include "record/include/RecordGoingPresenter.h" -#include "custom_utils.h" -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static RecordGoingPresenter *g_pRecordGoingPresenter = nullptr; - - RecordGoingPresenter::RecordGoingPresenter() - { - - g_pRecordGoingPresenter = this; - } - - RecordGoingPresenter::~RecordGoingPresenter() - { - - g_pRecordGoingPresenter = nullptr; - } - - RecordGoingPresenter *RecordGoingPresenter::GetInstance() - { - - return g_pRecordGoingPresenter; - } - - void RecordGoingPresenter::OnStart() - { - Presenter::OnStart(); - } - - void RecordGoingPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void RecordGoingPresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void RecordGoingPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool RecordGoingPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - UNUSED(event); - } - -#ifdef __cplusplus - extern "C" - { -#endif - int32_t AudioCaptureSample(int32_t argc, const char *argv[]); - -#ifdef __cplusplus - }; -#endif - - bool RecordGoingPresenter::OnClick(UIView &view, const ClickEvent &event) - { - - // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), RECORD_GOING_BUTTON_VIEWID) == 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "End of recording...."); - int32_t argc = 1; - uint8_t *argv = (uint8_t *)"stop"; - AudioCaptureSample(argc, (const char **)&argv); - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD); - return true; - } - return false; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingView.cpp index f5c437577..33b40d8bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordGoingView.cpp @@ -1,7 +1,7 @@ #include "record/include/RecordGoingView.h" -#include "record/include/RecordGoingPresenter.h" +#include "record/include/RecordingPresenter.h" #include "UiConfig.h" - +#include "wearable_log.h" namespace OHOS { @@ -9,238 +9,197 @@ namespace OHOS RecordGoingView::RecordGoingView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::RecordGoingView"); g_pRecordGoingView = this; } RecordGoingView::~RecordGoingView() { - DeInitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::~RecordGoingView"); + ClearAll(); g_pRecordGoingView = nullptr; } RecordGoingView *RecordGoingView::GetInstance() { - return g_pRecordGoingView; } - static void GetTime(char *buf, int len) + + void RecordGoingView::ClearAll() { - struct timeval tv; - gettimeofday(&tv, NULL); - uint32_t second = tv.tv_sec % TIME_CONVERT; - uint32_t minute = tv.tv_sec / TIME_CONVERT; - uint32_t hour = (minute / TIME_CONVERT) % 24; // 24: 24 hours per day - // uint32_t realMilliSecond = tv.tv_usec / USEC_TO_MILLI; - minute = minute % TIME_CONVERT; - snprintf(buf, len, "%02d : %02d : %02d", hour, minute, second); - // sprintf_s(buf, len, "%02d : %02d : %02d", hour, minute, second); + if (initViewStatus == true) + { + RecordGoingViewScrollView->RemoveAll(); + + delete TitleLabel; + TitleLabel = nullptr; + + delete RECORD_GOING_IMAGE; + RECORD_GOING_IMAGE = nullptr; + + delete RECORD_GOING_BUTTON; + RECORD_GOING_BUTTON = nullptr; + + delete Timer; + Timer = nullptr; + + delete RecordGoingLabel; + RecordGoingLabel = nullptr; + + delete RecordGoingViewScrollView; + RecordGoingViewScrollView = nullptr; + } } - void TimerAnimatorCallback::Callback(UIView *view) + bool RecordGoingView::SetUpScrollView(void) { - (void)view; - char buf[TEXT_BUFFER_SIEZ] = {0}; - GetTime(buf, TEXT_BUFFER_SIEZ); - label_->SetText(buf); - RootView::GetInstance()->Invalidate(); + RecordGoingViewScrollView = new UIScrollView(); + if (RecordGoingViewScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::RecordGoingViewScrollView new fail!"); + return false; + } + UIView::OnDragListener *draglistener = static_cast(RecordingPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::draglistener can not be nullptr!"); + return false; + } + RecordGoingViewScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + RecordGoingViewScrollView->SetTouchable(true); + RecordGoingViewScrollView->SetDraggable(true); + return true; } - void RecordGoingView::InitView() + UILabel *RecordGoingView::SetUpLabel(LabelConfig &labelconfig) // 设置标签 { - if (container_ == nullptr) + UILabel *label = new UILabel(); + if (label == nullptr) { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); - container_->SetTouchable(true); + return nullptr; } - if (scrollView == 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; + } + + bool RecordGoingView::SetRecordGoingViewLabel(void) + { + LabelConfig labelconfig = { + .left = 188, + .top = 52, + .width = 90, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .text = "录音机", + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + + TitleLabel = SetUpLabel(labelconfig); + if (nullptr == TitleLabel) { - scrollView = new UIScrollView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::SetRecordGoingViewLabel is nullptr!"); + return false; + } + labelconfig.top = 370; + labelconfig.text = "录音中"; + RecordGoingLabel = SetUpLabel(labelconfig); + if (nullptr == RecordGoingLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::RecordGoingLabel is nullptr!"); + return false; } - scrollView->SetPosition(0, 0); - scrollView->Resize(466, 466); - scrollView->SetViewId("scrollView"); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - - // Add to rootView - container_->Add(scrollView); - scrollView->SetVisible(true); - // Add Label to App - if (RECORD_GOING_LABEL1 == nullptr) + labelconfig = { + .left = 83, + .top = 290, + .width = 300, + .height = 77, + .fontSize = 65, + .lineHeigh = 76, + .text = "00:00:12", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + Timer = SetUpLabel(labelconfig); + if (nullptr == Timer) { - RECORD_GOING_LABEL1 = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::Timer is nullptr!"); + return false; } - RECORD_GOING_LABEL1->SetPosition(188, 52); - RECORD_GOING_LABEL1->Resize(90, 35); - RECORD_GOING_LABEL1->SetViewId("RECORD_GOING_LABEL1"); - RECORD_GOING_LABEL1->SetStyle(STYLE_TEXT_FONT, 30); - RECORD_GOING_LABEL1->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - RECORD_GOING_LABEL1->SetText("录音机"); - RECORD_GOING_LABEL1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - RECORD_GOING_LABEL1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - RECORD_GOING_LABEL1->SetRollSpeed(0); - RECORD_GOING_LABEL1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to rootView - scrollView->Add(RECORD_GOING_LABEL1); - RECORD_GOING_LABEL1->SetVisible(true); - - // Add ImageView to App + + return true; + } + + bool RecordGoingView::SetUpImageView(void) + { + RECORD_GOING_IMAGE = new UIImageView(); if (RECORD_GOING_IMAGE == nullptr) { - RECORD_GOING_IMAGE = new UIImageView(); } - RECORD_GOING_IMAGE->SetPosition(158, 129); - RECORD_GOING_IMAGE->Resize(150, 150); - RECORD_GOING_IMAGE->SetViewId("RECORD_GOING_IMAGE"); + RECORD_GOING_IMAGE->SetPosition(158, 129, 150, 150); RECORD_GOING_IMAGE->SetStyle(STYLE_BACKGROUND_OPA, 0xff); RECORD_GOING_IMAGE->SetStyle(STYLE_BORDER_RADIUS, 15); RECORD_GOING_IMAGE->SetSrc(PNG_RECORD3_IMAGE); - // Add to rootView - scrollView->Add(RECORD_GOING_IMAGE); - RECORD_GOING_IMAGE->SetVisible(true); + return true; + } - // Add Button to App + bool RecordGoingView::SetUpButton(void) + { + RECORD_GOING_BUTTON = new UIButton(); if (RECORD_GOING_BUTTON == nullptr) { - RECORD_GOING_BUTTON = new UIButton(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordGoingView::RECORD_GOING_BUTTON new fail!"); } - RECORD_GOING_BUTTON->SetPosition(210, 180); - RECORD_GOING_BUTTON->Resize(60, 60); + RECORD_GOING_BUTTON->SetPosition(210, 180, 60, 60); RECORD_GOING_BUTTON->SetViewId(RECORD_GOING_BUTTON_VIEWID); RECORD_GOING_BUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36); RECORD_GOING_BUTTON->SetStyle(STYLE_BORDER_RADIUS, 20); - // Set additional property RECORD_GOING_BUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); RECORD_GOING_BUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 20, UIButton::PRESSED); - // Add the CallBack about events - RECORD_GOING_BUTTON_CLICK = static_cast(RecordGoingPresenter::GetInstance()); - RECORD_GOING_BUTTON->SetOnClickListener(RECORD_GOING_BUTTON_CLICK); - // Add to rootView - scrollView->Add(RECORD_GOING_BUTTON); - RECORD_GOING_BUTTON->SetVisible(true); - - // Add Label to App - if (RECORD_GOING_LABEL2 == nullptr) - { - RECORD_GOING_LABEL2 = new UILabel(); - } - RECORD_GOING_LABEL2->SetPosition(107, 290); - RECORD_GOING_LABEL2->Resize(253, 77); - RECORD_GOING_LABEL2->SetViewId("RECORD_GOING_LABEL2"); - RECORD_GOING_LABEL2->SetStyle(STYLE_TEXT_FONT, 65); - RECORD_GOING_LABEL2->SetStyle(STYLE_LINE_HEIGHT, 77); - - // Set additional property - RECORD_GOING_LABEL2->SetText("00:00:00"); - RECORD_GOING_LABEL2->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - RECORD_GOING_LABEL2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - RECORD_GOING_LABEL2->SetRollSpeed(0); - RECORD_GOING_LABEL2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 65); - - callBack_ = new TimerAnimatorCallback(RECORD_GOING_LABEL2); - animator_ = new Animator(callBack_, RECORD_GOING_LABEL2, 0, true); - animator_->Start(); - // Add to rootView - container_->Add(RECORD_GOING_LABEL2); - RECORD_GOING_LABEL2->SetVisible(true); - - // Add Label to App - if (RECORD_GOING_LABEL3 == nullptr) - { - RECORD_GOING_LABEL3 = new UILabel(); - } - RECORD_GOING_LABEL3->SetPosition(188, 370); - RECORD_GOING_LABEL3->Resize(90, 95); - RECORD_GOING_LABEL3->SetViewId("RECORD_GOING_LABEL3"); - RECORD_GOING_LABEL3->SetStyle(STYLE_TEXT_FONT, 30); - RECORD_GOING_LABEL3->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - RECORD_GOING_LABEL3->SetText("录音中"); - RECORD_GOING_LABEL3->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - RECORD_GOING_LABEL3->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - RECORD_GOING_LABEL3->SetRollSpeed(0); - RECORD_GOING_LABEL3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to rootView - scrollView->Add(RECORD_GOING_LABEL3); - RECORD_GOING_LABEL3->SetVisible(true); + + UIView::OnClickListener *clickListener = static_cast(RecordingPresenter::GetInstance()); + RECORD_GOING_BUTTON->SetOnClickListener(clickListener); + return true; } - void RecordGoingView::DeInitView() + UIScrollView *RecordGoingView::RecordGoingViewInit() { - if (container_ != nullptr) - { - container_->RemoveAll(); - } - if (scrollView != nullptr) + if (!SetUpScrollView()) { - scrollView->RemoveAll(); - delete scrollView; - scrollView = nullptr; + return nullptr; } - if (RECORD_GOING_LABEL1 != nullptr) - { - delete RECORD_GOING_LABEL1; - RECORD_GOING_LABEL1 = nullptr; - } - if (RECORD_GOING_IMAGE != nullptr) - { - delete RECORD_GOING_IMAGE; - RECORD_GOING_IMAGE = nullptr; - } - if (RECORD_GOING_BUTTON != nullptr) + + if (!SetRecordGoingViewLabel()) { - delete RECORD_GOING_BUTTON; - RECORD_GOING_BUTTON = nullptr; + return nullptr; } - if (RECORD_GOING_LABEL2 != nullptr) + + if (!SetUpImageView()) { - delete RECORD_GOING_LABEL2; - RECORD_GOING_LABEL2 = nullptr; + return nullptr; } - if (RECORD_GOING_LABEL3 != nullptr) + + if (!SetUpButton()) { - delete RECORD_GOING_LABEL3; - RECORD_GOING_LABEL3 = nullptr; + return nullptr; } - delete container_; - container_ = nullptr; - } - void RecordGoingView::OnStart() - { - View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); + /* ----------------------------------- Add ---------------------------------- */ + RecordGoingViewScrollView->Add(TitleLabel); + RecordGoingViewScrollView->Add(RECORD_GOING_IMAGE); + RecordGoingViewScrollView->Add(RECORD_GOING_BUTTON); + RecordGoingViewScrollView->Add(Timer); + RecordGoingViewScrollView->Add(RecordGoingLabel); + initViewStatus = true; + return RecordGoingViewScrollView; } - void RecordGoingView::OnSetUpView() - { - View::OnSetUpView(); - Draw(); - } - - void RecordGoingView::OnTearDownView() - { - - View::OnTearDownView(); - return; - } - - void RecordGoingView::OnStop() - { - animator_->Stop(); - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } } \ No newline at end of file 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 98a08822c..8b86d99aa 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp @@ -116,7 +116,7 @@ namespace OHOS // 格式化输出为上午/下午几点几分几秒 strftime(formattedDateTime, 80, "%p %I点%M分%S秒", &timeinfo); - + //strftime(formattedDateTime, 80, "%p %H %M %S", &timeinfo); return 1; // 转换成功 } @@ -132,6 +132,13 @@ namespace OHOS bool RecordingPresenter::OnClick(UIView &view, const ClickEvent &event) { + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + if (strcmp(view.GetViewId(), RECORD_BUTTON) == 0) { char *args[6] = {0}; @@ -159,7 +166,7 @@ namespace OHOS /* ---------------------------------- 开始录音 ---------------------------------- */ AudioCaptureSample(6, (const char **)args); /* --------------------------------- 跳转到录音界面 -------------------------------- */ - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_GOING); + p_RecordingView->ChangeView(RECORDINGVIEW, RECORDGOINGVIEW); /* ---------------------------------- 释放内存 ---------------------------------- */ for (int i = 0; i < 6; ++i) { @@ -169,6 +176,14 @@ namespace OHOS /* -------------------------------------------------------------------------- */ return true; } + else if (strcmp(view.GetViewId(), RECORD_GOING_BUTTON_VIEWID) == 0) + { + int32_t argc = 1; + uint8_t *argv = (uint8_t *)"stop"; + AudioCaptureSample(argc, (const char **)&argv); + p_RecordingView->ChangeView(RECORDGOINGVIEW, RECORDINGVIEW); + return true; + } return true; } 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 c819088df..4a63230f3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp @@ -54,6 +54,9 @@ namespace OHOS delete p_RecordListView; p_RecordListView = nullptr; + delete p_RecordGoingView; + p_RecordGoingView = nullptr; + delete RecordingViewScrollView[RECORDINGVIEW]; RecordingViewScrollView[RECORDINGVIEW] = nullptr; } @@ -220,6 +223,24 @@ namespace OHOS return true; } + // 切换到“正在录音”视图 + bool RecordingView::ChangeRecordGoingView(int16_t thisView) + { + if (RecordingViewScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::ChangeRecordGoingView"); + p_RecordGoingView = new RecordGoingView(); + if (p_RecordGoingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView:: new scrollView[%d] fail", thisView); + return false; + } + RecordingViewScrollView[thisView] = p_RecordGoingView->RecordGoingViewInit(); + RootView::GetInstance()->Add(RecordingViewScrollView[thisView]); + } + return true; + } + /* -------------------------------------------------------------------------- */ // 1.RecordingViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 struct RecordingViewMapper @@ -232,6 +253,7 @@ namespace OHOS static const RecordingViewMapper ViewMapper[] = { {RECORDINGVIEW, &RecordingView::ChangeRecordingView}, {RECORDINGLISTVIEW, &RecordingView::ChangeRecordListView}, + {RECORDGOINGVIEW, &RecordingView::ChangeRecordGoingView}, }; // 3.根据传入的interface参数执行相应视图ID关联的成员函数。