From: Caisking Date: Fri, 18 Apr 2025 03:54:29 +0000 (+0800) Subject: 【密码锁】UI X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~371 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=14d46bc569d54d3b3d0c57cc410d00b4f3d355b2;p=mirrors%2FFD230.git 【密码锁】UI --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockModel.h new file mode 100644 index 000000000..ff260ae41 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockModel.h @@ -0,0 +1,63 @@ +/*** + * @Date: 2024-08-21 15:27:38 + * @LastEditors: Caisking 3449750381@qq.com + * @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 +#include +#include +#include +#include +#include +#include + +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 diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockPresenter.h new file mode 100644 index 000000000..1d37d8abe --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockPresenter.h @@ -0,0 +1,59 @@ + +#ifndef _CodedLock_PRESENTER_H +#define _CodedLock_PRESENTER_H + +#include "Presenter.h" +#include "codedlock/include/CodedLockPresenter.h" +#include "codedlock/include/CodedLockView.h" + +namespace OHOS +{ + // 数字常量宏定义 +#define NUM_ZERO 0 +#define NUM_ONE 1 +#define NUM_TWO 2 +#define NUM_THREE 3 +#define NUM_FOUR 4 +#define NUM_FIVE 5 +#define NUM_SIX 6 +#define NUM_SEVEN 7 +#define NUM_EIGHT 8 +#define NUM_NINE 9 + + static constexpr const char *LOCK_BUTTON_ONE = "lock_1"; + static constexpr const char *LOCK_BUTTON_TWO = "lock_2"; + static constexpr const char *LOCK_BUTTON_THREE = "lock_3"; + static constexpr const char *LOCK_BUTTON_FOUR = "lock_4"; + static constexpr const char *LOCK_BUTTON_FIVE = "lock_5"; + static constexpr const char *LOCK_BUTTON_SIX = "lock_6"; + static constexpr const char *LOCK_BUTTON_SEVEN = "lock_7"; + static constexpr const char *LOCK_BUTTON_EIGHT = "lock_8"; + static constexpr const char *LOCK_BUTTON_NINE = "lock_9"; + static constexpr const char *LOCK_BUTTON_ZERO = "lock_0"; + static constexpr const char *LOCK_BUTTON_DELETE = "lock_delete"; + + class CodedLockView; + + class CodedLockPresenter : public Presenter, + public UIView::OnClickListener + { + public: + CodedLockPresenter(); + virtual ~CodedLockPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CodedLockPresenter *GetInstance(); + void JudgeMatch(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + }; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockView.h new file mode 100644 index 000000000..8bfa08edf --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/include/CodedLockView.h @@ -0,0 +1,87 @@ +/*** + * @Date: 2024-08-21 15:26:54 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-21 19:33:54 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockView.h + */ + +#ifndef _CodedLock_VIEW_H +#define _CodedLock_VIEW_H + + +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_digital_clock.h" +#include "components/ui_box_progress.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" + +#include "CodedLockPresenter.h" +#include + +namespace OHOS +{ + struct PointConfig + { + UIImageView **imageView; + int x, y; + std::string viewId; + uint32_t backgroundColor; + uint8_t backgroundOpa; + int borderRadius; + }; + + class CodedLockPresenter; + class CodedLockView : public View + { + + public: + CodedLockView(); + virtual ~CodedLockView(); + static CodedLockView *GetInstance(void); + + void OnStart() override; + + void InitButtonsView(); + void InitImagesView(); + + void InitializePoint(UIImageView **imageView, int x, int y, const char *viewId, uint32_t backgroundColor, uint8_t backgroundOpa, int borderRadius); + + void UpdatePointShow(int num); + + private: + UIView::OnDragListener *draglistener{nullptr}; + + CodedLockView(CodedLockView &&) = delete; + CodedLockView &operator=(CodedLockView &&) = delete; + UIScrollView *scrollView_{nullptr}; + + /*密码锁 UI 0~9 删除*/ + UILabelButton *button_one{nullptr}; + UILabelButton *button_two{nullptr}; + UILabelButton *button_three{nullptr}; + UILabelButton *button_four{nullptr}; + UILabelButton *button_five{nullptr}; + UILabelButton *button_six{nullptr}; + UILabelButton *button_seven{nullptr}; + UILabelButton *button_eight{nullptr}; + UILabelButton *button_nine{nullptr}; + UILabelButton *button_zero{nullptr}; + // UILabelButton *button_delete{nullptr}; + + UIImageView *point_one{nullptr}; + UIImageView *point_two{nullptr}; + UIImageView *point_three{nullptr}; + UIImageView *point_four{nullptr}; + UIImageView *point_five{nullptr}; + UIImageView *point_six{nullptr}; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp new file mode 100644 index 000000000..c10f09db3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockModel.cpp @@ -0,0 +1,227 @@ +#include "codedlock/include/CodedLockModel.h" +#include "MainViewSample.h" +#include "codedlock/include/CodedLockView.h" +#include +#include +#include "wearable_log.h" +#include "string.h" +#include "ConfigModel.h" +#include "custom_utils.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); + } + + /** + * @brief 析构函数 + */ + CodedLockModel::~CodedLockModel() {} + + /** + * @brief 获取单例实例 + * @return CodedLockModel* 指向单例的指针 + */ + CodedLockModel *CodedLockModel::GetInstance() + { + static CodedLockModel instance; + return &instance; + } + + // ================== 密码设置和验证 ================== + + /** + * @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(); // 清空输入密码 + } + } + + /** + * @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 true 当前为锁定状态 + * @return false 当前为解锁状态 + */ + bool CodedLockModel::IsLockState() + { + return lockstate; + } + + /** + * @brief 重置锁定状态 + */ + void CodedLockModel::ResetLockState() + { + lockstate = false; + } + + /** + * @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); + } + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockPresenter.cpp new file mode 100644 index 000000000..a4a97dd3e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockPresenter.cpp @@ -0,0 +1,165 @@ +/*** + * @Date: 2024-08-21 15:28:04 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-21 16:25:31 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" +#include "ui_service.h" + +#include "codedlock/include/CodedLockPresenter.h" +#include "codedlock/include/CodedLockModel.h" +#include "MainModel.h" + +#include "string.h" + +extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status); + +#include "NativeRegisterManager.h" + +namespace OHOS +{ + + REGIST_SLICE(VIEW_CHECK_ABNORMAL, CodedLockView, CodedLockPresenter); + + + // 当前Presenter属性实例化的内存指针 + static CodedLockPresenter *g_pCodedLockPresenter = nullptr; + + CodedLockPresenter::CodedLockPresenter() + { + g_pCodedLockPresenter = this; + } + + CodedLockPresenter::~CodedLockPresenter() + { + g_pCodedLockPresenter = nullptr; + } + + CodedLockPresenter *CodedLockPresenter::GetInstance() + { + return g_pCodedLockPresenter; + } + + void CodedLockPresenter::OnStart() + { + /*重置密码状态*/ + CodedLockModel::GetInstance()->ClearPassword(); + CodedLockModel::GetInstance()->ResetLockState(); + Presenter::OnStart(); + } + + void CodedLockPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void CodedLockPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void CodedLockPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + void CodedLockPresenter::JudgeMatch() + { + const int REQUIRED_POINTS = 6; + int num = CodedLockModel::GetInstance()->GetPointNum(); + CodedLockView::GetInstance()->UpdatePointShow(num); + + if (num == REQUIRED_POINTS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "num is 6, sleeping for 1s"); + CodedLockModel::GetInstance()->SetPointNum(0); + + if (CodedLockModel::GetInstance()->IsLockState()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Returning to main interface"); + //解锁 + uapi_dev_runtime_set_lock_status(0); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + //恢复表盘状态 + MainModel::GetInstance().setDialState(DialState::LOCK, false); + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + } + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JudgeMatch is Ok"); + } + + bool CodedLockPresenter::OnClick(UIView &view, const ClickEvent &event) + { + if (strcmp(view.GetViewId(), LOCK_BUTTON_ONE) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_ONE"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_ONE); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_TWO) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_TWO"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_TWO); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_THREE) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_THREE"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_THREE); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_FOUR) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_FOUR"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_FOUR); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_FIVE) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_FIVE"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_FIVE); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_SIX) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_SIX"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_SIX); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_SEVEN) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_SEVEN"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_SEVEN); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_EIGHT) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_EIGHT"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_EIGHT); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_NINE) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_NINE"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_NINE); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_ZERO) == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_ZERO"); + CodedLockModel::GetInstance()->SetNumToPassword(NUM_ZERO); + } + else if (strcmp(view.GetViewId(), LOCK_BUTTON_DELETE) == 0) // 处理删除按钮的点击事件 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NUM_ONE"); + CodedLockModel::GetInstance()->DeleteLastDigit(); + } + + JudgeMatch(); + + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockView.cpp new file mode 100644 index 000000000..d8cffeeeb --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/codedlock/src/CodedLockView.cpp @@ -0,0 +1,336 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 14:41:32 + * @FilePath: + * /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" + +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(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 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::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