From: DXY <1731678236@qq.com> Date: Thu, 22 Aug 2024 09:40:31 +0000 (+0800) Subject: 合并 X-Git-Tag: release_V1.2.70_20241020_135402~555^2~6 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=687f615b4910d36582a8116620f9b714e59ba3fa;p=mirrors%2FFD230.git 合并 --- diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 6b8011647..d988e277a 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -229,6 +229,48 @@ namespace OHOS // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed"); return true; } + /*** + * @description: + * @param {UILabelButton} * + * @param {int} left + * @param {int} top + * @param {int} width + * @param {int} height + * @param {char} *viewId + * @param {UIResourceTextId} id + * @param {int} fontSize + * @return {*} + * @brief 初始化带label的button + */ + bool InitLabelButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId, const char *text, int fontSize) + { + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UILabelButton(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error"); + return false; // 内存分配失败,返回false + } + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UILabelButton UILabelButton is not nullptr"); + return false; // 内存分配失败,返回false + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetText(text); + button->SetStyle(STYLE_TEXT_FONT, fontSize); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize); + button->SetStyle(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED); + button->SetVisible(true); + return true; + } /* -------------------------------------------------------------------------- */ /*替换字符串中的变量*/ std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 3b0ea887f..a49674321 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-07-29 10:31:48 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-21 16:17:07 + * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h + */ /*** * @Date: 2024-05-30 15:59:37 * @LastEditors: Caisking 3449750381@qq.com @@ -51,7 +57,8 @@ namespace OHOS bool InitUILabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); /*初始化button*/ bool InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); - /*初始化buttonExt*/ + /*初始化labelbutton*/ + bool InitLabelButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId, const char *text, int fontSize); /*初始化image*/ bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); /*生成动画资源数组*/ diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 42019e1bd..3831c8d62 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -695,6 +695,11 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepControlPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepModel.cpp + #密码锁 + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/codedlock/src/CodedLockView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/codedlock/src/CodedLockPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/codedlock/src/CodedLockModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneCallView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneCallPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneDirView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 8b1b3f861..320eae05f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -96,6 +96,7 @@ typedef enum : uint16_t VIEW_ADD_CARD, // 添加卡片 VIEW_SET_DIAL, // 切换表盘 VIEW_SET_HEART, // 设置心率周期检测 + VIEW_CODED_LOCK, // 密码锁 /* ----------------------------------- 训练 ----------------------------------- */ VIEW_TRAINING, // 训练 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) @@ -130,7 +131,7 @@ typedef enum : uint16_t VIEW_TEST, // 测试 VIEW_GOAL, // 每日目标 VIEW_CALCULATOR, // 计算器 - VIEW_SCHEDULE, // schedule + VIEW_SCHEDULE, // schedule /* -------------------------------------------------------------------------- */ #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index c48bf5f6e..9722f44d1 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -108,6 +108,7 @@ namespace OHOS void InitSecondaryFunction(void); void InitFastTrainingSlice(void); void InitFastTrainingAttentionSlice(void); + void InitCodedlockSlice(void); /* -------------------------------------------------------------------------- */ // void InitPhoneSlice(void); void InitPhoneCallSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 08a4e9015..4ec1ca927 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -113,6 +113,9 @@ #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" @@ -406,10 +409,12 @@ namespace OHOS {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}, @@ -1234,6 +1239,18 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_HEART_CHART, heartchartView); } + // 密码锁 + void NativeLauncher::InitCodedlockSlice(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCodedlockSlice"); + SliceProxy *codedlockView = new AbilitySliceProxy; + if (codedlockView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "codedlockView is nullptr"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_CODED_LOCK, codedlockView); + } /* -------------------------------------------------------------------------- */ // 查找手机 void NativeLauncher::InitFindPhoneSlice(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockModel.h b/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockModel.h new file mode 100644 index 000000000..76e12d73e --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockModel.h @@ -0,0 +1,53 @@ +#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 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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockPresenter.h new file mode 100644 index 000000000..1d37d8abe --- /dev/null +++ b/code/sdk/application/wearable/fd230app/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/fd230app/nativeui/codedlock/include/CodedLockView.h b/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockView.h new file mode 100644 index 000000000..be68eb6dd --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/codedlock/include/CodedLockView.h @@ -0,0 +1,90 @@ +/*** + * @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 +#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 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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockModel.cpp new file mode 100644 index 000000000..25c7d8d25 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockModel.cpp @@ -0,0 +1,188 @@ +#include "codedlock/include/CodedLockModel.h" +#include +#include +#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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockPresenter.cpp new file mode 100644 index 000000000..616ebd1b3 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockPresenter.cpp @@ -0,0 +1,152 @@ +/*** + * @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::OnStart(); + } + + void CodedLockPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void CodedLockPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void CodedLockPresenter::OnStop(void) + { + /*关锁*/ + uapi_dev_runtime_set_lock_status(0); + /*设置表盘状态*/ + MainModel::GetInstance().setDialState(DialState::LOCK, false); + Presenter::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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp new file mode 100644 index 000000000..aacd71ec0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp @@ -0,0 +1,288 @@ +/*** + * @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(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 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::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::OnSetUpView(); + Draw(); + } + + void CodedLockView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void CodedLockView::OnStop() + { + View::OnStop(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp index 73f90f766..49dab4d82 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp @@ -21,6 +21,7 @@ #include "MainCallingPresenter.h" #include "secondaryfunction/include/SecondaryFunctionModel.h" #include "DialViewGroup.h" +#include "ui_service.h" namespace OHOS { static bool IsNotifyCallStatus() @@ -125,13 +126,14 @@ namespace OHOS uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len); uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len); uint8_t mcu_pms_is_screen_on(void); + uint8_t uapi_dev_runtime_get_lock_status(void); } void KeyInputListener::OnKeyRelease(const KeyEvent &event) { uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId(); uint16 keyID = event.GetKeyId(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyRelease keyID %d , longPressFlag = %d , pressFlag = %d ",keyID,longPressFlag,pressFlag); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyRelease keyID %d , longPressFlag = %d , pressFlag = %d ", keyID, longPressFlag, pressFlag); if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) // 如果按下的按键是电源键 { @@ -165,11 +167,22 @@ namespace OHOS } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + /*密码锁上锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); // NativeAbility::GetInstance().EnterSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); } - }else{ + } + else + { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " mcu_pms_is_screen_on = off "); } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 285daa121..dc366ab3b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -124,9 +124,18 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); return false; } - if(uapi_dev_runtime_get_sleep_monitoring_status()) + + /*发生点击进入密码锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + /*进入密码锁*/ + NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + return true; + } + + if (uapi_dev_runtime_get_sleep_monitoring_status()) { - if(VIEW_DNOTDISTURB == g_jumpView[curViewId]) + if (VIEW_DNOTDISTURB == g_jumpView[curViewId]) { return true; } @@ -194,7 +203,7 @@ namespace OHOS PullUpDownView::GetInstance()->UpdateDnotDisturbStatus(false); DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false); /*更新主界面配置*/ - MainModel::GetInstance().setDialState(DialState::DO_NOT_DISTURB,false); + MainModel::GetInstance().setDialState(DialState::DO_NOT_DISTURB, false); return true; } if (g_jumpView.count(curViewId) != 0) @@ -210,14 +219,26 @@ namespace OHOS UNUSED(view); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); uint8_t cardId = view_->GetHorCurrentCard(); - if (cardId != WATCH_FACE) - { - SetCardModel::GetInstance().SetSelectedCard(cardId); - // NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD); - } - else + /* + 卡片进入管理卡片界面 + if (cardId != WATCH_FACE) + { + SetCardModel::GetInstance().SetSelectedCard(cardId); + NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD); + } + */ + if (cardId == WATCH_FACE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); + if (uapi_dev_runtime_get_lock_status()) + { + /*进入密码锁*/ + NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + } + else + { + /*进入表盘设置*/ + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); + } } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index d2076360f..288512711 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -9,7 +9,11 @@ #include "graphic_service.h" #include "dialupdate/include/DialUpdateModel.h" #include "uicomponents/UIComponents.h" +#include "ui_service.h" extern DialInfo_1 dialInfo_1[MAX_DIALNUM_1]; + +extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); + namespace OHOS { static constexpr const char *DISTURBICON = "user/res/dial_state/disturbicon.bin"; @@ -191,7 +195,7 @@ namespace OHOS { if (messageicon_ == nullptr || dialstateicon_ == nullptr) return; - + /*配置未读状态*/ messageicon_->SetVisible(MainModel::GetInstance().getMessageActiveState()); /*配置表盘状态*/ @@ -253,19 +257,34 @@ namespace OHOS mainSwipeGroup->SetLoopState(false); // 主界面循环 mainSwipeGroup->EnableScreenCap(true); // 主界面截屏滑动 mainSwipeGroup->RegisterSwipeCallback(callback); // 主界面动画回调 - // 判断是否为从主界面前往的其他Slice - if (presenter_->IsFromSetCardView()) + /*密码锁上锁*/ + if (uapi_dev_runtime_get_lock_status()) { - // 回退标志位 - presenter_->SetFromSetCardView(false); - // 设置Id为主界面显示索引 - SwitchToCard(presenter_->GetFromCardId()); + // 回到表盘 + SwitchToClockPage(); + printf("密码锁\r\n"); + mainClockView->SetIntercept(true); + mainSwipeGroup->SetDraggable(false); + mainSwipeGroup->SetOnSwipeListener(nullptr); + mainSwipeGroup->SetOnClickListener(presenter_); } else { - // 回到表盘 - SwitchToClockPage(); + // 判断是否为从主界面前往的其他Slice + if (presenter_->IsFromSetCardView()) + { + // 回退标志位 + presenter_->SetFromSetCardView(false); + // 设置Id为主界面显示索引 + SwitchToCard(presenter_->GetFromCardId()); + } + else + { + // 回到表盘 + SwitchToClockPage(); + } } + #if DIALSTATE /*增加勿扰图标*/ @@ -360,7 +379,7 @@ namespace OHOS messageView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); messageView->PreLoad(); messageView->SetDraggable(false); - messageView->SetIntercept(true); + // messageView->SetIntercept(true); messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); #endif } @@ -436,6 +455,8 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); return nullptr; } + + mainClockView->SetViewId("mainClockView"); return mainClockView; } // 指南针卡片 diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testModel.cpp index 66cb47673..b85dd3305 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testModel.cpp @@ -1,6 +1,17 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-08-22 16:59:44 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-22 17:22:33 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testModel.cpp +* @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ #include "producttest/include/testModel.h" #include "producttest/include/testPresenter.h" #include "producttest/include/testLCDC.h" +#include "producttest/include/testTPC.h" namespace OHOS { @@ -15,26 +26,34 @@ namespace OHOS { switch (type) { - case 1: - /* code */ - break; - - default: - break; - } - if( testView::GetInstance()) - { - testView::GetInstance()->ChangeView(TESTVIEW,LCD); - - factorytest_hide_test_lcd_button(); + case 1: + if( testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW,LCD); + factorytest_hide_test_lcd_button(); + } + break; + + case 2: + if( testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW,TP); + factorytest_hide_test_tp_button(); + } + break; + case 3: + if( testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW,BUTTON); + factorytest_hide_test_lcd_button(); + } + break; + + default: + break; } - else - printf("xxxxxxxxxxxxxxxxxxxxx\r\n"); - - - return ; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index d2f7fb326..d5646ec32 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -18,6 +18,8 @@ #include "aivoice/include/AiVoiceModel.h" #include "graphic_service.h" #include "bleService.h" +#include "ui_service.h" +extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); namespace OHOS { RebootAndShutdownModel::RebootAndShutdownModel() {} @@ -231,6 +233,16 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面不做切换 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VIEW_AI_VOICE is not switched"); @@ -289,6 +301,16 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面单击切换模型 { AiVoiceModel::GetInstance().FunctionKeyOnClickToChangeAIModel(); @@ -348,6 +370,16 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } if (curSliceId != VIEW_AI_VOICE) { NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp index b24f0ba03..7d8315c70 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp @@ -15,7 +15,8 @@ #include "power_display_service.h" #include "aimodels/include/AiModelsModel.h" #include "themestyle/include/ThemeStyleModel.h" - +#include "ui_service.h" +extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); namespace OHOS { RebootModel::RebootModel() {} @@ -180,6 +181,17 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } + if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面不做切换 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VIEW_AI_VOICE is not switched"); @@ -220,6 +232,18 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { + uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } + AiModelsModel &aiModelsModel = AiModelsModel::GetInstance(); if (!aiModelsModel.ChangeAiModel()) { @@ -256,6 +280,18 @@ namespace OHOS } if (display_api->get_screen_state() == SCREEN_ON) { + uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + /*处于主界面 或者密码锁界面*/ + if (curSliceId == VIEW_MAIN || curSliceId == VIEW_CODED_LOCK) + { + /*被锁*/ + if (uapi_dev_runtime_get_lock_status()) + { + NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + return; + } + } + // 切换到显示方式界面 NativeAbility::GetInstance().EnterSlice(VIEW_AI_MODELS); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp index dba03e3ee..e83142710 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp @@ -1,7 +1,7 @@ /*** * @Date: 2024-08-16 09:26:06 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-20 16:59:59 + * @LastEditTime: 2024-08-21 17:03:11 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp */ /*** diff --git a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp index 09897531d..138b98b60 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp @@ -12,95 +12,120 @@ #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, -#ifdef SUPPORT_ALIPAY_SEC - VIEW_MAIN_ALIPAY, -#endif + uint16_t ignore_slice_ids[] = { + VIEW_INVALID, + VIEW_SAVEBAT, // 省电模式 + VIEW_TRAININGCRAD, // 训练卡片 }; - -static std::list 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 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 } diff --git a/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp index 176ef97f4..35feb1913 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp @@ -108,7 +108,7 @@ namespace OHOS int index = 0; for (int i = 5; i >= 0; i--) { - sprintf_s(btaddr_str + index, len, "%02X:", btaddr[i]); + sprintf_s(btaddr_str + index, len, "%02x:", btaddr[i]); index += 3; } btaddr_str[index - 1] = '\0'; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h index f09fd1382..7a4174bce 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-05-30 15:59:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-22 14:47:49 + * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: MainViewSample diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt index f7b3d8e6d..b345bf896 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt @@ -22,7 +22,7 @@ ${ROOT_DIR}/application/wearable/fd230app/nativeui/traing/training_card/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/config/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/traing/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/uiservice/include -${ROOT_DIR}/application/wearable/fd230app/nativeui/sleep/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/codedlock/include #${ROOT_DIR}/application/wearable/fd230app/nativeui/alarm/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/alarmclockmanage/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index b9ff6eafd..dd0dd712b 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -33,6 +33,7 @@ #include "TraingModel.h" #include "WeatherModel.h" #include "SleepModel.h" +#include "CodedLockModel.h" #endif #include "AlmmgrAlarmClockManage.h" @@ -581,18 +582,25 @@ 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); + + printf("设置手表密码 %d %s \r\n",falg, data); + + /*更新model密码配置*/ + 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); + 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); + printf("获取手表密码 %d %s \r\n",falg,str.c_str()); + return falg; } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 561d3995a..ae51d0065 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -1641,11 +1641,12 @@ void SetpasswordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u if(Check_CRC(data,len,crcvalue)) { - char* buf[6]={0}; - memcpy(buf,&data[1],6);// - + char* buf[7]={0}; + + sprintf_s(buf,7,"%d%d%d%d%d%d",data[1],data[2],data[3],data[4],data[5],data[6]); ble_set_password(data[0],buf); - printf("%s\r\n",&data[1]); + + printf("%s\r\n",buf); sendBuf[17] = 1; sendBuf[18] = Calculate_CRC(sendBuf,18); diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index f5c8a487d..8e57eef1d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -142,7 +142,6 @@ static void custom_cmd_service_check_task(void const *arg) { uapi_set_screen_on_api(); uapi_setScreenBrightness(255); - printf("111\n"); uapi_factorytest_enter_test_view(1); HandleUpdatelcdMode(1); // printf("222\n"); @@ -184,8 +183,9 @@ static void custom_cmd_service_check_task(void const *arg) { //uapi_set_screen_on_api(); //uapi_factorytest_enter_test_view(1); - uapi_factorytest_enter_test_tp_view(); - uapi_factorytest_hide_test_tp_button(); + //uapi_factorytest_enter_test_tp_view(); + HandleUpdatelcdMode(2); + //uapi_factorytest_hide_test_tp_button(); } else { @@ -197,7 +197,8 @@ static void custom_cmd_service_check_task(void const *arg) { //uapi_set_screen_on_api(); //uapi_factorytest_enter_test_view(1); - uapi_factorytest_enter_test_button_view(); + //uapi_factorytest_enter_test_button_view(); + HandleUpdatelcdMode(3); } else { diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index 141cd42ed..5d05fd128 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -77,6 +77,7 @@ typedef struct uint8_t drinkremind_status; uint8_t train_status;//训练状态 uint8_t saveele_status;//省电模式状态 + uint8_t lock_status;//密码锁状态 uint8_t motion_recognition_status;//运动识别开关状态 } runtime_status_t; @@ -361,7 +362,15 @@ uint8_t uapi_dev_runtime_get_saveele_status(void) { return g_runtime.saveele_status; } - +/*设置密码锁状态*/ +void uapi_dev_runtime_set_lock_status(uint8_t status) +{ + g_runtime.lock_status = status; +} +uint8_t uapi_dev_runtime_get_lock_status(void) +{ + return g_runtime.lock_status; +} /*设置运动识别状态*/ void uapi_dev_runtime_set_motion_recognition_status(uint8_t status) { diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 1223745ba..38ed9784c 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -72,6 +72,7 @@ uint8_t uapi_dev_runtime_get_drinkremind_status(void); */ void uapi_dev_runtime_set_train_status(uint8_t status); uint8_t uapi_dev_runtime_get_train_status(void); + /* 设置训练状态 0 未开启省电 @@ -80,6 +81,15 @@ uint8_t uapi_dev_runtime_get_train_status(void); void uapi_dev_runtime_set_saveele_status(uint8_t status); uint8_t uapi_dev_runtime_get_saveele_status(void); +/* + 设置密码锁状态 + 0 未开启密码锁 + 1 开启密码锁 +*/ +void uapi_dev_runtime_set_lock_status(uint8_t status); +uint8_t uapi_dev_runtime_get_lock_status(void); + + /*运动识别*/ void uapi_dev_runtime_set_motion_recognition_status(uint8_t status); uint8_t uapi_dev_runtime_get_motion_recognition_status(void);