From: luozheng <1732036298@qq.com> Date: Mon, 4 Mar 2024 09:25:01 +0000 (+0800) Subject: 修改录音列表视图 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~33 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=10a70d9ff33cb5c5519c9cb11cf9d575fd8c3706;p=mirrors%2FFD230.git 修改录音列表视图 --- 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 e16a37d79..15d07eba5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h @@ -16,6 +16,16 @@ namespace OHOS MAX_RECORDINGVIEWID, } RECORDINGVIEWID; + class RecordListViewOnClickListener : public UIView::OnClickListener + { + public: + RecordListViewOnClickListener() {} + + ~RecordListViewOnClickListener() {} + + bool OnClick(UIView &view, const ClickEvent &event) override; + }; + class RecordingView; class RecordingPresenter : public Presenter, public UIView::OnClickListener, @@ -32,13 +42,13 @@ namespace OHOS void OnStop() override; static RecordingPresenter *GetInstance(); - + int convertNumericDateTime(const char *numericDateTime, char *formattedDateTime); private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; - bool OnKeyAct(UIView &view, const KeyEvent &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 12d82208c..025a2e0d8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h @@ -12,6 +12,7 @@ #include "components/ui_image_animator.h" #include "record/include/RecordListView.h" +#include "record/include/RecordGoingView.h" namespace OHOS { static const char *RECORD_BUTTON = "RecordButton"; //录音按钮 @@ -47,7 +48,7 @@ namespace OHOS private: RecordListView *p_RecordListView{nullptr}; - + RecordGoingView*p_RecordGoingView{nullptr}; private: void RecordingViewInit(void); void ClearAll(void); 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 39492d1a6..c8a094fb6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordListView.cpp @@ -102,7 +102,7 @@ namespace OHOS .height = 35, .fontSize = 30, .lineHeigh = 35, - .text = "音乐列表", + .text = "录音列表", .lineBreakMode = UILabel::LINE_BREAK_ADAPT, }; @@ -120,7 +120,7 @@ namespace OHOS .height = 124, .fontSize = 26, .lineHeigh = 30, - .text = "当前音乐列表为空", + .text = "当前录音列表为空", .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, }; RecordListViewAttentionLabel = SetUpLabel(labelconfig); @@ -141,7 +141,7 @@ namespace OHOS { // UIList 的适配器 p_RecordingListAdapter = new RecordingListAdapter(); - p_RecordingListAdapter->SetItemClickListener(RecordingPresenter::GetInstance()); + p_RecordingListAdapter->SetItemClickListener(new RecordListViewOnClickListener()); recordList = new UIList(); if (recordList == nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp index 6486bed9d..cfb483c96 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingListitemView.cpp @@ -45,9 +45,9 @@ namespace OHOS 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); + SetLabelStyle(m_recordId, 35, 33, 96, 35, textColor, 25); + SetLabelStyle(m_recordTotalTime, 268, 19, 73, 35, textColor, 25); + SetLabelStyle(m_recordTime, 247, 57, 94, 23, subTextColor, 20); } void RecordingListitemView::SetLabelStyle(UILabel &label, int x, int y, int width, int height, OHOS::ColorType textColor, int fontSize) 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 956135360..3d1f560e1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp @@ -5,6 +5,7 @@ #include "bts_a2dp_source.h" #include "audio_manager.h" #include +#include "../../../../../../drivers/peripheral/utils/custom_utils.h" namespace OHOS { @@ -181,6 +182,7 @@ namespace OHOS void RecordingModel::InitRecordingListItem() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingModel::InitRecordingListItem"); + char *date = uapi_get_CurrentDate();//获取日期 RecordingMp3FileCount = 0; if (!fileNames.empty()) { @@ -202,13 +204,10 @@ namespace OHOS } 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[i] = {i, fileNames[i].c_str(), "09:51", date}; } // 记得在不需要使用 Recordings 后释放内存 // free(Recordings); 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 919ea0eed..98a08822c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp @@ -5,7 +5,9 @@ #include "record/include/RecordingPresenter.h" #include "record/include/RecordingModel.h" #include -#include "custom_utils.h" +#include "../../../../../../drivers/peripheral/utils/custom_utils.h" +#include "record/include/RecordingListitemView.h" + namespace OHOS { @@ -34,7 +36,7 @@ namespace OHOS // 初始化录音信息 RecordingModel::GetInstance()->InitRecordingListItem(); Presenter::OnStart(); - ScreenControl(1); + ScreenAlwaysOnCtr(1); } void RecordingPresenter::OnPause(void) @@ -51,7 +53,7 @@ namespace OHOS void RecordingPresenter::OnStop(void) { Presenter::OnStop(); - ScreenControl(0); + ScreenAlwaysOnCtr(0); } bool RecordingPresenter::OnDrag(UIView &view, const DragEvent &event) @@ -95,6 +97,29 @@ namespace OHOS return false; } + /// @brief 解析时间 + /// @param numericDateTime "19700101000641"; // 输入的数字形式日期时间 + /// @param formattedDateTime + /// @return + int RecordingPresenter::convertNumericDateTime(const char *numericDateTime, char *formattedDateTime) + { + if (strlen(numericDateTime) != 14) + { + return 0; // 如果输入的数字长度不为14,则转换失败 + } + + struct tm timeinfo = {0}; + if (strptime(numericDateTime, "%Y%m%d%H%M%S", &timeinfo) == NULL) + { + return 0; // 解析失败 + } + + // 格式化输出为上午/下午几点几分几秒 + strftime(formattedDateTime, 80, "%p %I点%M分%S秒", &timeinfo); + + return 1; // 转换成功 + } + #ifdef __cplusplus extern "C" { @@ -107,37 +132,41 @@ namespace OHOS bool RecordingPresenter::OnClick(UIView &view, const ClickEvent &event) { - - // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), RECORD_BUTTON) == 0) { - // 将参数保存到数组中 - char *args[6] = {0}; //{"01", "mp3", "16000", "1", "16", "/user/res/record/recording/recordyyyymmddhhmmss.mp3"}; - int argc = 6; - args[0] = (char *)malloc(25); - args[1] = (char *)malloc(25); - args[2] = (char *)malloc(25); - args[3] = (char *)malloc(25); - args[4] = (char *)malloc(25); - args[5] = (char *)malloc(100); - - sprintf(args[0], "01"); - sprintf(args[1], "mp3"); - sprintf(args[2], "16000"); - sprintf(args[3], "1"); - sprintf(args[4], "16"); - uapi_get_recordfilename(args[5]); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Recording...."); - AudioCaptureSample(argc, (const char **)args); - NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_GOING); + char *args[6] = {0}; + const char *defaultArgs[6] = {"01", "mp3", "16000", "1", "16", nullptr}; // 默认参数数组 - free(args[0]); - free(args[1]); - free(args[2]); - free(args[3]); - free(args[4]); - free(args[5]); + for (int i = 0; i < 5; ++i) + { + args[i] = (char *)malloc(25); // 分配内存 + sprintf(args[i], "%s", defaultArgs[i]); // 设置默认参数值 + } + args[5] = (char *)malloc(100); // 分配内存 + char *numericDateTime = (char *)malloc(20); + uapi_get_yyyymmddhhmmss_Date(numericDateTime); // 获取形如:19700101000641格式的日期时间 + char formattedDateTime[80]; + if (convertNumericDateTime(numericDateTime, formattedDateTime)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Formatted DateTime: %s\n", formattedDateTime); + sprintf(args[5], "/user/res/record/recording/%s.mp3", formattedDateTime); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to convert numeric date time\n", formattedDateTime); + } + /* ---------------------------------- 开始录音 ---------------------------------- */ + AudioCaptureSample(6, (const char **)args); + /* --------------------------------- 跳转到录音界面 -------------------------------- */ + NativeAbility::GetInstance().ChangeSlice(VIEW_RECORD_GOING); + /* ---------------------------------- 释放内存 ---------------------------------- */ + for (int i = 0; i < 6; ++i) + { + free(args[i]); + } + free(numericDateTime); + /* -------------------------------------------------------------------------- */ return true; } return true; @@ -155,4 +184,19 @@ namespace OHOS } return true; } + + bool RecordListViewOnClickListener::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + RecordingListitemView *p_RecordingListitemView = static_cast(&view); + int index = p_RecordingListitemView->GetRecordingListIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewOnClickListener::OnClick index:%d\n", index); + if (index >= RecordingModel::GetInstance()->GetRecordingListNum()) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewOnClickListener::OnClick is no index"); + return false; + } + + return true; + } } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 210913aa9..aaffb266c 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -284,7 +284,31 @@ errcode_t uapi_set_time_from_cat1(char* cat1time) return ERRCODE_SUCC; } -errcode_t uapi_get_recordfilename(char *date) +/// @brief 获取日期 +char *uapi_get_CurrentDate(void) +{ + + time_t rawtime; + struct tm* timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + char *buffer = (char*)malloc(80); // 动态分配内存 + if(buffer == NULL) + { + return NULL; // 内存分配失败 + } + + // 格式化输出当前时间为 "YYYY-MM-DD HH:MM:SS" 形式 + sprintf(buffer,"%04d.%02d.%02d\n", + timeinfo->tm_year + 1900, + timeinfo->tm_mon + 1, + timeinfo->tm_mday); + + return buffer; +} + +/// @brief 获取日期 +errcode_t uapi_get_yyyymmddhhmmss_Date(char *date) { if(date != NULL) { @@ -293,7 +317,7 @@ errcode_t uapi_get_recordfilename(char *date) time(&rawtime); timeinfo = localtime(&rawtime); - sprintf(date,"/user/res/record/recording/recording%04d%02d%02d%02d%02d%02d.mp3", + sprintf(date,"%04d%02d%02d%02d%02d%02d", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, @@ -304,7 +328,9 @@ errcode_t uapi_get_recordfilename(char *date) return ERRCODE_SUCC; } -void ScreenControl(uint8_t turnOnFlag) +/// @brief 控制屏幕是否常亮 +/// @param turnOnFlag 1:常亮屏幕 0:取消常亮 +void ScreenAlwaysOnCtr(uint8_t turnOnFlag) { const power_display_svr_api_t *display_api = power_display_svr_get_api(); if(turnOnFlag) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 4b45e5503..56d78e7a7 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -12,6 +12,7 @@ #include "hal_gpio.h" #include "soc_osal.h" #include "platform_core.h" +#include #ifdef __cplusplus #if __cplusplus @@ -31,9 +32,11 @@ errcode_t uapi_get_timestampe_ms(uint64_t *tm); errcode_t uapi_set_time_from_cat1(char* cat1time); /**获取日期*/ -errcode_t uapi_get_recordfilename(char *date); +errcode_t uapi_get_yyyymmddhhmmss_Date(char *date); -void ScreenControl(uint8_t turnOnFlag); +char *uapi_get_CurrentDate(void); + +void ScreenAlwaysOnCtr(uint8_t turnOnFlag); errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr); /**