From fc9f8f437c1638d27bf8a4343df2a7aa5fc5c307 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Mon, 14 Jul 2025 16:06:12 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=8B=A8=E5=8F=B7=E7=82=B9?= =?utf8?q?=E5=87=BB=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/phone/include/PhoneCallView.h | 8 ++- .../nativeui/phone/src/PhoneCallPresenter.cpp | 2 + .../nativeui/phone/src/PhoneCallView.cpp | 72 +++++++++++++------ 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h index 8878f6d40..80f6b3570 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h @@ -6,6 +6,7 @@ #include #include "components/ui_view_group.h" #include "components/ui_label.h" +#include "components/ui_label_button.h" #include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "components/ui_button.h" @@ -50,8 +51,8 @@ namespace OHOS int topPos; int width; int height; - const char *defaultImgSrc; - const char *triggeredImgSrc; + const char *text; + }; class PhoneCallPresenter; @@ -73,7 +74,8 @@ namespace OHOS void Init(); void DeInit(); void container_child_init(); - UIButton* initButton(const ButtonInitParams ¶ms); + UILabelButton* initButton(const ButtonInitParams ¶ms); + void initButtonImage(); void UpdateLabel(const std::string &text); void container_child_SetVisible(bool); void start_call_roll_timer(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp index e9f5947e5..fea1811fc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp @@ -160,6 +160,8 @@ namespace OHOS // 点击0键,将字符'0'追加到号码字符串中 phoneNumber += "0"; printf("----0-----\n"); + //增加点击效果 + } else if (strcmp(viewId, BUTTON1) == 0) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp index b6e1da1e1..e7a3e1ac9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp @@ -32,29 +32,28 @@ namespace OHOS return g_pPhoneCallView; } - UIButton* PhoneCallView ::initButton(const ButtonInitParams ¶ms) + UILabelButton* PhoneCallView ::initButton(const ButtonInitParams ¶ms) { - UIButton *button = new UIButton(); + UILabelButton *button = new UILabelButton(); const char *buttonNumber = params.buttonNumber; int leftPos = params.leftPos; int topPos = params.topPos; int width = params.width; int height = params.height; - const char *defaultImgSrc = params.defaultImgSrc; - const char *triggeredImgSrc = params.triggeredImgSrc; + const char *text = params.text; button->SetPosition(leftPos, topPos); button->Resize(width, height); button->SetViewId(buttonNumber); button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BORDER_COLOR, 0xff191919); + button->SetText(text); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + button->SetTextColor(Color::White()); // Set additional properties - button->SetImageSrc(defaultImgSrc, triggeredImgSrc); - button->SetStyleForState(STYLE_BORDER_COLOR, 0xff191919, UIButton::PRESSED); - button->SetStyleForState(STYLE_BORDER_WIDTH, 0, UIButton::PRESSED); - button->SetStyleForState(STYLE_BORDER_COLOR, 0xff191919, UIButton::PRESSED); + //button->SetImageSrc(defaultImgSrc, triggeredImgSrc); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); // Add the callback for events UIView::OnClickListener *buttonClick = static_cast(PhoneCallPresenter::GetInstance()); button->SetOnClickListener(buttonClick); @@ -64,8 +63,37 @@ namespace OHOS // Add to rootView container_->Add(button); button->SetVisible(true); - return button; + } + void PhoneCallView ::initButtonImage() + { + UIButton *button_call = new UIButton(); + UIButton *button_del = new UIButton(); + + button_call->SetPosition(69, 338); + button_call->Resize(104, 70); + button_call->SetViewId(BUTTONCALL); + button_del->SetPosition(293, 338); + button_del->Resize(104, 70); + button_del->SetViewId(BUTTONDEL); + + button_call->SetImageSrc(buttonCallPath,buttonCallPath); + button_del->SetImageSrc(buttonDelPath,buttonDelPath); + button_call->SetStyle(STYLE_BORDER_COLOR, 0xff191919); + button_del->SetStyle(STYLE_BORDER_COLOR, 0xff191919); + // Add the callback for events + UIView::OnClickListener *buttonClick = static_cast(PhoneCallPresenter::GetInstance()); + button_call->SetOnClickListener(buttonClick); + button_del->SetOnClickListener(buttonClick); + UIView::OnLongPressListener*buttonlongpress=static_cast(PhoneCallPresenter::GetInstance()); + button_call->SetOnLongPressListener(buttonlongpress); + button_del->SetOnLongPressListener(buttonlongpress); + + // Add to rootView + container_->Add(button_call); + button_call->SetVisible(true); + container_->Add(button_del); + button_del->SetVisible(true); } @@ -101,23 +129,23 @@ namespace OHOS container_->Add(label_); label_->SetVisible(true); ButtonInitParams buttonParams[] = { - { BUTTON1, 68, 104, 104, 70, button1Path, button1Path}, - {BUTTON2, 181, 104, 104, 70, button2Path, button2Path}, - { BUTTON3, 293, 104, 104, 70, button3Path, button3Path}, - { BUTTON4, 69, 182, 104, 70, button4Path, button4Path}, - { BUTTON5, 182, 182, 104, 70, button5Path, button5Path}, - { BUTTON6, 293, 182, 104, 70, button6Path, button6Path}, - { BUTTON7, 69, 260, 104, 70, button7Path, button7Path}, - { BUTTON8, 181, 260, 104, 70, button8Path, button8Path}, - { BUTTON9, 293, 260, 104, 70, button9Path, button9Path}, - { BUTTON0, 181, 338, 104, 70, button0Path, button0Path}, - { BUTTONCALL, 69, 338, 104, 70, buttonCallPath, buttonCallPath}, - { BUTTONDEL, 293, 338, 104, 70, buttonDelPath, buttonDelPath}, + { BUTTON1, 68, 104, 104, 70, "1"}, + { BUTTON2, 181, 104, 104, 70, "2"}, + { BUTTON3, 293, 104, 104, 70, "3"}, + { BUTTON4, 69, 182, 104, 70, "4"}, + { BUTTON5, 182, 182, 104, 70, "5"}, + { BUTTON6, 293, 182, 104, 70, "6"}, + { BUTTON7, 69, 260, 104, 70, "7 *"}, + { BUTTON8, 181, 260, 104, 70, "8"}, + { BUTTON9, 293, 260, 104, 70, "9 #"}, + { BUTTON0, 181, 338, 104, 70, "0 +"}, }; for(int i = 0;i<12;i++){ button_[i] = initButton(buttonParams[i]); } + initButtonImage(); + } static int8_t roll_falg=0;//0.1s一次变换 -- 2.17.1