UI添加通话纪录,及bug修复 374/1
authorhcj <1224667075@qq.com>
Mon, 24 Jun 2024 08:51:34 +0000 (16:51 +0800)
committerhcj <1224667075@qq.com>
Mon, 24 Jun 2024 08:51:34 +0000 (16:51 +0800)
code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhonePresenter.h
code/sdk/application/wearable/fd230app/nativeui/phone/include/MainPhoneView.h
code/sdk/application/wearable/fd230app/nativeui/phone/include/TelephonyInitInterface.h
code/sdk/application/wearable/fd230app/nativeui/phone/src/MainPhoneView.cpp
code/sdk/application/wearable/fd230app/nativeui/phone/src/TelephonyInitInterface.cpp
code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h
code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h
code/sdk/application/wearable/service/msg_center/include/notify/makephone_notification.h
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp

index 72237a1..9320bdd 100644 (file)
@@ -29,6 +29,8 @@ namespace OHOS
         void OnResume() override;
         void OnStop() override;
 
+        
+
         static MainPhonePresenter *GetInstance();
 
     private:
index 67be2c2..3f56576 100644 (file)
@@ -16,6 +16,8 @@
 #include "components/ui_label_ext.h"
 #include "components/ui_image_view.h"
 #include "phone/include/TelephonyInitInterface.h"
+#include "PhoneService.h"
+#include "components/ui_label_button_ext.h"
 
 namespace OHOS
 {
@@ -34,6 +36,19 @@ namespace OHOS
         void OnTearDownView() override;
         void OnStop() override;
 
+        struct MainPhoneView_ButtonConfig_ext_t
+        {
+            int x;
+            int y;
+            int w;
+            int h;
+            const char *str;
+            const char *ViewId;
+        };
+
+
+        UILabelButtonExt *SetTheButton_ext(MainPhoneView_ButtonConfig_ext_t &buttonconfig, UIView::OnClickListener *clickListener);
+
     private:
         void MainPhoneViewInit(void);
         void ClearAll(void);
@@ -44,6 +59,11 @@ namespace OHOS
         UILabelExt *RecentCallLabel{nullptr};         //"最近通话"
         UIImageView *TelephoneLineImageView{nullptr}; // 线
         UILabelExt *NoCallsLabel{nullptr};            // 暂无通话
+        UILabelExt *hintCallsLabel{nullptr};            // 提示
+        CallLogInfo *info{nullptr};
+        UILabelButtonExt *button_calllog[CALL_LOG_MAX_NUM]{nullptr};
+        UILabelExt *button_calllog_time[CALL_LOG_MAX_NUM]{nullptr};         //"时间"
+        UILabelExt *button_calllog_status[CALL_LOG_MAX_NUM]{nullptr};         //"通话状态"
     };
 }
 #endif
\ No newline at end of file
index ab1b4be..5f57926 100644 (file)
@@ -90,6 +90,7 @@ namespace OHOS
 
         static UIScrollView *ScrollViewInit(const ScrollViewParams &params);
         static UILabelExt *LabelViewInit(const LabelParams &params);
+        static UILabelExt *LabelViewInit(const LabelParams &params,ColorType color);
         static UIButton *ButtonViewInit(const ButtonParams &params);
         static UIImageView *ImageViewInit(const ImageParams &params);
 
index 2791bd4..55b7ab7 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "phone/include/MainPhoneView.h"
 #include "phone/include/MainPhonePresenter.h"
+#include "components/ui_label_button_ext.h"
 
 #include "wearable_log.h"
 namespace OHOS
@@ -32,6 +33,30 @@ namespace OHOS
         return g_pMainPhoneView;
     }
 
+    UILabelButtonExt *MainPhoneView::SetTheButton_ext(MainPhoneView_ButtonConfig_ext_t &buttonconfig, UIView::OnClickListener *clickListener)
+    {
+        UILabelButtonExt *button = new UILabelButtonExt();
+        if (button == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::SetTheButton: button new  fail!");
+            return nullptr;
+        }
+        button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h);
+        button->SetViewId(buttonconfig.ViewId);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "----------%s ---",buttonconfig.ViewId);
+        button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+        if(clickListener!=NULL)
+        button->SetOnClickListener(clickListener);
+
+        button->SetText(buttonconfig.str);
+        button->SetAlign(TEXT_ALIGNMENT_LEFT);
+        button->SetLabelPosition(50,-23);
+        button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35);
+
+        return button;
+    }
+
+
     void MainPhoneView::ClearAll(void)
     {
         if (MainPhoneViewScrollView != nullptr)
@@ -53,14 +78,51 @@ namespace OHOS
             delete TelephoneLineImageView;
             TelephoneLineImageView = nullptr;
 
-            delete NoCallsLabel;
-            NoCallsLabel = nullptr;
+            if(NoCallsLabel)
+            {
+                delete NoCallsLabel;
+                NoCallsLabel = nullptr;
+            }
+          
+            for(int i=0;i<20;i++)
+            {
+                if(button_calllog[i])
+                {
+                    delete button_calllog[i];
+                    button_calllog[i] = nullptr;
+                }
+            }
+           
+            for(int i=0;i<20;i++)
+            {
+                if(button_calllog_time[i])
+                {
+                    delete button_calllog_time[i];
+                    button_calllog_time[i] = nullptr;
+                }
+            }
+
+            for(int i=0;i<20;i++)
+            {
+                if(button_calllog_status[i])
+                {
+                    delete button_calllog_status[i];
+                    button_calllog_status[i] = nullptr;
+                }
+            }
+
+            if(hintCallsLabel)
+            {
+                delete hintCallsLabel;
+                hintCallsLabel = nullptr;
+            }
 
             delete MainPhoneViewScrollView;
             MainPhoneViewScrollView = nullptr;
         }
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::ClearAll success!!");
     }
+    static int32 num = 0;
 
     void MainPhoneView::MainPhoneViewInit(void)
     {
@@ -180,7 +242,119 @@ namespace OHOS
                 return;
             }
             /* ------------------------------ NoCallsLabel ------------------------------ */
+            info = new CallLogInfo[sizeof(CallLogInfo) * CALL_LOG_MAX_NUM];
+            if (GetCallLog(&info, &num) == -1) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallerLogModel::GetInstance()->ListIsEmpty");
+                return;
+            }
+
+            MainPhoneView_ButtonConfig_ext_t buttonconfig;
+            buttonconfig.x = 38;
+            buttonconfig.y = 360;
+            buttonconfig.w = 390;
+            buttonconfig.h = 104;
+            buttonconfig.ViewId="xxxx";
+
             labelParam = {
+                .x = 94,
+                .y = 420,
+                .width = 160,
+                .height = 35,
+                .fontSize = 23,
+                .lineHeigh = 0,
+                .text = "2023-1-23 14:22",
+                .lineBreakMode = UILabel::LINE_BREAK_ADAPT,
+            };
+
+
+            if (num != 0) {
+              
+                for (int i  = num; i != 0; i--) {
+                  
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",(info + i - 1)->tel);
+                    char buf[20]={0};
+                    sprintf_s(buf,20,"%s",(const char*)(info + i - 1)->tel);
+                    buttonconfig.str=buf;
+                    button_calllog[i]=SetTheButton_ext(buttonconfig,NULL);
+                    if(button_calllog[i]==nullptr)
+                    {
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::button_calllog new fail!");
+                    }
+                    buttonconfig.y += 20+104;
+                    MainPhoneViewScrollView->Add(button_calllog[i]);
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",(info + i - 1)->tel);
+                    
+                    time_t currtime;
+                    struct tm *timeinfo;
+                    currtime=(info + i - 1)->creationTime;
+                    timeinfo = localtime(&currtime);
+                    char time_buf[20]={0};
+
+                    labelParam.x=94,
+                    labelParam.text=time_buf;
+                    sprintf_s(time_buf,20 ,"%d-%d-%d %d:%d", timeinfo->tm_year + 1900,timeinfo->tm_mon + 1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min);
+    
+
+                    button_calllog_time[i] = TelephonyInitInterface::LabelViewInit(labelParam,Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff));
+                    if (button_calllog_time[i] == nullptr)
+                    {
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::MainPhoneViewTitleLabel new fail!");
+                    }
+                    MainPhoneViewScrollView->Add(button_calllog_time[i]);
+
+                    labelParam.fontSize=18;
+                    labelParam.x=286;
+                   
+                    
+                    ColorType color;
+
+                    if((info + i - 1)->status==CALL_MISSED)
+                    {
+                        labelParam.text="未接来电";
+                        color=Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff);
+                    }
+                    else if((info + i - 1)->status==CALL_INCOMING)
+                    {
+                        labelParam.text="拨入电话";
+                        color=Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff);
+                    }
+                    else if((info + i - 1)->status==CALL_OUTGOING)
+                    {
+                        labelParam.text="拨出电话";
+                        color=Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff);
+                    }
+
+
+                    button_calllog_status[i] = TelephonyInitInterface::LabelViewInit(labelParam,color);
+                    if (button_calllog_status[i] == nullptr)
+                    {
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::MainPhoneViewTitleLabel new fail!");
+                    }
+                    MainPhoneViewScrollView->Add(button_calllog_status[i]);
+
+                    labelParam.y += 20+104;
+                }
+                labelParam.x = 83;
+                labelParam.y -= 50;
+                labelParam.width = 300;
+                labelParam.height = 100;
+                labelParam.fontSize = 22;
+                labelParam.lineHeigh = 15;
+                labelParam.text = "注:只保留最近20条通话记录";
+                labelParam.lineBreakMode = UILabel::LINE_BREAK_MARQUEE,
+         
+
+                hintCallsLabel = TelephonyInitInterface::LabelViewInit(labelParam,Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
+                if (hintCallsLabel == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::MainPhoneViewTitleLabel new fail!");
+                }
+                
+                MainPhoneViewScrollView->Add(hintCallsLabel);
+            }
+            else
+            {
+                labelParam = {
                 .x = 83,
                 .y = 363,
                 .width = 300,
@@ -189,15 +363,20 @@ namespace OHOS
                 .lineHeigh = 40,
                 .text = "暂无通话",
                 .lineBreakMode = UILabel::LINE_BREAK_MARQUEE,
-            };
-            NoCallsLabel = TelephonyInitInterface::LabelViewInit(labelParam);
-            if (NoCallsLabel == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::NoCallsLabel new fail!");
-                return;
+                };
+                NoCallsLabel = TelephonyInitInterface::LabelViewInit(labelParam);
+                if (NoCallsLabel == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPhoneView::NoCallsLabel new fail!");
+                    return;
+                }
+                NoCallsLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff));
+                NoCallsLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+
             }
-            NoCallsLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff));
-            NoCallsLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+
+          
+           
             /* -------------------------------------------------------------------------- */
         }
     }
@@ -219,7 +398,10 @@ namespace OHOS
         MainPhoneViewScrollView->Add(FrequentlyContactedButton);
         MainPhoneViewScrollView->Add(RecentCallLabel);
         MainPhoneViewScrollView->Add(TelephoneLineImageView);
+
+        if(NoCallsLabel)
         MainPhoneViewScrollView->Add(NoCallsLabel);
+
         RootView::GetInstance()->Add(MainPhoneViewScrollView);
         Draw();
     }
index 77e291b..fab972e 100644 (file)
@@ -53,6 +53,24 @@ namespace OHOS
         return label;
     }
 
+    UILabelExt *TelephonyInitInterface::LabelViewInit(const LabelParams &params,ColorType color)
+    {
+        UILabelExt *label = new UILabelExt();
+        if (label == nullptr)
+        {
+            return nullptr;
+        }
+        label->SetPosition(params.x, params.y, params.width, params.height); // 位置大小
+        label->SetStyle(STYLE_TEXT_FONT, params.fontSize);                   // 字体大小
+        label->SetStyle(STYLE_LINE_HEIGHT, params.lineHeigh);                // 字体行高
+        label->SetText(params.text);                                         // 内容
+        label->SetTextColor(color);
+        label->SetLineBreakMode(params.lineBreakMode);                       // 断行模式
+        // label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);       // 设置此文本的对齐模式
+        label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, params.fontSize); // 设置标签的字体
+
+        return label;
+    }
     UIButton *TelephonyInitInterface::ButtonViewInit(const ButtonParams &params)
     {
         UIButton *button = new UIButton();
index 1e3f0fa..594b9fd 100644 (file)
@@ -17,7 +17,7 @@ extern "C" {
 #endif
 
 #define MULTI_CALL_MAX_NUME 5 // 最大多路通话路数
-#define CALL_LOG_MAX_NUM 30 // 最多记录30条通话记录,超出后删除最老的记录
+#define CALL_LOG_MAX_NUM 20 // 最多记录30条通话记录,超出后删除最老的记录
 #define NAME_SIZE 20
 #define MAX_PHONE_NUM 20
 #define CALL_VOLUME_MAX 15
index 1e3f0fa..594b9fd 100755 (executable)
@@ -17,7 +17,7 @@ extern "C" {
 #endif
 
 #define MULTI_CALL_MAX_NUME 5 // 最大多路通话路数
-#define CALL_LOG_MAX_NUM 30 // 最多记录30条通话记录,超出后删除最老的记录
+#define CALL_LOG_MAX_NUM 20 // 最多记录30条通话记录,超出后删除最老的记录
 #define NAME_SIZE 20
 #define MAX_PHONE_NUM 20
 #define CALL_VOLUME_MAX 15
index 89c807e..ade20be 100755 (executable)
@@ -16,6 +16,8 @@ enum class CallTimerType {
 };
 
 namespace OHOS {
+void addcalllog(void);
+
 class VolumeSettingView;
 UIViewGroup* CreatePhoneCallView(void);
 UIViewGroup* CreateCallingView(void);
index be46f56..14e37f6 100644 (file)
@@ -371,18 +371,18 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
     {
         //提醒低电充电
         set_lowpower_falg(0);
-        if (NotificationManager::GetInstance()->HasNotifyShowing())
-            NotificationManager::GetInstance()->StopNotify();
-        NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+        // if (NotificationManager::GetInstance()->HasNotifyShowing())
+        //     NotificationManager::GetInstance()->StopNotify();
+        NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
         NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
     }
     else
     {
         //电量过低,直接提醒关机
         set_lowpower_falg(1);
-        if (NotificationManager::GetInstance()->HasNotifyShowing())
-            NotificationManager::GetInstance()->StopNotify();
-        NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+        // if (NotificationManager::GetInstance()->HasNotifyShowing())
+        //     NotificationManager::GetInstance()->StopNotify();
+        NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
         NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
 
     }
@@ -733,11 +733,11 @@ void MsgCenterNotifyCat1CallEndedProc(const Topic topic, Request* req)
 {
     unused(topic);
     unused(req);
-
     // just stop the notify
     AlarmClockModel::GetInstance()->AlarmPlayerStop();
     if (CallerLogModel::GetInstance()->GetNotifyFlag() == true) {
         NotificationManager::GetInstance()->StopNotify();
+        addcalllog();
     }
 
 
index 0882016..6f77075 100755 (executable)
@@ -137,8 +137,12 @@ void addcalllog()
     info.status=CALL_INCOMING;
     if(call_stat==2)
     info.status=CALL_MISSED;
-
-    AddToCallLog(&info);
+    if(call_stat<=2)
+    {
+        AddToCallLog(&info);
+        call_stat=3;
+    }
+     
 }
 
 //     PhoneCallInfo tmp;
@@ -197,8 +201,11 @@ void CalldialTimerCallBackProc(int data)
     if(dail_falg<=70)
     dail_falg++;
     if(dail_falg>=70)
-    NotificationManager::GetInstance()->StopNotify();
-    addcalllog();
+    {
+        NotificationManager::GetInstance()->StopNotify();
+        addcalllog();
+    }
+   
 }
 
 
@@ -758,11 +765,9 @@ UIViewGroup* CreateCalldialView(void)
         button1dial->SetViewId("dialHandUp");  // Set style
 
         // Set additional property
-#ifdef _WIN32
-        char *button1defaultImgSrc = "c:/Users/caiking/project/image_converter_tool/output/Phone/phone-off-round.bin";
-#else
+
         char *button1defaultImgSrc = "/user/res/Phone/phone-off-round.bin";
-#endif
+
         char *button1triggeredImgSrc = nullptr;
         button1dial->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc);
         button1dial->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);