From: 袁清梦 <3449750381@qq.com> Date: Tue, 23 Jul 2024 01:51:20 +0000 (+0000) Subject: Merge #572 into sdk602patch0626 from refs/changes/572/head X-Git-Tag: release_V1.2.70_20241020_135402~745^2~15 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=595ae515064bfb172f8b6470959b43b3e59e2d76;p=mirrors%2FFD230.git Merge #572 into sdk602patch0626 from refs/changes/572/head Code review from 袁清梦 * refs/changes/572/head: (6 commits squashed) - 优化动态心率显示算法保证数据较为稳定 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 增加飞鸟表盘 - 增加自定义表盘配置 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/572 --- diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index 17499f084..78e5f7040 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -30,9 +30,14 @@ namespace OHOS MAX_CARD, } CardId; + /*自定义表盘最多5个*/ typedef enum { DIAL_CLOCK = 0, + DIAL_CLOCK_2 = 1, + DIAL_CLOCK_3 = 2, + DIAL_CLOCK_4 = 3, + DIAL_CLOCK_5 = 4, DIAL_MAX, } DialId; @@ -61,19 +66,24 @@ namespace OHOS #define APP_RES_PATH "/user/res" #define APP_MUSIC_PATH "/user/music" #define APP_VIDEO_PATH "/user/video" -#define APP_DEFAULT_DIAL_PATH "/user/dial" /*默认表盘路径*/ -#define APP_DOWNLOAD_DIAL_PATH "/user/userdata/dial" /*安装表盘路径*/ +#define APP_DEFAULT_DIAL_PATH "/user/dial" /*默认表盘安装路径*/ +#define APP_DOWNLOAD_DIAL_PATH "/user/userdata/dial" /*表盘市场安装路径*/ +#define APP_CUSTOM_DIAL_PATH "user/userdata/constom_dial" /*自定义表盘安装路径*/ #define APP_LIST_PATH "/user/res/applist_icon" /* ---------------------------------- 卡片管理 --------------------------------- */ static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin"; static constexpr const char *DEFAULT_DIAL_PATH = APP_RES_PATH "/dial_soures/KUMI.bin"; - #ifdef CUSTOM_Z1 +#ifdef CUSTOM_Z1 static constexpr const char *DEFAULT_DIALBACK_PATH = APP_RES_PATH "/dial_soures/z1background.bin"; static constexpr const char *DEFAULT_DIALPER_PATH = APP_RES_PATH "/dial_soures/Z1VIEW.bin"; - #else +#else static constexpr const char *DEFAULT_DIALBACK_PATH = APP_RES_PATH "/dial_soures/MAIN_FACE_IMAGE.bin"; static constexpr const char *DEFAULT_DIALPER_PATH = APP_RES_PATH "/dial_soures/KUMIVIEW.bin"; - #endif +#endif + + // static constexpr const char *DEFAULT_DIALPER_PATH_TEST = APP_CUSTOM_DIAL_PATH"/Classic_Geometry.bin"; + // static constexpr const char *DEFAULT_DIALPER_PATH_TEST = APP_CUSTOM_DIAL_PATH"/Classic_Geometry.bin"; + static constexpr const char *PNG_SET_CARD_ADD = APP_RES_PATH "/MainCard/CARD_ADD.bin"; static constexpr const char *PNG_SET_CARD_DEL = APP_RES_PATH "/MainCard/CARD_DEL.bin"; static constexpr const char *PNG_SET_CARD_HEART = APP_RES_PATH "/MainCard/HeartCard.bin"; @@ -286,9 +296,9 @@ namespace OHOS static constexpr const char *PNG_APPLIST_SLEEP_IMAGE = APP_LIST_PATH "/sleeping.bin"; // 睡眠 // AppList hexagon icon - static constexpr const char *PNG_APPLIST_DEFAULT_IMG = APP_RES_PATH"/regular_hexagon.bin"; - static constexpr const char *PNG_APPLIST_NOTSETUSE_IMG = APP_RES_PATH"/regular_hexagon_inverse.bin"; - + static constexpr const char *PNG_APPLIST_DEFAULT_IMG = APP_RES_PATH "/regular_hexagon.bin"; + static constexpr const char *PNG_APPLIST_NOTSETUSE_IMG = APP_RES_PATH "/regular_hexagon_inverse.bin"; + /* ---------------------------------- 快速训练 ---------------------------------- */ static constexpr const char *PNG_TRAING_BOUTTONMORE_IMAGE = APP_RES_PATH "/Training/More.bin"; static constexpr const char *PNG_TRAING_BUTTONGRONG_IMAGE = APP_RES_PATH "/Training/Bouttonground.bin"; diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h index 319ed495b..f039f3f4a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-07-17 14:09:04 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-20 15:26:53 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: MainClockView @@ -11,11 +17,15 @@ #include #include #include "View.h" -#include "components/ui_label.h" -#include "components/root_view.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_label_button.h" +#include "components/ui_box_progress.h" +#include "components/ui_image_animator.h" +#include "components/root_view.h" + #include "components/ui_sweep_clock.h" #include "BaseView.h" #include "ChangeSliceListener.h" @@ -30,48 +40,110 @@ #include "time.h" #include "sys/time.h" -namespace OHOS { -class MainClockView : public UICardPage { -public: - MainClockView(); - virtual ~MainClockView(); - static MainClockView *GetInstance(void); - bool InitView(void); - void PreLoad(void) override; - void UnLoad(void) override; - void RefreshStep(int step); - void RefreshHeartRate(int value); - void ClockAnimatorStart(void); - void ClockAnimatorStop(void); - void UpdateTime(void); +namespace OHOS +{ + /*表盘颜色配置*/ + enum ColorTypeSet + { + COLOR_WHITE = 0, + COLOR_BLACK, + COLOR_GRAY, + COLOR_GREEN, + COLOR_ORANGE, + COLOR_BLUE, + COLOR_DEFAULT = COLOR_WHITE // 默认颜色 + }; + /*表盘电量配置*/ + enum BatteryDisplayType + { + BATTERY_DISPLAY_NONE = 0, // 不显示图标 + BATTERY_DISPLAY_BLACK, // 显示黑色 + BATTERY_DISPLAY_WHITE, // 显示白色 + BATTERY_DISPLAY_DEFAULT = BATTERY_DISPLAY_WHITE // 默认:白色 + }; + /*表盘时间配置*/ + enum TimeDisplayPosition + { + TIME_DISPLAY_ABOVE = 0, // 显示在表盘上方 + TIME_DISPLAY_BELOW, // 显示在表盘下方 + TIME_DISPLAY_DEFAULT = TIME_DISPLAY_BELOW // 默认:下方 + }; + + class MainClockView : public UICardPage + { + public: + MainClockView(); + virtual ~MainClockView(); + static MainClockView *GetInstance(void); + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + /*刷新数据*/ + void RefreshStep(int step); + void RefreshHeartRate(int value); + void ClockAnimatorStart(void); + void ClockAnimatorStop(void); + /*更新数据*/ + void UpdateTime(void); + void UpdataBattery(void); + void SetViewColor(int64_t color); + void UpdateBatteryColor(void); + /*配置文件*/ + void SetDialPath(std::string dialpath); + bool InitialConfig(int Id); + /*配置函数*/ + bool InitBackground(const char *filename); + bool InitTimeView(TimeDisplayPosition type); // 时间 + bool InitBatteryView(BatteryDisplayType type); // 电量 + bool InitColor(ColorTypeSet type); // 颜色 + private: + void InitStepValue(); + bool InitLabelView(void); + bool InitCenterCircleView(void); + bool InitHandView(void); + void InitDateTime(void); + bool InitClock(void); + bool LoadClockImage(Image *view, uint32_t resId); + bool LoadClockImage(UIImageView *view, uint32_t resId); + + /*表盘背景*/ + UIImageView *curFace{nullptr}; + /*时间相关*/ + UILabel *timerlabel{nullptr}; + UILabel *weekLabel{nullptr}; + UILabel *datelabel{nullptr}; + /*电量相关*/ + UIImageView *batteryiamge{nullptr}; + UIBoxProgress *batteryprogress{nullptr}; + UILabel *batterylabel{nullptr}; + UIImageView *batteryicon{nullptr}; + /*数据相关*/ + UILabel *stepLabel{nullptr}; + UILabel *heartlabel{nullptr}; + + /*指针表盘相关 暂不使用*/ + UISweepClock *mainSweepClock{nullptr}; + Image *secondHand{nullptr}; + Image *minuteHand{nullptr}; + Image *hourHand{nullptr}; + UIImageView *heartRate{nullptr}; + Image *hand24Hour{nullptr}; + UIImageView *weekDay{nullptr}; + UIImageView *progress{nullptr}; + Image *bigCircle{nullptr}; + Image *medCircle{nullptr}; + Image *smallCircle{nullptr}; + + bool viewiInitStatus{false}; + bool resLoadStatus{false}; -private: - void InitStepValue(); - bool InitLabelView(void); - bool InitCenterCircleView(void); - bool InitHandView(void); - void InitDateTime(void); - bool InitSweepClock(void); - bool LoadClockImage(Image *view, uint32_t resId); - bool LoadClockImage(UIImageView *view, uint32_t resId); - UIImageView *curFace{nullptr}; - UILabelButton *stepLabel{nullptr}; - UILabel *timerlabel{nullptr}; - UILabel *weekLabel{nullptr}; - UILabel *datelabel{nullptr}; - UISweepClock *mainSweepClock{nullptr}; - Image *secondHand{nullptr}; - Image *minuteHand{nullptr}; - Image *hourHand{nullptr}; - UIImageView *heartRate{nullptr}; - Image *hand24Hour{nullptr}; - UIImageView *weekDay{nullptr}; - UIImageView *progress{nullptr}; - Image *bigCircle{nullptr}; - Image *medCircle{nullptr}; - Image *smallCircle{nullptr}; - bool viewiInitStatus{false}; - bool resLoadStatus{false}; -}; + std::string dialFile; // 表盘背景文件名 + ColorTypeSet colorType = COLOR_DEFAULT; // 颜色类型 + BatteryDisplayType batterySetting = BATTERY_DISPLAY_DEFAULT; // 电池设置 + TimeDisplayPosition timePosition = TIME_DISPLAY_DEFAULT; // 时间位置 + int64_t color_ = Color::White().full; // 电量颜色 + int32_t power_ = -1; // 电量 + bool isBatteryIconVisible{false}; // 电池暂停 + }; } // namespace OHOS #endif // MAIN_CLOCK_VIEW_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp index 02c476064..e429d0b30 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-07-17 14:09:09 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-22 09:33:10 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: MainClockView @@ -15,14 +21,33 @@ #include #include #include +#include #include "custom_runtime.h" #include "main/include/PullUpDownView.h" +#include "battery_hal.h" #include "message/include/MessageControlView.h" -std::string weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +extern uint8_t battery_get_voltage(float *voltage); + +#define TIMEVIEW_UP 0 +#define TIMEVIEW_DOWN 1 + +std::string Enweekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +std::string Cnweekdays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + +static constexpr const char *CHAGE_BATTERY = "/user/res/Battery/Charge_Icon.bin"; +static constexpr const char *WHITE_BATTERY = "/user/res/Battery/Battery-E.bin"; +static constexpr const char *BLACK_BATTERY = "/user/res/Battery/Charge_Icon.bin"; + +// 定义一些常量 +constexpr int HOURS_IN_DAY = 24; +constexpr int MINUTES_IN_HOUR = 60; +constexpr int HOUR_FORMAT_12 = 12; +constexpr int BATTERY_LOW_THRESHOLD = 10; +constexpr int BATTERY_MEDIUM_THRESHOLD = 20; + namespace OHOS { - static MainClockView *g_pMainClockView = nullptr; - +#if 0 static constexpr uint16_t FONT_DEFAULT_SIZE = 25; static constexpr uint16_t FONT_TEXT_SIZE = 24; static constexpr uint16_t STEP_LABEL_X = 100; @@ -36,7 +61,6 @@ namespace OHOS static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; static constexpr uint16_t POINT_CENTER_X = 25; static constexpr uint16_t POINT_CENTER_Y = 211; - static constexpr uint16_t STEP_CHAR_NUM = 255; static constexpr int16_t STEP_LABLE_WIDTH = 75; static constexpr int16_t STEP_LABLE_SIZE = 35; static constexpr uint16_t WEEKLABEL_POSITION_X = 181; @@ -60,7 +84,9 @@ namespace OHOS static constexpr int16_t MIN_TO_HOUR = 60; static constexpr int16_t HOURLY_SYSTEM = 24; static constexpr int16_t INTERVAL = 30; - +#endif + static constexpr uint16_t STEP_CHAR_NUM = 255; + static MainClockView *g_pMainClockView = nullptr; MainClockView::MainClockView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView"); @@ -71,55 +97,94 @@ namespace OHOS MainClockView::~MainClockView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView"); - /* -------------------------------------------------------------------------- */ delete curFace; // 背景 curFace = nullptr; delete timerlabel; // 时间 timerlabel = nullptr; delete weekLabel; // 星期 weekLabel = nullptr; - delete datelabel; // 日期 - datelabel = nullptr; - /* -------------------------------------------------------------------------- */ -#ifdef DEFULTDIAL - mainSweepClock->RemoveAll(); - delete stepLabel; + delete batteryiamge; // 电量框 + batteryiamge = nullptr; + delete batteryprogress; // 电量进度条 + batteryprogress = nullptr; + delete batterylabel; // 电量label + batterylabel = nullptr; + delete batteryicon; // 充电图标 + batteryicon = nullptr; + delete stepLabel; // 步数 stepLabel = nullptr; - delete secondHand; - secondHand = nullptr; - delete minuteHand; - minuteHand = nullptr; - delete hourHand; - hourHand = nullptr; - delete heartRate; - heartRate = nullptr; - delete hand24Hour; - hand24Hour = nullptr; - delete weekDay; - weekDay = nullptr; - delete progress; - progress = nullptr; - delete bigCircle; - bigCircle = nullptr; - delete medCircle; - medCircle = nullptr; - delete smallCircle; - smallCircle = nullptr; - Remove(mainSweepClock); - delete mainSweepClock; - mainSweepClock = nullptr; + delete heartlabel; // 心率 + heartlabel = nullptr; + g_pMainClockView = nullptr; -#endif } MainClockView *MainClockView::GetInstance(void) { return g_pMainClockView; } + /*设置表盘背景*/ + void MainClockView::SetDialPath(std::string dialpath) + { + if (dialpath.empty()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: The specified dial path does not exist:"); + return; + } + dialFile.clear(); + dialFile = dialpath; + } + /* + 从配置文件读取设置 + 配置文件名:表盘ID + 第一个字节:电池图标样式 + 第二个字节:时间label位置 + 第三个字节:字体颜色 + */ + bool MainClockView::InitialConfig(int Id) + { + std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(Id) + ".bin"; + + // 打开文件 + std::ifstream configFile(filename, std::ios::binary); + if (!configFile.is_open()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unable to open config file: %s", filename.c_str()); + return false; // 文件打开失败 + } + + // 读取配置 + char settings[3]; // 读取3个字节 + configFile.read(settings, sizeof(settings)); + if (configFile.gcount() != sizeof(settings)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to read config file or insufficient file content!"); + configFile.close(); + return false; // 读取失败 + } - bool MainClockView::InitSweepClock(void) + // 为成员变量赋值 + batterySetting = static_cast(settings[0]); // 第一个字节:电池图标样式 + timePosition = static_cast(settings[1]); // 第二个字节:时间label位置 + colorType = static_cast(settings[2]); // 第三个字节:字体颜色 + + // 关闭文件 + configFile.close(); + + return true; // 成功读取配置 + } + + bool MainClockView::InitClock(void) + { + InitBackground(dialFile.c_str()); + InitTimeView(timePosition); + InitBatteryView(batterySetting); + InitColor(colorType); + return true; + } + /*初始化表盘背景*/ + bool MainClockView::InitBackground(const char *filename) { - // 背景 curFace = new UIImageView(); if (curFace == nullptr) { @@ -127,62 +192,220 @@ namespace OHOS return false; } curFace->SetPosition(0, 0); - ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(DEFAULT_DIALBACK_PATH, false); + ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(filename, false); if (image == nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", - DEFAULT_DIALBACK_PATH); + filename); + curFace->SetSrc(DEFAULT_DIALBACK_PATH); + Add(curFace); return false; } - #ifndef CUSTOM_Z1 curFace->SetSrc(image); - #endif Add(curFace); + return true; + } + + /* + 时间显示 [时间 日期 星期] + 0 显示在表盘上方 + 1 显示在表盘下方 - // 时间 - timerlabel = new UILabel(); - if (timerlabel == nullptr) + 默认:下方 + */ + bool MainClockView::InitTimeView(TimeDisplayPosition type) + { + // 创建UILabel的助手函数 + auto createLabel = [](UILabel *&label, const std::string &labelName) -> bool { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timerlabel new fail"); - return false; + label = new UILabel(); + if (label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s creation failed", labelName.c_str()); + return false; + } + label->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + return true; + }; + + // 创建时间、星期、日期标签 + if (!createLabel(timerlabel, "timerlabel") || + !createLabel(weekLabel, "weekLabel") || + !createLabel(datelabel, "datelabel")) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Label creation failed, exiting InitTimeView"); + return false; // 分配失败 + } + + // 设置标签的位置和字体大小 + switch (type) + { + case TIME_DISPLAY_ABOVE: + timerlabel->SetPosition(104, 98, 200, 60); + timerlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 100); + datelabel->SetPosition(133, 206, 200, 60); + datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + weekLabel->SetPosition(242, 206, 200, 60); + weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + break; + + case TIME_DISPLAY_BELOW: + default: // 默认情况下显示在下方 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type is unknown, defaulting to TIMEVIEW_DOWN"); + timerlabel->SetPosition(147, 301, 200, 60); + timerlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 70); + datelabel->SetPosition(137, 387, 200, 60); + datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + weekLabel->SetPosition(252, 387, 200, 60); + weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + break; } - timerlabel->SetPosition(150, 290, 200, 150); - timerlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - timerlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 65); - timerlabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - timerlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - timerlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Add(timerlabel); + Add(datelabel); + Add(weekLabel); + return true; + } + /* + 界面颜色显示 + 0 白 + 1 黑 + 2 灰 + 3 绿 + 4 橙 + 5 蓝 + + 默认:白 + */ + bool MainClockView::InitColor(ColorTypeSet type) + { + if (!timerlabel || !datelabel || !weekLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is null"); + return false; + } + int16 textColor; + + // 根据传入的颜色类型设置文本颜色 + switch (type) + { + case COLOR_BLACK: + timerlabel->SetTextColor(Color::Black()); + datelabel->SetTextColor(Color::Black()); + weekLabel->SetTextColor(Color::Black()); + break; + case COLOR_GRAY: + timerlabel->SetTextColor(Color::Gray()); + datelabel->SetTextColor(Color::Gray()); + weekLabel->SetTextColor(Color::Gray()); + break; + case COLOR_GREEN: + timerlabel->SetTextColor(Color::Green()); + datelabel->SetTextColor(Color::Green()); + weekLabel->SetTextColor(Color::Green()); + break; + case COLOR_ORANGE: + timerlabel->SetTextColor(Color::Orange()); + datelabel->SetTextColor(Color::Orange()); + weekLabel->SetTextColor(Color::Orange()); + break; + case COLOR_BLUE: + timerlabel->SetTextColor(Color::Blue()); + datelabel->SetTextColor(Color::Blue()); + weekLabel->SetTextColor(Color::Blue()); + break; + case COLOR_WHITE: + default: // 默认情况下使用白色 + timerlabel->SetTextColor(Color::White()); + datelabel->SetTextColor(Color::White()); + weekLabel->SetTextColor(Color::White()); + break; + } + return true; + } + /* + 电量显示 [电池框图片 电池进度条 电池标签] + 0 不显示图标 + 1 显示黑色 + 2 显示白色 + + 默认:白色 + */ + bool MainClockView::InitBatteryView(BatteryDisplayType type) + { + // 不显示电池 icon + if (type == BATTERY_DISPLAY_NONE) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no show battery"); + return false; + } - // 星期 - weekLabel = new UILabel(); - if (weekLabel == nullptr) + // 创建电池框图像 + batteryiamge = new UIImageView(); + if (!batteryiamge) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryiamge creation failed"); return false; } - weekLabel->SetPosition(180, 375, TEXT_WIDTH, TEXT_HEIGHT); - weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); - weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - weekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - weekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - Add(weekLabel); - datelabel = new UILabel(); - if (datelabel == nullptr) + // 创建电池图标图像 + batteryicon = new UIImageView(); + if (!batteryicon) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryicon creation failed"); return false; } - datelabel->SetPosition(250, 375, TEXT_WIDTH, TEXT_HEIGHT); - datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); - datelabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - datelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - Add(datelabel); - InitDateTime(); + // 创建电池进度条 + batteryprogress = new UIBoxProgress(); + if (!batteryprogress) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryprogress creation failed"); + return false; + } + + // 创建电池标签 + batterylabel = new UILabel(); + if (!batterylabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batterylabel creation failed"); + return false; + } + + // 设置位置 + batteryicon->SetPosition(185, 52, 100, 100); + batteryiamge->SetPosition(173, 52, 100, 100); + batteryprogress->SetPosition(179, 59, 30, 18); + batteryprogress->SetViewId("progress"); + batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + batterylabel->SetPosition(228, 54, 200, 60); + batterylabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + // 设置图标和颜色 + switch (type) + { + case BATTERY_DISPLAY_BLACK: + batteryiamge->SetSrc(BLACK_BATTERY); + batterylabel->SetTextColor(Color::Black()); + batteryprogress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000); + break; + case BATTERY_DISPLAY_WHITE: + default: // 默认不做额外操作,保持白色 + batteryiamge->SetSrc(WHITE_BATTERY); + batterylabel->SetTextColor(Color::White()); + batteryprogress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xffffffff); + break; + } + batteryicon->SetSrc(CHAGE_BATTERY); + batteryicon->SetVisible(false); // 设置不可见 + + Add(batteryiamge); + Add(batterylabel); + Add(batteryprogress); + Add(batteryicon); return true; } @@ -195,13 +418,13 @@ namespace OHOS viewiInitStatus = true; } - if(!resLoadStatus) + if (!resLoadStatus) { - if(PullUpDownView::GetInstance()!=nullptr) + if (PullUpDownView::GetInstance() != nullptr) { PullUpDownView::GetInstance()->PreLoad(); } - if(MessageControlView::GetInstance()!=nullptr) + if (MessageControlView::GetInstance() != nullptr) { MessageControlView::GetInstance()->PreLoad(); } @@ -213,14 +436,14 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::UnLoad"); - if(resLoadStatus) + if (resLoadStatus) { - if(PullUpDownView::GetInstance()!=nullptr) + if (PullUpDownView::GetInstance() != nullptr) { PullUpDownView::GetInstance()->UnLoad(); } - if(MessageControlView::GetInstance()!=nullptr) + if (MessageControlView::GetInstance() != nullptr) { MessageControlView::GetInstance()->UnLoad(); } @@ -231,10 +454,12 @@ namespace OHOS bool MainClockView::InitView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); - if (InitSweepClock() == false) + if (InitClock() == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitClock is error"); return false; } + InitDateTime(); // 初始化数据 SetCoverable(true); return true; } @@ -244,75 +469,152 @@ namespace OHOS UpdateTime(); } + /* 更新时间 */ void MainClockView::UpdateTime(void) - { - struct tm local_time={0}; + { + struct tm local_time = {0}; time_t seconds = time(nullptr); - uint8_t hour = 0 ; - uint8_t minute = 0 ; - if (localtime_r(&seconds, &local_time) != NULL) { - hour = local_time.tm_hour; - minute = local_time.tm_min; - }else{ + + if (localtime_r(&seconds, &local_time) == nullptr) + { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get localtime error!"); - hour = 0 ; - minute = 0; - } - - if (hour > 24) hour = 0; - if (minute >= 60) minute = 0; - - char *phour = nullptr; - char timebuf[64]={0}; - if(uapi_dev_runtime_get_time_hour_show_model() == 12 ) - { - if(hour < 12) - { - phour="AM"; - }else if (hour == 12) - { - phour="PM"; - }else{ - phour="PM"; - hour = hour - 12; - } + return; } - if (phour == nullptr) + + // 处理小时和分钟 + uint8_t hour = local_time.tm_hour % HOURS_IN_DAY; + uint8_t minute = local_time.tm_min % MINUTES_IN_HOUR; + + // 处理12小时制显示 + char timebuf[64] = {0}; + const char *phour = (uapi_dev_runtime_get_time_hour_show_model() == HOUR_FORMAT_12) ? (hour < HOUR_FORMAT_12 ? "AM" : "PM") : nullptr; + + if (phour) + { + if (hour > HOUR_FORMAT_12) + hour -= HOUR_FORMAT_12; + sprintf_s(timebuf, sizeof(timebuf), "%s %02d:%02d", phour, hour, minute); + } + else { - sprintf_s(timebuf,sizeof(timebuf),"%02d:%02d",hour,minute); - }else{ - sprintf_s(timebuf,sizeof(timebuf),"%02d:%02d",hour,minute); - // sprintf_s(timebuf,sizeof(timebuf),"%s%02d:%02d",phour,hour,minute); - } + sprintf_s(timebuf, sizeof(timebuf), "%02d:%02d", hour, minute); + } // 更新界面上的文本 - timerlabel->SetText(timebuf); - // 更新日期需要nextday的消息 + if (timerlabel != nullptr) + timerlabel->SetText(timebuf); + + // 更新星期和日期 + std::string weekStr = Cnweekdays[local_time.tm_wday]; + std::string dateStr = std::to_string(local_time.tm_mon + 1) + "月" + + std::to_string(local_time.tm_mday) + "日"; + + if (weekLabel != nullptr) + weekLabel->SetText(weekStr.c_str()); + if (datelabel != nullptr) + datelabel->SetText(dateStr.c_str()); + + // 更新电量 + if (batterySetting == BATTERY_DISPLAY_NONE) + return; + + UpdateBatteryColor(); + + float voltage = 0.0F; + int power = battery_get_voltage(&voltage); + if (power == power_) + return; + + power_ = power; + if (batteryprogress != nullptr && batterylabel != nullptr) + { + batteryprogress->SetValue(power_); + std::string batteryStr = std::to_string(power_) + "%"; + batterylabel->SetText(batteryStr.c_str()); + } + } + + void MainClockView::UpdateBatteryColor(void) + { + bool isCharging = get_charge_stat(); // 获取充电状态 + + if (isCharging) + { + if (!isBatteryIconVisible) + { + batteryicon->SetVisible(true); + isBatteryIconVisible = true; + } + SetViewColor(Color::Green().full); // 充电状态为绿色 + return; + } + else + { + if (isBatteryIconVisible) + { + batteryicon->SetVisible(false); + isBatteryIconVisible = false; + } + + if (power_ <= BATTERY_LOW_THRESHOLD) + { + SetViewColor(Color::Red().full); + } + else if (power_ <= BATTERY_MEDIUM_THRESHOLD) + { + SetViewColor(Color::Yellow().full); + } + else + { + if (batterySetting == BATTERY_DISPLAY_BLACK) + { + SetViewColor(Color::Black().full); + } + else + { + SetViewColor(Color::White().full); + } + } + } + } + + void MainClockView::SetViewColor(int64_t color) + { + if (color == color_) + { + return; + } + color_ = color; + batteryprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, color_); } - /* -------------------------------------------------------------------------- */ + /*刷新步数*/ void MainClockView::RefreshStep(int step) { -#if DEFULTDIAL + if (stepLabel == nullptr) + return; + char stepChar[STEP_CHAR_NUM] = {0}; (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); stepLabel->SetText(stepChar); -#endif } + /*刷新心率*/ void MainClockView::RefreshHeartRate(int value) { -#if DEFULTDIAL + if (heartlabel == nullptr) + return; + if (value == 0) { - datelabel->SetText("--"); + heartlabel->SetText("--"); return; } char heartRateChar[STEP_CHAR_NUM] = {0}; (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value); - datelabel->SetText(heartRateChar); -#endif + heartlabel->SetText(heartRateChar); } -#ifdef DEFULTDIAL + + /*初始化步数*/ void MainClockView::InitStepValue() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); @@ -331,52 +633,8 @@ namespace OHOS return; } stepLabel->SetText(stepChar); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); - } - bool MainClockView::InitLabelView(void) - { - UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); - stepLabel = new UILabelButton(); - if (stepLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepLabel new fail"); - return false; - } - stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y); - stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE); - stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); - stepLabel->SetTouchable(true); - stepLabel->SetOnClickListener(clickListener); - InitStepValue(); - - datelabel = new UILabel(); - if (datelabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel new fail"); - return false; - } - datelabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); - datelabel->SetText("--"); - datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - datelabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - - weekLabel = new UILabel(); - if (weekLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); - return false; - } - weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); - weekLabel->SetText("2"); - weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); - weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - return true; } + /*初始化指针图片*/ bool MainClockView::InitCenterCircleView(void) { @@ -418,7 +676,6 @@ namespace OHOS bool MainClockView::InitHandView(void) { - secondHand = new Image(); if (secondHand == nullptr) { @@ -492,5 +749,4 @@ namespace OHOS view->SetSrc(image); return true; } -#endif } 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 c539f6d80..d6657bf67 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -211,20 +211,25 @@ namespace OHOS HorizontalViewInit(); HorViewLoad(); - VerticalViewInit(); - VertViewLoad(); + VerticalViewInit(); // 初始化上下拉界面 + VertViewLoad(); // 添加上下拉界面 mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - mainSwipeGroup->SetAnimatorTime(50); // 50: animator drag time(ms); - mainSwipeGroup->SetLoopState(true); // 关闭主界面循环 - mainSwipeGroup->EnableScreenCap(true); - mainSwipeGroup->RegisterSwipeCallback(callback); + mainSwipeGroup->SetAnimatorTime(50); + mainSwipeGroup->SetLoopState(true); // 主界面循环 + mainSwipeGroup->EnableScreenCap(true); // 主界面截屏滑动 + mainSwipeGroup->RegisterSwipeCallback(callback); // 主界面动画回调 + + // 判断是否为从主界面前往的其他Slice if (presenter_->IsFromSetCardView()) { + // 回退标志位 presenter_->SetFromSetCardView(false); + // 设置Id为主界面显示索引 SwitchToCard(presenter_->GetFromCardId()); } else { + // 回到表盘 SwitchToClockPage(); } SetContainerView(mainSwipeGroup); @@ -360,9 +365,11 @@ namespace OHOS // dial->SetDial(DEFAULT_DIAL_PATH); return dial; } + /*初始化自定义表盘*/ UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWathDial"); +#if 0 switch (setting.dialId) { case DIAL_CLOCK: @@ -373,6 +380,11 @@ namespace OHOS default: return nullptr; } +#endif + MainClockView *clock = new MainClockView(); + clock->SetDialPath(setting.dialFullName); + clock->InitialConfig(setting.dialId); + return clock; } UICardPage *MainViewSample::InitWatchFacePage(void) { @@ -437,7 +449,7 @@ namespace OHOS } return bloodView; } - + // 主界面训练卡片 UICardPage *MainViewSample::InitTrainingPage(void) { @@ -464,7 +476,7 @@ namespace OHOS return weatherControlView; } - //主界面每日目标卡片 + // 主界面每日目标卡片 UICardPage *MainViewSample::InitGoalPage(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWeatherPage"); @@ -489,7 +501,7 @@ namespace OHOS } return heartRateView; } - + // 主界面运动卡片 UICardPage *MainViewSample::InitActivityPage(void) { diff --git a/tools/dial_converter_tool/instance/112/Battery/Battery.png b/tools/dial_converter_tool/instance/112/Battery/Battery.png new file mode 100644 index 000000000..916febe86 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/Battery/Battery.png differ diff --git a/tools/dial_converter_tool/instance/112/Battery/BatteryCharge.png b/tools/dial_converter_tool/instance/112/Battery/BatteryCharge.png new file mode 100644 index 000000000..4c26888f3 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/Battery/BatteryCharge.png differ diff --git a/tools/dial_converter_tool/instance/112/birdie.mp4 b/tools/dial_converter_tool/instance/112/birdie.mp4 new file mode 100644 index 000000000..410aac76e Binary files /dev/null and b/tools/dial_converter_tool/instance/112/birdie.mp4 differ diff --git a/tools/dial_converter_tool/instance/112/birdie.png b/tools/dial_converter_tool/instance/112/birdie.png new file mode 100644 index 000000000..c802c9d05 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/birdie.png differ diff --git a/tools/dial_converter_tool/instance/112/birdie.xml b/tools/dial_converter_tool/instance/112/birdie.xml new file mode 100644 index 000000000..978c53571 --- /dev/null +++ b/tools/dial_converter_tool/instance/112/birdie.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/dial_converter_tool/instance/112/preview_birdie.png b/tools/dial_converter_tool/instance/112/preview_birdie.png new file mode 100644 index 000000000..1b2486d22 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/preview_birdie.png differ diff --git a/tools/dial_converter_tool/instance/112/week/1.png b/tools/dial_converter_tool/instance/112/week/1.png new file mode 100644 index 000000000..6304005b1 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/1.png differ diff --git a/tools/dial_converter_tool/instance/112/week/2.png b/tools/dial_converter_tool/instance/112/week/2.png new file mode 100644 index 000000000..5454b1190 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/2.png differ diff --git a/tools/dial_converter_tool/instance/112/week/3.png b/tools/dial_converter_tool/instance/112/week/3.png new file mode 100644 index 000000000..110a03318 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/3.png differ diff --git a/tools/dial_converter_tool/instance/112/week/4.png b/tools/dial_converter_tool/instance/112/week/4.png new file mode 100644 index 000000000..a8fbf5442 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/4.png differ diff --git a/tools/dial_converter_tool/instance/112/week/5.png b/tools/dial_converter_tool/instance/112/week/5.png new file mode 100644 index 000000000..8d7a3ee42 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/5.png differ diff --git a/tools/dial_converter_tool/instance/112/week/6.png b/tools/dial_converter_tool/instance/112/week/6.png new file mode 100644 index 000000000..f49f8ef98 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/6.png differ diff --git a/tools/dial_converter_tool/instance/112/week/7.png b/tools/dial_converter_tool/instance/112/week/7.png new file mode 100644 index 000000000..45dff3434 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/7.png differ diff --git a/tools/dial_converter_tool/instance/112/week/FIRDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/FIRDAY_IMAGE_PATH.png new file mode 100644 index 000000000..9c3993262 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/FIRDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/MONDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/MONDAY_IMAGE_PATH.png new file mode 100644 index 000000000..58d2cdd29 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/MONDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/SATURDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/SATURDAY_IMAGE_PATH.png new file mode 100644 index 000000000..861ad16a8 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/SATURDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/SUNDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/SUNDAY_IMAGE_PATH.png new file mode 100644 index 000000000..1a0947185 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/SUNDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/THURSDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/THURSDAY_IMAGE_PATH.png new file mode 100644 index 000000000..a2e27c6d8 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/THURSDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/TUESDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/TUESDAY_IMAGE_PATH.png new file mode 100644 index 000000000..c5b292dcb Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/TUESDAY_IMAGE_PATH.png differ diff --git a/tools/dial_converter_tool/instance/112/week/WEDNESDAY_IMAGE_PATH.png b/tools/dial_converter_tool/instance/112/week/WEDNESDAY_IMAGE_PATH.png new file mode 100644 index 000000000..e099b5661 Binary files /dev/null and b/tools/dial_converter_tool/instance/112/week/WEDNESDAY_IMAGE_PATH.png differ