修复密码锁不失效的问题
authorCaisking <Casiking@zhihuishixun.com>
Mon, 13 Oct 2025 02:50:11 +0000 (10:50 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 13 Oct 2025 02:50:11 +0000 (10:50 +0800)
code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockModel.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/codedlock/include/CodedLockModel.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/codedlock/src/CodedLockView.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/codedlock/include/CodedLockModel.h
code/sdk/application/wearable/n9/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/codedlock/src/CodedLockView.cpp
code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.h
code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp

index ff260ae..3399467 100644 (file)
@@ -4,60 +4,66 @@
  * @LastEditTime: 2024-08-28 18:32:09
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockModel.h
  */
-#ifndef CODEDLOCKMODEL_H
-#define CODEDLOCKMODEL_H
-
-#include <string>
-#include <memory>
-#include <cmath>
-#include <vector>
-#include <queue>
-#include <iostream>
-#include <unordered_map>
-
-namespace OHOS
-{
-    class CodedLockModel
-    {
-    public:
-        // 获取单例实例
-        static CodedLockModel *GetInstance(void);
-        // 添加数字到密码
-        void SetNumToPassword(const int num);
-        // 清空密码字符串
-        void ClearPassword();
-        // 删除密码字符串
-        void DeleteLastDigit();
-        // 获取当前密码字符串
-        std::string GetPassword() const;
-        std::string GetInputPassword() const;
-        // 匹配是否成功
-        bool IsPasswordMatch();
-        bool IsLockState();
-        void ResetLockState();
-        // 获取已经点击个数
-        uint8_t GetPointNum();
-        //配置已经点击的个数
-        void SetPointNum(uint8_t num);
-        // 配置用户密码
-        void SetUserPassWord(const std::string &password);
-        // ble进行解锁
-        void BleUnlock();
-
-    private:
-        CodedLockModel();
-        CodedLockModel(const CodedLockModel &);
-        CodedLockModel &operator=(const CodedLockModel &);
-        virtual ~CodedLockModel();
-
-        static const int PASSWORDNUM = 6;
-
-        std::string userpassword_ = "123456"; // 用于存储用户密码
-        std::string inputpassword_;           // 用于存储输入密码
-
-        uint8_t passcount{0};
-        bool lockstate{false};
-    };
-}
-
-#endif // CODEDLOCKMODEL_H
\ No newline at end of file
+ #ifndef CODEDLOCKMODEL_H
+ #define CODEDLOCKMODEL_H
+ 
+ #include <string>
+ #include <memory>
+ #include <cmath>
+ #include <vector>
+ #include <queue>
+ #include <iostream>
+ #include <unordered_map>
+ #include "bleInstruct.h"
+ 
+ namespace OHOS
+ {
+ 
+     #ifdef BLE_INSTRUCT
+     extern "C" void ble_codedlock_init(void);
+     #endif
+ 
+     class CodedLockModel
+     {
+     public:
+         // 获取单例实例
+         static CodedLockModel *GetInstance(void);
+         // 添加数字到密码
+         void SetNumToPassword(const int num);
+         // 清空密码字符串
+         void ClearPassword();
+         // 删除密码字符串
+         void DeleteLastDigit();
+         // 获取当前密码字符串
+         std::string GetPassword() const;
+         std::string GetInputPassword() const;
+         // 匹配是否成功
+         bool IsPasswordMatch();
+         bool IsLockState();
+         void ResetLockState();
+         // 获取已经点击个数
+         uint8_t GetPointNum();
+         //配置已经点击的个数
+         void SetPointNum(uint8_t num);
+         // 配置用户密码
+         void SetUserPassWord(const std::string &password);
+         // ble进行解锁
+         void BleUnlock();
+ 
+     private:
+         CodedLockModel();
+         CodedLockModel(const CodedLockModel &);
+         CodedLockModel &operator=(const CodedLockModel &);
+         virtual ~CodedLockModel();
+ 
+         static const int PASSWORDNUM = 6;
+ 
+         std::string userpassword_ = "123456"; // 用于存储用户密码
+         std::string inputpassword_;           // 用于存储输入密码
+ 
+         uint8_t passcount{0};
+         bool lockstate{false};
+     };
+ }
+ 
+ #endif // CODEDLOCKMODEL_H
\ No newline at end of file
index 5f3f43c..7371f00 100644 (file)
 #include "codedlock/include/CodedLockModel.h"
-#include "main/include/MainViewSample.h"
-#include "codedlock/include/CodedLockView.h"
-#include <cctype>
-#include <algorithm>
-#include "wearable_log.h"
-#include "string.h"
 #include "ConfigModel.h"
+#include "codedlock/include/CodedLockView.h"
 #include "custom_utils.h"
+#include "main/include/MainViewSample.h"
+#include "string.h"
+#include "wearable_log.h"
+#include <algorithm>
+#include <cctype>
+#include "graphic_service.h"
+
+
 extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status);
-namespace OHOS
-{
-    /**
-     * @brief 初始化用户密码和输入密码
-     */
-    CodedLockModel::CodedLockModel()
-    {
-        std::string password = ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
-
-        if (!password.empty())
-        {
-            userpassword_ = password; // 从配置中获取用户密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s", userpassword_.c_str());
-        }
-        else
-        {
-            userpassword_ = "000000"; // 默认密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
-        }
-
-        lockstate = false; // 锁定状态初始化为未锁
-        passcount = 0;     // 输入计数初始化为0
-
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "初始化完成: lockstate: %d passcount: %d ", lockstate, passcount);
-    }
+namespace OHOS {
+/**
+ * @brief 初始化用户密码和输入密码
+ */
+CodedLockModel::CodedLockModel() {
+  std::string password = ConfigModel::GetInstance()->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
 
-    /**
-     * @brief 析构函数
-     */
-    CodedLockModel::~CodedLockModel() {}
-
-    /**
-     * @brief 获取单例实例
-     * @return CodedLockModel* 指向单例的指针
-     */
-    CodedLockModel *CodedLockModel::GetInstance()
-    {
-        static CodedLockModel instance;
-        return &instance;
-    }
+  if (!password.empty()) {
+    userpassword_ = password; // 从配置中获取用户密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s",
+                  userpassword_.c_str());
+  } else {
+    userpassword_ = "000000"; // 默认密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
+  }
 
-    // ================== 密码设置和验证 ==================
-
-    /**
-     * @brief 设置当前输入密码
-     * @param num 输入的数字
-     */
-    void CodedLockModel::SetNumToPassword(const int num)
-    {
-        if (num < 0 || num > 9)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
-            return; // 处理无效输入
-        }
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
-
-        passcount++;
-        inputpassword_ += std::to_string(num);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ", inputpassword_.c_str(),passcount);
-
-        /*
-            检查当前输入密码的长度 等于6个 会进行清除 
-            但是不设置passcount==0 
-            我需要传一个6过去显示 然后过一秒再配置0
-        */
-        if (passcount >= PASSWORDNUM)
-        {
-            if (IsPasswordMatch())
-            {
-                lockstate = true; // 匹配成功,开锁
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
-            }
-            else
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
-            }
-
-            // passcount = 0;   // 重置输入计数
-            ClearPassword(); // 清空输入密码
-        }
-    }
+  lockstate = false; // 锁定状态初始化为未锁
+  passcount = 0;     // 输入计数初始化为0
 
-    /**
-     * @brief 判断输入的密码与当前密码是否匹配
-     * @return true 匹配成功
-     * @return false 匹配失败
-     */
-    bool CodedLockModel::IsPasswordMatch()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
-        bool isMatch = (inputpassword_ == userpassword_);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s", isMatch ? "匹配成功" : "不匹配");
-        return isMatch;
-    }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                "初始化完成: lockstate: %d passcount: %d ", lockstate,
+                passcount);
+}
 
-    /**
-     * @brief 获取当前锁定状态
-     * @return true 当前为锁定状态
-     * @return false 当前为解锁状态
-     */
-    bool CodedLockModel::IsLockState()
-    {
-        return lockstate;
-    }
+/**
+ * @brief 析构函数
+ */
+CodedLockModel::~CodedLockModel() {}
 
-    /**
-     * @brief 重置锁定状态
-     */
-    void CodedLockModel::ResetLockState()
-    {
-        lockstate = false;
-    }
+/**
+ * @brief 获取单例实例
+ * @return CodedLockModel* 指向单例的指针
+ */
+CodedLockModel *CodedLockModel::GetInstance() {
+  static CodedLockModel instance;
+  return &instance;
+}
 
-    /**
-     * @brief 获取当前输入的数字个数
-     * @return uint8_t 当前输入的数字个数
-     */
-    uint8_t CodedLockModel::GetPointNum()
-    {
-        return passcount;
-    }
+// ================== 密码设置和验证 ==================
 
-    /**
-     * @brief 设置当前输入的数字个数
-     * @param uint8_t 当前输入的数字个数
-     */
-    void CodedLockModel::SetPointNum(uint8_t num)
-    {
-        passcount = num;
-    }
+/**
+ * @brief 设置当前输入密码
+ * @param num 输入的数字
+ */
+void CodedLockModel::SetNumToPassword(const int num) {
+  if (num < 0 || num > 9) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
+    return; // 处理无效输入
+  }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
 
-    // ================== 输入密码管理 ==================
-
-    /**
-     * @brief 删除最后一个输入的数字
-     */
-    void CodedLockModel::DeleteLastDigit()
-    {
-        if (!inputpassword_.empty())
-        {
-            inputpassword_.pop_back(); // 删除最后一个字符
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
-        }
-    }
+  passcount++;
+  inputpassword_ += std::to_string(num);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ",
+                inputpassword_.c_str(), passcount);
 
-    /**
-     * @brief 清空输入密码
-     */
-    void CodedLockModel::ClearPassword()
-    {
-        inputpassword_.clear(); // 清空输入密码
+  /*
+      检查当前输入密码的长度 等于6个 会进行清除
+      但是不设置passcount==0
+      我需要传一个6过去显示 然后过一秒再配置0
+  */
+  if (passcount >= PASSWORDNUM) {
+    if (IsPasswordMatch()) {
+      lockstate = true; // 匹配成功,开锁
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
     }
 
-    // ================== 密码获取与更新 ==================
+    // passcount = 0;   // 重置输入计数
+    ClearPassword(); // 清空输入密码
+  }
+}
 
-    /**
-     * @brief 获取当前用户密码
-     * @return std::string 当前用户密码字符串
-     */
-    std::string CodedLockModel::GetPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
-        return userpassword_;
-    }
+/**
+ * @brief 判断输入的密码与当前密码是否匹配
+ * @return true 匹配成功
+ * @return false 匹配失败
+ */
+bool CodedLockModel::IsPasswordMatch() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
+  bool isMatch = (inputpassword_ == userpassword_);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s",
+                isMatch ? "匹配成功" : "不匹配");
+  return isMatch;
+}
 
-    /**
-     * @brief 获取当前输入的密码
-     * @return std::string 当前输入的密码字符串
-     */
-    std::string CodedLockModel::GetInputPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s", inputpassword_.c_str());
-        return inputpassword_;
-    }
+/**
+ * @brief 获取当前锁定状态
+ * @return true 当前为锁定状态
+ * @return false 当前为解锁状态
+ */
+bool CodedLockModel::IsLockState() { return lockstate; }
 
-    /**
-     * @brief 更新用户密码
-     * @param password 新密码
-     */
-    void CodedLockModel::SetUserPassWord(const std::string &password)
-    {
-        if (!password.empty())
-        {
-            userpassword_ = password; // 直接赋值
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
-        }
-    }
+/**
+ * @brief 重置锁定状态
+ */
+void CodedLockModel::ResetLockState() { lockstate = false; }
 
-    /**
-     * @brief 更新用户状态
-     */
-    void CodedLockModel::BleUnlock()
-    {
-        // 先进行解锁
-        uapi_dev_runtime_set_lock_status(0);
-        /*设置表盘状态*/
-        MainModel::GetInstance().setDialState(DialState::LOCK, false);
-
-        // 获取当前活动视图的实例
-        auto mainViewInstance = MainViewSample::GetInstance();
-        auto codedLockViewInstance = CodedLockView::GetInstance();
-
-        // 如果是在主界面或密码锁界面,重新进入主界面
-        if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
-            uapi_set_screen_on_api(); // 亮屏
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-        }
-    }
+/**
+ * @brief 获取当前输入的数字个数
+ * @return uint8_t 当前输入的数字个数
+ */
+uint8_t CodedLockModel::GetPointNum() { return passcount; }
+
+/**
+ * @brief 设置当前输入的数字个数
+ * @param uint8_t 当前输入的数字个数
+ */
+void CodedLockModel::SetPointNum(uint8_t num) { passcount = num; }
+
+// ================== 输入密码管理 ==================
+
+/**
+ * @brief 删除最后一个输入的数字
+ */
+void CodedLockModel::DeleteLastDigit() {
+  if (!inputpassword_.empty()) {
+    inputpassword_.pop_back(); // 删除最后一个字符
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
+  }
+}
+
+/**
+ * @brief 清空输入密码
+ */
+void CodedLockModel::ClearPassword() {
+  inputpassword_.clear(); // 清空输入密码
+}
+
+// ================== 密码获取与更新 ==================
+
+/**
+ * @brief 获取当前用户密码
+ * @return std::string 当前用户密码字符串
+ */
+std::string CodedLockModel::GetPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
+  return userpassword_;
+}
+
+/**
+ * @brief 获取当前输入的密码
+ * @return std::string 当前输入的密码字符串
+ */
+std::string CodedLockModel::GetInputPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s",
+                inputpassword_.c_str());
+  return inputpassword_;
+}
+
+/**
+ * @brief 更新用户密码
+ * @param password 新密码
+ */
+void CodedLockModel::SetUserPassWord(const std::string &password) {
+  if (!password.empty()) {
+    userpassword_ = password; // 直接赋值
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
+  }
+}
+
+/**
+ * @brief 更新用户状态
+ */
+void CodedLockModel::BleUnlock() {
+  // 先进行解锁
+  uapi_dev_runtime_set_lock_status(0);
+  /*设置表盘状态*/
+  MainModel::GetInstance().setDialState(DialState::LOCK, false);
+
+  // 获取当前活动视图的实例
+  auto mainViewInstance = MainViewSample::GetInstance();
+  auto codedLockViewInstance = CodedLockView::GetInstance();
+
+  // 如果是在主界面或密码锁界面,重新进入主界面
+  if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
+    uapi_set_screen_on_api(); // 亮屏
+    NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+  }
+}
+
+#ifdef BLE_INSTRUCT
+
+#include "bleEvent.h"
+#include "bleInstruct.h"
+
+//////////////////////////////ble////////////////////////////////////////////
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+void ble_set_password_(uint8_t falg, char *data) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  p_ConfigModel->set_condigData_Int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH, falg);
+  p_ConfigModel->set_condigData_String(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD, data);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "设置手表密码 %d %s \r\n", falg, data);
+
+  /*更新model密码配置*/
+  if (falg == 0) {
+    //更新手表状态
+    GraphicService::GetInstance()->PostGraphicEvent(std::bind(
+        &OHOS::CodedLockModel::BleUnlock, OHOS::CodedLockModel::GetInstance()));
+  }
+  OHOS::CodedLockModel::GetInstance()->SetUserPassWord(data);
+
+  return;
+}
+
+uint8_t ble_get_password_(void) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  std::string str = p_ConfigModel->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
+  uint8_t falg = p_ConfigModel->get_configData_int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "获取手表密码 %d %s \r\n", falg,
+                str.c_str());
+
+  return falg;
+}
+
+extern bleInstruct_t_ bleInstruct_t;
+
+void ble_codedlock_init(void) {
+  bleInstruct_t.ble_set_password = ble_set_password_;
+  bleInstruct_t.ble_get_password = ble_get_password_;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
 
-}
\ No newline at end of file
+} // namespace OHOS
\ No newline at end of file
index a846483..f41cecb 100644 (file)
  * /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp
  */
 
-#include "codedlock/include/CodedLockView.h"
-#include "codedlock/include/CodedLockPresenter.h"
-
-#include "UiConfig.h"
-#include "common/image_cache_manager.h"
-#include "components/ui_button.h"
-#include "components/ui_scroll_view.h"
-#include "ui_resource_image.h"
-#include "ui_resource_string.h"
-#include "uicomponents/UIComponents.h"
-#include "vector"
-
-namespace OHOS {
-
-static CodedLockView *g_pCodedLockView{nullptr};
-
-static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
-
-// 定义默认颜色和激活颜色
-static const uint32_t activeColor = 0xffaaaaaa;
-static const uint32_t defaultColor = 0xff191919;
-
-#define UI_IMAGE_TEST 1
-CodedLockView::CodedLockView() { g_pCodedLockView = this; }
-
-CodedLockView::~CodedLockView() {
-  // UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(scrollView_);
-  // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
-  if (scrollView_ != nullptr) {
-   
-  if (button_one) {
-    delete button_one;
-    button_one = nullptr;
-  }
-  if (button_two) {
-    delete button_two;
-    button_two = nullptr;
-  }
-  if (button_three) {
-    delete button_three;
-    button_three = nullptr;
-  }
-  if (button_four) {
-    delete button_four;
-    button_four = nullptr;
-  }
-  if (button_five) {
-    delete button_five;
-    button_five = nullptr;
-  }
-  if (button_six) {
-    delete button_six;
-    button_six = nullptr;
-  }
-  if (button_seven) {
-    delete button_seven;
-    button_seven = nullptr;
-  }
-  if (button_eight) {
-    delete button_eight;
-    button_eight = nullptr;
-  }
-  if (button_nine) {
-    delete button_nine;
-    button_nine = nullptr;
-  }
-  if (button_zero) {
-    delete button_zero;
-    button_zero = nullptr;
-  }
-
-
-  if (point_one) {
-    delete point_one;
-    point_one = nullptr;
-  }
-  if (point_two) {
-    delete point_two;
-    point_two = nullptr;
-  }
-  if (point_three) {
-    delete point_three;
-    point_three = nullptr;
-  }
-  if (point_four) {
-    delete point_four;
-    point_four = nullptr;
-  }
-  if (point_five) {
-    delete point_five;
-    point_five = nullptr;
-  }
-  if (point_six) {
-    delete point_six;
-    point_six = nullptr;
-  }
-  scrollView_->RemoveAll();
-  delete scrollView_;
-  scrollView_ = nullptr;
-}
-  g_pCodedLockView = nullptr;
-}
-
-CodedLockView *CodedLockView::GetInstance() { return g_pCodedLockView; }
-
-void CodedLockView::InitButtonsView() {
-  // 第一行
-  InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
-  button_one->SetOnClickListener(presenter_);
-  scrollView_->Add(button_one);
-
-  InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
-  button_two->SetOnClickListener(presenter_);
-  scrollView_->Add(button_two);
-
-  InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
-  button_three->SetOnClickListener(presenter_);
-  scrollView_->Add(button_three);
-
-  // 第二行
-  InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
-  button_four->SetOnClickListener(presenter_);
-  scrollView_->Add(button_four);
-
-  InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
-  button_five->SetOnClickListener(presenter_);
-  scrollView_->Add(button_five);
-
-  InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
-  button_six->SetOnClickListener(presenter_);
-  scrollView_->Add(button_six);
-
-  // 第三行
-  InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
-  button_seven->SetOnClickListener(presenter_);
-  scrollView_->Add(button_seven);
-
-  InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
-  button_eight->SetOnClickListener(presenter_);
-  scrollView_->Add(button_eight);
-
-  InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
-  button_nine->SetOnClickListener(presenter_);
-  scrollView_->Add(button_nine);
-
-  // 第四行 (0)
-  InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
-  button_zero->SetOnClickListener(presenter_);
-  scrollView_->Add(button_zero);
-
-  // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ",
-  // 40); button_delete->SetOnClickListener(presenter_);
-  // scrollView_->Add(button_delete);
-}
-void CodedLockView::InitImagesView() {
-  std::vector<PointConfig> points = {
-      {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
-      {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
-      {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
-      {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
-      {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
-      {&point_six, 310, 55, "image1", defaultColor, 0xff, 100},
-  };
-
-  for (const auto &config : points) {
-    InitializePoint(config.imageView, config.x, config.y,
-                    (config.viewId).c_str(), config.backgroundColor,
-                    config.backgroundOpa, config.borderRadius);
-  }
-}
-
-void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y,
-                                    const char *viewId,
-                                    uint32_t backgroundColor,
-                                    uint8_t backgroundOpa, int borderRadius) {
-  if (*imageView == nullptr) {
-    *imageView = new UIImageView();
-  }
-
-  (*imageView)->SetPosition(x, y);
-  (*imageView)->Resize(20, 20);
-  (*imageView)->SetViewId(viewId);
-  (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
-  (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
-  (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
-
-  scrollView_->Add(*imageView);
-}
-void CodedLockView::UpdatePointShow(int num) {
-
-  if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
-      point_four == nullptr || point_five == nullptr || point_six == nullptr)
-    return;
-
-  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
-
-#if UI_IMAGE_TEST
-  switch (num) {
-  case 0:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 1:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 2:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 3:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 4:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 5:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 6:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    break;
-  default:
-    break;
-  }
-#else
-  // 更新所有点的颜色
-  for (int i = 1; i <= 6; ++i) {
-    UIImageView *point = nullptr;
-    switch (i) {
-    case 1:
-      point = point_one;
-      break;
-    case 2:
-      point = point_two;
-      break;
-    case 3:
-      point = point_three;
-      break;
-    case 4:
-      point = point_four;
-      break;
-    case 5:
-      point = point_five;
-      break;
-    case 6:
-      point = point_six;
-      break;
-    default:
-      continue;
-    }
-
-    if (point != nullptr) {
-      if (i <= num) {
-        // 如果是前 num 个点,则设置为激活颜色
-        point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-      } else {
-        // 其他点设置为默认颜色
-        point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-      }
-    }
-  }
-#endif
-  /*ui刷新*/
-  point_one->Invalidate();
-  point_two->Invalidate();
-  point_three->Invalidate();
-  point_four->Invalidate();
-  point_five->Invalidate();
-  point_six->Invalidate();
-}
-
-void CodedLockView::OnStart() {
-  View<CodedLockPresenter>::OnStart();
-
-  scrollView_ = new UIScrollView();
-  if (scrollView_ == nullptr) {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView_ new fail");
-    return;
-  }
-  scrollView_->SetScrollBlankSize(35);
-  scrollView_->SetReboundSize(50);
-  scrollView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
-                          Screen::GetInstance().GetHeight());
-
-  scrollView_->SetTouchable(false);
-  scrollView_->SetDraggable(false);
-  scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
-  scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
-
-  InitButtonsView();
-  InitImagesView();
-
-  AddViewToRootContainer(scrollView_);
-}
-
-} // namespace OHOS
+ #include "codedlock/include/CodedLockView.h"
+ #include "codedlock/include/CodedLockPresenter.h"
+ 
+ #include "UiConfig.h"
+ #include "common/image_cache_manager.h"
+ #include "components/ui_button.h"
+ #include "components/ui_scroll_view.h"
+ #include "ui_resource_image.h"
+ #include "ui_resource_string.h"
+ #include "uicomponents/UIComponents.h"
+ #include "vector"
+ 
+ namespace OHOS {
+ 
+ static CodedLockView *g_pCodedLockView{nullptr};
+ 
+ static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
+ 
+ // 定义默认颜色和激活颜色
+ static const uint32_t activeColor = 0xffaaaaaa;
+ static const uint32_t defaultColor = 0xff191919;
+ 
+ #define UI_IMAGE_TEST 1
+ CodedLockView::CodedLockView() { g_pCodedLockView = this; }
+ 
+ CodedLockView::~CodedLockView() {
+   if (scrollView_ != nullptr) {
+   scrollView_->RemoveAll();
+   if (button_one) {
+     delete button_one;
+     button_one = nullptr;
+   }
+   if (button_two) {
+     delete button_two;
+     button_two = nullptr;
+   }
+   if (button_three) {
+     delete button_three;
+     button_three = nullptr;
+   }
+   if (button_four) {
+     delete button_four;
+     button_four = nullptr;
+   }
+   if (button_five) {
+     delete button_five;
+     button_five = nullptr;
+   }
+   if (button_six) {
+     delete button_six;
+     button_six = nullptr;
+   }
+   if (button_seven) {
+     delete button_seven;
+     button_seven = nullptr;
+   }
+   if (button_eight) {
+     delete button_eight;
+     button_eight = nullptr;
+   }
+   if (button_nine) {
+     delete button_nine;
+     button_nine = nullptr;
+   }
+   if (button_zero) {
+     delete button_zero;
+     button_zero = nullptr;
+   }
+   if (point_one) {
+     delete point_one;
+     point_one = nullptr;
+   }
+   if (point_two) {
+     delete point_two;
+     point_two = nullptr;
+   }
+   if (point_three) {
+     delete point_three;
+     point_three = nullptr;
+   }
+   if (point_four) {
+     delete point_four;
+     point_four = nullptr;
+   }
+   if (point_five) {
+     delete point_five;
+     point_five = nullptr;
+   }
+   if (point_six) {
+     delete point_six;
+     point_six = nullptr;
+   }
+   delete scrollView_;
+   scrollView_ = nullptr;
+ }
+   g_pCodedLockView = nullptr;
+ }
+ 
+ CodedLockView *CodedLockView::GetInstance() { return g_pCodedLockView; }
+ 
+ void CodedLockView::InitButtonsView() {
+   // 第一行
+   InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
+   button_one->SetOnClickListener(presenter_);
+   scrollView_->Add(button_one);
+ 
+   InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
+   button_two->SetOnClickListener(presenter_);
+   scrollView_->Add(button_two);
+ 
+   InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
+   button_three->SetOnClickListener(presenter_);
+   scrollView_->Add(button_three);
+ 
+   // 第二行
+   InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
+   button_four->SetOnClickListener(presenter_);
+   scrollView_->Add(button_four);
+ 
+   InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
+   button_five->SetOnClickListener(presenter_);
+   scrollView_->Add(button_five);
+ 
+   InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
+   button_six->SetOnClickListener(presenter_);
+   scrollView_->Add(button_six);
+ 
+   // 第三行
+   InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
+   button_seven->SetOnClickListener(presenter_);
+   scrollView_->Add(button_seven);
+ 
+   InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
+   button_eight->SetOnClickListener(presenter_);
+   scrollView_->Add(button_eight);
+ 
+   InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
+   button_nine->SetOnClickListener(presenter_);
+   scrollView_->Add(button_nine);
+ 
+   // 第四行 (0)
+   InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
+   button_zero->SetOnClickListener(presenter_);
+   scrollView_->Add(button_zero);
+ 
+   // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ",
+   // 40); button_delete->SetOnClickListener(presenter_);
+   // scrollView_->Add(button_delete);
+ }
+ void CodedLockView::InitImagesView() {
+   std::vector<PointConfig> points = {
+       {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
+       {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
+       {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
+       {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
+       {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
+       {&point_six, 310, 55, "image1", defaultColor, 0xff, 100}, 
+   };
+ 
+   for (const auto &config : points) {
+     InitializePoint(config.imageView, config.x, config.y,
+                     (config.viewId).c_str(), config.backgroundColor,
+                     config.backgroundOpa, config.borderRadius);
+   }
+ }
+ 
+ void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y,
+                                     const char *viewId,
+                                     uint32_t backgroundColor,
+                                     uint8_t backgroundOpa, int borderRadius) {
+   if (*imageView == nullptr) {
+     *imageView = new UIImageView();
+   }
+ 
+   (*imageView)->SetPosition(x, y);
+   (*imageView)->Resize(20, 20);
+   (*imageView)->SetViewId(viewId);
+   (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
+   (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
+   (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
+ 
+   scrollView_->Add(*imageView);
+ }
+ void CodedLockView::UpdatePointShow(int num) {
+ 
+   if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
+       point_four == nullptr || point_five == nullptr || point_six == nullptr)
+     return;
+ 
+   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
+ 
+ #if UI_IMAGE_TEST
+   switch (num) {
+   case 0:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 1:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 2:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 3:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 4:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 5:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 6:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     break;
+   default:
+     break;
+   }
+ #else
+   // 更新所有点的颜色
+   for (int i = 1; i <= 6; ++i) {
+     UIImageView *point = nullptr;
+     switch (i) {
+     case 1:
+       point = point_one;
+       break;
+     case 2:
+       point = point_two;
+       break;
+     case 3:
+       point = point_three;
+       break;
+     case 4:
+       point = point_four;
+       break;
+     case 5:
+       point = point_five;
+       break;
+     case 6:
+       point = point_six;
+       break;
+     default:
+       continue;
+     }
+ 
+     if (point != nullptr) {
+       if (i <= num) {
+         // 如果是前 num 个点,则设置为激活颜色
+         point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+       } else {
+         // 其他点设置为默认颜色
+         point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+       }
+     }
+   }
+ #endif
+   /*ui刷新*/
+   point_one->Invalidate();
+   point_two->Invalidate();
+   point_three->Invalidate();
+   point_four->Invalidate();
+   point_five->Invalidate();
+   point_six->Invalidate();
+ }
+ 
+ void CodedLockView::OnStart() {
+   View<CodedLockPresenter>::OnStart();
+ 
+   scrollView_ = new UIScrollView();
+   if (scrollView_ == nullptr) {
+     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView_ new fail");
+     return;
+   }
+   scrollView_->SetScrollBlankSize(35);
+   scrollView_->SetReboundSize(50);
+   scrollView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+                           Screen::GetInstance().GetHeight());
+ 
+   scrollView_->SetTouchable(false);
+   scrollView_->SetDraggable(false);
+   scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+   scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ 
+   InitButtonsView();
+   InitImagesView();
+ 
+   AddViewToRootContainer(scrollView_);
+ }
+ 
+ } // namespace OHOS
+ 
\ No newline at end of file
index ff260ae..3399467 100644 (file)
@@ -4,60 +4,66 @@
  * @LastEditTime: 2024-08-28 18:32:09
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockModel.h
  */
-#ifndef CODEDLOCKMODEL_H
-#define CODEDLOCKMODEL_H
-
-#include <string>
-#include <memory>
-#include <cmath>
-#include <vector>
-#include <queue>
-#include <iostream>
-#include <unordered_map>
-
-namespace OHOS
-{
-    class CodedLockModel
-    {
-    public:
-        // 获取单例实例
-        static CodedLockModel *GetInstance(void);
-        // 添加数字到密码
-        void SetNumToPassword(const int num);
-        // 清空密码字符串
-        void ClearPassword();
-        // 删除密码字符串
-        void DeleteLastDigit();
-        // 获取当前密码字符串
-        std::string GetPassword() const;
-        std::string GetInputPassword() const;
-        // 匹配是否成功
-        bool IsPasswordMatch();
-        bool IsLockState();
-        void ResetLockState();
-        // 获取已经点击个数
-        uint8_t GetPointNum();
-        //配置已经点击的个数
-        void SetPointNum(uint8_t num);
-        // 配置用户密码
-        void SetUserPassWord(const std::string &password);
-        // ble进行解锁
-        void BleUnlock();
-
-    private:
-        CodedLockModel();
-        CodedLockModel(const CodedLockModel &);
-        CodedLockModel &operator=(const CodedLockModel &);
-        virtual ~CodedLockModel();
-
-        static const int PASSWORDNUM = 6;
-
-        std::string userpassword_ = "123456"; // 用于存储用户密码
-        std::string inputpassword_;           // 用于存储输入密码
-
-        uint8_t passcount{0};
-        bool lockstate{false};
-    };
-}
-
-#endif // CODEDLOCKMODEL_H
\ No newline at end of file
+ #ifndef CODEDLOCKMODEL_H
+ #define CODEDLOCKMODEL_H
+ 
+ #include <string>
+ #include <memory>
+ #include <cmath>
+ #include <vector>
+ #include <queue>
+ #include <iostream>
+ #include <unordered_map>
+ #include "bleInstruct.h"
+ 
+ namespace OHOS
+ {
+ 
+     #ifdef BLE_INSTRUCT
+     extern "C" void ble_codedlock_init(void);
+     #endif
+ 
+     class CodedLockModel
+     {
+     public:
+         // 获取单例实例
+         static CodedLockModel *GetInstance(void);
+         // 添加数字到密码
+         void SetNumToPassword(const int num);
+         // 清空密码字符串
+         void ClearPassword();
+         // 删除密码字符串
+         void DeleteLastDigit();
+         // 获取当前密码字符串
+         std::string GetPassword() const;
+         std::string GetInputPassword() const;
+         // 匹配是否成功
+         bool IsPasswordMatch();
+         bool IsLockState();
+         void ResetLockState();
+         // 获取已经点击个数
+         uint8_t GetPointNum();
+         //配置已经点击的个数
+         void SetPointNum(uint8_t num);
+         // 配置用户密码
+         void SetUserPassWord(const std::string &password);
+         // ble进行解锁
+         void BleUnlock();
+ 
+     private:
+         CodedLockModel();
+         CodedLockModel(const CodedLockModel &);
+         CodedLockModel &operator=(const CodedLockModel &);
+         virtual ~CodedLockModel();
+ 
+         static const int PASSWORDNUM = 6;
+ 
+         std::string userpassword_ = "123456"; // 用于存储用户密码
+         std::string inputpassword_;           // 用于存储输入密码
+ 
+         uint8_t passcount{0};
+         bool lockstate{false};
+     };
+ }
+ 
+ #endif // CODEDLOCKMODEL_H
\ No newline at end of file
index 5f3f43c..7371f00 100644 (file)
 #include "codedlock/include/CodedLockModel.h"
-#include "main/include/MainViewSample.h"
-#include "codedlock/include/CodedLockView.h"
-#include <cctype>
-#include <algorithm>
-#include "wearable_log.h"
-#include "string.h"
 #include "ConfigModel.h"
+#include "codedlock/include/CodedLockView.h"
 #include "custom_utils.h"
+#include "main/include/MainViewSample.h"
+#include "string.h"
+#include "wearable_log.h"
+#include <algorithm>
+#include <cctype>
+#include "graphic_service.h"
+
+
 extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status);
-namespace OHOS
-{
-    /**
-     * @brief 初始化用户密码和输入密码
-     */
-    CodedLockModel::CodedLockModel()
-    {
-        std::string password = ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
-
-        if (!password.empty())
-        {
-            userpassword_ = password; // 从配置中获取用户密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s", userpassword_.c_str());
-        }
-        else
-        {
-            userpassword_ = "000000"; // 默认密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
-        }
-
-        lockstate = false; // 锁定状态初始化为未锁
-        passcount = 0;     // 输入计数初始化为0
-
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "初始化完成: lockstate: %d passcount: %d ", lockstate, passcount);
-    }
+namespace OHOS {
+/**
+ * @brief 初始化用户密码和输入密码
+ */
+CodedLockModel::CodedLockModel() {
+  std::string password = ConfigModel::GetInstance()->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
 
-    /**
-     * @brief 析构函数
-     */
-    CodedLockModel::~CodedLockModel() {}
-
-    /**
-     * @brief 获取单例实例
-     * @return CodedLockModel* 指向单例的指针
-     */
-    CodedLockModel *CodedLockModel::GetInstance()
-    {
-        static CodedLockModel instance;
-        return &instance;
-    }
+  if (!password.empty()) {
+    userpassword_ = password; // 从配置中获取用户密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s",
+                  userpassword_.c_str());
+  } else {
+    userpassword_ = "000000"; // 默认密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
+  }
 
-    // ================== 密码设置和验证 ==================
-
-    /**
-     * @brief 设置当前输入密码
-     * @param num 输入的数字
-     */
-    void CodedLockModel::SetNumToPassword(const int num)
-    {
-        if (num < 0 || num > 9)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
-            return; // 处理无效输入
-        }
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
-
-        passcount++;
-        inputpassword_ += std::to_string(num);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ", inputpassword_.c_str(),passcount);
-
-        /*
-            检查当前输入密码的长度 等于6个 会进行清除 
-            但是不设置passcount==0 
-            我需要传一个6过去显示 然后过一秒再配置0
-        */
-        if (passcount >= PASSWORDNUM)
-        {
-            if (IsPasswordMatch())
-            {
-                lockstate = true; // 匹配成功,开锁
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
-            }
-            else
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
-            }
-
-            // passcount = 0;   // 重置输入计数
-            ClearPassword(); // 清空输入密码
-        }
-    }
+  lockstate = false; // 锁定状态初始化为未锁
+  passcount = 0;     // 输入计数初始化为0
 
-    /**
-     * @brief 判断输入的密码与当前密码是否匹配
-     * @return true 匹配成功
-     * @return false 匹配失败
-     */
-    bool CodedLockModel::IsPasswordMatch()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
-        bool isMatch = (inputpassword_ == userpassword_);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s", isMatch ? "匹配成功" : "不匹配");
-        return isMatch;
-    }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                "初始化完成: lockstate: %d passcount: %d ", lockstate,
+                passcount);
+}
 
-    /**
-     * @brief 获取当前锁定状态
-     * @return true 当前为锁定状态
-     * @return false 当前为解锁状态
-     */
-    bool CodedLockModel::IsLockState()
-    {
-        return lockstate;
-    }
+/**
+ * @brief 析构函数
+ */
+CodedLockModel::~CodedLockModel() {}
 
-    /**
-     * @brief 重置锁定状态
-     */
-    void CodedLockModel::ResetLockState()
-    {
-        lockstate = false;
-    }
+/**
+ * @brief 获取单例实例
+ * @return CodedLockModel* 指向单例的指针
+ */
+CodedLockModel *CodedLockModel::GetInstance() {
+  static CodedLockModel instance;
+  return &instance;
+}
 
-    /**
-     * @brief 获取当前输入的数字个数
-     * @return uint8_t 当前输入的数字个数
-     */
-    uint8_t CodedLockModel::GetPointNum()
-    {
-        return passcount;
-    }
+// ================== 密码设置和验证 ==================
 
-    /**
-     * @brief 设置当前输入的数字个数
-     * @param uint8_t 当前输入的数字个数
-     */
-    void CodedLockModel::SetPointNum(uint8_t num)
-    {
-        passcount = num;
-    }
+/**
+ * @brief 设置当前输入密码
+ * @param num 输入的数字
+ */
+void CodedLockModel::SetNumToPassword(const int num) {
+  if (num < 0 || num > 9) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
+    return; // 处理无效输入
+  }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
 
-    // ================== 输入密码管理 ==================
-
-    /**
-     * @brief 删除最后一个输入的数字
-     */
-    void CodedLockModel::DeleteLastDigit()
-    {
-        if (!inputpassword_.empty())
-        {
-            inputpassword_.pop_back(); // 删除最后一个字符
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
-        }
-    }
+  passcount++;
+  inputpassword_ += std::to_string(num);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ",
+                inputpassword_.c_str(), passcount);
 
-    /**
-     * @brief 清空输入密码
-     */
-    void CodedLockModel::ClearPassword()
-    {
-        inputpassword_.clear(); // 清空输入密码
+  /*
+      检查当前输入密码的长度 等于6个 会进行清除
+      但是不设置passcount==0
+      我需要传一个6过去显示 然后过一秒再配置0
+  */
+  if (passcount >= PASSWORDNUM) {
+    if (IsPasswordMatch()) {
+      lockstate = true; // 匹配成功,开锁
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
     }
 
-    // ================== 密码获取与更新 ==================
+    // passcount = 0;   // 重置输入计数
+    ClearPassword(); // 清空输入密码
+  }
+}
 
-    /**
-     * @brief 获取当前用户密码
-     * @return std::string 当前用户密码字符串
-     */
-    std::string CodedLockModel::GetPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
-        return userpassword_;
-    }
+/**
+ * @brief 判断输入的密码与当前密码是否匹配
+ * @return true 匹配成功
+ * @return false 匹配失败
+ */
+bool CodedLockModel::IsPasswordMatch() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
+  bool isMatch = (inputpassword_ == userpassword_);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s",
+                isMatch ? "匹配成功" : "不匹配");
+  return isMatch;
+}
 
-    /**
-     * @brief 获取当前输入的密码
-     * @return std::string 当前输入的密码字符串
-     */
-    std::string CodedLockModel::GetInputPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s", inputpassword_.c_str());
-        return inputpassword_;
-    }
+/**
+ * @brief 获取当前锁定状态
+ * @return true 当前为锁定状态
+ * @return false 当前为解锁状态
+ */
+bool CodedLockModel::IsLockState() { return lockstate; }
 
-    /**
-     * @brief 更新用户密码
-     * @param password 新密码
-     */
-    void CodedLockModel::SetUserPassWord(const std::string &password)
-    {
-        if (!password.empty())
-        {
-            userpassword_ = password; // 直接赋值
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
-        }
-    }
+/**
+ * @brief 重置锁定状态
+ */
+void CodedLockModel::ResetLockState() { lockstate = false; }
 
-    /**
-     * @brief 更新用户状态
-     */
-    void CodedLockModel::BleUnlock()
-    {
-        // 先进行解锁
-        uapi_dev_runtime_set_lock_status(0);
-        /*设置表盘状态*/
-        MainModel::GetInstance().setDialState(DialState::LOCK, false);
-
-        // 获取当前活动视图的实例
-        auto mainViewInstance = MainViewSample::GetInstance();
-        auto codedLockViewInstance = CodedLockView::GetInstance();
-
-        // 如果是在主界面或密码锁界面,重新进入主界面
-        if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
-            uapi_set_screen_on_api(); // 亮屏
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-        }
-    }
+/**
+ * @brief 获取当前输入的数字个数
+ * @return uint8_t 当前输入的数字个数
+ */
+uint8_t CodedLockModel::GetPointNum() { return passcount; }
+
+/**
+ * @brief 设置当前输入的数字个数
+ * @param uint8_t 当前输入的数字个数
+ */
+void CodedLockModel::SetPointNum(uint8_t num) { passcount = num; }
+
+// ================== 输入密码管理 ==================
+
+/**
+ * @brief 删除最后一个输入的数字
+ */
+void CodedLockModel::DeleteLastDigit() {
+  if (!inputpassword_.empty()) {
+    inputpassword_.pop_back(); // 删除最后一个字符
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
+  }
+}
+
+/**
+ * @brief 清空输入密码
+ */
+void CodedLockModel::ClearPassword() {
+  inputpassword_.clear(); // 清空输入密码
+}
+
+// ================== 密码获取与更新 ==================
+
+/**
+ * @brief 获取当前用户密码
+ * @return std::string 当前用户密码字符串
+ */
+std::string CodedLockModel::GetPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
+  return userpassword_;
+}
+
+/**
+ * @brief 获取当前输入的密码
+ * @return std::string 当前输入的密码字符串
+ */
+std::string CodedLockModel::GetInputPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s",
+                inputpassword_.c_str());
+  return inputpassword_;
+}
+
+/**
+ * @brief 更新用户密码
+ * @param password 新密码
+ */
+void CodedLockModel::SetUserPassWord(const std::string &password) {
+  if (!password.empty()) {
+    userpassword_ = password; // 直接赋值
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
+  }
+}
+
+/**
+ * @brief 更新用户状态
+ */
+void CodedLockModel::BleUnlock() {
+  // 先进行解锁
+  uapi_dev_runtime_set_lock_status(0);
+  /*设置表盘状态*/
+  MainModel::GetInstance().setDialState(DialState::LOCK, false);
+
+  // 获取当前活动视图的实例
+  auto mainViewInstance = MainViewSample::GetInstance();
+  auto codedLockViewInstance = CodedLockView::GetInstance();
+
+  // 如果是在主界面或密码锁界面,重新进入主界面
+  if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
+    uapi_set_screen_on_api(); // 亮屏
+    NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+  }
+}
+
+#ifdef BLE_INSTRUCT
+
+#include "bleEvent.h"
+#include "bleInstruct.h"
+
+//////////////////////////////ble////////////////////////////////////////////
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+void ble_set_password_(uint8_t falg, char *data) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  p_ConfigModel->set_condigData_Int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH, falg);
+  p_ConfigModel->set_condigData_String(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD, data);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "设置手表密码 %d %s \r\n", falg, data);
+
+  /*更新model密码配置*/
+  if (falg == 0) {
+    //更新手表状态
+    GraphicService::GetInstance()->PostGraphicEvent(std::bind(
+        &OHOS::CodedLockModel::BleUnlock, OHOS::CodedLockModel::GetInstance()));
+  }
+  OHOS::CodedLockModel::GetInstance()->SetUserPassWord(data);
+
+  return;
+}
+
+uint8_t ble_get_password_(void) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  std::string str = p_ConfigModel->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
+  uint8_t falg = p_ConfigModel->get_configData_int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "获取手表密码 %d %s \r\n", falg,
+                str.c_str());
+
+  return falg;
+}
+
+extern bleInstruct_t_ bleInstruct_t;
+
+void ble_codedlock_init(void) {
+  bleInstruct_t.ble_set_password = ble_set_password_;
+  bleInstruct_t.ble_get_password = ble_get_password_;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
 
-}
\ No newline at end of file
+} // namespace OHOS
\ No newline at end of file
index a846483..f41cecb 100644 (file)
  * /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp
  */
 
-#include "codedlock/include/CodedLockView.h"
-#include "codedlock/include/CodedLockPresenter.h"
-
-#include "UiConfig.h"
-#include "common/image_cache_manager.h"
-#include "components/ui_button.h"
-#include "components/ui_scroll_view.h"
-#include "ui_resource_image.h"
-#include "ui_resource_string.h"
-#include "uicomponents/UIComponents.h"
-#include "vector"
-
-namespace OHOS {
-
-static CodedLockView *g_pCodedLockView{nullptr};
-
-static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
-
-// 定义默认颜色和激活颜色
-static const uint32_t activeColor = 0xffaaaaaa;
-static const uint32_t defaultColor = 0xff191919;
-
-#define UI_IMAGE_TEST 1
-CodedLockView::CodedLockView() { g_pCodedLockView = this; }
-
-CodedLockView::~CodedLockView() {
-  // UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(scrollView_);
-  // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
-  if (scrollView_ != nullptr) {
-   
-  if (button_one) {
-    delete button_one;
-    button_one = nullptr;
-  }
-  if (button_two) {
-    delete button_two;
-    button_two = nullptr;
-  }
-  if (button_three) {
-    delete button_three;
-    button_three = nullptr;
-  }
-  if (button_four) {
-    delete button_four;
-    button_four = nullptr;
-  }
-  if (button_five) {
-    delete button_five;
-    button_five = nullptr;
-  }
-  if (button_six) {
-    delete button_six;
-    button_six = nullptr;
-  }
-  if (button_seven) {
-    delete button_seven;
-    button_seven = nullptr;
-  }
-  if (button_eight) {
-    delete button_eight;
-    button_eight = nullptr;
-  }
-  if (button_nine) {
-    delete button_nine;
-    button_nine = nullptr;
-  }
-  if (button_zero) {
-    delete button_zero;
-    button_zero = nullptr;
-  }
-
-
-  if (point_one) {
-    delete point_one;
-    point_one = nullptr;
-  }
-  if (point_two) {
-    delete point_two;
-    point_two = nullptr;
-  }
-  if (point_three) {
-    delete point_three;
-    point_three = nullptr;
-  }
-  if (point_four) {
-    delete point_four;
-    point_four = nullptr;
-  }
-  if (point_five) {
-    delete point_five;
-    point_five = nullptr;
-  }
-  if (point_six) {
-    delete point_six;
-    point_six = nullptr;
-  }
-  scrollView_->RemoveAll();
-  delete scrollView_;
-  scrollView_ = nullptr;
-}
-  g_pCodedLockView = nullptr;
-}
-
-CodedLockView *CodedLockView::GetInstance() { return g_pCodedLockView; }
-
-void CodedLockView::InitButtonsView() {
-  // 第一行
-  InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
-  button_one->SetOnClickListener(presenter_);
-  scrollView_->Add(button_one);
-
-  InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
-  button_two->SetOnClickListener(presenter_);
-  scrollView_->Add(button_two);
-
-  InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
-  button_three->SetOnClickListener(presenter_);
-  scrollView_->Add(button_three);
-
-  // 第二行
-  InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
-  button_four->SetOnClickListener(presenter_);
-  scrollView_->Add(button_four);
-
-  InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
-  button_five->SetOnClickListener(presenter_);
-  scrollView_->Add(button_five);
-
-  InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
-  button_six->SetOnClickListener(presenter_);
-  scrollView_->Add(button_six);
-
-  // 第三行
-  InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
-  button_seven->SetOnClickListener(presenter_);
-  scrollView_->Add(button_seven);
-
-  InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
-  button_eight->SetOnClickListener(presenter_);
-  scrollView_->Add(button_eight);
-
-  InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
-  button_nine->SetOnClickListener(presenter_);
-  scrollView_->Add(button_nine);
-
-  // 第四行 (0)
-  InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
-  button_zero->SetOnClickListener(presenter_);
-  scrollView_->Add(button_zero);
-
-  // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ",
-  // 40); button_delete->SetOnClickListener(presenter_);
-  // scrollView_->Add(button_delete);
-}
-void CodedLockView::InitImagesView() {
-  std::vector<PointConfig> points = {
-      {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
-      {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
-      {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
-      {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
-      {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
-      {&point_six, 310, 55, "image1", defaultColor, 0xff, 100},
-  };
-
-  for (const auto &config : points) {
-    InitializePoint(config.imageView, config.x, config.y,
-                    (config.viewId).c_str(), config.backgroundColor,
-                    config.backgroundOpa, config.borderRadius);
-  }
-}
-
-void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y,
-                                    const char *viewId,
-                                    uint32_t backgroundColor,
-                                    uint8_t backgroundOpa, int borderRadius) {
-  if (*imageView == nullptr) {
-    *imageView = new UIImageView();
-  }
-
-  (*imageView)->SetPosition(x, y);
-  (*imageView)->Resize(20, 20);
-  (*imageView)->SetViewId(viewId);
-  (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
-  (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
-  (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
-
-  scrollView_->Add(*imageView);
-}
-void CodedLockView::UpdatePointShow(int num) {
-
-  if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
-      point_four == nullptr || point_five == nullptr || point_six == nullptr)
-    return;
-
-  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
-
-#if UI_IMAGE_TEST
-  switch (num) {
-  case 0:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 1:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 2:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 3:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 4:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 5:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-    break;
-  case 6:
-    point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-    break;
-  default:
-    break;
-  }
-#else
-  // 更新所有点的颜色
-  for (int i = 1; i <= 6; ++i) {
-    UIImageView *point = nullptr;
-    switch (i) {
-    case 1:
-      point = point_one;
-      break;
-    case 2:
-      point = point_two;
-      break;
-    case 3:
-      point = point_three;
-      break;
-    case 4:
-      point = point_four;
-      break;
-    case 5:
-      point = point_five;
-      break;
-    case 6:
-      point = point_six;
-      break;
-    default:
-      continue;
-    }
-
-    if (point != nullptr) {
-      if (i <= num) {
-        // 如果是前 num 个点,则设置为激活颜色
-        point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
-      } else {
-        // 其他点设置为默认颜色
-        point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
-      }
-    }
-  }
-#endif
-  /*ui刷新*/
-  point_one->Invalidate();
-  point_two->Invalidate();
-  point_three->Invalidate();
-  point_four->Invalidate();
-  point_five->Invalidate();
-  point_six->Invalidate();
-}
-
-void CodedLockView::OnStart() {
-  View<CodedLockPresenter>::OnStart();
-
-  scrollView_ = new UIScrollView();
-  if (scrollView_ == nullptr) {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView_ new fail");
-    return;
-  }
-  scrollView_->SetScrollBlankSize(35);
-  scrollView_->SetReboundSize(50);
-  scrollView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
-                          Screen::GetInstance().GetHeight());
-
-  scrollView_->SetTouchable(false);
-  scrollView_->SetDraggable(false);
-  scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
-  scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
-
-  InitButtonsView();
-  InitImagesView();
-
-  AddViewToRootContainer(scrollView_);
-}
-
-} // namespace OHOS
+ #include "codedlock/include/CodedLockView.h"
+ #include "codedlock/include/CodedLockPresenter.h"
+ 
+ #include "UiConfig.h"
+ #include "common/image_cache_manager.h"
+ #include "components/ui_button.h"
+ #include "components/ui_scroll_view.h"
+ #include "ui_resource_image.h"
+ #include "ui_resource_string.h"
+ #include "uicomponents/UIComponents.h"
+ #include "vector"
+ 
+ namespace OHOS {
+ 
+ static CodedLockView *g_pCodedLockView{nullptr};
+ 
+ static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
+ 
+ // 定义默认颜色和激活颜色
+ static const uint32_t activeColor = 0xffaaaaaa;
+ static const uint32_t defaultColor = 0xff191919;
+ 
+ #define UI_IMAGE_TEST 1
+ CodedLockView::CodedLockView() { g_pCodedLockView = this; }
+ 
+ CodedLockView::~CodedLockView() {
+   if (scrollView_ != nullptr) {
+   scrollView_->RemoveAll();
+   if (button_one) {
+     delete button_one;
+     button_one = nullptr;
+   }
+   if (button_two) {
+     delete button_two;
+     button_two = nullptr;
+   }
+   if (button_three) {
+     delete button_three;
+     button_three = nullptr;
+   }
+   if (button_four) {
+     delete button_four;
+     button_four = nullptr;
+   }
+   if (button_five) {
+     delete button_five;
+     button_five = nullptr;
+   }
+   if (button_six) {
+     delete button_six;
+     button_six = nullptr;
+   }
+   if (button_seven) {
+     delete button_seven;
+     button_seven = nullptr;
+   }
+   if (button_eight) {
+     delete button_eight;
+     button_eight = nullptr;
+   }
+   if (button_nine) {
+     delete button_nine;
+     button_nine = nullptr;
+   }
+   if (button_zero) {
+     delete button_zero;
+     button_zero = nullptr;
+   }
+   if (point_one) {
+     delete point_one;
+     point_one = nullptr;
+   }
+   if (point_two) {
+     delete point_two;
+     point_two = nullptr;
+   }
+   if (point_three) {
+     delete point_three;
+     point_three = nullptr;
+   }
+   if (point_four) {
+     delete point_four;
+     point_four = nullptr;
+   }
+   if (point_five) {
+     delete point_five;
+     point_five = nullptr;
+   }
+   if (point_six) {
+     delete point_six;
+     point_six = nullptr;
+   }
+   delete scrollView_;
+   scrollView_ = nullptr;
+ }
+   g_pCodedLockView = nullptr;
+ }
+ 
+ CodedLockView *CodedLockView::GetInstance() { return g_pCodedLockView; }
+ 
+ void CodedLockView::InitButtonsView() {
+   // 第一行
+   InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
+   button_one->SetOnClickListener(presenter_);
+   scrollView_->Add(button_one);
+ 
+   InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
+   button_two->SetOnClickListener(presenter_);
+   scrollView_->Add(button_two);
+ 
+   InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
+   button_three->SetOnClickListener(presenter_);
+   scrollView_->Add(button_three);
+ 
+   // 第二行
+   InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
+   button_four->SetOnClickListener(presenter_);
+   scrollView_->Add(button_four);
+ 
+   InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
+   button_five->SetOnClickListener(presenter_);
+   scrollView_->Add(button_five);
+ 
+   InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
+   button_six->SetOnClickListener(presenter_);
+   scrollView_->Add(button_six);
+ 
+   // 第三行
+   InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
+   button_seven->SetOnClickListener(presenter_);
+   scrollView_->Add(button_seven);
+ 
+   InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
+   button_eight->SetOnClickListener(presenter_);
+   scrollView_->Add(button_eight);
+ 
+   InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
+   button_nine->SetOnClickListener(presenter_);
+   scrollView_->Add(button_nine);
+ 
+   // 第四行 (0)
+   InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
+   button_zero->SetOnClickListener(presenter_);
+   scrollView_->Add(button_zero);
+ 
+   // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ",
+   // 40); button_delete->SetOnClickListener(presenter_);
+   // scrollView_->Add(button_delete);
+ }
+ void CodedLockView::InitImagesView() {
+   std::vector<PointConfig> points = {
+       {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
+       {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
+       {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
+       {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
+       {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
+       {&point_six, 310, 55, "image1", defaultColor, 0xff, 100}, 
+   };
+ 
+   for (const auto &config : points) {
+     InitializePoint(config.imageView, config.x, config.y,
+                     (config.viewId).c_str(), config.backgroundColor,
+                     config.backgroundOpa, config.borderRadius);
+   }
+ }
+ 
+ void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y,
+                                     const char *viewId,
+                                     uint32_t backgroundColor,
+                                     uint8_t backgroundOpa, int borderRadius) {
+   if (*imageView == nullptr) {
+     *imageView = new UIImageView();
+   }
+ 
+   (*imageView)->SetPosition(x, y);
+   (*imageView)->Resize(20, 20);
+   (*imageView)->SetViewId(viewId);
+   (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
+   (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
+   (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
+ 
+   scrollView_->Add(*imageView);
+ }
+ void CodedLockView::UpdatePointShow(int num) {
+ 
+   if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
+       point_four == nullptr || point_five == nullptr || point_six == nullptr)
+     return;
+ 
+   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
+ 
+ #if UI_IMAGE_TEST
+   switch (num) {
+   case 0:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 1:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 2:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 3:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 4:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 5:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+     break;
+   case 6:
+     point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+     break;
+   default:
+     break;
+   }
+ #else
+   // 更新所有点的颜色
+   for (int i = 1; i <= 6; ++i) {
+     UIImageView *point = nullptr;
+     switch (i) {
+     case 1:
+       point = point_one;
+       break;
+     case 2:
+       point = point_two;
+       break;
+     case 3:
+       point = point_three;
+       break;
+     case 4:
+       point = point_four;
+       break;
+     case 5:
+       point = point_five;
+       break;
+     case 6:
+       point = point_six;
+       break;
+     default:
+       continue;
+     }
+ 
+     if (point != nullptr) {
+       if (i <= num) {
+         // 如果是前 num 个点,则设置为激活颜色
+         point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+       } else {
+         // 其他点设置为默认颜色
+         point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+       }
+     }
+   }
+ #endif
+   /*ui刷新*/
+   point_one->Invalidate();
+   point_two->Invalidate();
+   point_three->Invalidate();
+   point_four->Invalidate();
+   point_five->Invalidate();
+   point_six->Invalidate();
+ }
+ 
+ void CodedLockView::OnStart() {
+   View<CodedLockPresenter>::OnStart();
+ 
+   scrollView_ = new UIScrollView();
+   if (scrollView_ == nullptr) {
+     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView_ new fail");
+     return;
+   }
+   scrollView_->SetScrollBlankSize(35);
+   scrollView_->SetReboundSize(50);
+   scrollView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+                           Screen::GetInstance().GetHeight());
+ 
+   scrollView_->SetTouchable(false);
+   scrollView_->SetDraggable(false);
+   scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+   scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ 
+   InitButtonsView();
+   InitImagesView();
+ 
+   AddViewToRootContainer(scrollView_);
+ }
+ 
+ } // namespace OHOS
+ 
\ No newline at end of file
index ff260ae..17a25ef 100644 (file)
 #include <queue>
 #include <iostream>
 #include <unordered_map>
+#include "bleInstruct.h"
 
 namespace OHOS
 {
+
+    #ifdef BLE_INSTRUCT
+    extern "C" void ble_codedlock_init(void);
+    #endif
+
     class CodedLockModel
     {
     public:
index 5f3f43c..7371f00 100644 (file)
 #include "codedlock/include/CodedLockModel.h"
-#include "main/include/MainViewSample.h"
-#include "codedlock/include/CodedLockView.h"
-#include <cctype>
-#include <algorithm>
-#include "wearable_log.h"
-#include "string.h"
 #include "ConfigModel.h"
+#include "codedlock/include/CodedLockView.h"
 #include "custom_utils.h"
+#include "main/include/MainViewSample.h"
+#include "string.h"
+#include "wearable_log.h"
+#include <algorithm>
+#include <cctype>
+#include "graphic_service.h"
+
+
 extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status);
-namespace OHOS
-{
-    /**
-     * @brief 初始化用户密码和输入密码
-     */
-    CodedLockModel::CodedLockModel()
-    {
-        std::string password = ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
-
-        if (!password.empty())
-        {
-            userpassword_ = password; // 从配置中获取用户密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s", userpassword_.c_str());
-        }
-        else
-        {
-            userpassword_ = "000000"; // 默认密码
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
-        }
-
-        lockstate = false; // 锁定状态初始化为未锁
-        passcount = 0;     // 输入计数初始化为0
-
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "初始化完成: lockstate: %d passcount: %d ", lockstate, passcount);
-    }
+namespace OHOS {
+/**
+ * @brief 初始化用户密码和输入密码
+ */
+CodedLockModel::CodedLockModel() {
+  std::string password = ConfigModel::GetInstance()->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
 
-    /**
-     * @brief 析构函数
-     */
-    CodedLockModel::~CodedLockModel() {}
-
-    /**
-     * @brief 获取单例实例
-     * @return CodedLockModel* 指向单例的指针
-     */
-    CodedLockModel *CodedLockModel::GetInstance()
-    {
-        static CodedLockModel instance;
-        return &instance;
-    }
+  if (!password.empty()) {
+    userpassword_ = password; // 从配置中获取用户密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置密码,使用密码 %s",
+                  userpassword_.c_str());
+  } else {
+    userpassword_ = "000000"; // 默认密码
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "未设置密码,使用默认密码 000000");
+  }
 
-    // ================== 密码设置和验证 ==================
-
-    /**
-     * @brief 设置当前输入密码
-     * @param num 输入的数字
-     */
-    void CodedLockModel::SetNumToPassword(const int num)
-    {
-        if (num < 0 || num > 9)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
-            return; // 处理无效输入
-        }
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
-
-        passcount++;
-        inputpassword_ += std::to_string(num);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ", inputpassword_.c_str(),passcount);
-
-        /*
-            检查当前输入密码的长度 等于6个 会进行清除 
-            但是不设置passcount==0 
-            我需要传一个6过去显示 然后过一秒再配置0
-        */
-        if (passcount >= PASSWORDNUM)
-        {
-            if (IsPasswordMatch())
-            {
-                lockstate = true; // 匹配成功,开锁
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
-            }
-            else
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
-            }
-
-            // passcount = 0;   // 重置输入计数
-            ClearPassword(); // 清空输入密码
-        }
-    }
+  lockstate = false; // 锁定状态初始化为未锁
+  passcount = 0;     // 输入计数初始化为0
 
-    /**
-     * @brief 判断输入的密码与当前密码是否匹配
-     * @return true 匹配成功
-     * @return false 匹配失败
-     */
-    bool CodedLockModel::IsPasswordMatch()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
-        bool isMatch = (inputpassword_ == userpassword_);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s", isMatch ? "匹配成功" : "不匹配");
-        return isMatch;
-    }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                "初始化完成: lockstate: %d passcount: %d ", lockstate,
+                passcount);
+}
 
-    /**
-     * @brief 获取当前锁定状态
-     * @return true 当前为锁定状态
-     * @return false 当前为解锁状态
-     */
-    bool CodedLockModel::IsLockState()
-    {
-        return lockstate;
-    }
+/**
+ * @brief 析构函数
+ */
+CodedLockModel::~CodedLockModel() {}
 
-    /**
-     * @brief 重置锁定状态
-     */
-    void CodedLockModel::ResetLockState()
-    {
-        lockstate = false;
-    }
+/**
+ * @brief 获取单例实例
+ * @return CodedLockModel* 指向单例的指针
+ */
+CodedLockModel *CodedLockModel::GetInstance() {
+  static CodedLockModel instance;
+  return &instance;
+}
 
-    /**
-     * @brief 获取当前输入的数字个数
-     * @return uint8_t 当前输入的数字个数
-     */
-    uint8_t CodedLockModel::GetPointNum()
-    {
-        return passcount;
-    }
+// ================== 密码设置和验证 ==================
 
-    /**
-     * @brief 设置当前输入的数字个数
-     * @param uint8_t 当前输入的数字个数
-     */
-    void CodedLockModel::SetPointNum(uint8_t num)
-    {
-        passcount = num;
-    }
+/**
+ * @brief 设置当前输入密码
+ * @param num 输入的数字
+ */
+void CodedLockModel::SetNumToPassword(const int num) {
+  if (num < 0 || num > 9) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入的数字无效: %d", num);
+    return; // 处理无效输入
+  }
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入数字: %d", num);
 
-    // ================== 输入密码管理 ==================
-
-    /**
-     * @brief 删除最后一个输入的数字
-     */
-    void CodedLockModel::DeleteLastDigit()
-    {
-        if (!inputpassword_.empty())
-        {
-            inputpassword_.pop_back(); // 删除最后一个字符
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
-        }
-    }
+  passcount++;
+  inputpassword_ += std::to_string(num);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前inputpassword_: %s %d ",
+                inputpassword_.c_str(), passcount);
 
-    /**
-     * @brief 清空输入密码
-     */
-    void CodedLockModel::ClearPassword()
-    {
-        inputpassword_.clear(); // 清空输入密码
+  /*
+      检查当前输入密码的长度 等于6个 会进行清除
+      但是不设置passcount==0
+      我需要传一个6过去显示 然后过一秒再配置0
+  */
+  if (passcount >= PASSWORDNUM) {
+    if (IsPasswordMatch()) {
+      lockstate = true; // 匹配成功,开锁
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开锁成功");
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码不匹配,已清空输入");
     }
 
-    // ================== 密码获取与更新 ==================
+    // passcount = 0;   // 重置输入计数
+    ClearPassword(); // 清空输入密码
+  }
+}
 
-    /**
-     * @brief 获取当前用户密码
-     * @return std::string 当前用户密码字符串
-     */
-    std::string CodedLockModel::GetPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
-        return userpassword_;
-    }
+/**
+ * @brief 判断输入的密码与当前密码是否匹配
+ * @return true 匹配成功
+ * @return false 匹配失败
+ */
+bool CodedLockModel::IsPasswordMatch() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始密码匹配");
+  bool isMatch = (inputpassword_ == userpassword_);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码 %s",
+                isMatch ? "匹配成功" : "不匹配");
+  return isMatch;
+}
 
-    /**
-     * @brief 获取当前输入的密码
-     * @return std::string 当前输入的密码字符串
-     */
-    std::string CodedLockModel::GetInputPassword() const
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s", inputpassword_.c_str());
-        return inputpassword_;
-    }
+/**
+ * @brief 获取当前锁定状态
+ * @return true 当前为锁定状态
+ * @return false 当前为解锁状态
+ */
+bool CodedLockModel::IsLockState() { return lockstate; }
 
-    /**
-     * @brief 更新用户密码
-     * @param password 新密码
-     */
-    void CodedLockModel::SetUserPassWord(const std::string &password)
-    {
-        if (!password.empty())
-        {
-            userpassword_ = password; // 直接赋值
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
-        }
-    }
+/**
+ * @brief 重置锁定状态
+ */
+void CodedLockModel::ResetLockState() { lockstate = false; }
 
-    /**
-     * @brief 更新用户状态
-     */
-    void CodedLockModel::BleUnlock()
-    {
-        // 先进行解锁
-        uapi_dev_runtime_set_lock_status(0);
-        /*设置表盘状态*/
-        MainModel::GetInstance().setDialState(DialState::LOCK, false);
-
-        // 获取当前活动视图的实例
-        auto mainViewInstance = MainViewSample::GetInstance();
-        auto codedLockViewInstance = CodedLockView::GetInstance();
-
-        // 如果是在主界面或密码锁界面,重新进入主界面
-        if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
-            uapi_set_screen_on_api(); // 亮屏
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-        }
-    }
+/**
+ * @brief 获取当前输入的数字个数
+ * @return uint8_t 当前输入的数字个数
+ */
+uint8_t CodedLockModel::GetPointNum() { return passcount; }
+
+/**
+ * @brief 设置当前输入的数字个数
+ * @param uint8_t 当前输入的数字个数
+ */
+void CodedLockModel::SetPointNum(uint8_t num) { passcount = num; }
+
+// ================== 输入密码管理 ==================
+
+/**
+ * @brief 删除最后一个输入的数字
+ */
+void CodedLockModel::DeleteLastDigit() {
+  if (!inputpassword_.empty()) {
+    inputpassword_.pop_back(); // 删除最后一个字符
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已删除最后一个输入");
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有可删除的输入");
+  }
+}
+
+/**
+ * @brief 清空输入密码
+ */
+void CodedLockModel::ClearPassword() {
+  inputpassword_.clear(); // 清空输入密码
+}
+
+// ================== 密码获取与更新 ==================
+
+/**
+ * @brief 获取当前用户密码
+ * @return std::string 当前用户密码字符串
+ */
+std::string CodedLockModel::GetPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实际密码: %s", userpassword_.c_str());
+  return userpassword_;
+}
+
+/**
+ * @brief 获取当前输入的密码
+ * @return std::string 当前输入的密码字符串
+ */
+std::string CodedLockModel::GetInputPassword() const {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "输入密码: %s",
+                inputpassword_.c_str());
+  return inputpassword_;
+}
+
+/**
+ * @brief 更新用户密码
+ * @param password 新密码
+ */
+void CodedLockModel::SetUserPassWord(const std::string &password) {
+  if (!password.empty()) {
+    userpassword_ = password; // 直接赋值
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "密码为空");
+  }
+}
+
+/**
+ * @brief 更新用户状态
+ */
+void CodedLockModel::BleUnlock() {
+  // 先进行解锁
+  uapi_dev_runtime_set_lock_status(0);
+  /*设置表盘状态*/
+  MainModel::GetInstance().setDialState(DialState::LOCK, false);
+
+  // 获取当前活动视图的实例
+  auto mainViewInstance = MainViewSample::GetInstance();
+  auto codedLockViewInstance = CodedLockView::GetInstance();
+
+  // 如果是在主界面或密码锁界面,重新进入主界面
+  if (mainViewInstance != nullptr || codedLockViewInstance != nullptr) {
+    uapi_set_screen_on_api(); // 亮屏
+    NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+  }
+}
+
+#ifdef BLE_INSTRUCT
+
+#include "bleEvent.h"
+#include "bleInstruct.h"
+
+//////////////////////////////ble////////////////////////////////////////////
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+void ble_set_password_(uint8_t falg, char *data) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  p_ConfigModel->set_condigData_Int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH, falg);
+  p_ConfigModel->set_condigData_String(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD, data);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "设置手表密码 %d %s \r\n", falg, data);
+
+  /*更新model密码配置*/
+  if (falg == 0) {
+    //更新手表状态
+    GraphicService::GetInstance()->PostGraphicEvent(std::bind(
+        &OHOS::CodedLockModel::BleUnlock, OHOS::CodedLockModel::GetInstance()));
+  }
+  OHOS::CodedLockModel::GetInstance()->SetUserPassWord(data);
+
+  return;
+}
+
+uint8_t ble_get_password_(void) {
+  OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance();
+
+  std::string str = p_ConfigModel->get_configData_string(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD);
+  uint8_t falg = p_ConfigModel->get_configData_int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH);
+
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "获取手表密码 %d %s \r\n", falg,
+                str.c_str());
+
+  return falg;
+}
+
+extern bleInstruct_t_ bleInstruct_t;
+
+void ble_codedlock_init(void) {
+  bleInstruct_t.ble_set_password = ble_set_password_;
+  bleInstruct_t.ble_get_password = ble_get_password_;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
 
-}
\ No newline at end of file
+} // namespace OHOS
\ No newline at end of file
index a846483..7ce8cde 100644 (file)
@@ -32,10 +32,8 @@ static const uint32_t defaultColor = 0xff191919;
 CodedLockView::CodedLockView() { g_pCodedLockView = this; }
 
 CodedLockView::~CodedLockView() {
-  // UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(scrollView_);
-  // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
   if (scrollView_ != nullptr) {
-   
+  scrollView_->RemoveAll();
   if (button_one) {
     delete button_one;
     button_one = nullptr;
@@ -76,8 +74,6 @@ CodedLockView::~CodedLockView() {
     delete button_zero;
     button_zero = nullptr;
   }
-
-
   if (point_one) {
     delete point_one;
     point_one = nullptr;
@@ -102,7 +98,6 @@ CodedLockView::~CodedLockView() {
     delete point_six;
     point_six = nullptr;
   }
-  scrollView_->RemoveAll();
   delete scrollView_;
   scrollView_ = nullptr;
 }
@@ -167,7 +162,7 @@ void CodedLockView::InitImagesView() {
       {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
       {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
       {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
-      {&point_six, 310, 55, "image1", defaultColor, 0xff, 100},
+      {&point_six, 310, 55, "image1", defaultColor, 0xff, 100}, 
   };
 
   for (const auto &config : points) {
index a50b1d3..7122bb4 100644 (file)
@@ -647,6 +647,8 @@ void ble_instruct_init(void);
 
 void ble_mp3_init(void);
 
+void ble_codedlock_init(void);
+
 bool ble_app_delete(const char *data);
 
 cJSON* ble_app_list(void);
index fcc943b..9bb87f6 100644 (file)
@@ -46,4 +46,6 @@ void ble_instruct_init(void)
 
     ble_watch_first_paired();
 
+    ble_codedlock_init();
+
 }
\ No newline at end of file