VIEW_ADD_CARD, // 添加卡片
VIEW_SET_DIAL, // 切换表盘
VIEW_SET_HEART, // 设置心率周期检测
+ VIEW_CODED_LOCK, // 密码锁
/* ----------------------------------- 训练 ----------------------------------- */
VIEW_TRAINING, // 训练
VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外)
VIEW_TEST, // 测试
VIEW_GOAL, // 每日目标
VIEW_CALCULATOR, // 计算器
- VIEW_SCHEDULE, // schedule
+ VIEW_SCHEDULE, // schedule
/* -------------------------------------------------------------------------- */
#ifdef SUPPORT_ALIPAY_SEC
VIEW_MAIN_ALIPAY,
void InitSecondaryFunction(void);
void InitFastTrainingSlice(void);
void InitFastTrainingAttentionSlice(void);
+ void InitCodedlockSlice(void);
/* -------------------------------------------------------------------------- */
// void InitPhoneSlice(void);
void InitPhoneCallSlice(void);
#include "heartrate/include/HeartResultPresenter.h"
#include "heartrate/include/HeartChartView.h"
#include "heartrate/include/HeartChartPresenter.h"
+/*密码锁*/
+#include "codedlock/include/CodedLockView.h"
+#include "codedlock/include/CodedLockPresenter.h"
/* -------------------------------------------------------------------------- */
#include "secondaryfunction/include/SecondaryFunctionPresenter.h"
#include "secondaryfunction/include/SecondaryFunctionView.h"
{VIEW_SET_DIAL_STYLE, &NativeLauncher::InitSetDialStyleSlice},
/*心率周期检测*/
//{VIEW_SET_HEART, &NativeLauncher::InitSetHeartSlice},
+ /*密码锁*/
+ {VIEW_CODED_LOCK, &NativeLauncher::InitCodedlockSlice},
/* -------------------------------------------------------------------------- */
/*智能助手*/
{VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice},
- // {VIEW_SCHEDULE, &NativeLauncher::InitScheduleSlice},
+ // {VIEW_SCHEDULE, &NativeLauncher::InitScheduleSlice},
#ifdef SUPPORT_ALIPAY_SEC
{VIEW_MAIN_ALIPAY, &NativeLauncher::InitMainAlipaySlice},
}
NativeAbility::GetInstance().AddSliceProxy(VIEW_HEART_CHART, heartchartView);
}
+ // 密码锁
+ void NativeLauncher::InitCodedlockSlice(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCodedlockSlice");
+ SliceProxy *codedlockView = new AbilitySliceProxy<CodedLockView, CodedLockPresenter>;
+ if (codedlockView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "codedlockView is nullptr");
+ return;
+ }
+ NativeAbility::GetInstance().AddSliceProxy(VIEW_CODED_LOCK, codedlockView);
+ }
/* -------------------------------------------------------------------------- */
// 查找手机
void NativeLauncher::InitFindPhoneSlice(void)
--- /dev/null
+#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 SetUserPassWord(const std::string &password);
+
+ 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
--- /dev/null
+
+#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<CodedLockView>,
+ 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
--- /dev/null
+/***
+ * @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 "BaseView.h"
+#include "View.h"
+#include <ui_scroll_view.h>
+#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 <thread>
+
+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<CodedLockPresenter>
+ {
+
+ public:
+ CodedLockView();
+ virtual ~CodedLockView();
+ static CodedLockView *GetInstance(void);
+
+ void OnStart() override;
+ void OnSetUpView() override;
+ void OnTearDownView() override;
+ void OnStop() 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 *container_{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
--- /dev/null
+#include "codedlock/include/CodedLockModel.h"
+#include <cctype>
+#include <algorithm>
+#include "wearable_log.h"
+#include "string.h"
+#include "ConfigModel.h"
+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", inputpassword_.c_str());
+
+ // 检查当前输入密码的长度
+ 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 删除最后一个输入的数字
+ */
+ 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, "密码为空");
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/***
+ * @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);
+
+namespace OHOS
+{
+ // 当前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<CodedLockView>::OnStart();
+ }
+
+ void CodedLockPresenter::OnPause(void)
+ {
+ Presenter<CodedLockView>::OnPause();
+ }
+
+ void CodedLockPresenter::OnResume(void)
+ {
+ Presenter<CodedLockView>::OnResume();
+ }
+
+ void CodedLockPresenter::OnStop(void)
+ {
+ /*关锁*/
+ uapi_dev_runtime_set_lock_status(0);
+ /*设置表盘状态*/
+ MainModel::GetInstance().setDialState(DialState::LOCK, false);
+ Presenter<CodedLockView>::OnStop();
+ }
+ void CodedLockPresenter::JudgeMatch()
+ {
+ /*进行现状密码打印*/
+ // CodedLockModel::GetInstance()->GetInputPassword();
+ // CodedLockModel::GetInstance()->GetPassword();
+
+ /*每次点击完成 更新 点击图片*/
+ int num = CodedLockModel::GetInstance()->GetPointNum();
+ CodedLockView::GetInstance()->UpdatePointShow(num);
+
+ /*每次点击完成判断 是否 完成密码匹配*/
+ if (CodedLockModel::GetInstance()->IsLockState())
+ {
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "回到主界面");
+ }
+ 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
--- /dev/null
+/***
+ * @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 "common/image_cache_manager.h"
+#include "UiConfig.h"
+#include "ui_resource_image.h"
+#include "components/ui_button.h"
+#include "uicomponents/UIComponents.h"
+#include "ui_resource_string.h"
+#include "components/ui_scroll_view.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<UIViewGroup *>(container_);
+ UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+ 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_);
+ container_->Add(button_one);
+
+ InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
+ button_two->SetOnClickListener(presenter_);
+ container_->Add(button_two);
+
+ InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
+ button_three->SetOnClickListener(presenter_);
+ container_->Add(button_three);
+
+ // 第二行
+ InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
+ button_four->SetOnClickListener(presenter_);
+ container_->Add(button_four);
+
+ InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
+ button_five->SetOnClickListener(presenter_);
+ container_->Add(button_five);
+
+ InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
+ button_six->SetOnClickListener(presenter_);
+ container_->Add(button_six);
+
+ // 第三行
+ InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
+ button_seven->SetOnClickListener(presenter_);
+ container_->Add(button_seven);
+
+ InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
+ button_eight->SetOnClickListener(presenter_);
+ container_->Add(button_eight);
+
+ InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
+ button_nine->SetOnClickListener(presenter_);
+ container_->Add(button_nine);
+
+ // 第四行 (0)
+ InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
+ button_zero->SetOnClickListener(presenter_);
+ container_->Add(button_zero);
+
+ // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ", 40);
+ // button_delete->SetOnClickListener(presenter_);
+ // container_->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);
+
+ container_->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);
+ break;
+ case 2:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ break;
+ case 3:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ 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);
+ 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);
+ 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();
+
+ container_ = new UIScrollView();
+ if (container_ == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
+ return;
+ }
+ container_->SetScrollBlankSize(35);
+ container_->SetReboundSize(50);
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+
+ container_->SetTouchable(false);
+ container_->SetDraggable(false);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+ InitButtonsView();
+ InitImagesView();
+
+ SetContainerView(container_);
+ }
+
+ void CodedLockView::OnSetUpView()
+ {
+ View<CodedLockPresenter>::OnSetUpView();
+ Draw();
+ }
+
+ void CodedLockView::OnTearDownView()
+ {
+ View<CodedLockPresenter>::OnTearDownView();
+ return;
+ }
+
+ void CodedLockView::OnStop()
+ {
+ View<CodedLockPresenter>::OnStop();
+ if (container_ != nullptr)
+ {
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ RootView::GetInstance()->RemoveAll();
+ return;
+ }
+}
#include "MainViewSample.h"
#include "ui_screennotify.h"
#include "components/root_view.h"
+#include "ConfigModel.h"
+
+#include "ui_service.h"
+extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status);
+extern "C" uint8_t uapi_dev_runtime_get_lock_status(void);
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
-static uint32_t g_back_to_home_interval = 5;
-
+ static uint32_t g_back_to_home_interval = 2; // 超时时间 秒
// 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面
-uint16_t ignore_slice_ids[] = {
-VIEW_INVALID,
-VIEW_SETTING,
-VIEW_UISAMPLE,
-VIEW_BLOODOXY, // 血氧功能
-VIEW_HEART, // 心率检测
-VIEW_SAVEBAT, // 省电模式
-VIEW_TEST,
+ uint16_t ignore_slice_ids[] = {
+ VIEW_INVALID,
+ VIEW_SAVEBAT, // 省电模式
+ VIEW_TRAININGCRAD, // 训练卡片
+ VIEW_TEST,
#ifdef SUPPORT_ALIPAY_SEC
- VIEW_MAIN_ALIPAY,
+ VIEW_MAIN_ALIPAY,
#endif
};
-
-static std::list<ScreenStatusNotifyCallback> g_callback;
-
-static void ChangeToHomeView(void)
-{
-#if 0
- screen_context_t *sc = power_display_get_screen_context();
- uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
- for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) {
- if (ignore_slice_ids[i] == current_slice_id) {
- return;
+ static std::list<ScreenStatusNotifyCallback> g_callback;
+ static void ChangeToHomeView(void)
+ {
+ screen_context_t *sc = power_display_get_screen_context();
+ uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+ for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++)
+ {
+ if (ignore_slice_ids[i] == current_slice_id)
+ {
+ return;
+ }
}
- }
- if (sc->screen_off_time_interval > g_back_to_home_interval) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
- sc->screen_off_time_interval);
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
- OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
- if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) {
- if (current_slice_id != VIEW_MAIN) { // 主表盘
- OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- } else {
- if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) {
- // 当前页面为主表盘的其他页面时,切换回主表盘页面
- OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
+ if (sc->screen_off_time_interval > g_back_to_home_interval)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
+ sc->screen_off_time_interval);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
+ OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
+ if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE)
+ {
+#if 0
+ if (current_slice_id != VIEW_MAIN)
+ {
+ /*进行主界面截断 不能滑动*/
+ OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ }
+ else
+ {
+ if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage())
+ {
+ // 当前页面为主表盘的其他页面时,切换回主表盘页面
+ OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
+ }
+ }
+#endif
+ /*密码锁开关被打开*/
+ if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH))
+ {
+ /*处于关闭密码锁状态*/
+ if (uapi_dev_runtime_get_lock_status() == 0)
+ {
+ /*重新进入一次主界面*/
+ OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ // 切换回主表盘页面
+ OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
+ /*上锁*/
+ uapi_dev_runtime_set_lock_status(1);
+ /*设置表盘状态*/
+ OHOS::MainModel::GetInstance().setDialState(OHOS::DialState::LOCK, true);
+ }
}
}
}
}
-#endif
-}
-void notify_screen_on_event(void)
-{
- for (auto callback : g_callback) {
- callback(SCREEN_STATUS_ON);
+ void notify_screen_on_event(void)
+ {
+ for (auto callback : g_callback)
+ {
+ callback(SCREEN_STATUS_ON);
+ }
+ ChangeToHomeView();
}
- ChangeToHomeView();
-}
-void notify_screen_off_event(void)
-{
- for (auto callback : g_callback) {
- callback(SCREEN_STATUS_OFF);
+ void notify_screen_off_event(void)
+ {
+ for (auto callback : g_callback)
+ {
+ callback(SCREEN_STATUS_OFF);
+ }
}
-}
-void set_back_to_home_interval(uint32_t time_sec)
-{
- g_back_to_home_interval = time_sec;
-}
+ void set_back_to_home_interval(uint32_t time_sec)
+ {
+ g_back_to_home_interval = time_sec;
+ }
-uint32_t get_back_to_home_interval(void)
-{
- return g_back_to_home_interval;
-}
+ uint32_t get_back_to_home_interval(void)
+ {
+ return g_back_to_home_interval;
+ }
-void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-{
- if (callback != nullptr) {
- g_callback.push_back(callback);
+ void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
+ {
+ if (callback != nullptr)
+ {
+ g_callback.push_back(callback);
+ }
}
-}
-void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-{
- if (callback != nullptr) {
- g_callback.remove(callback);
+ void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
+ {
+ if (callback != nullptr)
+ {
+ g_callback.remove(callback);
+ }
}
-}
#ifdef __cplusplus
}