增加拨号点击效果
authorxue <2144439972@qq.com>
Mon, 14 Jul 2025 08:06:12 +0000 (16:06 +0800)
committerxue <2144439972@qq.com>
Mon, 14 Jul 2025 08:06:12 +0000 (16:06 +0800)
code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h
code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp

index 8878f6d..80f6b35 100644 (file)
@@ -6,6 +6,7 @@
 #include <ui_scroll_view.h>\r
 #include "components/ui_view_group.h"\r
 #include "components/ui_label.h"\r
+#include "components/ui_label_button.h"\r
 #include "components/ui_label_ext.h"\r
 #include "components/ui_image_view.h"\r
 #include "components/ui_button.h"\r
@@ -50,8 +51,8 @@ namespace OHOS
         int topPos;\r
         int width;\r
         int height;\r
-        const char *defaultImgSrc;\r
-        const char *triggeredImgSrc;\r
+        const char *text;\r
+\r
     };\r
 \r
     class PhoneCallPresenter;\r
@@ -73,7 +74,8 @@ namespace OHOS
         void Init();\r
         void DeInit();\r
         void container_child_init();\r
-        UIButton* initButton(const ButtonInitParams &params);\r
+        UILabelButton* initButton(const ButtonInitParams &params);\r
+        void initButtonImage();\r
         void UpdateLabel(const std::string &text);\r
         void container_child_SetVisible(bool);\r
         void start_call_roll_timer();\r
index e9f5947..fea1811 100644 (file)
@@ -160,6 +160,8 @@ namespace OHOS
                 // 点击0键,将字符'0'追加到号码字符串中\r
                 phoneNumber += "0";\r
                 printf("----0-----\n");\r
+                //增加点击效果\r
+                \r
             }\r
             else if (strcmp(viewId, BUTTON1) == 0)\r
             {\r
index b6e1da1..e7a3e1a 100644 (file)
@@ -32,29 +32,28 @@ namespace OHOS
         return g_pPhoneCallView;\r
     }\r
 \r
-    UIButton* PhoneCallView ::initButton(const ButtonInitParams &params)\r
+    UILabelButton* PhoneCallView ::initButton(const ButtonInitParams &params)\r
     {\r
-        UIButton *button = new UIButton();\r
+        UILabelButton *button = new UILabelButton();\r
 \r
         const char *buttonNumber = params.buttonNumber;\r
         int leftPos = params.leftPos;\r
         int topPos = params.topPos;\r
         int width = params.width;\r
         int height = params.height;\r
-        const char *defaultImgSrc = params.defaultImgSrc;\r
-        const char *triggeredImgSrc = params.triggeredImgSrc;\r
+        const char *text = params.text;\r
 \r
         button->SetPosition(leftPos, topPos);\r
         button->Resize(width, height);\r
         button->SetViewId(buttonNumber);\r
 \r
         button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
-        button->SetStyle(STYLE_BORDER_COLOR, 0xff191919);\r
+        button->SetText(text);\r
+        button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+        button->SetTextColor(Color::White());\r
         // Set additional properties\r
-        button->SetImageSrc(defaultImgSrc, triggeredImgSrc);\r
-        button->SetStyleForState(STYLE_BORDER_COLOR, 0xff191919, UIButton::PRESSED);\r
-        button->SetStyleForState(STYLE_BORDER_WIDTH, 0, UIButton::PRESSED);\r
-        button->SetStyleForState(STYLE_BORDER_COLOR,  0xff191919, UIButton::PRESSED);\r
+        //button->SetImageSrc(defaultImgSrc, triggeredImgSrc);\r
+        button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED);\r
         // Add the callback for events\r
         UIView::OnClickListener *buttonClick = static_cast<UIView::OnClickListener *>(PhoneCallPresenter::GetInstance());\r
         button->SetOnClickListener(buttonClick);\r
@@ -64,8 +63,37 @@ namespace OHOS
         // Add to rootView\r
         container_->Add(button);\r
         button->SetVisible(true);\r
-\r
         return button;\r
+    }\r
+     void PhoneCallView ::initButtonImage()\r
+    {\r
+        UIButton *button_call = new UIButton();\r
+        UIButton *button_del = new UIButton();\r
+\r
+        button_call->SetPosition(69, 338);\r
+        button_call->Resize(104, 70);\r
+        button_call->SetViewId(BUTTONCALL);\r
+        button_del->SetPosition(293, 338);\r
+        button_del->Resize(104, 70);\r
+        button_del->SetViewId(BUTTONDEL);\r
+\r
+        button_call->SetImageSrc(buttonCallPath,buttonCallPath);\r
+        button_del->SetImageSrc(buttonDelPath,buttonDelPath);\r
+        button_call->SetStyle(STYLE_BORDER_COLOR, 0xff191919);\r
+        button_del->SetStyle(STYLE_BORDER_COLOR, 0xff191919);\r
+        // Add the callback for events\r
+        UIView::OnClickListener *buttonClick = static_cast<UIView::OnClickListener *>(PhoneCallPresenter::GetInstance());\r
+        button_call->SetOnClickListener(buttonClick);\r
+        button_del->SetOnClickListener(buttonClick);\r
+        UIView::OnLongPressListener*buttonlongpress=static_cast<UIView::OnLongPressListener *>(PhoneCallPresenter::GetInstance());\r
+        button_call->SetOnLongPressListener(buttonlongpress);\r
+        button_del->SetOnLongPressListener(buttonlongpress);\r
+\r
+        // Add to rootView\r
+        container_->Add(button_call);\r
+        button_call->SetVisible(true);\r
+        container_->Add(button_del);\r
+        button_del->SetVisible(true);\r
         \r
     }\r
 \r
@@ -101,23 +129,23 @@ namespace OHOS
         container_->Add(label_);\r
         label_->SetVisible(true);\r
         ButtonInitParams buttonParams[] = {\r
-            { BUTTON1, 68, 104, 104, 70, button1Path, button1Path},\r
-            {BUTTON2, 181, 104, 104, 70, button2Path, button2Path},\r
-            { BUTTON3, 293, 104, 104, 70, button3Path, button3Path},\r
-            { BUTTON4, 69, 182, 104, 70, button4Path, button4Path},\r
-            { BUTTON5, 182, 182, 104, 70, button5Path, button5Path},\r
-            { BUTTON6, 293, 182, 104, 70, button6Path, button6Path},\r
-            { BUTTON7, 69, 260, 104, 70, button7Path, button7Path},\r
-            { BUTTON8, 181, 260, 104, 70, button8Path, button8Path},\r
-            { BUTTON9, 293, 260, 104, 70, button9Path, button9Path},\r
-            { BUTTON0, 181, 338, 104, 70, button0Path, button0Path},\r
-            { BUTTONCALL, 69, 338, 104, 70, buttonCallPath, buttonCallPath},\r
-            { BUTTONDEL, 293, 338, 104, 70, buttonDelPath, buttonDelPath},\r
+            { BUTTON1, 68, 104, 104, 70, "1"},\r
+            { BUTTON2, 181, 104, 104, 70, "2"},\r
+            { BUTTON3, 293, 104, 104, 70, "3"},\r
+            { BUTTON4, 69, 182, 104, 70, "4"},\r
+            { BUTTON5, 182, 182, 104, 70, "5"},\r
+            { BUTTON6, 293, 182, 104, 70, "6"},\r
+            { BUTTON7, 69, 260, 104, 70, "7 *"},\r
+            { BUTTON8, 181, 260, 104, 70, "8"},\r
+            { BUTTON9, 293, 260, 104, 70, "9 #"},\r
+            { BUTTON0, 181, 338, 104, 70, "0 +"},\r
         };\r
 \r
         for(int i = 0;i<12;i++){\r
             button_[i] = initButton(buttonParams[i]);\r
         }\r
+        initButtonImage();\r
+\r
     }\r
     static int8_t  roll_falg=0;//0.1s一次变换\r
 \r