From: Caisking <3449750381@qq.com> Date: Tue, 13 Aug 2024 02:26:46 +0000 (+0800) Subject: 增加消息详情自适应(参考U6);消息弹窗增加title的滚动效果 X-Git-Tag: release_V1.2.70_20241020_135402~673^2~6 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F685%2F1;p=mirrors%2FFD230.git 增加消息详情自适应(参考U6);消息弹窗增加title的滚动效果 --- 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!!");