修复息屏切换表情bug
authorxue <2144439972@qq.com>
Fri, 26 Sep 2025 07:20:35 +0000 (15:20 +0800)
committerxue <2144439972@qq.com>
Fri, 26 Sep 2025 07:20:35 +0000 (15:20 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdLullabyView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp

index cad401f..235b07f 100644 (file)
@@ -166,9 +166,24 @@ namespace OHOS
         // 任务提醒处理函数
         void HandleTaskReminder(const char* scheduleName);
         
+        // 角色配置更改处理函数
+        void HandleCharacterConfigChange(const char* characterId, const char* characterName, 
+                                        const char* eyesShape, const char* hairColor, 
+                                        const char* eyesColor, const char* hairStyle, 
+                                        int screenImageAsEmoji);
+        
         // 表情切换函数
         bool SwitchExpression(const char* eyeShape, const char* eyeColor);
-
+        
+        // 发型切换函数
+        bool SwitchHair(const char* hairShape, const char* hairColor);
+        
+        // 表情视频切换函数
+        bool SwitchExpressionVideo(const char* videoPath);
+        
+        // 哄睡模式处理函数
+        void HandleSleepModeStart(const char* theme);
+        void HandleSleepModeEnd();
         // 减低视频帧率
         void LowFrequence();
         // 恢复视频帧率
index a607394..bd6177e 100644 (file)
@@ -349,11 +349,13 @@ namespace OHOS
                 RemindIcon2->SetSrc("/user/res/volume_up.bin");
                 RemindIcon2->SetVisible(true);
             }
+            
             break;
         }
         case THUNDERBIRD_LULLABYVIEW_4:
         {
-            ThunderBirdModel::GetInstance()->StartCountUpTimer(15 * 60);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdLullabyView::Show: THUNDERBIRD_LULLABYVIEW_4");
+            //ThunderBirdModel::GetInstance()->StartCountUpTimer(15 * 60);
             if (TextLabel)
             {
                 TextLabel->SetPosition(0, 64, 360, 42);
@@ -373,7 +375,6 @@ namespace OHOS
             ThunderBirdLullabyView::UpdateLullabyText(ThunderBirdModel::GetInstance()->GetTextStr().c_str());
             if(RemindLabel)
             {
-                
                 RemindLabel->SetPosition(115, 114, 131, 28);
                 RemindLabel->SetText("04:00/15:00");
                 RemindLabel->SetVisible(true);
index 9752273..9d16d3c 100644 (file)
@@ -337,6 +337,7 @@ namespace OHOS
         Surface *surface = surfaceView_->GetSurface();
         if (surface == nullptr)
         {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to get surface from surfaceView_");
             return false;
         }
 
@@ -344,11 +345,19 @@ namespace OHOS
         videoPlay_ = new MediaVideoPlay(surface, nullptr, std::string(uri), true);
         if (videoPlay_ == nullptr)
         {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to create MediaVideoPlay");
             return false;
         }
         g_videoPlay = videoPlay_;
         int32_t ret = videoPlay_->StartVideoPlay();
-        return (ret == 0);
+        if (ret != 0)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Failed to start video play, ret=%d", ret);
+            return false;
+        }
+        
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Successfully switched to video: %s", uri);
+        return true;
     }
 
     void ThunderBirdMainView::CloseVideo() // 关闭表情接口
@@ -383,6 +392,7 @@ namespace OHOS
             curFace = nullptr;
         }
     }
+  
 
     // OTA界面已独立为slice,不再需要此函数
 
@@ -628,7 +638,7 @@ namespace OHOS
         curFace->SetResizeMode(UIImageView::COVER);
         curFace->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
         //curFace->SetStyle(STYLE_BACKGROUND_COLOR, 0xffe0c7c1);
-        curFace->SetSrc("/user/res/hair/curly/orange.bin");
+        curFace->SetSrc("/user/res/hair/curly-hair/orange.bin");
 
         surfaceView_ = new UILiteSurfaceView();
         if (surfaceView_ == nullptr)
@@ -656,7 +666,7 @@ namespace OHOS
         surface->SetSize(bufferSize);
         if (videoPlay_ == nullptr)
         {
-            std::string uri("/user/res/video/CloseEyes/RoundEyes/amber.mp4");
+            std::string uri("/user/res/video/CloseEyes/round-eyes/amber.mp4");
             videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, true);
             if (videoPlay_ == nullptr)
             {
index 9870c7e..4067bc0 100644 (file)
  #include "custom_runtime.h"
  #include "ln_api.h"
  #include "kv_store.h"
- #include "AppViewIDs.h"
- #include "NativeRegisterManager.h"
- #include "graphic_service_wrapper.h"
-
+ #include "power_display_service.h"
+#include "AppViewIDs.h"
+#include "NativeRegisterManager.h"
  #define JUHEPINGTAI 1
  #if JUHEPINGTAI
  #include "websocket_server_manager.h"
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Processing task reminder: %s", scheduleName);
         }
     }
+    
+    void ThunderBirdModel::HandleCharacterConfigChange(const char* characterId, const char* characterName, 
+                                                      const char* eyesShape, const char* hairColor, 
+                                                      const char* eyesColor, const char* hairStyle, 
+                                                      int screenImageAsEmoji)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleCharacterConfigChange");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  characterId: %s", characterId ? characterId : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  characterName: %s", characterName ? characterName : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  eyesShape: %s", eyesShape ? eyesShape : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  hairColor: %s", hairColor ? hairColor : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  eyesColor: %s", eyesColor ? eyesColor : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  hairStyle: %s", hairStyle ? hairStyle : "null");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "  screenImageAsEmoji: %d", screenImageAsEmoji);
+        
+        // 这里可以添加角色配置更改的具体处理逻辑
+        // 例如:
+        // 1. 更新角色外观显示
+        // 2. 保存角色配置到本地存储
+        // 3. 通知UI更新角色显示
+        // 4. 如果screenImageAsEmoji为true,可能需要更新表情显示
+        
+        // 示例:调用表情切换功能
+        if (eyesShape && eyesColor) {
+            SwitchExpression(eyesShape, eyesColor);
+        }
+        
+        // 切换发型功能
+        if (hairStyle && hairColor) {
+            SwitchHair(hairStyle, hairColor);
+        }
+
+        // SaveCharacterConfig(characterId, characterName, eyesShape, hairColor, eyesColor, hairStyle, screenImageAsEmoji);
+    }
+    
     bool ThunderBirdModel::SwitchExpression(const char* eyeShape, const char* eyeColor)
    {
        // 参数验证
        if (eyeShape == nullptr || eyeColor == nullptr) {
+           WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchExpression: invalid parameters");
            return false;
        }
        
+       // 检查屏幕状态,如果息屏则自动亮屏
+           uapi_set_screen_on_api(); // 亮屏
+       
        // 构建表情文件路径:/user/res/video/CloseEyes/{eyeShape}/{eyeColor}.mp4
        std::string expressionPath = "/user/res/video/CloseEyes/";
        expressionPath += eyeShape;
        expressionPath += "/";
        expressionPath += eyeColor;
        expressionPath += ".mp4";
-       
+ 
+       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchExpression: switching to %s", expressionPath.c_str());
        // 通过图形服务调用 ThunderBirdMainView 的 SwitchVideo 函数
-       bool result = false;
+       // 注意:PostGraphicEvent 是异步的,这里直接返回 true 表示调用已提交
        GraphicService::GetInstance()->PostGraphicEvent(
-           [expressionPath, &result]() {
+           [expressionPath]() {
                if (ThunderBirdMainView::GetInstance()) {
-                   result = ThunderBirdMainView::GetInstance()->SwitchVideo(expressionPath.c_str());
+                   ThunderBirdMainView::GetInstance()->SwitchVideo(expressionPath.c_str());
+               } else {
+                   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchExpression: ThunderBirdMainView instance is null");
                }
            });
        
-       return result;
+       return true; // 异步调用,返回 true 表示调用已提交
    }
 
-   //减低视频帧率 开启对话调用开启
+    bool ThunderBirdModel::SwitchExpressionVideo(const char* videoPath)
+    {
+        // 参数验证
+        if (videoPath == nullptr) {
+            return false;
+        }
+        
+        // 通过图形服务调用 ThunderBirdMainView 的 SwitchVideo 函数
+        // 注意:PostGraphicEvent 是异步的,这里直接返回 true 表示调用已提交
+        GraphicService::GetInstance()->PostGraphicEvent(
+            [videoPath]() {
+                if (ThunderBirdMainView::GetInstance()) {
+                    ThunderBirdMainView::GetInstance()->SwitchVideo(videoPath);
+                }
+            });
+        
+        return true; // 异步调用,返回 true 表示调用已提交
+    }
+    //切换发型
+    bool ThunderBirdModel::SwitchHair(const char* hairShape, const char* hairColor)
+     {
+         // 参数验证
+         if (hairShape == nullptr || hairColor == nullptr) {
+             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchHair: invalid parameters");
+             return false;
+         }
+         
+         // 检查屏幕状态,如果息屏则自动亮屏
+             uapi_set_screen_on_api(); // 亮屏
+         
+         // 构建发型文件路径:/user/res/hair/{hairShape}/{hairColor}.bin
+         std::string hairPath = "/user/res/hair/";
+         hairPath += hairShape;
+         hairPath += "/";
+         hairPath += hairColor;
+         hairPath += ".bin";
+         
+         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchHair: switching to %s", hairPath.c_str());
+         
+         // 通过图形服务调用 ThunderBirdMainView 的 SwitchHair 函数
+         // 注意:PostGraphicEvent 是异步的,这里直接返回 true 表示调用已提交
+         GraphicService::GetInstance()->PostGraphicEvent(
+             [hairPath]() {
+                 if (ThunderBirdMainView::GetInstance()) {
+                     ThunderBirdMainView::GetInstance()->SwitchHair(hairPath.c_str());
+                 } else {
+                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::SwitchHair: ThunderBirdMainView instance is null");
+                 }
+             });
+         return true; // 异步调用,返回 true 表示调用已提交
+     }
+
+    void ThunderBirdModel::HandleSleepModeStart(const char* theme)
+    {
+        int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); //获取当前视图
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleSleepModeStart");
+        ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_2);
+    }
+
+    void ThunderBirdModel::HandleSleepModeEnd()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleSleepModeEnd");
+        int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); //获取当前视图
+        ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_LULLABYVIEW, ThunderBirdLullabyView::THUNDERBIRD_LULLABYVIEW_5);
+    }
+    //减低视频帧率 开启对话调用开启
    void ThunderBirdModel::LowFrequence()
    {
        SetFrequence(LOW_FREQUENCE);
    {
        return m_currentFps;
    }
- }
+
+
+}
  
\ No newline at end of file