From 32683e6e9788232610685e068f53624d7da404d3 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 13 Aug 2024 10:26:46 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E8=AF=A6?= =?utf8?q?=E6=83=85=E8=87=AA=E9=80=82=E5=BA=94=EF=BC=88=E5=8F=82=E8=80=83U?= =?utf8?q?6);=E6=B6=88=E6=81=AF=E5=BC=B9=E7=AA=97=E5=A2=9E=E5=8A=A0title?= =?utf8?q?=E7=9A=84=E6=BB=9A=E5=8A=A8=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../message/include/MessageShowView.h | 7 ++ .../nativeui/message/src/MessageShowView.cpp | 74 ++++++++++++++++--- .../src/notify/message_notification.cpp | 8 +- 3 files changed, 74 insertions(+), 15 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h index 8db3664dd..457d57e2e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-06-21 09:56:18 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-12 16:03:32 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageShowView.h + */ /*** * @Date: 2024-06-21 09:56:18 * @LastEditors: Caisking 3449750381@qq.com @@ -46,6 +52,7 @@ namespace OHOS void InitView(); void DeInitView(void); void PreLoad(void); + void UpdateShowConfig(); private: UIScrollView *container_ = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp index b3c7eb8cc..904671d60 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp @@ -35,11 +35,15 @@ namespace OHOS static constexpr const int kTimeHeight = 33; static constexpr const int kTimeFontSize = 28; static constexpr const char *kTimeViewId = "time"; + + // 配置默认值 + static constexpr const int defaultRectWidth = 100; + static constexpr const int defaultLabelWidth = 40; // static constexpr const Color kTimeTextColor = Color::Gray(); #if 0 std::string titleStr = "12306中国高速铁路"; std::string timeStr = "2023.12.26 17:23"; - std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/"; + std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/"; #endif MessageShowView::MessageShowView() @@ -83,7 +87,7 @@ namespace OHOS label = new UILabel(); if (label == nullptr) { - return; // 内存分配失败,返回 + return; // 内存分配失败,返回 } label->SetPosition(posX, posY); label->Resize(width, height); @@ -98,7 +102,7 @@ namespace OHOS button = new UILabelButton(); if (button == nullptr) { - return; // 内存分配失败,返回 + return; // 内存分配失败,返回 } button->SetPosition(left, top); button->Resize(width, height); @@ -108,29 +112,60 @@ namespace OHOS button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED); button->SetVisible(true); } + void MessageShowView::UpdateShowConfig() + { + /* + 默认配置 : + 矩形长:60 + label长:40 + 通过字符串内容配置 + 一行最多显示 30 个字符 + 一行 矩形背景长加 40 + 一行 label长加 50 + */ + + const int maxCharsPerLine = 30; + + // 计算行数 + int lines = (messageStr.size() / maxCharsPerLine) + (messageStr.size() % maxCharsPerLine ? 1 : 0); + + // 默认情况下,矩形宽度不变。如果有多行,则更新 + int updatedRectWidth = defaultRectWidth + (lines > 1 ? (lines * 10) : 0); + int updatedLabelWidth = defaultLabelWidth + (lines > 1 ? (lines * 50) : 0); + + /*小于2行不需要变化*/ + if (lines <= 2) + return; + + // 输出配置结果 + messageButton->SetPosition(33, 157, 400, updatedRectWidth); + deleteButton->SetPosition(43, 157 + updatedRectWidth + 20, 380, 100); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "updatedRectWidth %d updatedLabelWidth %d lines %d \r\n", updatedRectWidth, updatedLabelWidth, lines); + } void MessageShowView::InitView() { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView"); /* -------------------------------------------------------------------------- */ title = new UILabel(); if (title == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title:: new UILabel fail"); - return; // 内存分配失败,返回 + return; // 内存分配失败,返回 } title->SetPosition(83, 60, 300, 35); title->SetText(titleStr.c_str()); title->SetStyle(STYLE_TEXT_FONT, 30); - title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 + title->SetRollSpeed(70); title->SetVisible(true); /* -------------------------------------------------------------------------- */ time = new UILabel(); if (time == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time:: new UILabel fail"); - return; // 内存分配失败,返回 + return; // 内存分配失败,返回 } time->SetPosition(73, 104, 320, 33); time->SetViewId("time"); @@ -143,19 +178,25 @@ namespace OHOS time->SetVisible(true); /* -------------------------------------------------------------------------- */ /*初始化消息内容*/ - InitializeButton(messageButton, 33, 157, 380, 350, "message"); + InitializeButton(messageButton, 33, 157, 400, defaultRectWidth, "message"); messageButton->SetStyle(STYLE_BORDER_RADIUS, 30); - messageButton->SetText(messageStr.c_str()); + messageButton->SetAlign(TEXT_ALIGNMENT_LEFT); messageButton->SetTextColor(Color::Gray()); messageButton->SetTouchable(false); - messageButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // messageButton->SetText(messageStr.c_str()); + // messageButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + InitUILabel(message, 68, 170, 320, 100, "message", messageStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + message->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); // 宽固定 高度变长! + message->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); /*加载清除按键*/ - InitButtonExt(deleteButton, 43, 527, 380, 100, DELETEBUTTON, STR_CLEAN, 30); + InitButtonExt(deleteButton, 43, 157 + defaultRectWidth + 20, 380, 100, DELETEBUTTON, STR_CLEAN, 30); deleteButton->SetOnClickListener(static_cast(MessageShowPresenter::GetInstance())); /* -------------------------------------------------------------------------- */ container_->Add(title); container_->Add(time); container_->Add(messageButton); + container_->Add(message); container_->Add(deleteButton); /* -------------------------------------------------------------------------- */ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView is ok!"); @@ -190,16 +231,25 @@ namespace OHOS View::OnStart(); container_ = new UIScrollView(); - container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + if (container_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail"); + return; + } + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); container_->SetScrollBlankSize(35); container_->SetReboundSize(50); + container_->SetDirection(1); container_->SetOnDragListener(presenter_); container_->SetTouchable(true); container_->SetDraggable(true); + // container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); PreLoad(); + UpdateShowConfig(); SetContainerView(container_); RootView::GetInstance()->SetOnKeyActListener(presenter_); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp index e5b0723de..37e936d4d 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -123,7 +123,9 @@ namespace OHOS titleLabel->SetPosition(83, 60, 300, 35); titleLabel->SetText(titleStr.c_str()); titleLabel->SetStyle(STYLE_TEXT_FONT, 30); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + // titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 + titleLabel->SetRollSpeed(70); titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); titleLabel->SetVisible(true); @@ -198,12 +200,12 @@ namespace OHOS MessageGroupView->Add(messageLabel); MessageGroupView->Add(deleteButton); - if(true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) { // 震动提醒 ui_api_vibrate_once_func(); } - + int32_t timeout = 2000; // 亮屏操作 2000ms 2秒关闭 SendMsgToUIService(SCREEN_TURN_ON_TO_UI, 0, &timeout, sizeof(int32_t)); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); -- 2.17.1