From: luozheng <1732036298@qq.com> Date: Wed, 22 Apr 2026 08:26:31 +0000 (+0800) Subject: evb 文件夹 1201patch重新合并提交 X-Git-Url: http://git.snicker.com.cn/css/html/static/gitweb.css?a=commitdiff_plain;h=ee73e29bed56505157c71595f89c76bcfef8355f;p=mirrors%2FFD230.git evb 文件夹 1201patch重新合并提交 --- diff --git a/code/sdk/application/wearable/evb/auto_ota/auto_ota_service.c b/code/sdk/application/wearable/evb/auto_ota/auto_ota_service.c new file mode 100644 index 000000000..692202ea7 --- /dev/null +++ b/code/sdk/application/wearable/evb/auto_ota/auto_ota_service.c @@ -0,0 +1,603 @@ +/** + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Power display service. + * Author: + * Create: + */ + +#include +#include +#include +#include "cmsis_os2.h" +#include "systick.h" +#include "soc_errno.h" +#include "common_def.h" +#include "bts_def.h" +#include "bts_br_gap.h" +#include "oal_interface.h" +#include "wearable_log.h" +#include "local_device_manager.h" +#include "remote_device_manager.h" +#include "spp_service.h" +#include "bts_spp.h" +#include "btsrv_log.h" +#include "bts_feature.h" +#include "auto_ota_service.h" +#include "msg_center_ota.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AUTO_OTA_RETRY_TIMES 5 +#define AUTO_OTA_SEM_TIMEOUT (60*60*1000) /* 等待信号量超时时间,考虑资源大包传输时间长场景 */ +#define AUTO_OTA_DELAY_MS 100 +#define AUTO_OTA_SPP_TASK_STACK_SIZE 2048 +#define AUTO_OTA_SPP_TASK_PRI 20 +#define ADDR_MAC_LEN 6 +#define AUTO_OTA_RECORD_DEV_MAX_NUM 200 /* 设计成客户可定制 */ +#define AUTO_OTA_SCAN_WAIT_TIME (25*1000) /* 客户可定制 */ +#define AUTO_OTA_UPDATE_RSSI_WAIT_TIME (20*1000) /* 客户可定制 */ +#define AUTO_OTA_INQUERY_DEV_NUM 20 /* 客户可定制 */ +#define AUTO_OTA_OPRATE_DELAY_MS (2*1000) /* 客户可定制 */ +#define AUTO_OTA_ACL_CONN_DELAY (6*1000) /* 客户可定制 */ +#define AUTO_OTA_SPP_RECONN_TIMEOUT 10000 /* 客户可定制 */ +#define AUTO_OTA_WAIT_PREPARE_TIMEOUT (2 * 1000) /* 客户可定制, 用于更换升级包场景 */ +#define AUTO_OTA_DEV_NAME_PREFIX "Watch" /* 客户基于自己产品定义修改bt name前缀,用于黑名单管理 */ +#define AUTO_OTA_DEV_NAME_PREFIX_LEN 5 +#define AUTO_OTA_DST_UPG_VER_PATH "/user/dst_ver.txt" + +bool g_auto_ota_found_list_init = false; +struct osal_list_head g_auto_ota_found_dev_list_head; +osSemaphoreId_t g_auto_ota_transmit_done_sem = NULL; +uint8_t g_auto_ota_upload_mode = 0; /* 默认是0,不阻塞auto_ota */ +uint8_t g_auto_ota_mac_tmp[ADDR_MAC_LEN] = {0}; +static bool g_anti_back_link_flag = false; + +typedef struct auto_ota_record_dev { + uint8_t addr[ADDR_MAC_LEN]; /* mac地址 */ + uint8_t has_been_updated; /* 标记是否已经升级 */ + uint8_t reserved; /* 对齐 */ +} auto_ota_record_dev_t; + +static auto_ota_record_dev_t g_auto_ota_record_dev[AUTO_OTA_RECORD_DEV_MAX_NUM]; + +typedef struct { + struct osal_list_head node; + bd_addr_t bd_addr; + uint8_t name[BD_NAME_LEN]; + int32_t cod; + int32_t rssi; +} auto_ota_found_dev_list_node; + +typedef struct { + uint32_t sample_mode; + spp_create_socket_para_t socket_params; + bd_addr_t addr; +} auto_ota_spp_connect_task_params; + +/* 数据管理 */ +void auto_ota_dev_init(void) +{ + for (uint8_t i = 0; i < AUTO_OTA_RECORD_DEV_MAX_NUM; i++) { + (void)memset_s(&g_auto_ota_record_dev[i], sizeof(auto_ota_record_dev_t), 0, sizeof(auto_ota_record_dev_t)); + } + return; +} + +void auto_ota_dev_add(uint8_t *addr) +{ + for (uint16_t i = 0; i < AUTO_OTA_RECORD_DEV_MAX_NUM; i++) { + if (g_auto_ota_record_dev[i].has_been_updated == 0) { + (void)memcpy_s(g_auto_ota_record_dev[i].addr, ADDR_MAC_LEN, addr, ADDR_MAC_LEN); + g_auto_ota_record_dev[i].has_been_updated = 1; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "to add record dev_mac : ****%02x%02x%02x%02x\r\n", + g_auto_ota_record_dev[i].addr[3], g_auto_ota_record_dev[i].addr[2], g_auto_ota_record_dev[i].addr[1], + g_auto_ota_record_dev[i].addr[0]); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "alloc index = %d\r\n", i); + return; + } + } +} + +bool auto_ota_dev_del(uint8_t *addr) +{ + for (uint16_t i = 0; i < AUTO_OTA_RECORD_DEV_MAX_NUM; i++) { + if (g_auto_ota_record_dev[i].has_been_updated == 1 && + memcmp(g_auto_ota_record_dev[i].addr, addr, ADDR_MAC_LEN) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "found! to del record dev_mac : ****%02x%02x%02x%02x\r\n", + g_auto_ota_record_dev[i].addr[3], g_auto_ota_record_dev[i].addr[2], g_auto_ota_record_dev[i].addr[1], + g_auto_ota_record_dev[i].addr[0]); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "free index = %d\r\n", i); + (void)memset_s(g_auto_ota_record_dev[i].addr, ADDR_MAC_LEN, 0, ADDR_MAC_LEN); + g_auto_ota_record_dev[i].has_been_updated = 0; + return true; + } + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "dev_del: no found dev_mac.\r\n"); + return false; +} + +bool auto_ota_dev_found(uint8_t *addr) +{ + for (uint16_t i = 0; i < AUTO_OTA_RECORD_DEV_MAX_NUM; i++) { + if (g_auto_ota_record_dev[i].has_been_updated == 1 && + memcmp(g_auto_ota_record_dev[i].addr, addr, ADDR_MAC_LEN) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "no need to record dev_mac: ****%02x%02x%02x%02x\r\n", + g_auto_ota_record_dev[i].addr[3], g_auto_ota_record_dev[i].addr[2], g_auto_ota_record_dev[i].addr[1], + g_auto_ota_record_dev[i].addr[0]); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "taken index = %d\r\n", i); + return true; + } + } + return false; +} + +void auto_ota_dev_show(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "auto_ota total dev info :"); + for (uint16_t i = 0; i < AUTO_OTA_RECORD_DEV_MAX_NUM; i++) { + if (g_auto_ota_record_dev[i].has_been_updated == 1) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "already record dev_mac : ****%02x%02x%02x%02x\r\n", + g_auto_ota_record_dev[i].addr[3], g_auto_ota_record_dev[i].addr[2], g_auto_ota_record_dev[i].addr[1], + g_auto_ota_record_dev[i].addr[0]); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "taken index = %d\r\n", i); + } + } +} + +/* 黑名单处理 */ +static bool auto_ota_dev_check_dev_name(unsigned char *dev_name) +{ + if (strncmp((const char *)dev_name, AUTO_OTA_DEV_NAME_PREFIX, AUTO_OTA_DEV_NAME_PREFIX_LEN) == 0) { + return true; + } else { + return false; + } +} + +/* 重置发现设备链表 */ +void auto_ota_reset_found_dev_list(void) +{ + if (!g_auto_ota_found_list_init) { + g_auto_ota_found_list_init = true; + OSAL_INIT_LIST_HEAD(&g_auto_ota_found_dev_list_head); + return; + } + + while (osal_list_empty(&g_auto_ota_found_dev_list_head) == false) { + struct osal_list_head *node = g_auto_ota_found_dev_list_head.next; + osal_list_del(node); + oal_mem_free(node); + } +} + +bool auto_ota_bt_start_discovery(void) +{ + auto_ota_reset_found_dev_list(); + (void)gap_br_set_inquiry_paramters(0, AUTO_OTA_INQUERY_DEV_NUM); + for (uint8_t i = 0; i < AUTO_OTA_RETRY_TIMES; i++) { + bool res = gap_br_start_discovery(); + if (res != true) { + osDelay(AUTO_OTA_DELAY_MS); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "gap_br_start_discovery fail.\r\n"); + continue; + } else { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "gap_br_start_discovery succ.\r\n"); + return true; + } + } + return false; +} + +/* 新增节点 */ +static void auto_ota_add_node_to_found_dev_list(const bd_addr_t *bd_addr, const uint8_t *name, int32_t cod, int32_t rssi) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "auto_ota_add_node, addr: ****%02x%02x%02x%02x, name: %s", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], name); /* addr下标 0 1 2 3 */ + + auto_ota_found_dev_list_node *node = + (auto_ota_found_dev_list_node *)(void *)oal_mem_alloc(sizeof(auto_ota_found_dev_list_node)); + if (node == NULL) { + return; + } + (void)memset_s(node, sizeof(auto_ota_found_dev_list_node), 0, sizeof(auto_ota_found_dev_list_node)); + + if (memcpy_s(&node->bd_addr, sizeof(node->bd_addr), bd_addr, sizeof(bd_addr_t)) != EOK) { + oal_mem_free(node); + return; + } + + if (memcpy_s(node->name, sizeof(node->name), name, BD_NAME_LEN) != EOK) { + oal_mem_free(node); + return; + } + + node->cod = cod; + node->rssi = rssi; + osal_list_add_tail((struct osal_list_head *)node, &g_auto_ota_found_dev_list_head); +} + +static void auto_ota_sort_found_dev_list(void) +{ + struct osal_list_head *list_head = &g_auto_ota_found_dev_list_head; + + for (struct osal_list_head *node1 = list_head->next; node1 != NULL && node1 != list_head; node1 = node1->next) { + auto_ota_found_dev_list_node *dev_info1 = (auto_ota_found_dev_list_node *)node1; + for (struct osal_list_head *node2 = node1->next; node2 != NULL && node2 != list_head; node2 = node2->next) { + auto_ota_found_dev_list_node *dev_info2 = (auto_ota_found_dev_list_node *)node2; + + /* rssi大的在前 */ + if (dev_info1->rssi >= dev_info2->rssi) { + continue; + } + + /* 交换两个节点的信息 */ + auto_ota_found_dev_list_node tmp_node; + uint32_t ret = + (uint32_t)memcpy_s(&tmp_node, sizeof(tmp_node), dev_info1, sizeof(auto_ota_found_dev_list_node)); + ret |= (uint32_t)memcpy_s(&dev_info1->bd_addr, + sizeof(auto_ota_found_dev_list_node) - sizeof(struct osal_list_head), + &dev_info2->bd_addr, + sizeof(auto_ota_found_dev_list_node) - sizeof(struct osal_list_head)); + ret |= (uint32_t)memcpy_s(&dev_info2->bd_addr, + sizeof(auto_ota_found_dev_list_node) - sizeof(struct osal_list_head), + &tmp_node.bd_addr, + sizeof(auto_ota_found_dev_list_node) - sizeof(struct osal_list_head)); + if (ret != EOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "swap fail %x\n", ret); + } + } + } +} + +/* 异步返回,更新RSSI */ +static void auto_ota_update_found_dev_node_rssi(const bd_addr_t *bd_addr, int32_t rssi) +{ + struct osal_list_head *list_head = &g_auto_ota_found_dev_list_head; + struct osal_list_head *node = list_head->next; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER,"will update rssi, addr: ****%02x%02x%02x%02x, rssi = %d\n", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], rssi); /* addr下标 0 1 2 3 */ + + while (node != NULL && node != list_head) { + auto_ota_found_dev_list_node *dev_info = (auto_ota_found_dev_list_node *)node; + if (memcmp(dev_info->bd_addr.addr, bd_addr->addr, BD_ADDR_LEN) == 0) { + dev_info->rssi = rssi; + return; + } + + node = node->next; + } +} + +static void auto_ota_gap_read_remote_rssi_event_callback(const bd_addr_t *bd_addr, int rssi, int status) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, + " addr: ****%02x%02x%02x%02x rssi: %d status: %d\n", + bd_addr->addr[3], bd_addr->addr[2], /* addr下标 2 3 */ + bd_addr->addr[1], bd_addr->addr[0], rssi, status); /* addr下标 0 1 */ + + if (status == ERRCODE_BT_SUCCESS) { + auto_ota_update_found_dev_node_rssi(bd_addr, rssi); + } +} + +static bool auto_ota_get_top_dev_to_connect(void) +{ + struct osal_list_head *list_head = &g_auto_ota_found_dev_list_head; + uint8_t blank_addr[ADDR_MAC_LEN] = {0}; + + for (struct osal_list_head *node = list_head->next; node != NULL && node != list_head; node = node->next) { + auto_ota_found_dev_list_node *dev_info = (auto_ota_found_dev_list_node *)node; + if (memcmp(dev_info->bd_addr.addr, blank_addr, ADDR_MAC_LEN) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "ignore zero addr, name: %s\n", dev_info->name); + continue; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, + "plan to connect addr: ****%02x%02x%02x%02x name: \"%s\" cod: %x rssi: %d\n", + dev_info->bd_addr.addr[3], dev_info->bd_addr.addr[2], /* addr下标 3 2 */ + dev_info->bd_addr.addr[1], dev_info->bd_addr.addr[0], /* addr下标 1 0 */ + dev_info->name, + dev_info->cod, + dev_info->rssi); + + for (uint8_t i = 0; i < AUTO_OTA_RETRY_TIMES; i++) { + if (gap_connect_remote_device(&(dev_info->bd_addr)) != true) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "to connect acl fail\r\n"); + osDelay(100); + } else { + osDelay(AUTO_OTA_ACL_CONN_DELAY); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "to connect acl succ\r\n"); + return true; + } + } + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "no found_device\n"); + return false; +} + +static void auto_ota_discovery_result_callback(const bd_addr_t *bd_addr) +{ + unsigned char length = BD_NAME_LEN; + unsigned char *device_name = (unsigned char *)(void *)oal_mem_alloc(length); + if (device_name == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "gap_discovery_result_callback malloc error!\n"); + return; + } + (void)memset_s(device_name, length, 0, length); + + bool ret1 = gap_get_device_name(bd_addr, device_name, &length); + int cod = gap_get_device_class(bd_addr); + bool ret2 = gap_read_remote_rssi_value(bd_addr); + + if (auto_ota_dev_found(bd_addr->addr) != true && auto_ota_dev_check_dev_name(device_name) == true) { + auto_ota_add_node_to_found_dev_list(bd_addr, device_name, cod, 0); + } + + return; +} + +static bool auto_ota_upg_check(void) +{ + errcode_t ret = ERRCODE_SUCC; + + /* 目标版本从文件读取,方便客户每次推送不同版本 */ + FILE *fp = NULL; + + fp = fopen(AUTO_OTA_DST_UPG_VER_PATH, "rb"); + if (fp == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "open %s fail.\r\n", AUTO_OTA_DST_UPG_VER_PATH); + return false; + } + + fseek(fp, 0L, SEEK_END); + long file_len = ftell(fp); + char *dst_ver = (char *)malloc(sizeof(char) * (file_len + 1)); + if (dst_ver == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "malloc fail, file_len = %d.\r\n", file_len); + fclose(fp); + return false; + } + + fseek(fp, 0L, SEEK_SET); + if (fread(dst_ver, file_len, 1, fp) != 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "fread fail, file_len = %d.\r\n", file_len); + fclose(fp); + free(dst_ver); + dst_ver = NULL; + return false; + } + fclose(fp); + dst_ver[file_len] = '\0'; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "dst_ver = %s, file_len = %d.\r\n", dst_ver, file_len); + + ret = msg_center_send_data(MSGCENTER_CMD_OTA, MSGCENTER_TYPE_ID_OTA_UPG_CHECK, dst_ver, strlen(dst_ver)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send upgrade version check fail, ret = %d\r\n", ret); + free(dst_ver); + dst_ver = NULL; + return false; + } + + free(dst_ver); + dst_ver = NULL; + return true; +} + +static int auto_ota_spp_client_connect_task_body(void *data) +{ + auto_ota_spp_connect_task_params *task_params = (auto_ota_spp_connect_task_params *)data; + spp_create_socket_para_t *socket_param = &task_params->socket_params; + + int ret = spp_connect(socket_param, &task_params->addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "spp_connect ret: %x\n", ret); + + oal_mem_free(data); + return OSAL_SUCCESS; +} + +/* client连接server */ +bool auto_ota_spp_connect(const char *spp_uuid, const bd_addr_t *addr) +{ + uint8_t uuid_len = (uint8_t)strlen(spp_uuid); + auto_ota_spp_connect_task_params *task_params = + (auto_ota_spp_connect_task_params *)oal_mem_alloc(sizeof(auto_ota_spp_connect_task_params)); + + if (generate_uuid_from_string(spp_uuid, uuid_len + 1, &task_params->socket_params.uuid) != EXT_ERR_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "generate uuid fail\n"); + return false; + } + + task_params->sample_mode = 0; + task_params->socket_params.socket_type = SPP_SOCKET_RFCOMM; + task_params->socket_params.is_encrypt = true; + (void)memcpy_s(&(task_params->addr.addr), BD_ADDR_LEN, addr->addr, BD_ADDR_LEN); + + osal_task *task = osal_kthread_create(auto_ota_spp_client_connect_task_body, task_params, + "auto_ota_spp_client_connect_task", AUTO_OTA_SPP_TASK_STACK_SIZE); + if (task == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "create task fail\n"); + return false; + } + int ret = osal_kthread_set_priority(task, AUTO_OTA_SPP_TASK_PRI); + if (ret != OSAL_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "set pri error: %08x\n", ret); + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "create task success.\n"); + + bool is_connected = false; + uint64_t start_time = uapi_tcxo_get_ms(); + uint64_t current_time; + while (is_connected == false) { + is_connected = is_spp_connected(0); + osDelay(AUTO_OTA_OPRATE_DELAY_MS); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "spp reconnecting.\r\n"); + current_time = uapi_tcxo_get_ms(); + if (current_time - start_time > AUTO_OTA_SPP_RECONN_TIMEOUT || is_connected == true) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "spp connect %s.\r\n", is_connected == true ? "Succ" : "Fail"); + break; + } + } + + /* 升级版本号校验 */ + bool res = auto_ota_upg_check(); + if (res != true) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "auto_ota_upg_check fail.\n"); + return false; + } + + return true; +} + +static void auto_ota_acl_state_changed_callback(const bd_addr_t *bd_addr, gap_acl_state_t state, unsigned int reason) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "acl cb, state %d, reason %x", state, reason); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "addr: ****%02x%02x%02x%02x", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* mac下标 0 1 2 3 */ + char uuid[] = {"1101"}; + if (state == GAP_ACL_STATE_CONNECTED) { + if (g_anti_back_link_flag == true) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "anti back link addr: ****%02x%02x%02x%02x", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* mac下标 0 1 2 3 */ + return; + } + bool res = auto_ota_spp_connect(uuid, bd_addr); + if (res != true) { + (void)osSemaphoreRelease(g_auto_ota_transmit_done_sem); + return; + } + /* spp trans回调中释放信号量最准确,故此处临时记录mac地址 */ + (void)memcpy_s(g_auto_ota_mac_tmp, ADDR_MAC_LEN, (const char *)bd_addr->addr, ADDR_MAC_LEN); + g_anti_back_link_flag = true; + } +} + +void auto_ota_gap_register_callbacks(void) +{ + gap_call_backs_t cb = { + NULL, + auto_ota_acl_state_changed_callback, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + auto_ota_discovery_result_callback, + NULL, + NULL, + NULL, + NULL, + NULL, + auto_ota_gap_read_remote_rssi_event_callback, + NULL + }; + (void)gap_register_callbacks(&cb); +} + +errcode_t auto_ota_enable_bt(void) +{ +#if defined(SW_UART_DEBUG) || defined(SW_RTT_DEBUG) + g_bth_log_type_level = 0xFF2; /* BTSRV_LOG_UART_INFO */ +#endif + bts_feature_t feature = {0}; + feature.bt_auto_reconnect_closed = 1; + + auto_ota_gap_register_callbacks(); + bts_set_features(&feature); /* 关闭client回链 */ + errcode_t res = enable_bt_stack(); + if (res != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "bt enable fail, ret = %d\r\n", res); + return ERRCODE_FAIL; + } else { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "bt enable ok\r\n"); + return ERRCODE_SUCC; + } +} + +void auto_ota_task_init(void) +{ + g_auto_ota_transmit_done_sem = osSemaphoreNew(1, 0, NULL); + if (!g_auto_ota_transmit_done_sem) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "sem creat fail!\r\n"); + return; + } +} + +void auto_ota_task_main(void) +{ + errcode_t ret; + + auto_ota_dev_init(); + auto_ota_task_init(); + + if (auto_ota_enable_bt() != ERRCODE_SUCC) { + return; + } + + while (1) { + if (g_auto_ota_upload_mode == 1) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "enter upload fwpkg mode, auto_ota not run!\r\n"); + osDelay(AUTO_OTA_WAIT_PREPARE_TIMEOUT); + continue; + } + + /* 保证最开始不会有配对信息回连,可能导致Bæ ¸wait等回连 */ + if (gap_remove_all_pairs() != true) { + osDelay(AUTO_OTA_DELAY_MS); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "remove all pairs fail, auto retry...\r\n"); + continue; + } + osDelay(AUTO_OTA_OPRATE_DELAY_MS); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "gap_remove_all_pairs ok\r\n"); + + /* scan */ + if (auto_ota_bt_start_discovery() != true) { + osDelay(AUTO_OTA_DELAY_MS); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "start discovery fail, auto retry...\r\n"); + continue; + } + + osDelay(AUTO_OTA_SCAN_WAIT_TIME); /* 保证能扫到设备 */ + + (void)gap_br_cancel_discovery(); + osDelay(AUTO_OTA_UPDATE_RSSI_WAIT_TIME); + auto_ota_sort_found_dev_list(); /* 根据rssi降序排序 */ + /* connect */ + if (auto_ota_get_top_dev_to_connect() != true) { + osDelay(AUTO_OTA_DELAY_MS); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "connect fail, auto retry...\r\n"); + continue; + } + + osSemaphoreAcquire(g_auto_ota_transmit_done_sem, AUTO_OTA_SEM_TIMEOUT); + + /* clean, spp资源内部释放 */ + spp_disconnect(0); + /* 删除配对时会disconnect ACL */ + if (gap_remove_all_pairs() != true) { + osDelay(AUTO_OTA_DELAY_MS); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "remove all pairs fail, auto retry...\r\n"); + continue; + } + osDelay(AUTO_OTA_OPRATE_DELAY_MS); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "gap_remove_all_pairs ok\r\n"); + + osDelay(AUTO_OTA_DELAY_MS); + auto_ota_dev_show(); + memset_s(g_auto_ota_mac_tmp, sizeof(g_auto_ota_mac_tmp), 0, sizeof(g_auto_ota_mac_tmp)); + g_anti_back_link_flag = false; + osDelay(AUTO_OTA_DELAY_MS); + } + + return; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/ln/nativeapp/brandy-native-js-ln/libuikit_fwk.a b/code/sdk/application/wearable/evb/ln/nativeapp/brandy-native-js-ln/libuikit_fwk.a deleted file mode 100644 index e3ce469ad..000000000 Binary files a/code/sdk/application/wearable/evb/ln/nativeapp/brandy-native-js-ln/libuikit_fwk.a and /dev/null differ diff --git a/code/sdk/application/wearable/evb/ln/service/msg_center/brandy-native-js-ln/libmsg_center.a b/code/sdk/application/wearable/evb/ln/service/msg_center/brandy-native-js-ln/libmsg_center.a deleted file mode 100644 index b1e105a9c..000000000 Binary files a/code/sdk/application/wearable/evb/ln/service/msg_center/brandy-native-js-ln/libmsg_center.a and /dev/null differ diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/CMakeLists.txt b/code/sdk/application/wearable/evb/nativeabilityfwk/CMakeLists.txt index 63e56e84a..7a0140939 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/CMakeLists.txt +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/CMakeLists.txt @@ -27,12 +27,19 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/AbilitySlice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NativeAbility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/StartNative.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/ZoomOutTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/ZoomTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/ThreeDFoldTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/FadeInOutTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/HexagonsTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/BackToHexagonsTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/BackToWaterfallTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/WaterfallTransition.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/EnterWaterfallTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/TransparentGradientTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/GaussianBlurTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/CrossShapedTransition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/BackToCrossShapedTransition.cpp ) set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Ability.h index f6a6877ef..f835734d6 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Ability.h @@ -30,26 +30,56 @@ const static uint16_t gSliceInvalid = 0; const static uint16_t gPageInvalid = 0; const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级 +struct ExtralConfig { + uint16_t pageId; + TransitionType type; + bool enableSlideBack; +}; + +// 定义默认配置 +constexpr ExtralConfig DEFAULT_CONF = {gPageInvalid, TransitionType::TRANSITION_INVALID, false}; + class Ability { public: void AddSliceProxy(uint16_t sliceId, SliceProxy* proxy); /** - * @brief Switch to specified page in the current slice, matched page will be created, and current slice will not be - * recreated. if slices or pages is being switched, this operation will be canceled + * @brief Switch to specified page in the current slice, target page will be created, and current slice will + * not be recreated. if slices or pages is being switched, this operation will be canceled * @param pageId Indicates the specified id of the page in the current slice, it should not be zero - * @param data Indicates the data which will be transfered to next page, default value is nullptr * @param type Indicates Transition animation type, which is declared in TransitionType.h. The matched * Transitioncallback should have params: enableCurrentSnapshot_ = false enableTargetSnapshot_ = false - * @param canBack Indicates whether current page should be cached and can be back from target page + * @param canBack Indicates whether current page will be cached or destroyed. if cached, can back from target page + * @param data Indicates the data which will be transfered to next page, default value is nullptr, + * data can only be native C structures or basic data types + * @param dataLength Indicates the length of data * @return Returns true if the pages is switched successfully, returns false otherwise. + * @note It is recommended to call this method in the UI thread, and the event will be post into graphic event queue + */ + bool SwitchPageInSlice(uint16_t pageId, TransitionType type = TransitionType::TRANSITION_INVALID, + bool canBack = false, void* data = nullptr, uint16_t dataLength = 0); + + /** + * @brief Back to previous cached page in the current slice, current page will be destroyed, and previous + * cached page will be resumed. if slices or pages is being switched, this operation will be canceled + * @return Returns true if back to cached page successfully, returns false if no cached page. + * @note It is recommended to call this method in the UI thread, and the event will be post into graphic event queue */ - bool SwitchPageInSlice(uint16_t pageId, void* data = nullptr, - TransitionType type = TransitionType::TRANSITION_INVALID, bool canBack = false); + bool BackToPrevSlicePage(); + + /** + * @brief Back to target cached page in the current slice, current page and the cached pages on the top of target + * cached page will be destroyed, target cached page will be resumed. if slices or pages is being + * switched, this operation will be canceled + * @param pageId Indicates the target page id in cached pages, it should not be zero + * @return Returns true if back to target cached page successfully, returns false otherwise. + * @note It is recommended to call this method in the UI thread, and the event will be post into graphic event queue + */ + bool BackToCachedSlicePage(uint16_t pageId); /** * @brief Switch to specified slice. matched slice will be created. - * 1. If pageId is valid or default page is exist, matched page will also be created + * 1. If pageId is valid or default page exists, matched page will also be created * 2. If slices is being switched, this operation will be cached and run later. * @param sliceId Indicates the specified id of the slice * @param pageId Indicates the specified id of the slice, if pageId is invalid, default page will be used. @@ -59,6 +89,15 @@ public: void SwitchSlice(uint16_t sliceId, uint16_t pageId = gPageInvalid, TransitionType type = TransitionType::TRANSITION_INVALID, bool enableSlideBack = false); + /** + * @brief Switch to specified slice. matched slice will be created. + * 1. If pageId is valid or default page exists, matched page will also be created + * 2. If slices is being switched, this operation will be cached and run later. + * @param config Indicates the extern config of the slice. + */ + void SwitchSliceWithData(uint16_t sliceId, void* data, uint16_t dataLength, + const ExtralConfig& config = DEFAULT_CONF); + /** * @brief Switch to specified slice. matched slice will be created. * 1. If default page is exist, default page will also be created @@ -73,6 +112,8 @@ public: void ChangeSlice(uint16_t sliceId, TransitionType type = TransitionType::TRANSITION_INVALID, uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false); + void ChangeSliceToApplist(); + /** * @brief Get SlicePageManager of currrent slice. you can Use SlicePageManager to get page info in the slice. * @return Returns nullptr if slices is being switched, or js ability is running @@ -141,10 +182,12 @@ public: void PauseSlice(); void StopSliceTransition(); void BackToPreSlice(); + void EnterAod(); + void ExitAod(uint32_t targetId); protected: // targetId consists of slice id and page id - void StartSlice(uint32_t targetId); + void StartSlice(uint32_t targetId, void* data = nullptr); void ResumeSliceWithoutJS(); void StopSlice(); Ability() = default; @@ -172,10 +215,11 @@ protected: SliceStruct curSlice_; SliceStruct nextSlice_; + SliceStruct prevAodSlice_; uint32_t targetIdFromJS_ = 0; uint32_t defaultTargetId_ = gSliceInvalid; uint16_t curSlicePriority_ = gSliceDefaultPriority; - void PostChangeSlice(uint32_t targetId, TransitionType type); + void PostChangeSlice(uint32_t targetId, TransitionType type, void* data); Ability::ProxyStruct* Find(const uint16_t sliceId); }; } diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/AbilitySlice.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/AbilitySlice.h index 09a8c81e4..1e201d71f 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/AbilitySlice.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/AbilitySlice.h @@ -35,7 +35,7 @@ public: : sliceId_(targetId & SLICE_MASK), view_(viewBase), presenter_(presenterBase), slicePageMgr_(targetId), state_(SliceState::UNINITIALIZED) {} - void OnStart() override; + void OnStart(void* data) override; void OnResume() override; @@ -47,6 +47,10 @@ public: bool ChangeSlicePage(uint16_t pageId, void* data, TransitionType type, bool canBack); + bool BackToPrevSlicePage(); + + bool BackToCachedSlicePage(uint16_t pageId); + SlicePageManager* GetSlicePageManger() { return &slicePageMgr_; diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/BackDragListener.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/BackDragListener.h index 4cca1dfbe..b7f3132b8 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/BackDragListener.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/BackDragListener.h @@ -14,6 +14,7 @@ namespace OHOS { class BackDragListener : public UIView::OnDragListener { public: + static int16_t maxDragRegionX_; BackDragListener() = default; ~BackDragListener() override; bool OnDragStart(UIView& view, const DragEvent& event) override; diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/PageTransitionMgr.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/PageTransitionMgr.h index 5b58fecc8..ab12b0586 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/PageTransitionMgr.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/PageTransitionMgr.h @@ -154,7 +154,7 @@ private: #endif TransitionCaller transitionCaller_{TransitionCaller::INVALID}; TransitionCaller slideBackCaller_{TransitionCaller::INVALID}; - TransitionTarget slideBackTarget_{0}; + TransitionTarget slideBackTarget_{{0, nullptr, 0}}; bool isTransAnimNeeded_ = false; bool isCurrentSnapShotEnabled_ = false; bool isTargetSnapShotEnabled_ = false; diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Presenter.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Presenter.h index b8cbc7a4c..b08e02fce 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Presenter.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Presenter.h @@ -24,12 +24,17 @@ public: PresenterBase() : viewBase_(nullptr) {} virtual ~PresenterBase() = default; + /** + * @deprecated 推荐使用方法OnStart(void* data) + */ + virtual void OnStart() {} + /** * @brief Scheduled by slice when it is started and before transition animator starts if exsit * * You can create non-ui resource and update ui based on Model data here */ - virtual void OnStart() {} + virtual void OnStart(void* data) {} /** * @brief Scheduled by slice when it will be visiable and after transition animator ends if exsit diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/RecentManager.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/RecentManager.h index 76e9598db..588d535be 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/RecentManager.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/RecentManager.h @@ -28,7 +28,7 @@ namespace OHOS { typedef struct { bool isNativeSlice; // true: native; false: js union { - uint32_t targetId; + uint32_t targetId; // sliceId + pageId char bundleName[RECENT_APP_BUNDLE_NAME_MAX_LEN]; }; ImageInfo* snapshot; @@ -158,6 +158,11 @@ public: */ uint32_t GetLoadingCnt(); + /** + * @brief Remove a native app with same sliceId. If pageId is same, file will be deleted as well. + */ + bool RemoveNativeRecentApp(uint32_t targetId); + private: RecentManager(); virtual ~RecentManager(); diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Slice.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Slice.h index 047cc6085..5d5640f21 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/Slice.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/Slice.h @@ -30,7 +30,7 @@ public: * Its system implemention is in the AbilitySlice, you can define your own processing logic by overriding * Prenseter::OnStart And View::OnStart */ - virtual void OnStart() = 0; + virtual void OnStart(void* data) = 0; /** * @brief Called when the slice will be visible and after transition animator ends if exits * diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageFactory.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageFactory.h index 49dd1c7b0..f81896e66 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageFactory.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageFactory.h @@ -27,6 +27,8 @@ public: void RegisterPage(uint16_t sliceId, uint16_t pageId, SlicePageProxyInterface* proxy, bool isMainPage); + void SetMainPage(uint16_t sliceId, uint16_t pageId); + private: SlicePageFactory() {}; ~SlicePageFactory() {}; @@ -64,6 +66,7 @@ public: }; } -#define REGIST_SLICE_PAGE(sliceId, pageId, V, isMainPage) \ - const static OHOS::SlicePageRegister (STATIC_VAR)(sliceId, pageId, new OHOS::SlicePageProxy(), isMainPage) +#define REGIST_SLICE_PAGE(sliceId, pageId, V, isMainPage) \ + const static OHOS::SlicePageRegister(STATIC_VAR##sliceId)( \ + sliceId, pageId, new OHOS::SlicePageProxy(), isMainPage) #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageManager.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageManager.h index c69ef48f4..4308f3064 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageManager.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/SlicePageManager.h @@ -63,7 +63,9 @@ public: return ((animator_ != nullptr) && (animator_->GetState() != Animator::STOP)); } - void BackToPrevSlicePage(); + bool BackToPrevSlicePage(); + + bool BackToCachedSlicePage(uint16_t pageId); SlicePageManager(const SlicePageManager&) = delete; SlicePageManager& operator=(const SlicePageManager&) = delete; diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/TransitionType.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/TransitionType.h index 0e894b4c6..70e14a968 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/TransitionType.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/TransitionType.h @@ -15,11 +15,18 @@ namespace OHOS { enum class TransitionType { TRANSITION_INVALID = 0, TRANSITION_ZOOM, + TRANSITION_ZOOM_OUT, TRANSITION_HEXAGONS, TRANSITION_BACK_TO_HEXAGONS, TRANSITION_WATERFALL, TRANSITION_BACK_TO_WATERFALL, TRANSITION_ENTER_WATERFALL, + TRANSITION_FADEINOUT, + TRANSITION_TRANSPARENT_GRADIENT, + TRANSITION_GAUSSIAN_BLUR, + TRANSITION_CROSS_SHAPED, + TRANSITION_BACK_TO_CROSS_SHAPED, + TRANSITION_3DFOLD, TRANSITION_MAX, }; @@ -35,8 +42,14 @@ enum class TransitionCaller { INVALID }; +typedef struct { + uint32_t sliceAndPageId; + void *data; + uint16_t dataLength; +} SliceInfo; + typedef union { - uint32_t sliceInfo; // The number of high 16 bits is priority, and the number of low 16 bits is slice id + SliceInfo sliceInfo; // The number of high 16 bits is priority, and the number of low 16 bits is slice id #ifdef JS_ENABLE Want* want; char* bundleName; diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/include/View.h b/code/sdk/application/wearable/evb/nativeabilityfwk/include/View.h index 207926648..e91e6e490 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/include/View.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/include/View.h @@ -46,6 +46,11 @@ public: return backDragListener_; } + /** + * @deprecated 推荐使用方法OnStart(void* data) + */ + virtual void OnStart() {} + /** * @brief Scheduled by slice after funtion SetupView and before transition animator starts if exits. * @@ -58,7 +63,7 @@ public: * AddViewToRootContainer(label_); // add label_ into container * } */ - virtual void OnStart() {} + virtual void OnStart(void* data) {} /** * @brief Scheduled by slice after function TearDownView. diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/Ability.cpp index 82e0d033d..45c5ce874 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/Ability.cpp @@ -25,6 +25,9 @@ #include "PageTransitionMgr.h" #include "gfx_utils/list.h" #include "AbilitySlice.h" +#include "settings/model/SettingDesktopModel.h" +#include "NativeAbility.h" +#include "power_display_service.h" namespace OHOS { void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) @@ -42,7 +45,7 @@ void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) allSlicesProxy_.PushBack(proxyPair); } -void Ability::StartSlice(uint32_t targetId) +void Ability::StartSlice(uint32_t targetId, void* data) { if (targetId <= gSliceInvalid) { return; @@ -74,7 +77,7 @@ void Ability::StartSlice(uint32_t targetId) targetId >> PAGE_OFFSET, allSlices_.Size()); nextSlice_.sliceId = sliceId; nextSlice_.slice = newSlice; - newSlice->OnStart(); + newSlice->OnStart(data); } Ability::ProxyStruct* Ability::Find(const uint16_t sliceId) @@ -119,7 +122,7 @@ void Ability::UpdateCurSlicePageId(uint16_t pageId) allSlices_[allSlices_.Size() - 1] = sliceId | (static_cast(pageId) << PAGE_OFFSET); } -bool Ability::SwitchPageInSlice(uint16_t pageId, void* data, TransitionType type, bool canBack) +bool Ability::SwitchPageInSlice(uint16_t pageId, TransitionType type, bool canBack, void* data, uint16_t dataLength) { if (pageId == 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page id should be valid but no zero"); @@ -129,39 +132,114 @@ bool Ability::SwitchPageInSlice(uint16_t pageId, void* data, TransitionType type WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched during transition"); return false; } + if (!GraphicService::IsNativeUITask()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "SwitchPageInSlice is called not in ui task"); + return false; + } + AbilitySlice* slice = dynamic_cast(curSlice_.slice); + if (slice == nullptr) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched because current slice is nullptr"); + return false; + } + void* sliceData = static_cast(UIMalloc(dataLength)); + memcpy_s(sliceData, dataLength, data, dataLength); + GraphicService::GetInstance()->PostGraphicEvent([slice, pageId, sliceData, type, canBack]() { + slice->ChangeSlicePage(pageId, sliceData, type, canBack); + UIFree(sliceData); + }); + return true; +} + +bool Ability::BackToPrevSlicePage() +{ + if (PageTransitionMgr::GetInstance().IsTransitionRunning()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched during transition"); + return false; + } + if (!GraphicService::IsNativeUITask()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "BackToPrevSlicePage is not called in ui task"); + return false; + } AbilitySlice* slice = dynamic_cast(curSlice_.slice); if (slice == nullptr) { WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched because current slice is nullptr"); return false; } - return slice->ChangeSlicePage(pageId, data, type, canBack); + GraphicService::GetInstance()->PostGraphicEvent([slice]() { + slice->BackToPrevSlicePage(); + }); + return true; +} + +bool Ability::BackToCachedSlicePage(uint16_t pageId) +{ + if (PageTransitionMgr::GetInstance().IsTransitionRunning()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched during transition"); + return false; + } + if (!GraphicService::IsNativeUITask()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "BackToCachedSlicePage is not called in ui task"); + return false; + } + AbilitySlice* slice = dynamic_cast(curSlice_.slice); + if (slice == nullptr) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched because current slice is nullptr"); + return false; + } + GraphicService::GetInstance()->PostGraphicEvent([slice, pageId]() { + slice->BackToCachedSlicePage(pageId); + }); + return true; } void Ability::SwitchSlice(uint16_t sliceId, uint16_t pageId, TransitionType type, bool enableSlideBack) { + ExtralConfig config = {pageId, type, enableSlideBack}; + SwitchSliceWithData(sliceId, nullptr, 0, config); +} + +void Ability::SwitchSliceWithData(uint16_t sliceId, void* data, uint16_t dataLength, const ExtralConfig& config) +{ + if (sliceId == VIEW_AOD) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "cannot enter aod by switch slice!"); + return; + } if (Find(sliceId) == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "slice %d is not registered", sliceId); return; } + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_context_t *sc = power_display_get_screen_context(); + if (sc != nullptr && display_api != nullptr && sc->current_state == SCREEN_ON) { + display_api->turn_on_screen(); + } #ifdef JS_ENABLE ElementName *elementName = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); if (elementName != nullptr && strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { - OHOS::AbilityMsClient::GetInstance().ForceStop(elementName->bundleName, type); - targetIdFromJS_ = sliceId | (static_cast(pageId) << PAGE_OFFSET); + OHOS::AbilityMsClient::GetInstance().ForceStop(elementName->bundleName, config.type); + targetIdFromJS_ = sliceId | (static_cast(config.pageId) << PAGE_OFFSET); FreeElement(elementName); return; } FreeElement(elementName); #endif TransitionTarget target; - target.sliceInfo = sliceId | (static_cast(pageId) << PAGE_OFFSET); + target.sliceInfo.sliceAndPageId = sliceId | (static_cast(config.pageId) << PAGE_OFFSET); + void* sliceData = nullptr; + if (dataLength != 0 && data != nullptr) { + sliceData = static_cast(UIMalloc(dataLength)); + memcpy_s(sliceData, dataLength, data, dataLength); + } + target.sliceInfo.data = sliceData; + target.sliceInfo.dataLength = dataLength; bool runImmed = PageTransitionMgr::GetInstance().BeginTransition(TransitionCaller::CHANGE_SLICE, target, - type, enableSlideBack); + config.type, config.enableSlideBack); if (!runImmed) { - printf("pending change slice id:%d type:%d enableSlideBack:%d\n", target.sliceInfo, type, enableSlideBack); + printf("pending change slice id:%d type:%d enableSlideBack:%d\n", target.sliceInfo.sliceAndPageId, config.type, config.enableSlideBack); return; } - GraphicService::GetInstance()->PostGraphicEvent(std::bind(&Ability::PostChangeSlice, this, target.sliceInfo, type)); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&Ability::PostChangeSlice, this, + target.sliceInfo.sliceAndPageId, config.type, target.sliceInfo.data)); } void Ability::ChangeSlice(uint16_t sliceId, TransitionType type, @@ -171,21 +249,103 @@ void Ability::ChangeSlice(uint16_t sliceId, TransitionType type, SwitchSlice(sliceId, gPageInvalid, type, enableSlideBack); } -void Ability::PostChangeSlice(uint32_t targetId, TransitionType type) +void Ability::ChangeSliceToApplist() { + if (SettingDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } else if (SettingDesktopModel::GetInstance().GetDesktopStyle() == WATERFALL_STYLE) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_WATERFALL); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } +} + +void Ability::EnterAod() +{ +#ifdef JS_ENABLE + ElementName *elementName = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); + if (elementName != nullptr && strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { + OHOS::AbilityMsClient::GetInstance().ForceStop(elementName->bundleName); + targetIdFromJS_ = VIEW_AOD | (static_cast(gPageInvalid) << PAGE_OFFSET); + FreeElement(elementName); + return; + } + FreeElement(elementName); +#endif + TransitionTarget target; + target.sliceInfo.sliceAndPageId = VIEW_AOD | (static_cast(gPageInvalid) << PAGE_OFFSET); + target.sliceInfo.data = nullptr; + target.sliceInfo.dataLength = 0; + bool runImmed = PageTransitionMgr::GetInstance().BeginTransition( + TransitionCaller::CHANGE_SLICE, target, TransitionType::TRANSITION_INVALID, false); + if (!runImmed) { + printf("pending change slice id:%d type:%d enableSlideBack:%d\n", + target.sliceInfo.sliceAndPageId, TransitionType::TRANSITION_INVALID, false); + return; + } PauseSlice(); - if (allSlices_.Size() > 0 && allSlices_[allSlices_.Size() - 1] == VIEW_AOD) { - allSlices_.PopBack(); - if (allSlices_.Size() > 0 && (allSlices_[allSlices_.Size() - 1] & SLICE_MASK) == (targetId & SLICE_MASK)) { - allSlices_.PopBack(); + prevAodSlice_ = curSlice_; + curSlice_.slice = nullptr; + curSlice_.sliceId = gSliceInvalid; + ImageCacheManager::GetInstance().EnterAod(); + StartSlice(VIEW_AOD); + ResumeSlice(); + PageTransitionMgr::GetInstance().EndTransition(true); +} + +void Ability::ExitAod(uint32_t targetId) +{ + TransitionTarget target; + target.sliceInfo.sliceAndPageId = targetId; + target.sliceInfo.data = nullptr; + target.sliceInfo.dataLength = 0; + bool runImmed = PageTransitionMgr::GetInstance().BeginTransition( + TransitionCaller::CHANGE_SLICE, target, TransitionType::TRANSITION_INVALID, false); + if (!runImmed) { + printf("pending change slice id:%d type:%d enableSlideBack:%d\n", + target.sliceInfo.sliceAndPageId, TransitionType::TRANSITION_INVALID, false); + return; + } + allSlices_.PopBack(); + PauseSlice(); + StopSlice(); + ImageCacheManager::GetInstance().ExitAod(); + if ((targetId & SLICE_MASK) == prevAodSlice_.sliceId) { // back to prev slice + if (prevAodSlice_.slice != nullptr) { + nextSlice_ = prevAodSlice_; + prevAodSlice_.slice = nullptr; + prevAodSlice_.sliceId = gSliceInvalid; + } + InputDeviceManager::GetInstance()->ClearInputDeviceState(); + } else { + if (prevAodSlice_.slice != nullptr) { + WEARABLE_LOGI( + WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability StopSlice when exits aod %d", prevAodSlice_.sliceId); + prevAodSlice_.slice->OnStop(); + prevAodSlice_.sliceId = gSliceInvalid; + delete prevAodSlice_.slice; + prevAodSlice_.slice = nullptr; } + StartSlice(targetId); } + ResumeSlice(); + PageTransitionMgr::GetInstance().EndTransition(true); +} + +void Ability::PostChangeSlice(uint32_t targetId, TransitionType type, void* data) +{ + if (curSlice_.sliceId == VIEW_AOD) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "cannot exit aod by switch slice!"); + PageTransitionMgr::GetInstance().EndTransition(true); + return; + } + PauseSlice(); PageTransitionMgr::GetInstance().SaveCurrentSourceIfNecessary(curSlice_.slice->GetSliceContainer()); if (!PageTransitionMgr::GetInstance().IsTransAnimNeeded() || PageTransitionMgr::GetInstance().IsCurrentSnapshotEnabled()) { StopSlice(); } - StartSlice(targetId); + StartSlice(targetId, data); if (!PageTransitionMgr::GetInstance().IsTransAnimNeeded()) { ResumeSliceWithoutJS(); @@ -193,6 +353,9 @@ void Ability::PostChangeSlice(uint32_t targetId, TransitionType type) PageTransitionMgr::GetInstance().SaveTargetSource(nextSlice_.slice->GetSliceContainer()); PageTransitionMgr::GetInstance().StartTransAnim(std::bind(&Ability::ResumeSliceWithoutJS, this)); } + if (data != nullptr) { + UIFree(data); + } } void Ability::ResumeSliceWithoutJS() @@ -265,7 +428,9 @@ void Ability::BackToPreSlice() return; } TransitionTarget target; - target.sliceInfo = targetId; + target.sliceInfo.sliceAndPageId = targetId; + target.sliceInfo.data = nullptr; + target.sliceInfo.dataLength = 0; uint16_t sliceId = static_cast(targetId & SLICE_MASK); uint16_t pageId = static_cast(targetId >> PAGE_OFFSET); PageTransitionMgr::GetInstance().BeginBackTransition(TransitionCaller::CHANGE_SLICE, target); diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/AbilitySlice.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/AbilitySlice.cpp index 37810c795..3fec56bb8 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/AbilitySlice.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/AbilitySlice.cpp @@ -14,12 +14,13 @@ #include "View.h" #include "Presenter.h" #include "key/KeyInputListener.h" +#include "common/image_cache_manager.h" namespace OHOS { const uint16_t SLICE_MASK = 0xFFFF; const uint32_t PAGE_OFFSET = 16; -void AbilitySlice::OnStart() +void AbilitySlice::OnStart(void* data) { if ((presenter_ == nullptr) || (view_ == nullptr)) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Presenter or View was nullptr for slice %s", sliceId_); @@ -36,8 +37,10 @@ void AbilitySlice::OnStart() view_->SetupView(); view_->OnStart(); - slicePageMgr_.StartSlicePage(); + view_->OnStart(data); + slicePageMgr_.StartSlicePage(data); presenter_->OnStart(); + presenter_->OnStart(data); state_ = SliceState::START; } @@ -54,7 +57,9 @@ void AbilitySlice::OnResume() RootView::GetInstance()->Add(view_->GetRootContainer()); } // Reset the default key listener - RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance()); + if (!ImageCacheManager::GetInstance().IsInAod()) { + RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance()); + } NativeAbility::GetInstance().SetCurSlicePriority(gSliceDefaultPriority); UIView* backView = PageTransitionMgr::GetInstance().GetTopSlideBackImage(); @@ -131,4 +136,14 @@ bool AbilitySlice::ChangeSlicePage(uint16_t pageId, void* data, TransitionType t { return slicePageMgr_.ChangeSlicePage(pageId, data, type, canBack); } + +bool AbilitySlice::BackToPrevSlicePage() +{ + return slicePageMgr_.BackToPrevSlicePage(); +} + +bool AbilitySlice::BackToCachedSlicePage(uint16_t pageId) +{ + return slicePageMgr_.BackToCachedSlicePage(pageId); +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.cpp new file mode 100644 index 000000000..6eb9e3b62 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BackToCrossShapedTransition + * Create: 2025-04 + */ + +#include "applist/AppItemView.h" +#include "animator/easing_equation.h" +#include "common/screen.h" +#include "components/root_view.h" +#include "components/ui_view.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "BackToCrossShapedTransition.h" + +namespace OHOS { + static constexpr uint16_t DURATION = 200; + static constexpr int16_t CAMERA_DISTANCE = 600; + static constexpr uint16_t NUM2 = 2; + static constexpr uint16_t HALF_DURATION = DURATION / NUM2; + static constexpr int16_t MIN_OFFSET = 10; + static constexpr int16_t EASE_RANGE = 100; + + REGIST_TRANSITION(TransitionType::TRANSITION_BACK_TO_CROSS_SHAPED, + BackToCrossShapedTransition, DURATION, true, true); + + void BackToCrossShapedTransition::OnTransitionStart(UIImageView *current, UIImageView *target) + { + if (current == nullptr || target == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "BackToCrossShapedTransition ImageView is empty!"); + return; + } + + currentView_ = current; + targetView_ = target; + + if (cameraView_ == nullptr) { + cameraView_ = new UIImageView(); + } + + screenWidth_ = Screen::GetInstance().GetWidth(); + screenHeight_ = Screen::GetInstance().GetHeight(); + middleHeight_ = screenHeight_ / NUM2; + middleWidth_ = screenWidth_ / NUM2; + + cameraView_->SetPosition(0, 0, screenWidth_, screenHeight_); + cameraView_->SetCameraPosition(Vector2(middleWidth_, middleHeight_)); + cameraView_->SetCameraDistance(CAMERA_DISTANCE); + currentView_->SetVisible(false); + targetView_->SetVisible(false); + RootView::GetInstance()->Add(cameraView_); + } + + void BackToCrossShapedTransition::TransitionAlg(uint32_t time) + { + int16_t offSet = 0; + if (time < HALF_DURATION) { + offSet = EasingEquation::QuadEaseIn(-MIN_OFFSET, -middleWidth_, time, HALF_DURATION); + } else { + offSet = EasingEquation::QuadEaseIn(middleWidth_, MIN_OFFSET, + time - HALF_DURATION, DURATION - HALF_DURATION); + } + + UIView* tmpCard = GetVisibleView(offSet); + CommonAlg(tmpCard, offSet); + } + + UIView* BackToCrossShapedTransition::GetVisibleView(int16_t offSet) + { + UIView* view = nullptr; + if (offSet > 0) { + if (offSet < middleWidth_) { + return targetView_; + } + return currentView_; + } else { + if (abs(offSet) < middleWidth_) { + return currentView_; + } + return targetView_; + } + return view; + } + + void BackToCrossShapedTransition::OnTransitionEnd() + { + if (cameraView_ != nullptr) { + RootView::GetInstance()->Remove(cameraView_); + } + + if (targetView_ != nullptr) { + targetView_->SetVisible(true); + } + } + + void BackToCrossShapedTransition::CommonAlg(UIView* visualView, int16_t offSet) + { + if (visualView == nullptr) { + return; + } + + float factor; + if (abs(offSet) < middleWidth_) { + factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, abs(offSet), middleWidth_); + } else { + factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, screenWidth_ - abs(offSet), middleWidth_); + } + + float scale = 1.0 - 0.2 * factor / EASE_RANGE; // 0.2: scale range + float angle = 90 * factor / EASE_RANGE; // 90: quarter cycle degrees + if (visualView != currentView_) { + angle = -angle; + } + + Vector3 scaleCenter = {middleWidth_, middleHeight_, 0}; + Vector3 rotateStart = {middleWidth_, 0, 0}; + Vector3 rotateEnd = {middleWidth_, 2, 0}; + UIView* tmpCard = nullptr; + + cameraView_->SetSrc(static_cast(visualView)->GetImageInfo()); + cameraView_->Scale(Vector3(scale, scale, 0), scaleCenter); + cameraView_->Rotate(angle, rotateStart, rotateEnd); + } +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.h new file mode 100644 index 000000000..8ad17d421 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToCrossShapedTransition.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BackToCrossShapedTransition + * Create: 2025-04 + */ + +#ifndef BACK_TO_CROSS_SHAPED_TRANSITION_H +#define BACK_TO_CROSS_SHAPED_TRANSITION_H + +#include "TransitionCallback.h" + +namespace OHOS { + class BackToCrossShapedTransition : public TransitionCallback { + public: + BackToCrossShapedTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~BackToCrossShapedTransition() override {} + + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; + private: + + void CommonAlg(UIView* visualView, int16_t offSet); + UIView* GetVisibleView(int16_t offSet); + + UIImageView* currentView_ = nullptr; + UIImageView* targetView_ = nullptr; + UIImageView* cameraView_ = nullptr; + + int16_t middleWidth_; + int16_t middleHeight_; + int16_t screenWidth_; + int16_t screenHeight_; + }; + +} // namespace OHOS + +#endif // BACK_TO_CROSS_SHAPED_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp index da9c42185..3ccd66e2e 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp @@ -9,12 +9,13 @@ #include "TransitionManager.h" #include "NativeAbility.h" #include "components/root_view.h" -#include "applist/AppItemView.h" +#include "applist/HexagonsDesktopFragment.h" #include "hal_tick.h" #include "wearable_log.h" #ifdef JS_ENABLE #include "abilityms_slite_client.h" #endif +#include "TransitionUtils.h" namespace OHOS { REGIST_TRANSITION(TransitionType::TRANSITION_BACK_TO_HEXAGONS, BackToHexagonsTransition, 300, true, false); @@ -24,7 +25,7 @@ static const float TARGET_SCALE_END = 1.0f; void BackToHexagonsTransition::OnTransitionStart(UIImageView* current, UIViewGroup* target) { current_ = current; - target_ = dynamic_cast(target->GetChildrenHead()); + target_ = dynamic_cast(TransitionUtils::GetViewAndTransparentizePath(target, UI_HEXAGONS_LIST)); if ((target_ == nullptr) || (current_ == nullptr)) { return; } diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp index a5bb73077..f2167b122 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp @@ -9,12 +9,13 @@ #include "TransitionManager.h" #include "NativeAbility.h" #include "components/root_view.h" -#include "applist/AppItemView.h" +#include "applist/WaterfallDesktopFragment.h" #include "hal_tick.h" #include "wearable_log.h" #ifdef JS_ENABLE #include "abilityms_slite_client.h" #endif +#include "TransitionUtils.h" namespace OHOS { REGIST_TRANSITION(TransitionType::TRANSITION_BACK_TO_WATERFALL, BackToWaterfallTransition, 300, true, false); @@ -24,7 +25,7 @@ static const float TARGET_SCALE_END = 1.0f; void BackToWaterfallTransition::OnTransitionStart(UIImageView* current, UIViewGroup* target) { current_ = current; - target_ = dynamic_cast(target->GetChildrenHead()); + target_ = dynamic_cast(TransitionUtils::GetViewAndTransparentizePath(target, UI_WATERFALL_LIST)); if ((target_ == nullptr) || (current_ == nullptr)) { return; } diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.cpp new file mode 100644 index 000000000..64a7f768a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CrossShapedTransition + * Create: 2025-04 + */ + +#include "applist/AppItemView.h" +#include "animator/easing_equation.h" +#include "common/screen.h" +#include "components/root_view.h" +#include "components/ui_view.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "CrossShapedTransition.h" + +namespace OHOS { + static constexpr uint16_t DURATION = 200; + static constexpr uint16_t NUM2 = 2; + static constexpr uint16_t HALF_DURATION = DURATION / NUM2; + static constexpr int16_t CAMERA_DISTANCE = 600; + static constexpr int16_t EASE_RANGE = 100; + static constexpr int16_t MIN_OFFSET = 10; + + REGIST_TRANSITION(TransitionType::TRANSITION_CROSS_SHAPED, CrossShapedTransition, DURATION, true, true); + + void CrossShapedTransition::OnTransitionStart(UIImageView *current, UIImageView *target) + { + if (current == nullptr || target == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "CrossShapedTransition ImageView is empty!"); + return; + } + + currentView_ = current; + targetView_ = target; + + currentView_->SetVisible(false); + targetView_->SetVisible(false); + + if (cameraView_ == nullptr) { + cameraView_ = new UIImageView(); + } + + screenWidth_ = Screen::GetInstance().GetWidth(); + screenHeight_ = Screen::GetInstance().GetHeight(); + + middleWidth_ = screenWidth_ / NUM2; + middleHeight_ = screenHeight_ / NUM2; + + cameraView_->SetPosition(0, 0, screenWidth_, screenHeight_); + cameraView_->SetCameraPosition(Vector2(middleWidth_, middleHeight_)); + cameraView_->SetCameraDistance(CAMERA_DISTANCE); + RootView::GetInstance()->Add(cameraView_); + } + + void CrossShapedTransition::TransitionAlg(uint32_t time) + { + int16_t xOffset = 0; + if (time < HALF_DURATION) { + xOffset = EasingEquation::QuadEaseIn(-MIN_OFFSET, -middleWidth_, time, HALF_DURATION); + } else { + xOffset = EasingEquation::QuadEaseIn(middleWidth_, MIN_OFFSET, + time - HALF_DURATION, DURATION - HALF_DURATION); + } + + bool visible = false; // true: current; false: target + UIView* tmpCard = GetVisibleView(xOffset, visible); + CommonAlg(tmpCard, xOffset, visible); + } + + UIView* CrossShapedTransition::GetVisibleView(int16_t xOffset, bool &visible) + { + UIView* view = nullptr; + if (xOffset > 0) { + if (xOffset < middleWidth_) { + view = targetView_; + visible = false; + return view; + } + + view = currentView_; + visible = true; + } else { + if (abs(xOffset) < middleWidth_) { + view = currentView_; + visible = true; + return view; + } + + view = targetView_; + visible = false; + } + + return view; + } + + void CrossShapedTransition::OnTransitionEnd() + { + if (cameraView_ != nullptr) { + RootView::GetInstance()->Remove(cameraView_); + } + + if (targetView_ != nullptr) { + targetView_->SetVisible(true); + } + } + + void CrossShapedTransition::CommonAlg(UIView* visualView, int16_t xOffset, bool visible) + { + if (visualView == nullptr) { + return; + } + + float factor; + if (abs(xOffset) < middleWidth_) { + factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, abs(xOffset), middleWidth_); + } else { + factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, screenWidth_ - abs(xOffset), middleWidth_); + } + + float scale = 1.0 - 0.2 * factor / EASE_RANGE; // 0.2: scale range + float angle = 90 * factor / EASE_RANGE; // 90: quarter cycle degrees + if (visible) { + angle = -angle; + } + + Vector3 scaleCenter = {middleWidth_, middleHeight_, 0}; + Vector3 rotateStart = {middleWidth_, 0, 0}; + Vector3 rotateEnd = {middleWidth_, 2, 0}; + UIView* tmpCard = nullptr; + + cameraView_->SetSrc(static_cast(visualView)->GetImageInfo()); + cameraView_->Scale(Vector3(scale, scale, 0), scaleCenter); + cameraView_->Rotate(angle, rotateStart, rotateEnd); + } +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.h new file mode 100644 index 000000000..1ff7f5634 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/CrossShapedTransition.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CrossShapedTransition + * Create: 2025-04 + */ + +#ifndef CROSS_SHAPED_TRANSITION_H +#define CROSS_SHAPED_TRANSITION_H + +#include "TransitionCallback.h" + +namespace OHOS { + class CrossShapedTransition : public TransitionCallback { + public: + CrossShapedTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~CrossShapedTransition() override {} + + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; + private: + + void CommonAlg(UIView* visualView, int16_t xOffset, bool visible); + UIView* GetVisibleView(int16_t xOffset, bool &visible); + + UIImageView* currentView_ = nullptr; + UIImageView* targetView_ = nullptr; + UIImageView* cameraView_ = nullptr; + + int16_t middleWidth_; + int16_t middleHeight_; + int16_t screenWidth_; + int16_t screenHeight_; + }; + +} // namespace OHOS + +#endif // CROSS_SHAPED_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/EnterWaterfallTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/EnterWaterfallTransition.cpp index cc20f4ffc..1d7dd6c5c 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/EnterWaterfallTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/EnterWaterfallTransition.cpp @@ -11,6 +11,7 @@ #include "components/root_view.h" #include "TransitionManager.h" #include "wearable_log.h" +#include "TransitionUtils.h" namespace OHOS { REGIST_TRANSITION(TransitionType::TRANSITION_ENTER_WATERFALL, EnterWaterfallTransition, 300, true, false); @@ -20,7 +21,7 @@ static const float SCALE_END = 1.0f; void EnterWaterfallTransition::OnTransitionStart(UIImageView* current, UIViewGroup* target) { current_ = current; - target_ = dynamic_cast(target->GetChildrenHead()); + target_ = dynamic_cast(TransitionUtils::GetViewAndTransparentizePath(target, UI_WATERFALL_LIST)); if ((target_ == nullptr) || (current_ == nullptr)) { return; } diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.cpp new file mode 100644 index 000000000..48634a73e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FadeInOutTransition + * Create: 2025-04 + */ + +#include "animator/easing_equation.h" +#include "common/screen.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "FadeInOutTransition.h" + +namespace OHOS { +static constexpr int16_t DURA_RANGE = 400; +static constexpr int16_t FADE_IN_END = 300; +static constexpr int16_t FADE_IN_OPASTART = OPA_OPAQUE - 30; +static constexpr int16_t FADE_IN_OPAEND = 0; +static constexpr int16_t FADE_OUT_START = 100; +static constexpr int16_t FADE_OUT_OPASTART = 0; +static constexpr int16_t FADE_OUT_OPAEND = OPA_OPAQUE - 30; +static constexpr int16_t FADE_OPA_DELTA = 15; + +REGIST_TRANSITION(TransitionType::TRANSITION_FADEINOUT, FadeInOutTransition, DURA_RANGE, true, true); + +void FadeInOutTransition::OnTransitionStart(UIImageView* current, UIImageView* target) +{ + if ((current == nullptr) || (target == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "FadeInOutTransition no current or target\n"); + return; + } + current_ = current; + target_ = target; + target_->SetVisible(false); + current_->SetOpaScale(OPA_OPAQUE - FADE_OPA_DELTA); + current_->Invalidate(); + target_->SetOpaScale(0); +} + +void FadeInOutTransition::TransitionAlg(uint32_t time) +{ + if ((current_ == nullptr) || (target_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "FadeInOutTransition no current or target\n"); + return; + } + if (time < FADE_IN_END) { + float curFloatOpa = (FADE_IN_OPASTART - FADE_IN_OPAEND) * (FADE_IN_END - time) * 1.0f; + uint8_t curOpa = static_cast (curFloatOpa / FADE_IN_END); + curOpa = curOpa + FADE_IN_OPAEND; + current_->SetOpaScale(curOpa); + current_->Invalidate(); + } + if (time > FADE_OUT_START) { + target_->SetVisible(true); + float curFloatOpa = (FADE_OUT_OPAEND - FADE_OUT_OPASTART) * (time - FADE_OUT_START) * 1.0f; + uint8_t tarOpa = static_cast (curFloatOpa / (DURA_RANGE - FADE_OUT_START)); + tarOpa = tarOpa + FADE_OUT_OPASTART; + target_->SetOpaScale(tarOpa); + target_->Invalidate(); + } +} + +void FadeInOutTransition::OnTransitionEnd() +{ + if ((current_ == nullptr) || (target_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "FadeInOutTransition no current or target\n"); + return; + } + current_->SetVisible(false); + target_->SetVisible(true); + target_->SetOpaScale(OPA_OPAQUE - FADE_OPA_DELTA); + target_->Invalidate(); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.h new file mode 100644 index 000000000..0b1d8a02d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/FadeInOutTransition.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FadeInOutTransition + * Create: 2025-04 + */ + +#ifndef FADE_IN_OUT_TRANSITION_H +#define FADE_IN_OUT_TRANSITION_H +#include "TransitionCallback.h" + +namespace OHOS { +class FadeInOutTransition : public TransitionCallback { +public: + FadeInOutTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~FadeInOutTransition() override {} + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; +private: + UIImageView* current_ = nullptr; + UIImageView* target_ = nullptr; +}; +} // namespace OHOS +#endif // FADE_IN_OUT_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.cpp new file mode 100644 index 000000000..0f1a21a86 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GaussianBlurTransition + * Create: 2025-04 + */ + +#include "animator/easing_equation.h" +#include "components/root_view.h" +#include "components/ui_view.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "GaussianBlurTransition.h" + +namespace OHOS { + static constexpr int64_t VIEW_COLOR = 0xff505050; + static constexpr uint8_t VIEW_OPACITY = 10; + static constexpr uint64_t VIEW_BLUR_OPACITY = 150; + static constexpr uint8_t BLUR_MIN = 5; + static constexpr float BLUR_MAX = 31.0; + static constexpr int16_t BREAK_TIME = 125; + static constexpr int16_t DURITION = 200; + static constexpr char* BLURVIEW_NAME = "blur"; + + REGIST_TRANSITION(TransitionType::TRANSITION_GAUSSIAN_BLUR, GaussianBlurTransition, DURITION, false, false); + + void GaussianBlurTransition::AddBlurView(UIViewGroup* groupView) + { + if (groupView == nullptr) { + return; + } + + UIView* blurCurent = new UIView(BLURVIEW_NAME); + if (blurCurent == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_AAFWK, "GaussianBlurTransition new view failed!"); + return; + } + + Rect currRect = groupView->GetVisibleRect(); + blurCurent->SetPosition(currRect.GetX(), currRect.GetY(), currRect.GetWidth(), currRect.GetHeight()); + blurCurent->SetStyle(STYLE_BACKGROUND_COLOR, VIEW_COLOR); + blurCurent->SetStyle(STYLE_BACKGROUND_OPA, VIEW_OPACITY); + + UIView* tailView = groupView->GetChildrenTail(); + if (tailView != nullptr) { + groupView->Insert(tailView, blurCurent); + } + } + + void GaussianBlurTransition::SetViewBlur(UIViewGroup* groupView, float guassScale) + { + if (nullptr == groupView) { + return; + } + + UIView* tailView = groupView->GetChildrenTail(); + if (tailView == nullptr && tailView->GetViewId() != BLURVIEW_NAME) { + return; + } + + UIView* testView = RootView::GetInstance()->GetBlurView(); + RootView::GetInstance()->ClearBlurView(tailView); + tailView->SetBackgroundBlur(guassScale); + tailView->SetStyle(STYLE_BACKGROUND_OPA, VIEW_BLUR_OPACITY); + } + + void GaussianBlurTransition::ClearBlurView(UIViewGroup* groupView) + { + if (groupView == nullptr) { + return; + } + + UIView* tailView = groupView->GetChildrenTail(); + if (tailView != nullptr && tailView->GetViewId() == BLURVIEW_NAME) { + RootView::GetInstance()->ClearBlurView(tailView); + groupView->Remove(tailView); + } + } + + void GaussianBlurTransition::OnTransitionStart(UIViewGroup* current, UIViewGroup* target) + { + if ((current == nullptr) || (target == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_AAFWK, "GaussianBlurTransition ImageView is empty!"); + return; + } + + current_ = current; + target_ = target; + blurFlag_ = false; + + AddBlurView(current_); + AddBlurView(target_); + target_->SetVisible(false); + } + + void GaussianBlurTransition::TransitionAlg(uint32_t time) + { + if (time <= BREAK_TIME) { + float scale = EasingEquation::QuadEaseIn(BLUR_MIN, static_cast(BLUR_MAX), time,\ + BREAK_TIME)/ BLUR_MAX; + float guassScale = scale * BLUR_MAX; + + SetViewBlur(current_, guassScale); + } else { + if (!blurFlag_) { + UIView* tailView = current_->GetChildrenTail(); + if (tailView != nullptr) { + tailView->ClearBackgroundBlur(); + } + + if (current_->IsVisible()) { + current_->SetVisible(false); + } + + target_->SetVisible(true); + SetViewBlur(target_, BLUR_MAX); + blurFlag_ = true; + return; + } + + float scale = EasingEquation::QuadEaseIn(static_cast(BLUR_MAX), BLUR_MIN, time - BREAK_TIME,\ + DURITION) / BLUR_MAX; + float guassScale = scale * BLUR_MAX; + SetViewBlur(target_, guassScale); + } + } + + void GaussianBlurTransition::OnTransitionEnd() + { + if (current_ == nullptr || target_ == nullptr) { + return; + } + + ClearBlurView(current_); + ClearBlurView(target_); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.h new file mode 100644 index 000000000..ecbf52991 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/GaussianBlurTransition.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GaussianBlurTransition + * Create: 2025-04 + */ + +#ifndef GAUSSIAN_BLUR_TRANSITION_H +#define GAUSSIAN_BLUR_TRANSITION_H + +#include "TransitionCallback.h" + +namespace OHOS { + class GaussianBlurTransition : public TransitionCallback { + public: + GaussianBlurTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~GaussianBlurTransition() override {} + + void OnTransitionStart(UIViewGroup* current, UIViewGroup* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; + private: + + void AddBlurView(UIViewGroup* groupView); + void SetViewBlur(UIViewGroup* groupView, float guassScale); + void ClearBlurView(UIViewGroup* groupView); + + UIViewGroup* current_ = nullptr; + UIViewGroup* target_ = nullptr; + bool blurFlag_; + }; +} // namespace OHOS + +#endif // GAUSSIAN_BLUR_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/HexagonsTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/HexagonsTransition.cpp index 45ebd7616..a76848fd3 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/HexagonsTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/HexagonsTransition.cpp @@ -10,6 +10,7 @@ #include "components/root_view.h" #include "TransitionManager.h" #include "wearable_log.h" +#include "TransitionUtils.h" namespace OHOS { REGIST_TRANSITION(TransitionType::TRANSITION_HEXAGONS, HexagonsTransition, 300, false, true); @@ -20,8 +21,7 @@ static const float TARGET_SCALE_END = 1.0f; void HexagonsTransition::OnTransitionStart(UIViewGroup* current, UIImageView* target) { - current->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - current_ = dynamic_cast(current->GetChildrenHead()); + current_ = dynamic_cast(TransitionUtils::GetViewAndTransparentizePath(current, UI_HEXAGONS_LIST)); if (current_ == nullptr) { return; } @@ -37,7 +37,6 @@ void HexagonsTransition::OnTransitionStart(UIViewGroup* current, UIImageView* ta WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "HexagonsTransition no focus view\n"); return; } - current_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); Vector2 delta = Vector2(current_->GetWidth() / 2, current_->GetHeight() / 2) - current_->GetCurrentPosition(focusIndex_); opaStart_ = focusView_->GetOpaScale(); diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.cpp new file mode 100644 index 000000000..91e53e929 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ThreeDFoldTransition + * Create: 2025-04 + */ + +#include "ThreeDFoldTransition.h" +#include "animator/easing_equation.h" +#include "TransitionManager.h" +#include "common/screen.h" +#include "wearable_log.h" +namespace OHOS { +static constexpr int16_t DURA_RANGE = 200; +static const float ROTATE_END = 90.0f; +static constexpr int16_t ROTATE_RANGE_MAX = 90; +static constexpr int16_t CAMERA_DISTANCE = 500; + +REGIST_TRANSITION(TransitionType::TRANSITION_3DFOLD, ThreeDFoldTransition, DURA_RANGE, true, true); +void ThreeDFoldTransition::OnTransitionStart(UIImageView* current, UIImageView* target) +{ + if ((current == nullptr) || (target == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "ThreeDFoldTransition no current or target\n"); + return; + } + current_ = current; + target_ = target; + current_->SetVisible(true); + target_->SetVisible(true); + + current_->SetCameraPosition(Vector2(current_->GetWidth(), current_->GetHeight() / 2)); // 2: half + current_->SetCameraDistance(CAMERA_DISTANCE); + + target_->SetCameraPosition(Vector2(0, target_->GetHeight() / 2)); // 2: half + target_->SetCameraDistance(CAMERA_DISTANCE); +} + +void ThreeDFoldTransition::TransitionAlg(uint32_t time) +{ + if ((current_ == nullptr) || (target_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "ThreeDFoldTransition no current or target\n"); + return; + } + + int16_t width = Screen::GetInstance().GetWidth(); + float moveOffset = time * 1.0f / (float)DURA_RANGE; + float angle = ROTATE_RANGE_MAX * moveOffset; + + Vector3 currRotateStart = {current_->GetWidth(), current_->GetHeight(), 0}; + Vector3 currRotateEnd = {current_->GetWidth(), 0, 0}; + Vector3 targRotateStart = {0, 0, 0}; + Vector3 targRotateEnd = {0, target_->GetHeight(), 0}; + + current_->Rotate(angle, currRotateStart, currRotateEnd); + current_->SetPosition(-moveOffset * width, current_->GetY()); + + target_->Rotate(ROTATE_RANGE_MAX - angle, targRotateStart, targRotateEnd); + target_->SetPosition((width - moveOffset * width), target_->GetY()); +} + +void ThreeDFoldTransition::OnTransitionEnd() +{ + if ((current_ == nullptr) || (target_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "ThreeDFoldTransition no current or target\n"); + return; + } + current_->SetVisible(false); + target_->SetVisible(true); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.h new file mode 100644 index 000000000..32f6f95fd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ThreeDFoldTransition.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ThreeDFoldTransition + * Create: 2025-04 + */ + +#ifndef THREE_D_FOLD_TRANSITION_H +#define THREE_D_FOLD_TRANSITION_H +#include "TransitionCallback.h" + +namespace OHOS { +class ThreeDFoldTransition : public TransitionCallback { +public: + ThreeDFoldTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~ThreeDFoldTransition() override {} + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; +private: + UIImageView* current_ = nullptr; + UIImageView* target_ = nullptr; +}; +} // namespace OHOS +#endif // THREE_D_FOLD_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransitionUtils.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransitionUtils.h new file mode 100644 index 000000000..b5b493e5f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransitionUtils.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TransitionUtils + * Author: Hisi Graphic Team + * Created: 2025-10 + */ + +#ifndef TRANSITION_UTILS_H +#define TRANSITION_UTILS_H + +#include "components/ui_view.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class TransitionUtils { +public: + static UIView* GetViewAndTransparentizePath(UIView* current, UIViewType viewType) + { + if (current->GetViewType() == viewType) { + current->SetStyle(STYLE_BACKGROUND_OPA, 0); + return current; + } + + if (!current->IsViewGroup()) { + return nullptr; + } + + UIView* target = nullptr; + UIView* child = dynamic_cast(current)->GetChildrenHead(); + while (child != nullptr) { + target = GetViewAndTransparentizePath(child, viewType); + if (target != nullptr) { + current->SetStyle(STYLE_BACKGROUND_OPA, 0); + break; + } + child = child->GetNextSibling(); + } + return target; + } +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.cpp new file mode 100644 index 000000000..d14f3c9d5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TransparentGradientTransition + * Create: 2025-04 + */ + +#include "animator/easing_equation.h" +#include "components/root_view.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "TransparentGradientTransition.h" + + +namespace OHOS { + static const uint8_t FADE_OUT_OPACITY = 250; + static const uint8_t FADE_IN_OPACITY = 30; + static const uint8_t FADE_DELTA = 200; + static const int16_t FADE_IN_TRANS = 5; + static const int16_t FADE_OUT_TRANS = -5; + static constexpr int16_t OPA_MAX = 255; + + REGIST_TRANSITION(TransitionType::TRANSITION_TRANSPARENT_GRADIENT, TransparentGradientTransition, 400, true, true); + void TransparentGradientTransition::OnTransitionStart(UIImageView* current, UIImageView* target) + { + if ((current == nullptr) || (target == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "TransparentGradientTransition ImageView is empty!"); + return; + } + + current_ = current; + target_ = target; + + // currentView fade out + currentOpa_ = FADE_OUT_OPACITY; + transOut_ = 0; + Vector2 transTarget(transIn_, 0); + current_->SetOpaScale(currentOpa_); + + // targeview fade in + transIn_ = FADE_IN_TRANS; + targetOpa_ = FADE_IN_OPACITY; + target_->Translate(transTarget); + target_->SetOpaScale(targetOpa_); + } + + void TransparentGradientTransition::TransitionAlg(uint32_t time) + { + if ((current_ == nullptr) || (target_ == nullptr)) { + return; + } + + float scale = EasingEquation::QuadEaseIn(0, OPA_MAX, time, duration_) / static_cast(OPA_MAX); + uint8_t opa = uint8_t(scale * FADE_DELTA); + currentOpa_ = FADE_OUT_OPACITY - opa; + targetOpa_ = FADE_IN_OPACITY + opa; + transIn_ = FADE_IN_TRANS - int16_t(scale*FADE_IN_TRANS); + transOut_ = int16_t(scale*FADE_OUT_TRANS); + + Vector2 transCurrent(transOut_, 0); + Vector2 transTarget(transIn_, 0); + + current_->Translate(transCurrent); + current_->SetOpaScale(currentOpa_); + + target_->Translate(transTarget); + target_->SetOpaScale(targetOpa_); + } + + void TransparentGradientTransition::OnTransitionEnd() + { + if (current_ == nullptr || target_ == nullptr) { + return; + } + + target_->SetOpaScale(OPA_OPAQUE); + current_->SetOpaScale(OPA_TRANSPARENT); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.h new file mode 100644 index 000000000..2f03e6840 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/TransparentGradientTransition.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TransparentGradientTransition + * Create: 2025-04 + */ + +#ifndef TRANSPARENT_GRADIENT_TRANSITION_H +#define TRANSPARENT_GRADIENT_TRANSITION_H + +#include "TransitionCallback.h" + +namespace OHOS { + class TransparentGradientTransition : public TransitionCallback { + public: + TransparentGradientTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~TransparentGradientTransition() override {} + + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; + void OnTransitionEnd() override; + private: + + UIImageView* current_ = nullptr; + UIImageView* target_ = nullptr; + uint8_t currentOpa_; + uint8_t targetOpa_; + int16_t transIn_; + int16_t transOut_; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/WaterfallTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/WaterfallTransition.cpp index 5663f7007..11656bcb0 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/WaterfallTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/WaterfallTransition.cpp @@ -10,6 +10,7 @@ #include "components/root_view.h" #include "TransitionManager.h" #include "wearable_log.h" +#include "TransitionUtils.h" namespace OHOS { REGIST_TRANSITION(TransitionType::TRANSITION_WATERFALL, WaterfallTransition, 300, false, true); @@ -20,8 +21,7 @@ static const float TARGET_SCALE_END = 1.0f; void WaterfallTransition::OnTransitionStart(UIViewGroup* current, UIImageView* target) { - current->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - current_ = dynamic_cast(current->GetChildrenHead()); + current_ = dynamic_cast(TransitionUtils::GetViewAndTransparentizePath(current, UI_WATERFALL_LIST)); if (current_ == nullptr) { return; } @@ -37,7 +37,6 @@ void WaterfallTransition::OnTransitionStart(UIViewGroup* current, UIImageView* t WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "WaterfallTransition no focus view\n"); return; } - current_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); opaStart_ = focusView_->GetOpaScale(); scaleStart_ = current_->GetGlobalScale(); Rect rect = focusView_->GetRect(); diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.cpp new file mode 100644 index 000000000..d4c4c52cc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ZoomOutTransition + * Create: 2025-04 + */ + +#include "animator/easing_equation.h" +#include "common/screen.h" +#include "components/root_view.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "ZoomOutTransition.h" + +namespace OHOS { +static constexpr int16_t DURATION = 200; +static constexpr float HALF = 0.5f; +static constexpr float NUM2 = 2.0f; +static constexpr int16_t SCALE_BASE = 1; +REGIST_TRANSITION(TransitionType::TRANSITION_ZOOM_OUT, ZoomOutTransition, DURATION, true, true); + +void ZoomOutTransition::OnTransitionStart(UIImageView* current, UIImageView* target) +{ + if (current == nullptr || target == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "ZoomOutTransition ImageView is empty!"); + return; + } + target_ = target; + current_ = current; + RootView::GetInstance()->Remove(target); + RootView::GetInstance()->Insert(nullptr, target); + middleWidth_ = Screen::GetInstance().GetWidth() / NUM2; + middleHeight_ = Screen::GetInstance().GetHeight() / NUM2; +} + +void ZoomOutTransition::TransitionAlg(uint32_t time) +{ + float zoom_scale = EasingEquation::LinearEaseNone(DURATION, 0, time, duration_) / static_cast(DURATION); + float zoom_in_scale = zoom_scale; + current_->Scale(Vector2{zoom_in_scale, zoom_in_scale}, Vector2{middleWidth_, middleHeight_}); + float zoom_out_scale = SCALE_BASE + zoom_scale; + target_->Scale(Vector2{zoom_out_scale, zoom_out_scale}, Vector2{middleWidth_, middleHeight_}); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.h new file mode 100644 index 000000000..1bbd02a0a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomOutTransition.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ZoomOutTransition + * Create: 2025-04 + */ + +#ifndef ZOOM_OUT_TRANSITION_H +#define ZOOM_OUT_TRANSITION_H +#include "TransitionCallback.h" + +namespace OHOS { +class ZoomOutTransition : public TransitionCallback { +public: + ZoomOutTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~ZoomOutTransition() override {} + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; +private: + UIImageView* current_ = nullptr; + UIImageView* target_ = nullptr; + float middleWidth_; + float middleHeight_; +}; +} // namespace OHOS +#endif // ZOOM_OUT_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.cpp b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.cpp index 233f2761b..9191033db 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.cpp +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.cpp @@ -1,52 +1,44 @@ -/* - * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. - * Description: ZoomTransition - * Author: - * Create: 2023-11 - */ - -#include "ZoomTransition.h" -#include "animator/easing_equation.h" -#include "TransitionManager.h" - -namespace OHOS { -static constexpr int16_t RANGE = 1000; -REGIST_TRANSITION(TransitionType::TRANSITION_ZOOM, ZoomTransition, 800, true, true); - -void ZoomTransition::OnTransitionStart(UIImageView* current, UIImageView* target) -{ - current_ = current; - target_ = target; -} - -void ZoomTransition::TransitionAlg(uint32_t time) -{ - if ((current_ == nullptr) || (target_ == nullptr)) { - return; - } - - float scale; - uint32_t half = duration_ / 2; // 2: half of duration - if (time < half) { - scale = 1 - EasingEquation::QuadEaseOut(0, RANGE, time, half) / static_cast(RANGE); - } else { - scale = EasingEquation::QuadEaseIn(0, RANGE, time - half, half) / static_cast(RANGE); - } - uint8_t opa = scale * OPA_OPAQUE; - if (time < half) { - float centerX = current_->GetX() + current_->GetWidth() / 2.0f; // 2.0: half of width - float centerY = current_->GetY() + current_->GetHeight() / 2.0f; // 2.0: half of height - current_->SetVisible(true); - target_->SetVisible(false); - current_->Scale(Vector2{scale, scale}, Vector2{centerX, centerY}); - current_->SetOpaScale(opa); - } else { - float centerX = target_->GetX() + target_->GetWidth() / 2.0f; // 2.0: half of width - float centerY = target_->GetY() + target_->GetHeight() / 2.0f; // 2.0: half of height - target_->SetVisible(true); - current_->SetVisible(false); - target_->Scale(Vector2{scale, scale}, Vector2{centerX, centerY}); - target_->SetOpaScale(opa); - } -} -} // namespace OHOS +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ZoomTransition + * Create: 2025-04 + */ + +#include "animator/easing_equation.h" +#include "common/screen.h" +#include "TransitionManager.h" +#include "wearable_log.h" +#include "ZoomTransition.h" + +namespace OHOS { +static constexpr uint16_t DURATION = 160; +static constexpr uint16_t OPA_DURATION = 100; +static constexpr float NUM2 = 2.0f; +static constexpr float SCALE_BASE = 1; + +REGIST_TRANSITION(TransitionType::TRANSITION_ZOOM, ZoomTransition, DURATION, true, true); + +void ZoomTransition::OnTransitionStart(UIImageView* current, UIImageView* target) +{ + if (current == nullptr || target == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "ZoomTransition ImageView is empty!"); + return; + } + current_ = current; + target_ = target; + middleWidth_ = Screen::GetInstance().GetWidth() / NUM2; + middleHeight_ = Screen::GetInstance().GetHeight() / NUM2; +} + +void ZoomTransition::TransitionAlg(uint32_t time) +{ + float zoom_scale = EasingEquation::LinearEaseNone(0, DURATION, time, duration_) \ + / static_cast(DURATION); + float zoom_out_scale = SCALE_BASE + zoom_scale; + float zoom_in_scale = zoom_scale; + uint8_t opaScale = EasingEquation::CubicEaseOut(OPA_OPAQUE / NUM2, OPA_OPAQUE, time, OPA_DURATION); + current_->Scale(Vector2{zoom_out_scale, zoom_out_scale}, Vector2{middleWidth_, middleHeight_}); + target_->SetOpaScale(opaScale); + target_->Scale(Vector2{zoom_in_scale, zoom_in_scale}, Vector2{middleWidth_, middleHeight_}); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.h b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.h index 419f2c086..ad604e5ff 100644 --- a/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.h +++ b/code/sdk/application/wearable/evb/nativeabilityfwk/src/transition/ZoomTransition.h @@ -1,25 +1,26 @@ -/* - * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. - * Description: ZoomTransition - * Author: - * Create: 2023-11 - */ - -#ifndef ZOOM_TRANSITION_H -#define ZOOM_TRANSITION_H -#include "TransitionCallback.h" - -namespace OHOS { -class ZoomTransition : public TransitionCallback { -public: - ZoomTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : - TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} - ~ZoomTransition() override {} - void OnTransitionStart(UIImageView* current, UIImageView* target) override; - void TransitionAlg(uint32_t time) override; -private: - UIImageView* current_ = nullptr; - UIImageView* target_ = nullptr; -}; -} // namespace OHOS +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ZoomTransition + * Create: 2025-04 + */ + +#ifndef ZOOM_TRANSITION_H +#define ZOOM_TRANSITION_H +#include "TransitionCallback.h" + +namespace OHOS { +class ZoomTransition : public TransitionCallback { +public: + ZoomTransition(uint32_t time, bool enableCurrentSnapshot, bool enableTargetSnapshot) : + TransitionCallback(time, enableCurrentSnapshot, enableTargetSnapshot) {} + ~ZoomTransition() override {} + void OnTransitionStart(UIImageView* current, UIImageView* target) override; + void TransitionAlg(uint32_t time) override; +private: + UIImageView* current_ = nullptr; + UIImageView* target_ = nullptr; + float middleWidth_; + float middleHeight_; +}; +} // namespace OHOS #endif // ZOOM_TRANSITION_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/evb/nativeapp/CMakeLists.txt index 779b0cc29..b0fdeb985 100644 --- a/code/sdk/application/wearable/evb/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/evb/nativeapp/CMakeLists.txt @@ -13,7 +13,7 @@ set(PUBLIC_HEADER set(PRIVATE_HEADER ${NativeApp}/nativeui/ ${NativeApp}/nativeui/uisample/uitest/framework/include - ${UI_SAMPLE_ROOT}/components + ${NativeApp}/nativeui/inlcude/screennotify ${NativeApp}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include ${NativeApp}/../service/smart_voice/voice_engine_hal/interfaces/innerkits/native_c/include ${NativeApp}/../ohos_deps @@ -23,6 +23,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits + ${UI_SAMPLE_ROOT}/components ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/events ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits @@ -63,39 +64,40 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/animator ${ROOTDIR}/open_source/flatbuffers/include ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/calendarManager + ${ROOTDIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/public ) file(GLOB_RECURSE SOURCES "${NativeApp}/nativeui/*.cpp") +file(GLOB_RECURSE UI_SAMPLE_SRC "${UI_SAMPLE_ROOT}/components/*.cpp") +list(REMOVE_ITEM UI_SAMPLE_SRC + ${UI_SAMPLE_ROOT}/components/ui_test_bitmap_font/ui_test_bitmap_font.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/ui_test_clock_dial.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/ScreenModel.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/PullUpDownView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/MainClockView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/HeartRateView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/CompassView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/CompassControlView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_clock_dial/ActivityWeekView.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_compass/ui_test_compass.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_dump_dom_tree/ui_test_dump_dom.cpp +) + +if(NOT "CONFIG_NATIVEAPP_TEST" IN_LIST DEFINES) + file(GLOB FILES_TO_REMOVE_MONKEY "${CMAKE_CURRENT_SOURCE_DIR}/nativeui/monkey/src/*.cpp") + file(GLOB FILES_TO_REMOVE_EMPTY "${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emptypage/src/*.cpp") + list(APPEND FILES_TO_REMOVE ${FILES_TO_REMOVE_MONKEY} ${FILES_TO_REMOVE_EMPTY}) + list(REMOVE_ITEM SOURCES ${FILES_TO_REMOVE}) +endif() + set(SOURCES ${SOURCES} ${NativeApp}/nativelauncher/src/NativeLauncher.cpp ${NativeApp}/nativelauncher/src/NativeRegisterManager.cpp ${NativeApp}/nativelauncher/src/UICardPageFactory.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_lottie/ui_test_lottie.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_tiger/tiger_view.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_tiger/ui_test_tiger.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_running_ball/ui_test_running_ball.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_breath/ui_test_breath.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_card_switch/ui_test_card_switch.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_countdown/ui_test_countdown.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_list_fps/image_text_adapter.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_list_fps/ui_test_list_fps.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_particle/ui_test_particle.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_message/ui_test_message.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_icosahedron/ui_test_icosahedron.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/cube_rotate_view.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/ui_test_cube_rotate.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_video_play/ui_test_video_play.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_keyboard/ui_test_keyboard.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_waterfall_list/ui_test_waterfall_list.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_coverflow/ui_test_coverflow.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_slipflow/ui_test_slipflow.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_roller_view/ui_test_roller_view.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_emoji/ui_test_emoji.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_sphere_view/ui_test_sphere_view.cpp - ${UI_SAMPLE_ROOT}/components/ui_test_nested/ui_test_nested.cpp + ${NativeApp}/nativelauncher/src/UIWatchDialFactory.cpp + ${UI_SAMPLE_SRC} ) list(REMOVE_ITEM SOURCES @@ -209,7 +211,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/base ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/utils/innerkits - ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks/ + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils diff --git a/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a b/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a index eede3b370..1bf80f959 100644 Binary files a/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a and b/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a b/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a index 40a9458c8..a29f4e72c 100644 Binary files a/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a and b/code/sdk/application/wearable/evb/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/evb/nativeapp/brandy-native-js/libuikit_fwk.a b/code/sdk/application/wearable/evb/nativeapp/brandy-native-js/libuikit_fwk.a index e3ce469ad..dd5873d60 100644 Binary files a/code/sdk/application/wearable/evb/nativeapp/brandy-native-js/libuikit_fwk.a and b/code/sdk/application/wearable/evb/nativeapp/brandy-native-js/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/evb/nativeapp/brandy-xts/libuikit_fwk.a b/code/sdk/application/wearable/evb/nativeapp/brandy-xts/libuikit_fwk.a index 337b034d5..ae7f995dc 100644 Binary files a/code/sdk/application/wearable/evb/nativeapp/brandy-xts/libuikit_fwk.a and b/code/sdk/application/wearable/evb/nativeapp/brandy-xts/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/AppViewIDs.h index 6c6b38fcb..40cacd2a6 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/AppViewIDs.h @@ -33,7 +33,6 @@ typedef enum : uint16_t { VIEW_MAIN_ACTIVITY = 7, VIEW_ALARM_POP_UP, VIEW_CALLER_SAMPLE, - VIEW_MAEKPHONE_SAMPLE, VIEW_BLOODOXY_SAMPLE, VIEW_BLUETOOTH_EARPHONE, VIEW_OFFLINEVOICE, @@ -42,10 +41,9 @@ typedef enum : uint16_t { VIEW_COMPASS, VIEW_CONNECT_PHONE, VIEW_MAIN_TEMP, - VIEW_INDOORWALK, VIEW_REBOOT, VIEW_UISAMPLE, - VIEW_MAIN_BREATHEASE, + VIEW_BREATH, VIEW_FLASHLIGHT, // 手电筒; VIEW_STOPWATCH, // 秒表; VIEW_WEATHER, // 天气 @@ -54,20 +52,15 @@ typedef enum : uint16_t { VIEW_CAMERA, // 相机 VIEW_FIND_PHONE, // 寻找手机 VIEW_DATE, // 日期 - VIEW_QRCODE_CONN, // 二维码连接; - VIEW_SPORTS, + VIEW_SPORT, + VIEW_PHONE_MENU, VIEW_SLEEPING, - VIEW_TRAINING, VIEW_EMPTY, + VIEW_HEARTRATE, + VIEW_MONKEY, #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, #endif - VIEW_SET_DESKTOP, - VIEW_SET_OTA, - VIEW_SET_CARD, - VIEW_ADD_CARD, - VIEW_SET_DIAL, - VIEW_SET_DIAL_STYLE, VIEW_AOD, VIEW_RESTORE_DEFAULTS, VIEW_RECENT_APP, diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UICardPageFactory.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UICardPageFactory.h index 761e137c7..33f0fc3a1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UICardPageFactory.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UICardPageFactory.h @@ -21,22 +21,22 @@ public: static UICardPageFactory instance; return instance; } - void RegisterWatchDial(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage); - UICardPage* CreateWatchDial(uint16_t mode, uint16_t id); + void RegisterCardPage(const uint16_t id, UICardPageProxyInterface* uiCardPage); + UICardPage* CreateCardPage(uint16_t id); private: UICardPageFactory() {}; ~UICardPageFactory() {}; UICardPageFactory(const UICardPageFactory&) = delete; UICardPageFactory &operator=(const UICardPageFactory&) = delete; - std::unordered_map watchDials_[static_cast(DIAL_DISPLAY_MODE_MAX)]; + std::unordered_map cardPage_; }; -class WatchDialRegister { +class CardPageRegister { public: - WatchDialRegister(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage) + CardPageRegister(const uint16_t id, UICardPageProxyInterface* uiCardPage) { - UICardPageFactory::GetInstance().RegisterWatchDial(mode, id, uiCardPage); + UICardPageFactory::GetInstance().RegisterCardPage(id, uiCardPage); } }; @@ -52,7 +52,7 @@ public: }; template -class WatchDialProxy : public UICardPageProxyInterface { +class CardPageProxy : public UICardPageProxyInterface { public: UICardPage* CreateUICardPage() override { @@ -66,8 +66,8 @@ public: }; } // namespace OHOS -#define REGIST_WATCH_DIAL(mode, id, U) \ - const static OHOS::WatchDialRegister (STATIC_VAR)(static_cast(mode), static_cast(id), \ - new WatchDialProxy()) +#define REGIST_CARD_PAGE(id, U) \ + const static OHOS::CardPageRegister (STATIC_VAR)(static_cast(id), \ + new CardPageProxy()) #endif // UI_CARD_PAGE_FACTORY_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UIWatchDialFactory.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UIWatchDialFactory.h new file mode 100644 index 000000000..086b2a201 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UIWatchDialFactory.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: UIWatchDialFactory + * Author: + * Create: 2025-06 + */ + +#ifndef UI_WATCH_DIAL_FACTORY_H +#define UI_WATCH_DIAL_FACTORY_H + +#include +#include "components/ui_card_page.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "main/MainModel.h" +#include "components/ui_fragment.h" + +namespace OHOS { +class UIWatchDialProxyInterface; +class UIWatchDialFactory { +public: + static UIWatchDialFactory& GetInstance() + { + static UIWatchDialFactory instance; + return instance; + } + void RegisterWatchDial(const uint16_t ability, const uint16_t id, UIWatchDialProxyInterface* uiWatchDial, + const DialInfo* dialInfo); + UICardPage* CreateNormalDial(uint16_t id); + UIFragment* CreateAodDial(uint16_t id); + const DialInfo* GetNormalDialInfo(uint16_t id); + uint8_t GetNormalDialInfoNum(); + +private: + UIWatchDialFactory() {}; + ~UIWatchDialFactory() {}; + UIWatchDialFactory(const UIWatchDialFactory&) = delete; + UIWatchDialFactory &operator=(const UIWatchDialFactory&) = delete; + std::unordered_map watchDials_[static_cast(DIAL_DISPLAY_MODE_MAX)]; + std::unordered_map normalDialInfo_; +}; + +class WatchDialRegister { +public: + WatchDialRegister(const uint16_t ability, const uint16_t id, UIWatchDialProxyInterface* uiWatchDial, + const DialInfo* dialInfo) + { + UIWatchDialFactory::GetInstance().RegisterWatchDial(ability, id, uiWatchDial, dialInfo); + } +}; + +class UIWatchDialProxyInterface { +public: + virtual UICardPage* CreateWatchDialCardPage(const uint16_t id) = 0; + virtual UIFragment* CreateWatchDialFragment(const uint16_t id) = 0; + UIWatchDialProxyInterface() = default; + virtual ~UIWatchDialProxyInterface() = default; + UIWatchDialProxyInterface(const UIWatchDialProxyInterface&) = delete; + UIWatchDialProxyInterface& operator=(const UIWatchDialProxyInterface&) = delete; + UIWatchDialProxyInterface(UIWatchDialProxyInterface&&) = delete; + UIWatchDialProxyInterface& operator=(UIWatchDialProxyInterface&&) = delete; +}; + +template +class WatchDialProxy : public UIWatchDialProxyInterface { +public: + UICardPage* CreateWatchDialCardPage(const uint16_t id) override + { + U* u = new U(); + UICardPage* page = dynamic_cast(u); + if (page == nullptr) { + delete u; + } + return page; + } + + UIFragment* CreateWatchDialFragment(const uint16_t id) override + { + U* u = new U(); + UIFragment* fragment = dynamic_cast(u); + if (fragment == nullptr) { + delete u; + } + fragment->CreateView(); + return fragment; + } +}; +} // namespace OHOS + +#define REGIST_WATCH_DIAL(ability, id, U, info) \ + const static OHOS::WatchDialRegister (STATIC_VAR)(static_cast(ability), static_cast(id), \ + new WatchDialProxy(), static_cast(info)) + +#endif // UI_WATCH_DIAL_FACTORY_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UiConfig.h index b04a143ac..5af46ad89 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/UiConfig.h @@ -15,7 +15,6 @@ namespace OHOS { typedef enum { WATCH_FACE = 0, /* 主表盘枚举值不能修改 */ - HEART_RATE, COMPASS, ACTIVITY, MUSIC_PLAYER, @@ -28,14 +27,22 @@ namespace OHOS { typedef enum { DIAL_CLOCK = 0, + GRADIENT_CLOCK, DIAL_MAX, } DialId; typedef enum { - DIAL_DISPLAY_MODE_MAIN = 0, + DIAL_DISPLAY_MODE_NORMAL = 0, DIAL_DISPLAY_MODE_AOD, DIAL_DISPLAY_MODE_MAX, - } DialDispayMode; + } DialDisplayMode; + + typedef enum { + DIAL_DISPLAY_SUPPORT_NORMAL = 0, + DIAL_DISPLAY_SUPPORT_AOD, + DIAL_DISPLAY_SUPPORT_NORMAL_AOD, + DIAL_DISPLAY_SUPPORT_MAX, + } DialDisplayAbility; #ifndef UNUSED #define UNUSED(x) ((void)(x)) @@ -64,17 +71,20 @@ namespace OHOS { #define APP_MUSIC_PATH "/user/music" #define APP_VIDEO_PATH "/user/video" #define APP_DIAL_PATH "/user/dial" + #define APP_RECENT_PATH "/system/recent/" #else #ifdef RELEASE_VERSION #define APP_RES_PATH "res/res" #define APP_MUSIC_PATH "res/music" #define APP_VIDEO_PATH "res/video" #define APP_DIAL_PATH "res/dial" + #define APP_RECENT_PATH "/res/recent/" #else #define APP_RES_PATH "../../../wearable/res/res" #define APP_MUSIC_PATH "../../../wearable/res/music" #define APP_VIDEO_PATH "../../../wearable/res/video" #define APP_DIAL_PATH "../../../wearable/res/dial" + #define APP_RECENT_PATH "../../../wearable/res/recent/" #endif #endif @@ -86,87 +96,12 @@ namespace OHOS { static constexpr const char *DROPDOWN_IAMGES = APP_RES_PATH"/dropdown/dropdown.bin"; static constexpr const char *HEART_IAMGES = APP_RES_PATH"/heart/heart.bin"; static constexpr const char *PNG_BLUETOOTH_HINTS_PATH = APP_RES_PATH"/BLUETOOTH_HINTS.bin"; - static constexpr const char *PNG_BLOODOXYGEN_IMAGE_PATH = APP_RES_PATH"/BLOODOXYGEN_VIEW.bin"; - - static constexpr const char *PNG_BLOOD_ICON_ENTER = APP_RES_PATH"/BLOOD_ICON_ENTER.bin"; - - static constexpr const char *PNG_AGREEING_IMAGE_PATH = APP_RES_PATH"/AGREEING.bin"; - static constexpr const char *PNG_DISSGREE_IMAGE_PATH = APP_RES_PATH"/DISSGREE.bin"; - static constexpr const char *PNG_MICROPHONE_OPEN_IMAGE_PATH = APP_RES_PATH"/MICRO_PHONE_OPEN.bin"; - static constexpr const char *PNG_MICROPHONE_CLOSE_IMAGE_PATH = APP_RES_PATH"/MICRO_PHONE_CLOSE.bin"; - static constexpr const char *PNG_HANDUP_IMAGE_PATH = APP_RES_PATH"/HANDUP.bin"; - static constexpr const char *PNG_ANSWER_TMAGE_PATH = APP_RES_PATH"/ANSWER_PHONE.bin"; - static constexpr const char *PNG_CALLING_TMAGE_PATH = APP_RES_PATH"/CALLING_PHONE.bin"; - static constexpr const char *PNG_CALLER_TMAGE_PATH = APP_RES_PATH"/CALLER_LOG_IMAGE.bin"; - static constexpr const char *PNG_NO_CALLER_LOG_IMAGE = APP_RES_PATH"/NO_CALLER_LOG_IMAGE.bin"; - static constexpr const char *PNG_APPLIST_CALLER_IMAGE = APP_RES_PATH"/APPLIST_CALLER_IMAGE.bin"; static constexpr const char *PNG_APPLIST_COMPASS_IMAGE = APP_RES_PATH"/APPLIST_COMPASS_IMAGE.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_0 = APP_RES_PATH"/COUNTDOWN_IMAGE_01.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_1 = APP_RES_PATH"/COUNTDOWN_IMAGE_02.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_2 = APP_RES_PATH"/COUNTDOWN_IMAGE_03.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_3 = APP_RES_PATH"/COUNTDOWN_IMAGE_04.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_4 = APP_RES_PATH"/COUNTDOWN_IMAGE_05.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_5 = APP_RES_PATH"/COUNTDOWN_IMAGE_06.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_6 = APP_RES_PATH"/COUNTDOWN_IMAGE_07.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_7 = APP_RES_PATH"/COUNTDOWN_IMAGE_08.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_8 = APP_RES_PATH"/COUNTDOWN_IMAGE_09.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_9 = APP_RES_PATH"/COUNTDOWN_IMAGE_10.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_10 = APP_RES_PATH"/COUNTDOWN_IMAGE_11.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_11 = APP_RES_PATH"/COUNTDOWN_IMAGE_12.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_12 = APP_RES_PATH"/COUNTDOWN_IMAGE_13.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_13 = APP_RES_PATH"/COUNTDOWN_IMAGE_14.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_14 = APP_RES_PATH"/COUNTDOWN_IMAGE_15.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_15 = APP_RES_PATH"/COUNTDOWN_IMAGE_16.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_16 = APP_RES_PATH"/COUNTDOWN_IMAGE_17.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_17 = APP_RES_PATH"/COUNTDOWN_IMAGE_18.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_18 = APP_RES_PATH"/COUNTDOWN_IMAGE_19.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_19 = APP_RES_PATH"/COUNTDOWN_IMAGE_20.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_20 = APP_RES_PATH"/COUNTDOWN_IMAGE_21.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_21 = APP_RES_PATH"/COUNTDOWN_IMAGE_22.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_22 = APP_RES_PATH"/COUNTDOWN_IMAGE_23.bin"; - static constexpr const char *PNG_COUNTDOWN_TIME_IMAGE_23 = APP_RES_PATH"/COUNTDOWN_IMAGE_24.bin"; - static constexpr const char *PNG_PROGRESS_BAR_TMAGE = APP_RES_PATH"/PROGRESS_BAR_TMAGE.bin"; - static constexpr const char *TEMP_WAITING = APP_RES_PATH"/TEMP_WAITING.bin"; - static constexpr const char *TEMP_REPORT = APP_RES_PATH"/TEMP_REPORT.bin"; - static constexpr const char *TEMP_POINT = APP_RES_PATH"/TEMP_POINT.bin"; - static constexpr const char *TEMP_REV_POINTER = APP_RES_PATH"/TEMP_REV_POINTER.bin"; - - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_0 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_02.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_1 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_03.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_2 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_04.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_3 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_05.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_4 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_06.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_5 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_07.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_6 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_08.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_7 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_09.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_8 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_10.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_9 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_11.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_10 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_12.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_11 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_13.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_12 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_14.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_13 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_15.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_14 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_16.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_15 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_17.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_16 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_18.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_17 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_19.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_18 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_20.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_19 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_21.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_20 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_22.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_21 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_23.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_22 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_24.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_23 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_25.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_24 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_26.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_25 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_27.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_26 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_28.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_27 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_29.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_28 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_30.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_29 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_31.bin"; - static constexpr const char *PNG_BLOOD_FLOW_IMAGE_30 = APP_RES_PATH"/BLOOD_FLOW_IMAGE_32.bin"; static constexpr const char *PNG_SOUNDBUTTON2 = APP_RES_PATH"/SOUND_IMAGE.bin"; - static constexpr const char *PNG_PULLBUTTON_FACE_IMAGE = APP_RES_PATH"/BLOOD_FLOW_IMAGE_01.bin"; + static constexpr const char *PNG_PULLUP_BUTTON = APP_RES_PATH"/PNG_PULLUP_BUTTON.bin"; static constexpr const char *MUSIC_2 = APP_RES_PATH"/mp3_48k_caiqing.mp3"; static constexpr const char *MUSIC_1 = APP_RES_PATH"/one.mp3"; @@ -174,17 +109,6 @@ namespace OHOS { static constexpr const char *PNG_BLUETOOTH_IMAGE = APP_RES_PATH"/BLUETOOTH_IMAGE.bin"; static constexpr const char *PNG_WATCH_IMAGE = APP_RES_PATH"/WATCH_IMAGE.bin"; static constexpr const char *PNG_PHONE_IMAGE = APP_RES_PATH"/PHONE_IMAGE.bin"; - static constexpr const char *PNG_REBOOT_BUTTON_IMAGE = APP_RES_PATH"/REBOOT_BUTTON.bin"; - static constexpr const char *PNG_SHUTDOWN_BUTTON_IMAGE = APP_RES_PATH"/SHUTDOWN_BUTTON.bin"; - static constexpr const char *PNG_SETTTING_REBOOT_IMAGE = APP_RES_PATH"/SETTTING_REBOOT.bin"; - static constexpr const char *PNG_SETTTING_SHUTDOWN_IMAGE = APP_RES_PATH"/SETTTING_SHUTDOWN.bin"; - static constexpr const char *PNG_SETTTING_DESKTOP_IMAGE = APP_RES_PATH"/SETTTING_DESKTOP.bin"; - static constexpr const char *PNG_SET_DESKTOP_LIST_IMAGE = APP_RES_PATH"/SET_DESKTOP_LIST.bin"; - static constexpr const char *PNG_SET_DESKTOP_HEXAGONS_IMAGE = APP_RES_PATH"/SET_DESKTOP_HEXAGONS.bin"; - static constexpr const char *PNG_SET_DESKTOP_BG_IMAGE = APP_RES_PATH"/SET_DESKTOP_BG.bin"; - - static constexpr const char *PNG_CONNECT_PHONE_IMAGE = APP_RES_PATH"/CONNECT_PHONE.bin"; - static constexpr const char *PNG_BLUETOOTH_STITLE = APP_RES_PATH"/BLUETOOTH_TITLE.bin"; static constexpr const char *PNG_NEW_DEVICE = APP_RES_PATH"/NEW_DEVICE.bin"; static constexpr const char *PNG_BT_LIST = APP_RES_PATH"/BT_LIST.bin"; @@ -205,20 +129,6 @@ namespace OHOS { static constexpr const char *ALARM_CLOCK_POP_ADD_PATH = APP_RES_PATH"/RING_CLOCK.bin"; static constexpr const char *ALARM_DELETE_ADD_PATH = APP_RES_PATH"/DELETE.bin"; static constexpr const char *ALARM_TRUE_ADD_PATH = APP_RES_PATH"/TRUE_ADD.bin"; - static constexpr const char *TEMP_MEASURE = APP_RES_PATH"/TEMP_MEASURE.bin"; - static constexpr const char *TEMP_UP_DROP = APP_RES_PATH"/TEMP_UP_DROP.bin"; - static constexpr const char *TEMP_EXIT = APP_RES_PATH"/TEMP_EXIT.bin"; - static constexpr const char *TEMP_ROTATE = APP_RES_PATH"/TEMP_ROTATE.bin"; - static constexpr const char *TEMP_ICON_ENTER = APP_RES_PATH"/TEMP_ICON_ENTER.bin"; - static constexpr const char *TEMP_BACKGROUND = APP_RES_PATH"/TEMP_BACKGROUND.bin"; - static constexpr const char *TEMP_WARN = APP_RES_PATH"/TEMP_WARN.bin"; - static constexpr const char *TEMP_LITTLE_MEASURE = APP_RES_PATH"/TEMP_LITTLE_MEASURE.bin"; - static constexpr const char *TEMP_HOT = APP_RES_PATH"/TEMP_HOT.bin"; - static constexpr const char *TEMP_COLD = APP_RES_PATH"/TEMP_COLD.bin"; - static constexpr const char *TEMP_LIT_TIP = APP_RES_PATH"/TEMP_LIT_TIP.bin"; - static constexpr const char *TEMP_ABOUT_STUDY = APP_RES_PATH"/TEMP_ABOUT_STUDY.bin"; - static constexpr const char *TEMP_TRUE = APP_RES_PATH"/TEMP_TRUE.bin"; - static constexpr const char *TEMP_DELETE = APP_RES_PATH"/TEMP_DELETE.bin"; static constexpr const char *COMPASS_CALIBRATE_IMAGE = APP_RES_PATH"/COMPASS_CALIBRATE_IMAGE.bin"; static constexpr const char *PNG_SETTING_NEXT_IMAGE = APP_RES_PATH"/SETTING_NEXT.bin"; @@ -298,26 +208,6 @@ namespace OHOS { static constexpr const char *PNG_STEP_SHOE_IMAGE_PATH = APP_RES_PATH"/SHOE_IMAGE.bin"; - static constexpr const char *PNG_A004_070_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_01.bin"; - static constexpr const char *PNG_A004_071_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_02.bin"; - static constexpr const char *PNG_A004_072_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_03.bin"; - static constexpr const char *PNG_A004_073_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_04.bin"; - static constexpr const char *PNG_A004_074_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_05.bin"; - static constexpr const char *PNG_A004_075_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_06.bin"; - static constexpr const char *PNG_A004_076_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_07.bin"; - static constexpr const char *PNG_A004_077_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_08.bin"; - static constexpr const char *PNG_A004_078_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_09.bin"; - static constexpr const char *PNG_A004_079_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_10.bin"; - static constexpr const char *PNG_A004_080_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_11.bin"; - static constexpr const char *PNG_A004_081_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_12.bin"; - static constexpr const char *PNG_A004_082_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_13.bin"; - static constexpr const char *PNG_A004_083_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_14.bin"; - static constexpr const char *PNG_A004_084_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_15.bin"; - static constexpr const char *PNG_A004_085_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_16.bin"; - static constexpr const char *PNG_A004_086_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_17.bin"; - static constexpr const char *PNG_A004_087_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_18.bin"; - static constexpr const char *PNG_A004_088_IMAGE_PATH = APP_RES_PATH"/HEARTBEAT_IMAGE_19.bin"; - static constexpr const char *PNG_A019_080_IMAGE_PATH = APP_RES_PATH"/BLUETOOTH_IMAGE_01.bin"; static constexpr const char *PNG_A019_081_IMAGE_PATH = APP_RES_PATH"/BLUETOOTH_IMAGE_02.bin"; static constexpr const char *PNG_A019_082_IMAGE_PATH = APP_RES_PATH"/BLUETOOTH_IMAGE_03.bin"; @@ -339,9 +229,7 @@ namespace OHOS { // AppList static constexpr const char *PNG_APPLIST_ALARM_IMAGE = APP_RES_PATH"/APPLIST_ALARM.bin"; // 闹钟 - static constexpr const char *PNG_APPLIST_SPO2_IMAGE = APP_RES_PATH"/APPLIST_SPO2.bin"; // 血氧 static constexpr const char *PNG_APPLIST_SETTING_IMAGE = APP_RES_PATH"/APPLIST_SETTING.bin"; // 设置 - static constexpr const char *PNG_APPLIST_TEMP_IMAGE = APP_RES_PATH"/TEMP_IMAGE.bin"; // 体温 static constexpr const char *PNG_APPLIST_ALIPAY_IMAGE = APP_RES_PATH"/alipay_logo.bin"; // 支付宝 static constexpr const char *PNG_ALIPAY_BIND_FAILURE = APP_RES_PATH"/ALIPAY_BIND_FAILURE.bin"; @@ -357,27 +245,8 @@ namespace OHOS { 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_WALK_IMAGE = APP_RES_PATH"/APPLIST_WALK.bin"; // Applist图标 - static constexpr const char *PNG_WALK_BACK_GROUND = APP_RES_PATH"/WALK_BACK_GROUND.bin"; - static constexpr const char *PNG_WALK_IMAGE = APP_RES_PATH"/INDOORWALK.bin"; - static constexpr const char *PNG_AEROBIC_IMAGE = APP_RES_PATH"/AEROBIC.bin"; - static constexpr const char *PNG_ANAEROBIC_IMAGE = APP_RES_PATH"/ANAEROBIC.bin"; - static constexpr const char *PNG_OPTIONS_BOX1_IMAGE = APP_RES_PATH"/OPTIONS_BOX1.bin"; - static constexpr const char *PNG_OPTIONS_BOX2_IMAGE = APP_RES_PATH"/OPTIONS_BOX2.bin"; - static constexpr const char *PNG_OPTIONS_BOX3_IMAGE = APP_RES_PATH"/OPTIONS_BOX3.bin"; - static constexpr const char *PNG_OPTIONS_BOX4_IMAGE = APP_RES_PATH"/OPTIONS_BOX4.bin"; - static constexpr const char *PNG_WALK_TIME_IMAGE = APP_RES_PATH"/TIME_IMAGE.bin"; - static constexpr const char *PNG_WALK_DISTANCES_IMAGE = APP_RES_PATH"/DISTANCES_IMAGE.bin"; - static constexpr const char *PNG_WALK_HEART_IMAGE = APP_RES_PATH"/HEART_IMAGE.bin"; - static constexpr const char *PNG_WALK_SPEED_IMAGE = APP_RES_PATH"/SPEED_IMAGE.bin"; - static constexpr const char *PNG_WALK_STEPS_IMAGE = APP_RES_PATH"/STEPS_IMAGE.bin"; - static constexpr const char *PNG_APPLIST_UI_SAMPLE_IMAGE = APP_RES_PATH"/APPLIST_UI_SAMPLE.bin"; // Applist图标 - static constexpr const char *PNG_SET_CARD_ADD = APP_RES_PATH"/CARD_ADD.bin"; - static constexpr const char *PNG_SET_CARD_DEL = APP_RES_PATH"/CARD_DEL.bin"; - static constexpr const char *PNG_SET_CARD_HEART = APP_RES_PATH"/CARD_HEART.bin"; static constexpr const char *PNG_SET_CARD_COMPASS = APP_RES_PATH"/CARD_COMPASS.bin"; static constexpr const char *PNG_SET_CARD_ACTIVITY = APP_RES_PATH"/CARD_ACTIVITY.bin"; static constexpr const char *PNG_SET_CARD_PLAYER = APP_RES_PATH"/CARD_PLAYER.bin"; @@ -386,24 +255,41 @@ namespace OHOS { static constexpr const char *PNG_SET_DIAL_CLOCK = APP_RES_PATH"/DIAL_CLOCK.bin"; - static constexpr const char *PNG_APPLIST_STOPWATCH_LOGO = APP_RES_PATH"/STOPWATCH_LOGO.bin"; - static constexpr const char *PNG_APPLIST_STOPWATCH_IMAGE = APP_RES_PATH"/STOPWATCH.bin"; + static constexpr const char *SPORT_ICON = APP_RES_PATH"/SPORT_ICON.bin"; + static constexpr const char *SPORT_IMAGE = APP_RES_PATH"/SPORT.bin"; + static constexpr const char *STOPWATCH_ICON = APP_RES_PATH"/STOPWATCH_ICON.bin"; + static constexpr const char *STOPWATCH_IMAGE = APP_RES_PATH"/STOPWATCH.bin"; static constexpr const char *WEATHER_IMAGE = APP_RES_PATH"/WEATHER.bin"; - static constexpr const char *WEATHER_MAIN_ICON = APP_RES_PATH"/WEATHER_LOGO.bin"; + static constexpr const char *WEATHER_ICON = APP_RES_PATH"/WEATHER_ICON.bin"; static constexpr const char *TIMER_IMAGE = APP_RES_PATH"/TIMER.bin"; - static constexpr const char *TIMER_MAIN_ICON = APP_RES_PATH"/TIMER_ICON.bin"; + static constexpr const char *TIMER_ICON = APP_RES_PATH"/TIMER_ICON.bin"; static constexpr const char *DATE_IMAGE = APP_RES_PATH"/DATE.bin"; - static constexpr const char *DATE_MAIN_ICON = APP_RES_PATH"/DATE_LOGO.bin"; + static constexpr const char *DATE_ICON = APP_RES_PATH"/DATE_ICON.bin"; static constexpr const char *FLASHLIGHT_IMAGE = APP_RES_PATH"/FLASHLIGHT.bin"; - static constexpr const char *FLASHLIGHT_MAIN_ICON = APP_RES_PATH"/FLASHLIGHT_LOGO.bin"; + static constexpr const char *FLASHLIGHT_ICON = APP_RES_PATH"/FLASHLIGHT_ICON.bin"; static constexpr const char *SLEEP_IMAGE = APP_RES_PATH"/SLEEP.bin"; static constexpr const char *SLEEP_ICON = APP_RES_PATH"/SLEEP_ICON.bin"; static constexpr const char *BREATH_IMAGE = APP_RES_PATH"/BREATH.bin"; - static constexpr const char *BREATH_MAIN_ICON = APP_RES_PATH"/BREATH_ICON.bin"; + static constexpr const char *BREATH_ICON = APP_RES_PATH"/BREATH_ICON.bin"; static constexpr const char *FINDPHONE_IMAGE = APP_RES_PATH"/FINDPHONE.bin"; - static constexpr const char *FINDPHONE_MAIN_ICON = APP_RES_PATH"/FINDPHONE_LOGO.bin"; + static constexpr const char *FINDPHONE_ICON = APP_RES_PATH"/FINDPHONE_ICON.bin"; static constexpr const char *CAMERA_IMAGE = APP_RES_PATH"/CAMERA.bin"; - static constexpr const char *CAMERA_MAIN_ICON = APP_RES_PATH"/CAMERA_ICON.bin"; + static constexpr const char *CAMERA_ICON = APP_RES_PATH"/CAMERA_ICON.bin"; + static constexpr const char *PHONEMENU_IMAGE = APP_RES_PATH"/PHONEMENU.bin"; + static constexpr const char *PHONEMENU_ICON = APP_RES_PATH"/PHONEMENU_ICON.bin"; + static constexpr const char *HEART_RATE_IMAGE = APP_RES_PATH"/HEART_RATE.bin"; + static constexpr const char *HEART_RATE_ICON = APP_RES_PATH"/HEART_RATE_ICON.bin"; + static constexpr const char *MESSAGE_IMAGE = APP_RES_PATH"/MESSAGE.bin"; + static constexpr const char *BLOOD_IMAGE = APP_RES_PATH"/BLOOD.bin"; + static constexpr const char *BLOOD_ICON = APP_RES_PATH"/BLOOD_ICON.bin"; + static constexpr const char *SETTING_IMAGE = APP_RES_PATH"/SETTING.bin"; + static constexpr const char *SETTING_ICON = APP_RES_PATH"/SETTING_ICON.bin"; + static constexpr const char *EMPTY_IMAGE = APP_RES_PATH"/EMPTY.bin"; + static constexpr const char *EMPTY_ICON = APP_RES_PATH"/EMPTY_ICON.bin"; + static constexpr const char *MONKEY_ICON = APP_RES_PATH"/MONKEY_ICON.bin"; + + static constexpr const char *PNG_SET_GRADIENT_CLOCK = APP_RES_PATH"/GRADIENT_CLOCK.bin"; + static constexpr const char *PNG_TRANSITION_SLICE_SAMPLE = APP_RES_PATH"/TRANSITION_SLICE_SAMPLE.bin"; } #endif // UI_CONFIG_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_blood.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_blood.h new file mode 100644 index 000000000..0901ff41e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_blood.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceBlood + * Create: 2025-06 + */ + +#ifndef UI_RESOURCE_BLOOD_H +#define UI_RESOURCE_BLOOD_H + +namespace OHOS { +static const int IMAGE_BLOOD_ABNORMAL = 0x100001; +static const int IMAGE_BLOOD_AGAIN = 0x100002; +static const int IMAGE_BLOOD_BG = 0x100003; +static const int IMAGE_BLOOD_COMMON = 0x100004; +static const int IMAGE_BLOOD_FRAME00 = 0x100005; +static const int IMAGE_BLOOD_FRAME01 = 0x100006; +static const int IMAGE_BLOOD_FRAME02 = 0x100007; +static const int IMAGE_BLOOD_FRAME03 = 0x100008; +static const int IMAGE_BLOOD_FRAME04 = 0x100009; +static const int IMAGE_BLOOD_FRAME05 = 0x10000a; +static const int IMAGE_BLOOD_FRAME06 = 0x10000b; +static const int IMAGE_BLOOD_FRAME07 = 0x10000c; +static const int IMAGE_BLOOD_FRAME08 = 0x10000d; +static const int IMAGE_BLOOD_FRAME09 = 0x10000e; +static const int IMAGE_BLOOD_FRAME10 = 0x10000f; +static const int IMAGE_BLOOD_FRAME11 = 0x100010; +static const int IMAGE_BLOOD_FRAME12 = 0x100011; +static const int IMAGE_BLOOD_FRAME13 = 0x100012; +static const int IMAGE_BLOOD_FRAME14 = 0x100013; +static const int IMAGE_BLOOD_FRAME15 = 0x100014; +static const int IMAGE_BLOOD_FRAME16 = 0x100015; +static const int IMAGE_BLOOD_FRAME17 = 0x100016; +static const int IMAGE_BLOOD_FRAME18 = 0x100017; +static const int IMAGE_BLOOD_FRAME19 = 0x100018; +static const int IMAGE_BLOOD_FRAME20 = 0x100019; +static const int IMAGE_BLOOD_FRAME21 = 0x10001a; +static const int IMAGE_BLOOD_FRAME22 = 0x10001b; +static const int IMAGE_BLOOD_FRAME23 = 0x10001c; +static const int IMAGE_BLOOD_FRAME24 = 0x10001d; +static const int IMAGE_BLOOD_FRAME25 = 0x10001e; +static const int IMAGE_BLOOD_FRAME26 = 0x10001f; +static const int IMAGE_BLOOD_FRAME27 = 0x100020; +static const int IMAGE_BLOOD_FRAME28 = 0x100021; +static const int IMAGE_BLOOD_FRAME29 = 0x100022; +static const int IMAGE_BLOOD_NORMAL = 0x100023; +static const int IMAGE_BLOOD_PREVIEW1 = 0x100024; +static const int IMAGE_BLOOD_PREVIEW2 = 0x100025; +static const int IMAGE_BLOOD_RESET = 0x100026; +static const int IMAGE_BLOOD_SCALE = 0x100027; +} // OHOS +#endif // UI_RESOURCE_BLOOD_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_breath.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_breath.h index ca668341c..9c42b093b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_breath.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_breath.h @@ -1,102 +1,33 @@ /* * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UIBreathResource + * Description: UIResourceBreath * Create: 2025-06-05 */ -#ifndef UI_RESOURCE_BREATH_IMAGE_H -#define UI_RESOURCE_BREATH_IMAGE_H -#include + +#ifndef UI_RESOURCE_BREATH_H +#define UI_RESOURCE_BREATH_H + namespace OHOS { - static const int IMAGE_CONVERTER_TOOL_BREATH001 = 0x100001; - static const int IMAGE_CONVERTER_TOOL_BREATH002 = 0x100002; - static const int IMAGE_CONVERTER_TOOL_BREATH003 = 0x100003; - static const int IMAGE_CONVERTER_TOOL_BREATH004 = 0x100004; - static const int IMAGE_CONVERTER_TOOL_BREATH005 = 0x100005; - static const int IMAGE_CONVERTER_TOOL_BREATH006 = 0x100006; - static const int IMAGE_CONVERTER_TOOL_BREATH007 = 0x100007; - static const int IMAGE_CONVERTER_TOOL_BREATH008 = 0x100008; - static const int IMAGE_CONVERTER_TOOL_BREATH009 = 0x100009; - static const int IMAGE_CONVERTER_TOOL_BREATH010 = 0x10000a; - static const int IMAGE_CONVERTER_TOOL_BREATH011 = 0x10000b; - static const int IMAGE_CONVERTER_TOOL_BREATH012 = 0x10000c; - static const int IMAGE_CONVERTER_TOOL_BREATH013 = 0x10000d; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE001 = 0x10000e; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE002 = 0x10000f; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE003 = 0x100010; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE004 = 0x100011; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE005 = 0x100012; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE006 = 0x100013; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE007 = 0x100014; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE008 = 0x100015; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE009 = 0x100016; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE010 = 0x100017; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE011 = 0x100018; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE012 = 0x100019; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE013 = 0x10001a; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE014 = 0x10001b; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE015 = 0x10001c; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE016 = 0x10001d; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE017 = 0x10001e; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE018 = 0x10001f; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE019 = 0x100020; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE020 = 0x100021; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE021 = 0x100022; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE022 = 0x100023; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE023 = 0x100024; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE024 = 0x100025; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE025 = 0x100026; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE026 = 0x100027; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE027 = 0x100028; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE028 = 0x100029; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE029 = 0x10002a; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE030 = 0x10002b; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE031 = 0x10002c; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE032 = 0x10002d; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE033 = 0x10002e; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE034 = 0x10002f; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE035 = 0x100030; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE036 = 0x100031; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE037 = 0x100032; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE038 = 0x100033; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE039 = 0x100034; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE040 = 0x100035; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE041 = 0x100036; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE042 = 0x100037; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE043 = 0x100038; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE044 = 0x100039; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE045 = 0x10003a; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE046 = 0x10003b; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE047 = 0x10003c; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE048 = 0x10003d; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE049 = 0x10003e; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE050 = 0x10003f; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE051 = 0x100040; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE052 = 0x100041; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE053 = 0x100042; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE054 = 0x100043; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE055 = 0x100044; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE056 = 0x100045; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE057 = 0x100046; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE058 = 0x100047; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE059 = 0x100048; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE060 = 0x100049; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE061 = 0x10004a; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE062 = 0x10004b; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE063 = 0x10004c; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE064 = 0x10004d; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE065 = 0x10004e; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE066 = 0x10004f; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE067 = 0x100050; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE068 = 0x100051; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE069 = 0x100052; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE070 = 0x100053; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE071 = 0x100054; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE072 = 0x100055; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE073 = 0x100056; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE074 = 0x100057; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE075 = 0x100058; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE076 = 0x100059; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE077 = 0x10005a; - static const int IMAGE_CONVERTER_TOOL_INOREX_HALE078 = 0x10005b; -} // OHOS -#endif // UI_RESOURCE_BREATH_IMAGE_H \ No newline at end of file +static const int IMAGE_BREATH_BAD = 0x100001; +static const int IMAGE_BREATH_BG1 = 0x100002; +static const int IMAGE_BREATH_BG2 = 0x100003; +static const int IMAGE_BREATH_BG3 = 0x100004; +static const int IMAGE_BREATH_BG4 = 0x100005; +static const int IMAGE_BREATH_CENTER = 0x100006; +static const int IMAGE_BREATH_CENTER1 = 0x100007; +static const int IMAGE_BREATH_CENTER2 = 0x100008; +static const int IMAGE_BREATH_COMPLETE = 0x100009; +static const int IMAGE_BREATH_EXCELLENT = 0x10000a; +static const int IMAGE_BREATH_GOOD = 0x10000b; +static const int IMAGE_BREATH_NORMAL = 0x10000c; +static const int IMAGE_BREATH_OK = 0x10000d; +static const int IMAGE_BREATH_PASS = 0x10000e; +static const int IMAGE_BREATH_RESULT = 0x10000f; +static const int IMAGE_BREATH_RETEST = 0x100010; +static const int IMAGE_BREATH_ROMATA1 = 0x100011; +static const int IMAGE_BREATH_ROMATA2 = 0x100012; +static const int IMAGE_BREATH_SETTING = 0x100013; +static const int IMAGE_BREATH_START = 0x100014; +static const int IMAGE_BREATH_TIME = 0x100015; +} // OHOS +#endif // UI_RESOURCE_BREATH_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_camera.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_camera.h index 022ddfca0..ba0bb98c0 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_camera.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_camera.h @@ -1,17 +1,14 @@ /* * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UICameraResource + * Description: UIResourceCamera * Create: 2025-06-05 */ + #ifndef UI_RESOURCE_CAMERA_H #define UI_RESOURCE_CAMERA_H -#include -namespace OHOS { - static const int IMAGE_CONVERTER_TOOL_CAMERA_1 = 0x100001; - static const int IMAGE_CONVERTER_TOOL_CAMERA_2 = 0x100002; - static const int IMAGE_CONVERTER_TOOL_CAMERA_3 = 0x100003; - static const int IMAGE_CONVERTER_TOOL_CAMERA_4 = 0x100004; - static const int IMAGE_CONVERTER_TOOL_CAMERA_5 = 0x100005; -} // OHOS -#endif // UI_RESOURCE_CAMERA_H +namespace OHOS { +static const int IMAGE_CAMERA_TAKEPHOTO = 0x100001; +static const int IMAGE_CAMERA_DISCONNECT = 0x100002; +} // OHOS +#endif // UI_RESOURCE_CAMERA_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_date.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_date.h index 0bccb8b0e..78e677744 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_date.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_date.h @@ -1,21 +1,19 @@ /* * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UIWeatherResource + * Description: UIResourceDate * Create: 2025-06-10 */ + #ifndef UI_RESOURCE_DATE_H #define UI_RESOURCE_DATE_H -#include + namespace OHOS { - static const int DIR_MASK = 0xfff00000; - static const int PNG_MASK = 0x000fffff; - static const int IMAGE_CONVERTER_TOOL_DATE1 = 0x100001; - static const int IMAGE_CONVERTER_TOOL_DATE2 = 0x100002; - static const int IMAGE_CONVERTER_TOOL_DATE3 = 0x100003; - static const int IMAGE_CONVERTER_TOOL_DATE4 = 0x100004; - static const int IMAGE_CONVERTER_TOOL_DATE5 = 0x100005; - static const int IMAGE_CONVERTER_TOOL_DATE6 = 0x100006; - static const int IMAGE_CONVERTER_TOOL_DATE7 = 0x100007; - static const int IMAGE_CONVERTER_TOOL_DATE8 = 0x100008; -} // OHOS -#endif // UI_RESOURCE_DATE_H +static const int IMAGE_DATE_BG1 = 0x100001; +static const int IMAGE_DATE_BG2 = 0x100002; +static const int IMAGE_DATE_GRAY = 0x100003; +static const int IMAGE_DATE_RED = 0x100004; +static const int IMAGE_DATE_SELECT = 0x100005; +static const int IMAGE_DATE_SIGNS = 0x100006; +static const int IMAGE_DATE_WHITE = 0x100007; +} // OHOS +#endif // UI_RESOURCE_DATE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_empty.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_empty.h new file mode 100644 index 000000000..b7b2e6431 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_empty.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceEmpty + * Create: 2025-06-05 + */ + +#ifndef UI_RESOURCE_EMPTY_H +#define UI_RESOURCE_EMPTY_H + +namespace OHOS { +static const int IMAGE_EMPTY_BG = 0x100001; +} // OHOS +#endif // UI_RESOURCE_EMPTY_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_findPhone.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_findPhone.h index 9a51cdf10..45a097ad1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_findPhone.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_findPhone.h @@ -1,46 +1,43 @@ /* * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UIFindPhoneResource + * Description: UIResourceFindPhone * Create: 2025-2-13 */ + #ifndef UI_RESOURCE_FINDPHONE_H #define UI_RESOURCE_FINDPHONE_H -#include + namespace OHOS { - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_1 = 0x100001; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_2 = 0x100002; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_3 = 0x100003; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4 = 0x100004; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5 = 0x100005; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_6 = 0x100006; - static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7 = 0x100007; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE001 = 0x100008; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE002 = 0x100009; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE003 = 0x10000a; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE004 = 0x10000b; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE005 = 0x10000c; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE006 = 0x10000d; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE007 = 0x10000e; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE008 = 0x10000f; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE009 = 0x100010; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE010 = 0x100011; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE011 = 0x100012; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE012 = 0x100013; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE013 = 0x100014; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE014 = 0x100015; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE015 = 0x100016; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE016 = 0x100017; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE017 = 0x100018; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE018 = 0x100019; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE019 = 0x10001a; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE020 = 0x10001b; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE021 = 0x10001c; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE022 = 0x10001d; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE023 = 0x10001e; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE024 = 0x10001f; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE025 = 0x100020; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE026 = 0x100021; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE027 = 0x100022; - static const int IMAGE_CONVERTER_TOOL_FINDPHONE028 = 0x100023; -} // OHOS -#endif // UI_RESOURCE_FINDPHONE_H +static const int IMAGE_FINDPHONE_CONNECT = 0x100001; +static const int IMAGE_FINDPHONE_DISCONNECT = 0x100002; +static const int IMAGE_FINDPHONE_FRAME01 = 0x100003; +static const int IMAGE_FINDPHONE_FRAME02 = 0x100004; +static const int IMAGE_FINDPHONE_FRAME03 = 0x100005; +static const int IMAGE_FINDPHONE_FRAME04 = 0x100006; +static const int IMAGE_FINDPHONE_FRAME05 = 0x100007; +static const int IMAGE_FINDPHONE_FRAME06 = 0x100008; +static const int IMAGE_FINDPHONE_FRAME07 = 0x100009; +static const int IMAGE_FINDPHONE_FRAME08 = 0x10000a; +static const int IMAGE_FINDPHONE_FRAME09 = 0x10000b; +static const int IMAGE_FINDPHONE_FRAME10 = 0x10000c; +static const int IMAGE_FINDPHONE_FRAME11 = 0x10000d; +static const int IMAGE_FINDPHONE_FRAME12 = 0x10000e; +static const int IMAGE_FINDPHONE_FRAME13 = 0x10000f; +static const int IMAGE_FINDPHONE_FRAME14 = 0x100010; +static const int IMAGE_FINDPHONE_FRAME15 = 0x100011; +static const int IMAGE_FINDPHONE_FRAME16 = 0x100012; +static const int IMAGE_FINDPHONE_FRAME17 = 0x100013; +static const int IMAGE_FINDPHONE_FRAME18 = 0x100014; +static const int IMAGE_FINDPHONE_FRAME19 = 0x100015; +static const int IMAGE_FINDPHONE_FRAME20 = 0x100016; +static const int IMAGE_FINDPHONE_FRAME21 = 0x100017; +static const int IMAGE_FINDPHONE_FRAME22 = 0x100018; +static const int IMAGE_FINDPHONE_FRAME23 = 0x100019; +static const int IMAGE_FINDPHONE_FRAME24 = 0x10001a; +static const int IMAGE_FINDPHONE_FRAME25 = 0x10001b; +static const int IMAGE_FINDPHONE_FRAME26 = 0x10001c; +static const int IMAGE_FINDPHONE_FRAME27 = 0x10001d; +static const int IMAGE_FINDPHONE_FRAME28 = 0x10001e; +static const int IMAGE_FINDPHONE_RESET = 0x10001f; +} // OHOS +#endif // UI_RESOURCE_FINDPHONE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_flashlight.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_flashlight.h new file mode 100644 index 000000000..bd94ffb4e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_flashlight.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResouceFlashlight + * Create: 2025-04-24 + */ + +#ifndef UI_RESOURCE_FLASHLIGHT_H +#define UI_RESOURCE_FLASHLIGHT_H + +namespace OHOS { +static const int IMAGE_FLASHLIGHT_BLINKBUTTON = 0x100001; +static const int IMAGE_FLASHLIGHT_BLINKITEM = 0x100002; +static const int IMAGE_FLASHLIGHT_COLORITEM = 0x100003; +static const int IMAGE_FLASHLIGHT_COLOR_DARK_BLUE_BUTTON = 0x100004; +static const int IMAGE_FLASHLIGHT_COLOR_DARK_BLUE_PRESSBUTTON = 0x100005; +static const int IMAGE_FLASHLIGHT_COLOR_GREEN_BUTTON = 0x100006; +static const int IMAGE_FLASHLIGHT_COLOR_GREEN_PRESSBUTTON = 0x100007; +static const int IMAGE_FLASHLIGHT_COLOR_LIGHT_BLUE_BUTTON = 0x100008; +static const int IMAGE_FLASHLIGHT_COLOR_LIGHT_BLUE_PRESSBUTTON = 0x100009; +static const int IMAGE_FLASHLIGHT_COLOR_MULTI_BUTTON = 0x10000a; +static const int IMAGE_FLASHLIGHT_COLOR_MULTI_PRESSBUTTON = 0x10000b; +static const int IMAGE_FLASHLIGHT_COLOR_ORANGE_BUTTON = 0x10000c; +static const int IMAGE_FLASHLIGHT_COLOR_ORANGE_PRESSBUTTON = 0x10000d; +static const int IMAGE_FLASHLIGHT_COLOR_PURPLE_BUTTON = 0x10000e; +static const int IMAGE_FLASHLIGHT_COLOR_PURPLE_PRESSBUTTON = 0x10000f; +static const int IMAGE_FLASHLIGHT_COLOR_RED_BUTTON = 0x100010; +static const int IMAGE_FLASHLIGHT_COLOR_RED_PRESSBUTTON = 0x100011; +static const int IMAGE_FLASHLIGHT_COLOR_WHITE_BUTTON = 0x100012; +static const int IMAGE_FLASHLIGHT_COLOR_WHITE_PRESSBUTTON = 0x100013; +static const int IMAGE_FLASHLIGHT_COLOR_YELLOW_BUTTON = 0x100014; +static const int IMAGE_FLASHLIGHT_COLOR_YELLOW_PRESSBUTTON = 0x100015; +static const int IMAGE_FLASHLIGHT_DOWNARROW = 0x100016; +static const int IMAGE_FLASHLIGHT_FLASHLIGHTON = 0x100017; +static const int IMAGE_FLASHLIGHT_PLAY_BLACK_PAGE = 0x100018; +static const int IMAGE_FLASHLIGHT_PLAY_DARK_BLUE_PAGE = 0x100019; +static const int IMAGE_FLASHLIGHT_PLAY_GREEN_PAGE = 0x10001a; +static const int IMAGE_FLASHLIGHT_PLAY_LIGHT_BLUE_PAGE = 0x10001b; +static const int IMAGE_FLASHLIGHT_PLAY_MULTI_PAGE = 0x10001c; +static const int IMAGE_FLASHLIGHT_PLAY_ORANGE_PAGE = 0x10001d; +static const int IMAGE_FLASHLIGHT_PLAY_PURPLE_PAGE = 0x10001e; +static const int IMAGE_FLASHLIGHT_PLAY_RED_PAGE = 0x10001f; +static const int IMAGE_FLASHLIGHT_PLAY_WHITE_PAGE = 0x100020; +static const int IMAGE_FLASHLIGHT_PLAY_YELLOW_PAGE = 0x100021; +static const int IMAGE_FLASHLIGHT_RECOVERBUTTON = 0x100022; +static const int IMAGE_FLASHLIGHT_RECOVERCANCLE = 0x100023; +static const int IMAGE_FLASHLIGHT_RECOVERCONFIRM = 0x100024; +static const int IMAGE_FLASHLIGHT_RIGHTARROW = 0x100025; +} // OHOS +#endif // UI_RESOURCE_FLASHLIGHT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_heartRate.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_heartRate.h new file mode 100644 index 000000000..97ffed1db --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_heartRate.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceHeartRate + * Create: 2025-06 + */ + +#ifndef UI_RESOURCE_HEARTRATE_H +#define UI_RESOURCE_HEARTRATE_H + +namespace OHOS { +static const int IMAGE_HEART_RATE_BG1 = 0x100001; +static const int IMAGE_HEART_RATE_BG2 = 0x100002; +static const int IMAGE_HEART_RATE_DOWN = 0x100003; +static const int IMAGE_HEART_RATE_FRAME00 = 0x100004; +static const int IMAGE_HEART_RATE_FRAME01 = 0x100005; +static const int IMAGE_HEART_RATE_FRAME02 = 0x100006; +static const int IMAGE_HEART_RATE_FRAME03 = 0x100007; +static const int IMAGE_HEART_RATE_FRAME04 = 0x100008; +static const int IMAGE_HEART_RATE_FRAME05 = 0x100009; +static const int IMAGE_HEART_RATE_FRAME06 = 0x10000a; +static const int IMAGE_HEART_RATE_FRAME07 = 0x10000b; +static const int IMAGE_HEART_RATE_FRAME08 = 0x10000c; +static const int IMAGE_HEART_RATE_FRAME09 = 0x10000d; +static const int IMAGE_HEART_RATE_FRAME10 = 0x10000e; +static const int IMAGE_HEART_RATE_FRAME11 = 0x10000f; +static const int IMAGE_HEART_RATE_FRAME12 = 0x100010; +static const int IMAGE_HEART_RATE_FRAME13 = 0x100011; +static const int IMAGE_HEART_RATE_FRAME14 = 0x100012; +static const int IMAGE_HEART_RATE_FRAME15 = 0x100013; +static const int IMAGE_HEART_RATE_FRAME16 = 0x100014; +static const int IMAGE_HEART_RATE_FRAME17 = 0x100015; +static const int IMAGE_HEART_RATE_FRAME18 = 0x100016; +static const int IMAGE_HEART_RATE_FRAME19 = 0x100017; +static const int IMAGE_HEART_RATE_FRAME20 = 0x100018; +static const int IMAGE_HEART_RATE_FRAME21 = 0x100019; +static const int IMAGE_HEART_RATE_FRAME22 = 0x10001a; +static const int IMAGE_HEART_RATE_FRAME23 = 0x10001b; +static const int IMAGE_HEART_RATE_FRAME24 = 0x10001c; +static const int IMAGE_HEART_RATE_FRAME25 = 0x10001d; +static const int IMAGE_HEART_RATE_FRAME26 = 0x10001e; +static const int IMAGE_HEART_RATE_FRAME27 = 0x10001f; +static const int IMAGE_HEART_RATE_FRAME28 = 0x100020; +static const int IMAGE_HEART_RATE_FRAME29 = 0x100021; +static const int IMAGE_HEART_RATE_PREVIEW1 = 0x100022; +static const int IMAGE_HEART_RATE_PREVIEW2 = 0x100023; +static const int IMAGE_HEART_RATE_RESET = 0x100024; +static const int IMAGE_HEART_RATE_UP = 0x100025; +} // OHOS +#endif // UI_RESOURCE_HEARTRATE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_message.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_message.h new file mode 100644 index 000000000..1758c87a6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_message.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceMessage + * Create: 2025-06-29 + */ + +#ifndef UI_RESOURCE_MESSAGE_H +#define UI_RESOURCE_MESSAGE_H + +namespace OHOS { +static const int IMAGE_MESSAGE_BG = 0x100001; +static const int IMAGE_MESSAGE_CALENDAR = 0x100002; +static const int IMAGE_MESSAGE_CANCEL = 0x100003; +static const int IMAGE_MESSAGE_CONFIRM = 0x100004; +static const int IMAGE_MESSAGE_DELETE = 0x100005; +static const int IMAGE_MESSAGE_DUANXIN = 0x100006; +static const int IMAGE_MESSAGE_DY = 0x100007; +static const int IMAGE_MESSAGE_QQ = 0x100008; +static const int IMAGE_MESSAGE_RING = 0x100009; +static const int IMAGE_MESSAGE_SINGLE_DELETE = 0x10000a; +static const int IMAGE_MESSAGE_TOUTIAO = 0x10000b; +static const int IMAGE_MESSAGE_WB = 0x10000c; +static const int IMAGE_MESSAGE_WX = 0x10000d; +static const int IMAGE_MESSAGE_XHS = 0x10000e; +} // OHOS +#endif // UI_RESOURCE_MESSAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_phonemenu.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_phonemenu.h new file mode 100644 index 000000000..dcbe2ad2c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_phonemenu.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UiResourcePhoneMenu + * Create: 2025-2-13 + */ + +#ifndef UI_RESOURCE_PHONEMENU_H +#define UI_RESOURCE_PHONEMENU_H + +namespace OHOS { +static const int IMAGE_PHONEMENU_ANSWER = 0x100001; +static const int IMAGE_PHONEMENU_CALL = 0x100002; +static const int IMAGE_PHONEMENU_CALLIN = 0x100003; +static const int IMAGE_PHONEMENU_CALLIN_ICON = 0x100004; +static const int IMAGE_PHONEMENU_CALLOUT = 0x100005; +static const int IMAGE_PHONEMENU_CALLOUT_ICON = 0x100006; +static const int IMAGE_PHONEMENU_CONTACTS = 0x100007; +static const int IMAGE_PHONEMENU_CONTACTS_BOOKS = 0x100008; +static const int IMAGE_PHONEMENU_DEL = 0x100009; +static const int IMAGE_PHONEMENU_DIAL = 0x10000a; +static const int IMAGE_PHONEMENU_DISCONNECT = 0x10000b; +static const int IMAGE_PHONEMENU_HANGUP = 0x10000c; +static const int IMAGE_PHONEMENU_MIC = 0x10000d; +static const int IMAGE_PHONEMENU_MIC_MUTE = 0x10000e; +static const int IMAGE_PHONEMENU_PHONE = 0x10000f; +static const int IMAGE_PHONEMENU_POUND_KEY = 0x100010; +static const int IMAGE_PHONEMENU_RECENT_CALL = 0x100011; +static const int IMAGE_PHONEMENU_STAR_KEY = 0x100012; +} // OHOS +#endif // UI_RESOURCE_PHONEMENU_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_settings.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_settings.h new file mode 100644 index 000000000..39ed3a4b0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_settings.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceSettings + * Create: 2025-06-05 + */ + +#ifndef UI_RESOURCE_SETTINGS_H +#define UI_RESOURCE_SETTINGS_H + +namespace OHOS { +static const int IMAGE_3D_FOLD_01 = 0x100001; +static const int IMAGE_3D_FOLD_02 = 0x100002; +static const int IMAGE_3D_FOLD_03 = 0x100003; +static const int IMAGE_3D_FOLD_04 = 0x100004; +static const int IMAGE_3D_FOLD_05 = 0x100005; +static const int IMAGE_3D_FOLD_06 = 0x100006; +static const int IMAGE_3D_FOLD_07 = 0x100007; +static const int IMAGE_3D_FOLD_08 = 0x100008; +static const int IMAGE_3D_FOLD_09 = 0x100009; +static const int IMAGE_3D_FOLD_10 = 0x10000a; +static const int IMAGE_ARROW = 0x10000b; +static const int IMAGE_BG = 0x10000c; +static const int IMAGE_BLUETOOTH = 0x10000d; +static const int IMAGE_CANCEL = 0x10000e; +static const int IMAGE_CARD_ADD_ADD = 0x10000f; +static const int IMAGE_CARD_ADD_ADDED = 0x100010; +static const int IMAGE_CARD_FLIP_01 = 0x100011; +static const int IMAGE_CARD_FLIP_02 = 0x100012; +static const int IMAGE_CARD_FLIP_03 = 0x100013; +static const int IMAGE_CARD_FLIP_04 = 0x100014; +static const int IMAGE_CARD_FLIP_05 = 0x100015; +static const int IMAGE_CARD_FLIP_06 = 0x100016; +static const int IMAGE_CARD_FLIP_07 = 0x100017; +static const int IMAGE_CARD_FLIP_08 = 0x100018; +static const int IMAGE_CARD_FLIP_09 = 0x100019; +static const int IMAGE_CARD_FLIP_10 = 0x10001a; +static const int IMAGE_CARD_LIST_CARDANIMATOR = 0x10001b; +static const int IMAGE_CARD_LIST_CARDMANAGER = 0x10001c; +static const int IMAGE_CARD_MGR_ADD = 0x10001d; +static const int IMAGE_CARD_MGR_DEL = 0x10001e; +static const int IMAGE_CONNECT = 0x10001f; +static const int IMAGE_DESKTOP_BG = 0x100020; +static const int IMAGE_DESKTOP_BRIGHTNESS_BG = 0x100021; +static const int IMAGE_DESKTOP_BRIGHTNESS_FG = 0x100022; +static const int IMAGE_DESKTOP_DIALSTYLE_AOD = 0x100023; +static const int IMAGE_DESKTOP_DIALSTYLE_COVERFLOW = 0x100024; +static const int IMAGE_DESKTOP_DIALSTYLE_ROLLER = 0x100025; +static const int IMAGE_DESKTOP_HOME_SELECTED_APPLIST = 0x100026; +static const int IMAGE_DESKTOP_HOME_SELECTED_FOOTBALL = 0x100027; +static const int IMAGE_DESKTOP_HOME_SELECTED_HEXAGONS = 0x100028; +static const int IMAGE_DESKTOP_HOME_SELECTED_PLANET = 0x100029; +static const int IMAGE_DESKTOP_HOME_SELECTED_SPHERE = 0x10002a; +static const int IMAGE_DESKTOP_HOME_SELECTED_WATERFALL = 0x10002b; +static const int IMAGE_DESKTOP_HOME_UNSELECT_APPLIST = 0x10002c; +static const int IMAGE_DESKTOP_HOME_UNSELECT_FOOTBALL = 0x10002d; +static const int IMAGE_DESKTOP_HOME_UNSELECT_HEXAGONS = 0x10002e; +static const int IMAGE_DESKTOP_HOME_UNSELECT_PLANET = 0x10002f; +static const int IMAGE_DESKTOP_HOME_UNSELECT_SPHERE = 0x100030; +static const int IMAGE_DESKTOP_HOME_UNSELECT_WATERFALL = 0x100031; +static const int IMAGE_DESKTOP_LIST_DIAL = 0x100032; +static const int IMAGE_DESKTOP_LIST_DIAL_STYLE = 0x100033; +static const int IMAGE_DESKTOP_LIST_HOME = 0x100034; +static const int IMAGE_DISPLAY_BRIGHTNESS_ADD = 0x100035; +static const int IMAGE_DISPLAY_BRIGHTNESS_SUB = 0x100036; +static const int IMAGE_DISPLAY_LIST_ADJUST_BRIGHTNESS = 0x100037; +static const int IMAGE_DISPLAY_LIST_AUTO_ADJUST = 0x100038; +static const int IMAGE_DISPLAY_LIST_SCREEN_OFF_TIME = 0x100039; +static const int IMAGE_DISPLAY_LIST_SCREEN_ON_TIME = 0x10003a; +static const int IMAGE_DISPLAY_OK = 0x10003b; +static const int IMAGE_MAIN_LIST_ABOUT = 0x10003c; +static const int IMAGE_MAIN_LIST_ARROW = 0x10003d; +static const int IMAGE_MAIN_LIST_BLUETOOTH = 0x10003e; +static const int IMAGE_MAIN_LIST_CARD = 0x10003f; +static const int IMAGE_MAIN_LIST_DESKTOP = 0x100040; +static const int IMAGE_MAIN_LIST_DISPLAY = 0x100041; +static const int IMAGE_MAIN_LIST_POWER = 0x100042; +static const int IMAGE_MAIN_LIST_SYSTEM = 0x100043; +static const int IMAGE_OK = 0x100044; +static const int IMAGE_OK_BLUE = 0x100045; +static const int IMAGE_OK_DOWN = 0x100046; +static const int IMAGE_PAGE_BACKGROUND = 0x100047; +static const int IMAGE_PHONE = 0x100048; +static const int IMAGE_PUSH_PRESS_01 = 0x100049; +static const int IMAGE_PUSH_PRESS_02 = 0x10004a; +static const int IMAGE_PUSH_PRESS_03 = 0x10004b; +static const int IMAGE_PUSH_PRESS_04 = 0x10004c; +static const int IMAGE_PUSH_PRESS_05 = 0x10004d; +static const int IMAGE_PUSH_PRESS_06 = 0x10004e; +static const int IMAGE_PUSH_PRESS_07 = 0x10004f; +static const int IMAGE_PUSH_PRESS_08 = 0x100050; +static const int IMAGE_PUSH_PRESS_09 = 0x100051; +static const int IMAGE_PUSH_PRESS_10 = 0x100052; +static const int IMAGE_QCODE = 0x100053; +static const int IMAGE_SURPRISE = 0x100054; +static const int IMAGE_SYSTEM_LIST_OTA = 0x100055; +static const int IMAGE_SYSTEM_LIST_POWEROFF = 0x100056; +static const int IMAGE_SYSTEM_LIST_RESTART = 0x100057; +static const int IMAGE_SYSTEM_LIST_RESUME = 0x100058; +static const int IMAGE_SYSTEM_OPERATION_CLOSE = 0x100059; +static const int IMAGE_SYSTEM_OTA_UNBLUETOOTH = 0x10005a; +static const int IMAGE_SYSTEM_OTA_UNUPDATE = 0x10005b; +static const int IMAGE_SYSTEM_OTA_UPDATE = 0x10005c; +static const int IMAGE_TRAINSTION_END = 0x10005d; +static const int IMAGE_TRAINSTION_START = 0x10005e; +static const int IMAGE_TURN_PAGE_01 = 0x10005f; +static const int IMAGE_TURN_PAGE_02 = 0x100060; +static const int IMAGE_TURN_PAGE_03 = 0x100061; +static const int IMAGE_TURN_PAGE_04 = 0x100062; +static const int IMAGE_TURN_PAGE_05 = 0x100063; +static const int IMAGE_TURN_PAGE_06 = 0x100064; +static const int IMAGE_TURN_PAGE_07 = 0x100065; +static const int IMAGE_TURN_PAGE_08 = 0x100066; +static const int IMAGE_TURN_PAGE_09 = 0x100067; +static const int IMAGE_TURN_PAGE_10 = 0x100068; +static const int IMAGE_UNPAIR = 0x100069; +static const int IMAGE_WINDMILL_01 = 0x10006a; +static const int IMAGE_WINDMILL_02 = 0x10006b; +static const int IMAGE_WINDMILL_03 = 0x10006c; +static const int IMAGE_WINDMILL_04 = 0x10006d; +static const int IMAGE_WINDMILL_05 = 0x10006e; +static const int IMAGE_WINDMILL_06 = 0x10006f; +static const int IMAGE_WINDMILL_07 = 0x100070; +static const int IMAGE_WINDMILL_08 = 0x100071; +static const int IMAGE_WINDMILL_09 = 0x100072; +static const int IMAGE_WINDMILL_10 = 0x100073; +static const int IMAGE_Y3_1 = 0x100074; +static const int IMAGE_Y3_10 = 0x100075; +static const int IMAGE_Y3_11 = 0x100076; +static const int IMAGE_Y3_12 = 0x100077; +static const int IMAGE_Y3_13 = 0x100078; +static const int IMAGE_Y3_14 = 0x100079; +static const int IMAGE_Y3_15 = 0x10007a; +static const int IMAGE_Y3_16 = 0x10007b; +static const int IMAGE_Y3_17 = 0x10007c; +static const int IMAGE_Y3_18 = 0x10007d; +static const int IMAGE_Y3_19 = 0x10007e; +static const int IMAGE_Y3_2 = 0x10007f; +static const int IMAGE_Y3_20 = 0x100080; +static const int IMAGE_Y3_21 = 0x100081; +static const int IMAGE_Y3_22 = 0x100082; +static const int IMAGE_Y3_23 = 0x100083; +static const int IMAGE_Y3_24 = 0x100084; +static const int IMAGE_Y3_25 = 0x100085; +static const int IMAGE_Y3_26 = 0x100086; +static const int IMAGE_Y3_27 = 0x100087; +static const int IMAGE_Y3_28 = 0x100088; +static const int IMAGE_Y3_29 = 0x100089; +static const int IMAGE_Y3_3 = 0x10008a; +static const int IMAGE_Y3_30 = 0x10008b; +static const int IMAGE_Y3_31 = 0x10008c; +static const int IMAGE_Y3_4 = 0x10008d; +static const int IMAGE_Y3_5 = 0x10008e; +static const int IMAGE_Y3_6 = 0x10008f; +static const int IMAGE_Y3_7 = 0x100090; +static const int IMAGE_Y3_8 = 0x100091; +static const int IMAGE_Y3_9 = 0x100092; +static const int IMAGE_ZOOM_01 = 0x100093; +static const int IMAGE_ZOOM_02 = 0x100094; +static const int IMAGE_ZOOM_03 = 0x100095; +static const int IMAGE_ZOOM_04 = 0x100096; +static const int IMAGE_ZOOM_05 = 0x100097; +static const int IMAGE_ZOOM_06 = 0x100098; +static const int IMAGE_ZOOM_07 = 0x100099; +static const int IMAGE_ZOOM_08 = 0x10009a; +static const int IMAGE_ZOOM_09 = 0x10009b; +static const int IMAGE_ZOOM_10 = 0x10009c; +static const int IMAGE_MAIN_LIST_LANGUAGE = 0x100043; +} // OHOS +#endif // UI_RESOURCE_SETTING_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sleep.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sleep.h index c5d369d71..4057088e1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sleep.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sleep.h @@ -1,28 +1,27 @@ /* * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UISleepResource + * Description: UIResourceSleep * Create: 2025-06-05 */ + #ifndef UI_RESOURCE_SLEEP_H #define UI_RESOURCE_SLEEP_H -#include + namespace OHOS { - static const int IMAGE_CONVERTER_TOOL_BACKGROUND = 0x100001; - static const int IMAGE_CONVERTER_TOOL_BLACK_BG = 0x100002; - static const int IMAGE_CONVERTER_TOOL_BLUE_CIR = 0x100003; - static const int IMAGE_CONVERTER_TOOL_GREEN_CIR = 0x100004; - static const int IMAGE_CONVERTER_TOOL_NORECORD_SLEEP = 0x100005; - static const int IMAGE_CONVERTER_TOOL_ORANGE_CIR = 0x100006; - static const int IMAGE_CONVERTER_TOOL_RECORD_BG = 0x100007; - static const int IMAGE_CONVERTER_TOOL_RECORD_SLEEP = 0x100008; - static const int IMAGE_CONVERTER_TOOL_RED_CIR = 0x100009; - static const int IMAGE_CONVERTER_TOOL_SELECTEDTIME = 0x10000a; - static const int IMAGE_CONVERTER_TOOL_SELECTTIME = 0x10000b; - static const int IMAGE_CONVERTER_TOOL_SETTIMEBTN = 0x10000c; - static const int IMAGE_CONVERTER_TOOL_SETTING = 0x10000d; - static const int IMAGE_CONVERTER_TOOL_START_GRAY = 0x10000e; - static const int IMAGE_CONVERTER_TOOL_STAR_GRAY = 0x10000f; - static const int IMAGE_CONVERTER_TOOL_STAR_YELLOW = 0x100010; - static const int IMAGE_CONVERTER_TOOL_TIPS = 0x100011; -} // OHOS -#endif // UI_RESOURCE_SLEEP_H +static const int IMAGE_SLEEP_BACKGROUND = 0x100001; +static const int IMAGE_SLEEP_BLUE_CIR = 0x100002; +static const int IMAGE_SLEEP_GREEN_CIR = 0x100003; +static const int IMAGE_SLEEP_NORECORD_SLEEP = 0x100004; +static const int IMAGE_SLEEP_ORANGE_CIR = 0x100005; +static const int IMAGE_SLEEP_RECORD_BG = 0x100006; +static const int IMAGE_SLEEP_RECORD_SLEEP = 0x100007; +static const int IMAGE_SLEEP_RED_CIR = 0x100008; +static const int IMAGE_SLEEP_SETTIMEBTN = 0x100009; +static const int IMAGE_SLEEP_SETTING = 0x10000a; +static const int IMAGE_SLEEP_SLEEPING_MOON = 0x10000b; +static const int IMAGE_SLEEP_SLEEPING_TIME = 0x10000c; +static const int IMAGE_SLEEP_START_GRAY = 0x10000d; +static const int IMAGE_SLEEP_STAR_GRAY = 0x10000e; +static const int IMAGE_SLEEP_STAR_YELLOW = 0x10000f; +} // OHOS +#endif // UI_RESOURCE_SLEEP_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sport.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sport.h new file mode 100644 index 000000000..c81672bfb --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_sport.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceSport + * Create: 2025-06-05 + */ + +#ifndef UI_RESOURCE_SPORT_H +#define UI_RESOURCE_SPORT_H + +namespace OHOS { +static const int IMAGE_SPORT_10KM = 0x100001; +static const int IMAGE_SPORT_10MIN = 0x100002; +static const int IMAGE_SPORT_120MIN = 0x100003; +static const int IMAGE_SPORT_15KM = 0x100004; +static const int IMAGE_SPORT_180MIN = 0x100005; +static const int IMAGE_SPORT_1KM = 0x100006; +static const int IMAGE_SPORT_200MIN = 0x100007; +static const int IMAGE_SPORT_20KM = 0x100008; +static const int IMAGE_SPORT_20MIN = 0x100009; +static const int IMAGE_SPORT_25KM = 0x10000a; +static const int IMAGE_SPORT_30KM = 0x10000b; +static const int IMAGE_SPORT_30MIN = 0x10000c; +static const int IMAGE_SPORT_3KM = 0x10000d; +static const int IMAGE_SPORT_40KM = 0x10000e; +static const int IMAGE_SPORT_5KM = 0x10000f; +static const int IMAGE_SPORT_60MIN = 0x100010; +static const int IMAGE_SPORT_7KM = 0x100011; +static const int IMAGE_SPORT_BATTERY1 = 0x100012; +static const int IMAGE_SPORT_BATTERY2 = 0x100013; +static const int IMAGE_SPORT_BATTERY3 = 0x100014; +static const int IMAGE_SPORT_BATTERY4 = 0x100015; +static const int IMAGE_SPORT_BATTERY5 = 0x100016; +static const int IMAGE_SPORT_BG = 0x100017; +static const int IMAGE_SPORT_BG1 = 0x100018; +static const int IMAGE_SPORT_BG2 = 0x100019; +static const int IMAGE_SPORT_BG3 = 0x10001a; +static const int IMAGE_SPORT_BG4 = 0x10001b; +static const int IMAGE_SPORT_BG5 = 0x10001c; +static const int IMAGE_SPORT_BG6 = 0x10001d; +static const int IMAGE_SPORT_CALORIE = 0x10001e; +static const int IMAGE_SPORT_CANCEL = 0x10001f; +static const int IMAGE_SPORT_CLIMBING1 = 0x100020; +static const int IMAGE_SPORT_CLIMBING2 = 0x100021; +static const int IMAGE_SPORT_CONFIRM = 0x100022; +static const int IMAGE_SPORT_CROWN = 0x100023; +static const int IMAGE_SPORT_CYCLING1 = 0x100024; +static const int IMAGE_SPORT_CYCLING2 = 0x100025; +static const int IMAGE_SPORT_DISTANCE = 0x100026; +static const int IMAGE_SPORT_FACE = 0x100027; +static const int IMAGE_SPORT_FINISH = 0x100028; +static const int IMAGE_SPORT_GO1 = 0x100029; +static const int IMAGE_SPORT_GO2 = 0x10002a; +static const int IMAGE_SPORT_GO3 = 0x10002b; +static const int IMAGE_SPORT_GO4 = 0x10002c; +static const int IMAGE_SPORT_GO5 = 0x10002d; +static const int IMAGE_SPORT_GO6 = 0x10002e; +static const int IMAGE_SPORT_GPS = 0x10002f; +static const int IMAGE_SPORT_HALF = 0x100030; +static const int IMAGE_SPORT_HEART1 = 0x100031; +static const int IMAGE_SPORT_HEART2 = 0x100032; +static const int IMAGE_SPORT_HEART3 = 0x100033; +static const int IMAGE_SPORT_HEARTRATE = 0x100034; +static const int IMAGE_SPORT_INDOOR_RUNNING1 = 0x100035; +static const int IMAGE_SPORT_INDOOR_RUNNING2 = 0x100036; +static const int IMAGE_SPORT_INDOOR_SWIMMING1 = 0x100037; +static const int IMAGE_SPORT_INDOOR_SWIMMING2 = 0x100038; +static const int IMAGE_SPORT_INTERVAL = 0x100039; +static const int IMAGE_SPORT_ITEMBG = 0x10003a; +static const int IMAGE_SPORT_ITEMBG1 = 0x10003b; +static const int IMAGE_SPORT_ITEMBG2 = 0x10003c; +static const int IMAGE_SPORT_ITEMBG3 = 0x10003d; +static const int IMAGE_SPORT_ITEMBG4 = 0x10003e; +static const int IMAGE_SPORT_ITEMBG5 = 0x10003f; +static const int IMAGE_SPORT_ITEMBG6 = 0x100040; +static const int IMAGE_SPORT_LAP = 0x100041; +static const int IMAGE_SPORT_LAP1 = 0x100042; +static const int IMAGE_SPORT_LAP10 = 0x100043; +static const int IMAGE_SPORT_LAP12 = 0x100044; +static const int IMAGE_SPORT_LAP16 = 0x100045; +static const int IMAGE_SPORT_LAP2 = 0x100046; +static const int IMAGE_SPORT_LAP20 = 0x100047; +static const int IMAGE_SPORT_LAP30 = 0x100048; +static const int IMAGE_SPORT_LAP4 = 0x100049; +static const int IMAGE_SPORT_LAP6 = 0x10004a; +static const int IMAGE_SPORT_LAP8 = 0x10004b; +static const int IMAGE_SPORT_MISTOUCH = 0x10004c; +static const int IMAGE_SPORT_NEXT = 0x10004d; +static const int IMAGE_SPORT_NONE = 0x10004e; +static const int IMAGE_SPORT_OK1 = 0x10004f; +static const int IMAGE_SPORT_OK2 = 0x100050; +static const int IMAGE_SPORT_OK3 = 0x100051; +static const int IMAGE_SPORT_OUTDOOR_RUNNING1 = 0x100052; +static const int IMAGE_SPORT_OUTDOOR_RUNNING2 = 0x100053; +static const int IMAGE_SPORT_OUTDOOR_SWIMMING1 = 0x100054; +static const int IMAGE_SPORT_OUTDOOR_SWIMMING2 = 0x100055; +static const int IMAGE_SPORT_RADIO0 = 0x100056; +static const int IMAGE_SPORT_RADIO1 = 0x100057; +static const int IMAGE_SPORT_REMIND = 0x100058; +static const int IMAGE_SPORT_SCALE = 0x100059; +static const int IMAGE_SPORT_SCREEN = 0x10005a; +static const int IMAGE_SPORT_SETTING = 0x10005b; +static const int IMAGE_SPORT_SIGNAL0 = 0x10005c; +static const int IMAGE_SPORT_SIGNAL1 = 0x10005d; +static const int IMAGE_SPORT_SIGNAL2 = 0x10005e; +static const int IMAGE_SPORT_SIGNAL3 = 0x10005f; +static const int IMAGE_SPORT_START = 0x100060; +static const int IMAGE_SPORT_STOP = 0x100061; +static const int IMAGE_SPORT_TARGET = 0x100062; +static const int IMAGE_SPORT_TIME = 0x100063; +static const int IMAGE_SPORT_TOGGLE0 = 0x100064; +static const int IMAGE_SPORT_TOGGLE1 = 0x100065; +static const int IMAGE_SPORT_TRIANGLE = 0x100066; +} // OHOS +#endif // UI_RESOURCE_SPORT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_stopwatch.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_stopwatch.h new file mode 100644 index 000000000..de08fefc6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_stopwatch.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceStopwatch + * Create: 2025-06-05 + */ + +#ifndef UI_RESOURCE_STOPWATCH_H +#define UI_RESOURCE_STOPWATCH_H + +namespace OHOS { +static const int IMAGE_STOPWATCH_BG = 0x100001; +static const int IMAGE_STOPWATCH_HAND = 0x100002; +static const int IMAGE_STOPWATCH_PAUSE = 0x100003; +static const int IMAGE_STOPWATCH_RECORD = 0x100004; +static const int IMAGE_STOPWATCH_RECORD_DISABLE = 0x100005; +static const int IMAGE_STOPWATCH_RESET = 0x100006; +static const int IMAGE_STOPWATCH_RESET_DISABLE = 0x100007; +static const int IMAGE_STOPWATCH_SCALE = 0x100008; +static const int IMAGE_STOPWATCH_START = 0x100009; +} // OHOS +#endif // UI_RESOURCE_STOPWATCH_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_timer.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_timer.h index b9a462900..1d02c8441 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_timer.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_timer.h @@ -1,27 +1,25 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UITimerResource + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceTimer * Create: 2025-06-05 */ + #ifndef UI_RESOURCE_TIMER_H #define UI_RESOURCE_TIMER_H -#include + namespace OHOS { - static const int IMAGE_CONVERTER_TOOL_BG_CIR = 0x100001; - static const int IMAGE_CONVERTER_TOOL_TIMER_1 = 0x100002; - static const int IMAGE_CONVERTER_TOOL_TIMER_15 = 0x100003; - static const int IMAGE_CONVERTER_TOOL_TIMER_3 = 0x100004; - static const int IMAGE_CONVERTER_TOOL_TIMER_30 = 0x100005; - static const int IMAGE_CONVERTER_TOOL_TIMER_BEGIN_GRAY = 0x100006; - static const int IMAGE_CONVERTER_TOOL_TIMER_BEGIN_ORANGE = 0x100007; - static const int IMAGE_CONVERTER_TOOL_TIMER_BG = 0x100008; - static const int IMAGE_CONVERTER_TOOL_TIMER_EXIT = 0x100009; - static const int IMAGE_CONVERTER_TOOL_TIMER_PAUSE = 0x10000a; - static const int IMAGE_CONVERTER_TOOL_TIMER_PAUSE_ORANGE = 0x10000b; - static const int IMAGE_CONVERTER_TOOL_TIMER_PBG = 0x10000c; - static const int IMAGE_CONVERTER_TOOL_TIMER_PLAY = 0x10000d; - static const int IMAGE_CONVERTER_TOOL_TIMER_POINTER = 0x10000e; - static const int IMAGE_CONVERTER_TOOL_TIMER_RESTART = 0x10000f; - static const int IMAGE_CONVERTER_TOOL_TIMER_USER = 0x100010; -} // OHOS -#endif // UI_RESOURCE_TIMER_H +static const int IMAGE_TIMER_1 = 0x100001; +static const int IMAGE_TIMER_15 = 0x100002; +static const int IMAGE_TIMER_3 = 0x100003; +static const int IMAGE_TIMER_30 = 0x100004; +static const int IMAGE_TIMER_BEGIN_GRAY = 0x100005; +static const int IMAGE_TIMER_BEGIN_ORANGE = 0x100006; +static const int IMAGE_TIMER_BG = 0x100007; +static const int IMAGE_TIMER_EXIT = 0x100008; +static const int IMAGE_TIMER_PAUSE = 0x100009; +static const int IMAGE_TIMER_PAUSE_ORANGE = 0x10000a; +static const int IMAGE_TIMER_PLAY = 0x10000b; +static const int IMAGE_TIMER_RESTART = 0x10000c; +static const int IMAGE_TIMER_USER = 0x10000d; +} // OHOS +#endif // UI_RESOURCE_TIMER_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_weather.h b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_weather.h index 874ba3f93..13eeebc34 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_weather.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/include/ui_resource_weather.h @@ -1,89 +1,106 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: UIWeatherResource + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIResourceWeather * Create: 2025-06-05 */ -#ifndef UI_RESOURCE_WEATHER_IMAGE_H -#define UI_RESOURCE_WEATHER_IMAGE_H -#include + +#ifndef UI_RESOURCE_WEATHER_H +#define UI_RESOURCE_WEATHER_H + namespace OHOS { -static const int IMAGE_CONVERTER_TOOL_WEATHER00 = 0x100001; -static const int IMAGE_CONVERTER_TOOL_WEATHER01 = 0x100002; -static const int IMAGE_CONVERTER_TOOL_WEATHER02 = 0x100003; -static const int IMAGE_CONVERTER_TOOL_WEATHER03 = 0x100004; -static const int IMAGE_CONVERTER_TOOL_WEATHER04 = 0x100005; -static const int IMAGE_CONVERTER_TOOL_WEATHER05 = 0x100006; -static const int IMAGE_CONVERTER_TOOL_WEATHER06 = 0x100007; -static const int IMAGE_CONVERTER_TOOL_WEATHER07 = 0x100008; -static const int IMAGE_CONVERTER_TOOL_WEATHER08 = 0x100009; -static const int IMAGE_CONVERTER_TOOL_WEATHER09 = 0x10000a; -static const int IMAGE_CONVERTER_TOOL_WEATHER10 = 0x10000b; -static const int IMAGE_CONVERTER_TOOL_WEATHER11 = 0x10000c; -static const int IMAGE_CONVERTER_TOOL_WEATHER12 = 0x10000d; -static const int IMAGE_CONVERTER_TOOL_WEATHER13 = 0x10000e; -static const int IMAGE_CONVERTER_TOOL_WEATHER14 = 0x10000f; -static const int IMAGE_CONVERTER_TOOL_WEATHER15 = 0x100010; -static const int IMAGE_CONVERTER_TOOL_WEATHER16 = 0x100011; -static const int IMAGE_CONVERTER_TOOL_WEATHER17 = 0x100012; -static const int IMAGE_CONVERTER_TOOL_WEATHER18 = 0x100013; -static const int IMAGE_CONVERTER_TOOL_WEATHER19 = 0x100014; -static const int IMAGE_CONVERTER_TOOL_WEATHER20 = 0x100015; -static const int IMAGE_CONVERTER_TOOL_WEATHER21 = 0x100016; -static const int IMAGE_CONVERTER_TOOL_WEATHER22 = 0x100017; -static const int IMAGE_CONVERTER_TOOL_WEATHER23 = 0x100018; -static const int IMAGE_CONVERTER_TOOL_WEATHER24 = 0x100019; -static const int IMAGE_CONVERTER_TOOL_WEATHER25 = 0x10001a; -static const int IMAGE_CONVERTER_TOOL_WEATHER26 = 0x10001b; -static const int IMAGE_CONVERTER_TOOL_WEATHER27 = 0x10001c; -static const int IMAGE_CONVERTER_TOOL_WEATHER28 = 0x10001d; -static const int IMAGE_CONVERTER_TOOL_WEATHER29 = 0x10001e; -static const int IMAGE_CONVERTER_TOOL_WEATHER30 = 0x10001f; -static const int IMAGE_CONVERTER_TOOL_WEATHER31 = 0x100020; -static const int IMAGE_CONVERTER_TOOL_WEATHER32 = 0x100021; -static const int IMAGE_CONVERTER_TOOL_WEATHER33 = 0x100022; -static const int IMAGE_CONVERTER_TOOL_WEATHER34 = 0x100023; -static const int IMAGE_CONVERTER_TOOL_WEATHER35 = 0x100024; -static const int IMAGE_CONVERTER_TOOL_WEATHER36 = 0x100025; -static const int IMAGE_CONVERTER_TOOL_WEATHER37 = 0x100026; -static const int IMAGE_CONVERTER_TOOL_WEATHER38 = 0x100027; -static const int IMAGE_CONVERTER_TOOL_WEATHER39 = 0x100028; -static const int IMAGE_CONVERTER_TOOL_WEATHER40 = 0x100029; -static const int IMAGE_CONVERTER_TOOL_WEATHER41 = 0x10002a; -static const int IMAGE_CONVERTER_TOOL_WEATHER42 = 0x10002b; -static const int IMAGE_CONVERTER_TOOL_WEATHER43 = 0x10002c; -static const int IMAGE_CONVERTER_TOOL_WEATHER44 = 0x10002d; -static const int IMAGE_CONVERTER_TOOL_WEATHER45 = 0x10002e; -static const int IMAGE_CONVERTER_TOOL_WEATHER46 = 0x10002f; -static const int IMAGE_CONVERTER_TOOL_WEATHER47 = 0x100030; -static const int IMAGE_CONVERTER_TOOL_WEATHER48 = 0x100031; -static const int IMAGE_CONVERTER_TOOL_WEATHER49 = 0x100032; -static const int IMAGE_CONVERTER_TOOL_WEATHER50 = 0x100033; -static const int IMAGE_CONVERTER_TOOL_WEATHER51 = 0x100034; -static const int IMAGE_CONVERTER_TOOL_WEATHER52 = 0x100035; -static const int IMAGE_CONVERTER_TOOL_WEATHER53 = 0x100036; -static const int IMAGE_CONVERTER_TOOL_WEATHER54 = 0x100037; -static const int IMAGE_CONVERTER_TOOL_WEATHER55 = 0x100038; -static const int IMAGE_CONVERTER_TOOL_WEATHER56 = 0x100039; -static const int IMAGE_CONVERTER_TOOL_WEATHER57 = 0x10003a; -static const int IMAGE_CONVERTER_TOOL_WEATHER58 = 0x10003b; -static const int IMAGE_CONVERTER_TOOL_WEATHER59 = 0x10003c; -static const int IMAGE_CONVERTER_TOOL_WEATHER60 = 0x10003d; -static const int IMAGE_CONVERTER_TOOL_WEATHER61 = 0x10003e; -static const int IMAGE_CONVERTER_TOOL_WEATHER62 = 0x10003f; -static const int IMAGE_CONVERTER_TOOL_WEATHER63 = 0x100040; -static const int IMAGE_CONVERTER_TOOL_WEATHER64 = 0x100041; -static const int IMAGE_CONVERTER_TOOL_WEATHER65 = 0x100042; -static const int IMAGE_CONVERTER_TOOL_WEATHER66 = 0x100043; -static const int IMAGE_CONVERTER_TOOL_WEATHER67 = 0x100044; -static const int IMAGE_CONVERTER_TOOL_WEATHER68 = 0x100045; -static const int IMAGE_CONVERTER_TOOL_WEATHER69 = 0x100046; -static const int IMAGE_CONVERTER_TOOL_WEATHER70 = 0x100047; -static const int IMAGE_CONVERTER_TOOL_WEATHER71 = 0x100048; -static const int IMAGE_CONVERTER_TOOL_WEATHER72 = 0x100049; -static const int IMAGE_CONVERTER_TOOL_WEATHER73 = 0x10004a; -static const int IMAGE_CONVERTER_TOOL_WEATHER74 = 0x10004b; -static const int IMAGE_CONVERTER_TOOL_WEATHER75 = 0x10004c; -static const int IMAGE_CONVERTER_TOOL_WEATHER76 = 0x10004d; -static const int IMAGE_CONVERTER_TOOL_WEATHER77 = 0x10004e; +static const int IMAGE_WEATHER_AIR = 0x100001; +static const int IMAGE_WEATHER_BG1 = 0x100002; +static const int IMAGE_WEATHER_BG2 = 0x100003; +static const int IMAGE_WEATHER_ITEM1 = 0x100004; +static const int IMAGE_WEATHER_ITEM2 = 0x100005; +static const int IMAGE_WEATHER_ITEM3 = 0x100006; +static const int IMAGE_WEATHER_ITEM4 = 0x100007; +static const int IMAGE_WEATHER_ITEM5 = 0x100008; +static const int IMAGE_WEATHER_ITEM6 = 0x100009; +static const int IMAGE_WEATHER_LOCATE = 0x10000a; +static const int IMAGE_WEATHER_MOON = 0x10000b; +static const int IMAGE_WEATHER_MOON1 = 0x10000c; +static const int IMAGE_WEATHER_MOON2 = 0x10000d; +static const int IMAGE_WEATHER_MOON3 = 0x10000e; +static const int IMAGE_WEATHER_MOON4 = 0x10000f; +static const int IMAGE_WEATHER_MOON5 = 0x100010; +static const int IMAGE_WEATHER_MOON6 = 0x100011; +static const int IMAGE_WEATHER_MOON7 = 0x100012; +static const int IMAGE_WEATHER_MOON8 = 0x100013; +static const int IMAGE_WEATHER_NEXT = 0x100014; +static const int IMAGE_WEATHER_NEXT_GRAY = 0x100015; +static const int IMAGE_WEATHER_PAGE1 = 0x100016; +static const int IMAGE_WEATHER_PAGE2 = 0x100017; +static const int IMAGE_WEATHER_PAGE3 = 0x100018; +static const int IMAGE_WEATHER_PREV = 0x100019; +static const int IMAGE_WEATHER_PREV_GRAY = 0x10001a; +static const int IMAGE_WEATHER_SUN = 0x10001b; +static const int IMAGE_WEATHER_SUNRISE = 0x10001c; +static const int IMAGE_WEATHER_SUNSET = 0x10001d; +static const int IMAGE_WEATHER_WEATHER00 = 0x10001e; +static const int IMAGE_WEATHER_WEATHER01 = 0x10001f; +static const int IMAGE_WEATHER_WEATHER02 = 0x100020; +static const int IMAGE_WEATHER_WEATHER03 = 0x100021; +static const int IMAGE_WEATHER_WEATHER04 = 0x100022; +static const int IMAGE_WEATHER_WEATHER05 = 0x100023; +static const int IMAGE_WEATHER_WEATHER06 = 0x100024; +static const int IMAGE_WEATHER_WEATHER07 = 0x100025; +static const int IMAGE_WEATHER_WEATHER08 = 0x100026; +static const int IMAGE_WEATHER_WEATHER09 = 0x100027; +static const int IMAGE_WEATHER_WEATHER10 = 0x100028; +static const int IMAGE_WEATHER_WEATHER11 = 0x100029; +static const int IMAGE_WEATHER_WEATHER12 = 0x10002a; +static const int IMAGE_WEATHER_WEATHER13 = 0x10002b; +static const int IMAGE_WEATHER_WEATHER14 = 0x10002c; +static const int IMAGE_WEATHER_WEATHER15 = 0x10002d; +static const int IMAGE_WEATHER_WEATHER16 = 0x10002e; +static const int IMAGE_WEATHER_WEATHER17 = 0x10002f; +static const int IMAGE_WEATHER_WEATHER18 = 0x100030; +static const int IMAGE_WEATHER_WEATHER19 = 0x100031; +static const int IMAGE_WEATHER_WEATHER20 = 0x100032; +static const int IMAGE_WEATHER_WEATHER21 = 0x100033; +static const int IMAGE_WEATHER_WEATHER22 = 0x100034; +static const int IMAGE_WEATHER_WEATHER23 = 0x100035; +static const int IMAGE_WEATHER_WEATHER24 = 0x100036; +static const int IMAGE_WEATHER_WEATHER25 = 0x100037; +static const int IMAGE_WEATHER_WEATHER26 = 0x100038; +static const int IMAGE_WEATHER_WEATHER27 = 0x100039; +static const int IMAGE_WEATHER_WEATHER28 = 0x10003a; +static const int IMAGE_WEATHER_WEATHER29 = 0x10003b; +static const int IMAGE_WEATHER_WEATHER30 = 0x10003c; +static const int IMAGE_WEATHER_WEATHER31 = 0x10003d; +static const int IMAGE_WEATHER_WEATHER32 = 0x10003e; +static const int IMAGE_WEATHER_WEATHER33 = 0x10003f; +static const int IMAGE_WEATHER_WEATHER34 = 0x100040; +static const int IMAGE_WEATHER_WEATHER35 = 0x100041; +static const int IMAGE_WEATHER_WEATHER36 = 0x100042; +static const int IMAGE_WEATHER_WEATHER37 = 0x100043; +static const int IMAGE_WEATHER_WEATHER38 = 0x100044; +static const int IMAGE_WEATHER_WEATHER39 = 0x100045; +static const int IMAGE_WEATHER_WEATHER40 = 0x100046; +static const int IMAGE_WEATHER_WEATHER41 = 0x100047; +static const int IMAGE_WEATHER_WEATHER42 = 0x100048; +static const int IMAGE_WEATHER_WEATHER43 = 0x100049; +static const int IMAGE_WEATHER_WEATHER44 = 0x10004a; +static const int IMAGE_WEATHER_WEATHER45 = 0x10004b; +static const int IMAGE_WEATHER_WEATHER46 = 0x10004c; +static const int IMAGE_WEATHER_WEATHER47 = 0x10004d; +static const int IMAGE_WEATHER_WEATHER48 = 0x10004e; +static const int IMAGE_WEATHER_WEATHER49 = 0x10004f; +static const int IMAGE_WEATHER_WEATHER50 = 0x100050; +static const int IMAGE_WEATHER_WEATHER51 = 0x100051; +static const int IMAGE_WEATHER_WEATHER52 = 0x100052; +static const int IMAGE_WEATHER_WEATHER53 = 0x100053; +static const int IMAGE_WEATHER_WEATHER54 = 0x100054; +static const int IMAGE_WEATHER_WEATHER55 = 0x100055; +static const int IMAGE_WEATHER_WEATHER56 = 0x100056; +static const int IMAGE_WEATHER_WEATHER57 = 0x100057; +static const int IMAGE_WEATHER_WEATHER58 = 0x100058; +static const int IMAGE_WEATHER_WEATHER59 = 0x100059; +static const int IMAGE_WEATHER_WEATHER60 = 0x10005a; +static const int IMAGE_WEATHER_WEATHER61 = 0x10005b; +static const int IMAGE_WEATHER_WEATHER62 = 0x10005c; +static const int IMAGE_WEATHER_WEATHER63 = 0x10005d; +static const int IMAGE_WEATHER_WET = 0x10005e; } // OHOS -#endif // UI_RESOURCE_IMAGE_H +#endif // UI_RESOURCE_WEATHER_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/NativeLauncher.cpp index be0ab5890..be7df9d4d 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -18,26 +18,30 @@ #include "SliceProxy.h" #include "AbilitySliceProxy.h" #include "wearable_log.h" -#include "callerlog/CallerLogModel.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" #include "activity/ActivityModel.h" -#include "heartrate/HeartModel.h" #include "player/PlayersModel.h" #include "main/HealthModel.h" -#include "sports/SportsModel.h" #include "offlinevoice/VocassistModel.h" #include "screensetting/ScreenModels.h" -#include "bluetooth/BluetoothHeadsetEvent.h" #include "graphic_hardware_config.h" #include "graphic_service.h" #include "common/graphic_startup.h" #ifdef JS_ENABLE #include "product_adapter.h" #endif +#ifdef ENABLE_MODULE_CALENDAR +#include "event_id_manager.h" +#endif #include "RecentManager.h" #include "PageTransitionMgr.h" - +#include "date/DateModel.h" +#include "settings/model/SettingDisplayModel.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/model/SettingBluetoothHeadsetEvent.h" +#include "NativeLauncher.h" namespace OHOS { - +int16_t BackDragListener::maxDragRegionX_ = MAX_X_IN_DRAG_REGION; NativeLauncher::NativeLauncher() {} NativeLauncher::~NativeLauncher() {} @@ -56,29 +60,34 @@ void NativeLauncher::InitNativeLauncher() #endif GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); + GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, + OHOS::VECTOR_FONT_DIR, BOLD_VECTOR_FONT_FILENAME); WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeLauncher::InitNativeLauncher"); // 初始化所有预加载slice - InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 + SettingInitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 NativeRegisterManager::GetInstance().InitAllNativesSlices(); - CallerLogModel::GetInstance()->InitPhoneService(); + PhoneMenuCallerLogModel::GetInstance()->InitPhoneService(); PlayersModel::GetInstance()->AudioInit(); ActivityModel::GetInstance()->Init(); ScreenModels::GetInstance()->InitKvStorage(); +#ifdef ENABLE_MODULE_CALENDAR + ACELite::InitEventMaps(); +#endif VocassistModel::GetInstance()->Init(); - HeartModel::GetInstance()->Init(); - BluetoothModel::GetInstance()->Init(); - SportsModel::GetInstance()->Init(); + SettingBluetoothModel::GetInstance()->Init(); // 初始化默认首页 ScreenModels::GetInstance()->PreLoadAppimages(); NativeAbility::GetInstance().SetDefaultSliceId(VIEW_MAIN_SAMPLE); - RecentManager::GetInstance()->SetDirPath("system/recent/"); + RecentManager::GetInstance()->SetDirPath(APP_RECENT_PATH); RecentManager::GetInstance()->AddToBlackList(VIEW_AOD); RecentManager::GetInstance()->AddToBlackList(VIEW_RECENT_APP); RecentManager::GetInstance()->AddToBlackList(VIEW_APPLIST); RecentManager::GetInstance()->AddToBlackList(VIEW_MAIN_SAMPLE); RecentManager::GetInstance()->SetMaxSize(5); // 5: max number of recent apps. PageTransitionMgr::GetInstance().SetRecentMinPeriod(1000); // 1000: min period -} + DateModel::GetInstance().Init(); + SettingDisplayModel::GetInstance().InitDisplayModel(); +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UICardPageFactory.cpp b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UICardPageFactory.cpp index 649aa2f3c..3bed49085 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UICardPageFactory.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UICardPageFactory.cpp @@ -10,33 +10,28 @@ namespace OHOS { -void UICardPageFactory::RegisterWatchDial(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage) +void UICardPageFactory::RegisterCardPage(const uint16_t id, UICardPageProxyInterface* uiCardPage) { - if (mode >= DIAL_DISPLAY_MODE_MAX || uiCardPage == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't register watch dial using invalid mode or proxy %d-%p", - mode, uiCardPage); + if (uiCardPage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't register watch dial using invalid proxy %p", + uiCardPage); return; } - if (watchDials_[mode].find(id) != watchDials_[mode].end()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial mode %d id:%d has already been registered", mode, id); + if (cardPage_.find(id) != cardPage_.end()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial id:%d has already been registered", id); return; } else { - watchDials_[mode].insert({id, uiCardPage}); + cardPage_.insert({id, uiCardPage}); } } -UICardPage* UICardPageFactory::CreateWatchDial(uint16_t mode, uint16_t id) +UICardPage* UICardPageFactory::CreateCardPage(uint16_t id) { - if (mode >= DIAL_DISPLAY_MODE_MAX ) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't create watch dial using invalid mode %d", mode); - return nullptr; - } - - auto it = watchDials_[mode].find(id); - if (it != watchDials_[mode].end()) { + auto it = cardPage_.find(id); + if (it != cardPage_.end()) { return it->second->CreateUICardPage(); } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial mode %d id:%d was not registered", mode, id); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial id:%d was not registered", id); return nullptr; } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UIWatchDialFactory.cpp b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UIWatchDialFactory.cpp new file mode 100644 index 000000000..7f7aeae24 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativelauncher/src/UIWatchDialFactory.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: UICardPageFactory + * Author: + * Create: 2025-06 + */ + +#include "UIWatchDialFactory.h" +#include "wearable_log.h" + +namespace OHOS { + +void UIWatchDialFactory::RegisterWatchDial(const uint16_t ability, const uint16_t id, + UIWatchDialProxyInterface* uiWatchDial, const DialInfo* dialInfo) +{ + if (ability >= DIAL_DISPLAY_SUPPORT_MAX || uiWatchDial == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't register watch dial using invalid ability or proxy %d-%p", + ability, uiWatchDial); + return; + } + + if ((ability == DIAL_DISPLAY_SUPPORT_NORMAL || ability == DIAL_DISPLAY_SUPPORT_NORMAL_AOD) && dialInfo != nullptr) { + if (watchDials_[DIAL_DISPLAY_MODE_NORMAL].find(id) != watchDials_[DIAL_DISPLAY_MODE_NORMAL].end() || + normalDialInfo_.find(id) != normalDialInfo_.end()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "normal dial(info) id:%d has already been registered", id); + return; + } else { + watchDials_[DIAL_DISPLAY_MODE_NORMAL].insert({id, uiWatchDial}); + normalDialInfo_.insert({id, dialInfo}); + } + } + + if ((ability == DIAL_DISPLAY_SUPPORT_AOD || ability == DIAL_DISPLAY_SUPPORT_NORMAL_AOD)) { + if (watchDials_[DIAL_DISPLAY_MODE_AOD].find(id) != watchDials_[DIAL_DISPLAY_MODE_AOD].end()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aod dial id:%d has already been registered", id); + return; + } else { + watchDials_[DIAL_DISPLAY_MODE_AOD].insert({id, uiWatchDial}); + } + } +} + +const DialInfo* UIWatchDialFactory::GetNormalDialInfo(uint16_t id) +{ + auto it = normalDialInfo_.find(id); + if (it != normalDialInfo_.end()) { + return it->second; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "normal dial info id:%d was not created", id); + return nullptr; + } +} + +uint8_t UIWatchDialFactory::GetNormalDialInfoNum() +{ + return normalDialInfo_.size(); +} + +UICardPage* UIWatchDialFactory::CreateNormalDial(uint16_t id) +{ + auto it = watchDials_[DIAL_DISPLAY_MODE_NORMAL].find(id); + if (it != watchDials_[DIAL_DISPLAY_MODE_NORMAL].end()) { + return it->second->CreateWatchDialCardPage(id); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "normal dial id:%d was not registered", id); + return nullptr; + } +} + +UIFragment* UIWatchDialFactory::CreateAodDial(uint16_t id) +{ + auto it = watchDials_[DIAL_DISPLAY_MODE_AOD].find(id); + if (it != watchDials_[DIAL_DISPLAY_MODE_AOD].end()) { + return it->second->CreateWatchDialFragment(id); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aod dial id:%d was not registered", id); + return nullptr; + } +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityModel.cpp index a68a6c7e5..a9a2c8520 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityModel.cpp @@ -18,7 +18,6 @@ #include "securec.h" #include "broadcast_service.h" #include "clock/MainClockView.h" -#include "indoorwalk/IndoorWalkPresenter.h" #include "activity/ActivityWeekView.h" #include "graphic_service.h" @@ -83,15 +82,6 @@ static void RefreshStepControls(const uint32_t &value, const uint16 &msgId) }); } - IndoorWalkPresenter *indoorWalkPresenter = OHOS::IndoorWalkPresenter::GetInstance(); - if (indoorWalkPresenter != nullptr) { - GraphicService::GetInstance()->PostGraphicEvent([value]() { - if (OHOS::IndoorWalkPresenter::GetInstance() != nullptr) { - OHOS::IndoorWalkPresenter::GetInstance()->ModifiesSteps(value); - } - }); - } - ActivityWeekView *activityWeekView = OHOS::ActivityWeekView::GetInstance(); if (activityWeekView == nullptr) { return; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityPresenter.cpp index 4603a46c0..5689d86c1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/activity/src/ActivityPresenter.cpp @@ -15,7 +15,7 @@ namespace OHOS { REGIST_SLICE(VIEW_MAIN_ACTIVITY, MainActivityView, ActivityPresenter); - + static ActivityPresenter *g_pActivityPresenter = nullptr; ActivityPresenter::ActivityPresenter() { diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp index e2863a5a4..87bd62156 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp @@ -17,6 +17,7 @@ #include "graphic_service.h" #include "player/PlayersModel.h" #include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" #include "uiservice/ui_service.h" #ifdef __cplusplus @@ -810,10 +811,12 @@ void AlarmPlayerCallbackImpl::OnPlaybackComplete() uint16_t AlarmClockModel::JudgePreSlice(void) { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + uint32_t targetId = NativeAbility::GetInstance().GetPreTargetId(); + uint16_t preSlice = static_cast(targetId & SLICE_MASK); + uint16_t prePage = static_cast(targetId >> PAGE_OFFSET); if (preSlice == VIEW_ALARM_POP_UP || preSlice < VIEW_SETTING) { preSlice = VIEW_MAIN_SAMPLE; - } else if ((preSlice == VIEW_MAEKPHONE_SAMPLE) && + } else if ((preSlice == VIEW_PHONE_MENU && prePage == PhoneMenuPages::PHONE_MENU_CALLING_PAGE) && (GetCurrCallNum() == 0 || GetScoConnectState() != HFP_SCO_STATE_CONNECTED)) { int num; PhoneCallInfo callList[MULTI_CALL_MAX_NUME]{}; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp index d13509d96..97f0c23f4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp @@ -9,6 +9,9 @@ #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif #include #include #include diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp index 972cc0e3e..e09321d21 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp @@ -119,7 +119,7 @@ bool AlarmPopUpPresenter::OnDragEnd(UIView& view, const DragEvent& event) return true; } -void AlarmPopUpPresenter::Notify() +void AlarmPopUpPresenter::Callback() { if (isStartCalcu) { if (calcuNotifyNums == RENDER_FINISH) { @@ -131,4 +131,14 @@ void AlarmPopUpPresenter::Notify() ++calcuNotifyNums; } } + +void AlarmPopUpPresenter::OnResume() +{ + Init(); +} + +void AlarmPopUpPresenter::OnPause() +{ + Deinit(); +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp index 3d54a5ce9..9cc578610 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp @@ -10,6 +10,9 @@ #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif #include namespace OHOS { diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayMainView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayMainView.cpp index d45093f13..4a7e1b33f 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayMainView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayMainView.cpp @@ -200,7 +200,7 @@ void AlipayMainView::DropView(UIView &view) AlipayModel::GetInstance()->AlipayFinishBind(); } AlipayModel::GetInstance()->AlipayStopSwitchTimer(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } else if (&view == container[ALIPAY_TRANS_LIST_VIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_LIST_VIEW]"); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp index 4909bd08d..a7257699f 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp @@ -54,7 +54,7 @@ void AlipayPresenter::OnStart() alipayMode_->AlipayExitLpm(); if (!alipayMode_->AlipayInitModel()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnStart AlipayInitModel fail."); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); return; } } @@ -179,7 +179,7 @@ void AlipayPresenter::ClickTransToTransCode(UIView &view) view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); return; } - + ret = alipayMode_->AlipayGetTransCode(index); if (ret == 0) { view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodPresenter.cpp index 9d47082d9..615716e67 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodPresenter.cpp @@ -7,13 +7,26 @@ #include "aod_view/AodPresenter.h" #include "NativeRegisterManager.h" +#include "main/dial/DialViewGroup.h" namespace OHOS { REGIST_SLICE(VIEW_AOD, AodView, AodPresenter); -void AodPresenter::Notify() +void AodPresenter::Callback() { - view_->PeriodicUpdate(); + if (view_ != nullptr) { + view_->Update(); + } +} + +void AodPresenter::OnResume() +{ + Init(); +} + +void AodPresenter::OnPause() +{ + Deinit(); } } // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodView.cpp index 6bb9f8cec..6e1ff18ee 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/aod_view/src/AodView.cpp @@ -9,15 +9,24 @@ #include "aod_view/AodPresenter.h" #include "aod_view/AodModel.h" #include "common/graphic_utils.h" -#include "UICardPageFactory.h" +#include "UIWatchDialFactory.h" #include "main/DialBinParser.h" #include "main/dial/DialViewGroup.h" #include "clock/AmbientClockView.h" #include "main/dial/DialModelTime.h" +#include "clock/GradientAodView.h" +#include "common/task.h" +#include "common/periodicupdate_interface.h" namespace OHOS { AodView::~AodView() { + if (clockDialFragment_ != nullptr) { + delete clockDialFragment_; + clockDialFragment_ = nullptr; + clockDial_ = nullptr; + } + if (clockDial_ != nullptr) { delete clockDial_; clockDial_ = nullptr; @@ -42,13 +51,14 @@ void AodView::OnStart() DialViewGroup *dial = dynamic_cast(clockDial_); if (dial != nullptr) { dial->PreLoad(); - dial->OnActive(); presenter_->SetPeriod(dial->GetPeriod()); - } else { - AmbientClockView *clock = dynamic_cast(clockDial_); - if (clock != nullptr) { - presenter_->SetPeriod(clock->GetPeriod()); + } else if (clockDialFragment_ != nullptr) { +#ifndef __WIN32 + PeriodicUpdateInterface *interface = dynamic_cast(clockDialFragment_); + if (interface != nullptr) { + presenter_->SetPeriod(interface->GetPeriod()); } +#endif } isLoaded_ = true; AddViewToRootContainer(clockDial_); @@ -57,7 +67,7 @@ void AodView::OnStart() void AodView::OnStop() { if (clockDial_ != nullptr) { - DialViewGroup *dial = dynamic_cast(clockDial_); + DialViewGroup *dial = dynamic_cast(clockDial_); if (dial != nullptr) { dial->OnInactive(); dial->UnLoad(); @@ -68,7 +78,11 @@ void AodView::OnStop() UIViewGroup *AodView::InitAodDial(DialSetting &setting) { - return UICardPageFactory::GetInstance().CreateWatchDial(DIAL_DISPLAY_MODE_AOD, setting.dialId); + clockDialFragment_ = UIWatchDialFactory::GetInstance().CreateAodDial(setting.dialId); + if (clockDialFragment_ != nullptr) { + return dynamic_cast(clockDialFragment_->GetFragmentView()); + } + return nullptr; } UIViewGroup *AodView::InitAodOffDial(DialSetting &setting) @@ -79,7 +93,7 @@ UIViewGroup *AodView::InitAodOffDial(DialSetting &setting) if (fp == nullptr) { return nullptr; } - bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(setting.dialFullName, fp, &preview); + bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(setting.dialFullName, fp, &preview, false); fclose(fp); if (!ret) { return nullptr; @@ -103,7 +117,7 @@ UIViewGroup *AodView::InitDefaultAod() return InitAodOffDial(setting); } -void AodView::PeriodicUpdate() +void AodView::Update() { if (clockDial_ == nullptr || !isLoaded_) { return; @@ -116,9 +130,11 @@ void AodView::PeriodicUpdate() return; } - AmbientClockView *clock = dynamic_cast(clockDial_); - if (clockDial_ != nullptr) { - clock->UpdateTime(); +#ifndef __WIN32 + PeriodicUpdateInterface *interface = dynamic_cast(clockDialFragment_); + if (interface != nullptr) { + interface->Update(); } +#endif } } // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/AppItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/AppItemView.cpp index f5dca80fd..d4727a9fe 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/AppItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/AppItemView.cpp @@ -102,74 +102,4 @@ namespace OHOS { label_.SetTextColor(Color::Gray()); icon_.ResetTransParameter(); } - - HexagonsItemView::HexagonsItemView() - { - } - - HexagonsItemView::~HexagonsItemView() - { - if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { - ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); - } - } - - void HexagonsItemView::SetItemInfo(const AppItem &itemInfo) - { - itemInfo_ = itemInfo; - } - - AppViewId HexagonsItemView::GetViewId() - { - return static_cast(itemInfo_.id); - } - - const char *HexagonsItemView::GetAppUid() - { - return itemInfo_.uid; - } - - FootballItemView::~FootballItemView() - { - if (itemInfo_.iconHexagon == nullptr && itemInfo_.hexagonPath != nullptr) { - ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.hexagonId, itemInfo_.hexagonPath); - } - } - - void FootballItemView::SetItemInfo(const AppItem &itemInfo) - { - itemInfo_ = itemInfo; - } - - AppViewId FootballItemView::GetViewId() - { - return static_cast(itemInfo_.id); - } - - const char *FootballItemView::GetAppUid() - { - return itemInfo_.uid; - } - - WaterfallItemView::~WaterfallItemView() - { - if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { - ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); - } - } - - void WaterfallItemView::SetItemInfo(const AppItem &itemInfo) - { - itemInfo_ = itemInfo; - } - - AppViewId WaterfallItemView::GetViewId() - { - return static_cast(itemInfo_.id); - } - - const char *WaterfallItemView::GetAppUid() - { - return itemInfo_.uid; - } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistModel.cpp index b3eabbb23..865d59958 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistModel.cpp @@ -16,7 +16,6 @@ #include "applist/ApplistModel.h" #include "applist/ApplistPresenter.h" #include "font/font_global_manager.h" -#include "settings/SetDesktopModel.h" #include "NativeRegisterManager.h" namespace OHOS { @@ -55,22 +54,22 @@ namespace OHOS { initFlag = flag; } - void ApplistModel::ResolvingJSAppItems(void) + void ApplistModel::CleanupApplistStrings(uint8_t nativeAppNumTotal) { -#ifdef JS_ENABLE - if (bundleInfos != nullptr) { - for (uint8_t i = 0; i < bundleLen; i++) { - ClearBundleInfo(bundleInfos + i); - } - - if (bundleInfos != nullptr) { - AdapterFree(bundleInfos); - bundleInfos = nullptr; - } + for (uint8_t i = nativeAppNumTotal; i < appLen; i++) { + free((void*)applist[i].iconSmall); + free((void*)applist[i].iconHexagon); + free((void*)applist[i].label); + free((void*)applist[i].uid); + applist[i].iconSmall = nullptr; + applist[i].iconHexagon = nullptr; + applist[i].label = nullptr; + applist[i].uid = nullptr; } -#endif - bundleLen = 0; - appLen = 0; + } + + void ApplistModel::ResolvingJSAppItems(void) + { List& nativeAppLists = NativeRegisterManager::GetInstance().GetNativeAppLists(); uint8_t registerNativeAppNum = nativeAppLists.Size(); if (registerNativeAppNum > APP_MAX_NUM) { @@ -83,6 +82,9 @@ namespace OHOS { applist[index] = appNode->data_; appNode = appNode->next_; } + CleanupApplistStrings(nativeAppNumTotal); + bundleLen = 0; + appLen = 0; appLen = nativeAppNumTotal; #ifdef JS_ENABLE int32_t len = 0; @@ -93,23 +95,36 @@ namespace OHOS { len = APP_MAX_NUM - nativeAppNumTotal; } while (len--) { - applist[appLen] = { - VIEW_EXTERN_APP, - bundleInfos[len].smallIconPath, - bundleInfos[len].bigIconPath, - bundleInfos[len].label, - bundleInfos[len].bundleName - }; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bundleName is %s \r", bundleInfos[len].bundleName); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems label is %s \r", bundleInfos[len].label); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems smallIconPath is %s \r", bundleInfos[len].smallIconPath); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bigIconPath is %s \r", bundleInfos[len].bigIconPath); + char* smallIconPath = strdup(bundleInfos[len].smallIconPath); + char* bigIconPath = strdup(bundleInfos[len].bigIconPath); + char* label = strdup(bundleInfos[len].label); + char* bundleName = strdup(bundleInfos[len].bundleName); + applist[appLen] = AppItem( + VIEW_EXTERN_APP, // id + smallIconPath, // iconSmall + bigIconPath, // iconHexagon + label, // label + bundleName // uid + ); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bundleName is %s \r", bundleName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems label is %s \r", label); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems smallIconPath is %s \r", smallIconPath); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bigIconPath is %s \r", bigIconPath); appLen++; bundleInfos[len].abilityInfo = nullptr; } } else { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems GetBundleInfos ret = %d \r", ret); } + if (bundleInfos != nullptr) { + for (uint8_t i = 0; i < bundleLen; i++) { + ClearBundleInfo(bundleInfos + i); + } + if (bundleInfos != nullptr) { + AdapterFree(bundleInfos); + bundleInfos = nullptr; + } + } #endif } @@ -132,6 +147,18 @@ namespace OHOS { return startIndex; } + void ApplistModel::SetLastOffset(int16_t x, int16_t y) + { + lastOffsetX = x; + lastOffsetY = y; + } + + void ApplistModel::GetLastOffset(int16_t& x, int16_t& y) + { + x = lastOffsetX; + y = lastOffsetY; + } + void ApplistModel::SetHeadItemY(int y) { headItemY = y; @@ -159,9 +186,4 @@ namespace OHOS { { presenter = p; } - - AppListStyle ApplistModel::GetCurrentStyle(void) - { - return static_cast(SetDesktopModel::GetInstance().GetDesktopStyle()); - } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistPresenter.cpp index 382786a39..5963625a7 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistPresenter.cpp @@ -6,195 +6,44 @@ */ #include "applist/ApplistPresenter.h" -#include "ability_manager.h" -#include "securec.h" -#include "components/ui_hexagons_list.h" -#include "components/ui_waterfall_list.h" -#include "TransitionType.h" #include "NativeRegisterManager.h" +#include "wearable_log.h" namespace OHOS { - REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter); - ApplistPresenter::ApplistPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::ApplistPresenter()"); - model = &ApplistModel::GetInstance(); - model->Init(); - model->SetPresenter(this); - } - - ApplistPresenter::~ApplistPresenter() - { - model->SetPresenter(nullptr); - } - - void ApplistPresenter::OnStart() - { - if (view_ == nullptr) { - return; - } - const AppItem *itemInfo = model->GetApplistItems(); - for (uint8 i = 0; i < model->GetAppListNum(); i++) { - view_->AddAppItemToList(itemInfo[i]); - } - view_->RefreshAppList(); - } - - void ApplistPresenter::OnResume() - { - if (GetCurrentStyle() == AppListStyle::FOOTBALL_STYLE) { - view_->StartFootBallAnimator(); - } else if (GetCurrentStyle() == AppListStyle::WATERFALL_STYLE) { - view_->ResumeWaterFallDraggable(); - } - } - - bool ApplistPresenter::OnRotate(UIView& view, const RotateEvent& event) - { - UICustomHexagonsList* hexagonsView = dynamic_cast(&view); - if (hexagonsView == nullptr) { - return false; - } - int8_t index = hexagonsView->GetFocusedImgIndex(); - uint8_t focusIndex_ = 0; - if (index >= 0) { - focusIndex_ = static_cast(index); - } - HexagonsItemView *itemView = dynamic_cast(hexagonsView->GetViewByIndex(focusIndex_)); - AppViewId viewId = itemView->GetViewId(); - if (FloatMore(hexagonsView->GetGlobalScale(), 2.0f)) { // 2.0 threshold for beginning transition - hexagonsView->StopRotateAnimator(); - NativeAbility::GetInstance().ChangeSlice(viewId, TransitionType::TRANSITION_HEXAGONS); - hexagonsView->ClearFocus(); - } - return true; - } - - bool ApplistPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - AppViewId viewId = VIEW_INVALID; - char *uid = nullptr; - TransitionType type = TransitionType::TRANSITION_INVALID; - AppListStyle style = GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - FootballItemView *itemView = dynamic_cast(&view); - viewId = itemView->GetViewId(); - uid = (char *)itemView->GetAppUid(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsItemView *itemView = dynamic_cast(&view); - UIHexagonsList *hexagonsView = dynamic_cast(itemView->GetParent()); - if (hexagonsView == nullptr || itemView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hexagonsView or itemView is nullptr"); - return false; - } - viewId = itemView->GetViewId(); - uid = (char *)itemView->GetAppUid(); - hexagonsView->SetDraggable(false); - hexagonsView->Scale(1.0f, itemView->GetViewIndex()); // switch focus to click view - type = TransitionType::TRANSITION_HEXAGONS; - } else if (style == AppListStyle::WATERFALL_STYLE) { - WaterfallItemView *itemView = dynamic_cast(&view); - UIWaterfallList *waterfallView = dynamic_cast(itemView->GetParent()); - if (waterfallView == nullptr || itemView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "waterfallView or itemView is nullptr"); - return false; - } - viewId = itemView->GetViewId(); - uid = (char *)itemView->GetAppUid(); - waterfallView->SetDraggable(false); - waterfallView->Scale(1.0f, itemView->GetViewIndex()); - type = TransitionType::TRANSITION_WATERFALL; - } else { - AppItemView *itemView = dynamic_cast(&view); - if (itemView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "itemView is nullptr", viewId); - return false; - } - viewId = itemView->GetViewId(); - uid = (char *)itemView->GetAppUid(); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d", viewId); - if (viewId < VIEW_MAX_INTER_APP) { - if (viewId == VIEW_SETTING && style == AppListStyle::APPLIST_STYLE) { - NativeAbility::GetInstance().ChangeSlice(viewId, type, gSliceDefaultPriority, true); - } else { - NativeAbility::GetInstance().ChangeSlice(viewId, type); - } - return true; - } else if (viewId == VIEW_EXTERN_APP) { -#ifdef JS_ENABLE - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", uid); - Want *want = new Want(); - memset_s(want, sizeof(Want), 0, sizeof(Want)); - ElementName startElement = {}; - startElement.abilityName = (char *)"default"; - startElement.bundleName = uid; - startElement.deviceId = nullptr; - SetWantElement(want, startElement); - if (viewId == VIEW_SETTING && style == AppListStyle::APPLIST_STYLE) { - StartAbilityWithAnimation(want, static_cast(type), true); - } else { - StartAbilityWithAnimation(want, static_cast(type), false); - } - ClearWant(want); - delete want; - return true; -#endif - } - return false; - } - - void ApplistPresenter::OnItemSelected(int16 index, UIView *view) - { - UNUSED(index); - if (view != nullptr) { - itemViewSele = static_cast(view); - itemViewSele->SelectedChange(); +ApplistPresenter::ApplistPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::ApplistPresenter()"); + model = &ApplistModel::GetInstance(); + model->Init(); + model->SetPresenter(this); +} - if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { - preItemViewSele->Reset(); - } - preItemViewSele = itemViewSele; - } - } - void ApplistPresenter::SetStartIndex(uint16_t index) - { - model->SetStartIndex(index); +ApplistPresenter::~ApplistPresenter() +{ + model->SetPresenter(nullptr); +} +void ApplistPresenter::OnStart() +{ + if (view_ == nullptr) { return; } - - uint16_t ApplistPresenter::GetStartIndex(void) - { - return model->GetStartIndex(); - } - - void ApplistPresenter::SetHeadItemY(int y) - { - model->SetHeadItemY(y); - } - - int ApplistPresenter::GetHeadItemY(void) - { - return model->GetHeadItemY(); - } - - uint8_t ApplistPresenter::GetListItemNum(void) - { - return model->GetAppListNum(); - } - - AppListStyle ApplistPresenter::GetCurrentStyle(void) - { - return model->GetCurrentStyle(); + const AppItem *itemInfo = model->GetApplistItems(); + for (uint8 i = 0; i < model->GetAppListNum(); i++) { + view_->AddAppItemToList(itemInfo[i]); } + view_->RefreshAppList(); +} - ApplistView* ApplistPresenter::GetAppListView() - { - return view_; - } +void ApplistPresenter::OnResume() +{ + view_->OnResume(); +} +ApplistView* ApplistPresenter::GetAppListView() +{ + return view_; +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistView.cpp index fbb18801e..7c15fc37e 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ApplistView.cpp @@ -5,383 +5,63 @@ * Create: 2021-09-18 */ -#include "components/ui_view_group.h" #include "applist/ApplistView.h" #include "applist/ApplistPresenter.h" -#include "applist/AppItemView.h" +#include "applist/DesktopFactory.h" #include "common/image_cache_manager.h" -#include "common/screen.h" -#include "hal_tick.h" namespace OHOS { -static constexpr int16 NUM_2 = 2; -static constexpr int16 MAX_SCROLL_DIS = 1000; - -ApplistView::ApplistView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ApplistView "); -} - -ApplistView::~ApplistView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView "); - if (listAdapter_ != nullptr) { - delete listAdapter_; - listAdapter_ = nullptr; - } - if (contentList_ != nullptr) { - delete contentList_; - contentList_ = nullptr; - } - if (dragListener_ != nullptr) { - delete dragListener_; - dragListener_ = nullptr; - } - if (hexagonsList_ != nullptr) { - delete hexagonsList_; - hexagonsList_ = nullptr; - } - if (footballList_ != nullptr) { - delete footballList_; - footballList_ = nullptr; - } - if (waterfallList_ != nullptr) { - delete waterfallList_; - waterfallList_ = nullptr; - } - if (callback_ != nullptr) { - delete callback_; - callback_ = nullptr; - } - enterAnimator_ = nullptr; -} - void ApplistView::OnStart() { - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - FootballStyleOnStart(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsStyleOnStart(); - } else if (style == AppListStyle::WATERFALL_STYLE) { - WaterfallStyleOnStart(); - } else { - ListStyleOnStart(); - } -} - -void ApplistView::FootballStyleOnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::FootballStyleOnStart "); - if (footballList_ == nullptr) { - footballList_ = new UIIcosahedronView(); - } - footballList_->SetThrowDrag(true); - if (footballDefaultImg_ == nullptr) { - footballDefaultImg_ = ImageCacheManager::GetInstance().LoadSingleRes(PNG_APPLIST_NOTSETUSE_IMG); - if (footballDefaultImg_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load res faild"); - return; - } - } - if (callback_ == nullptr) { - callback_ = new FootballAnimatorCallback(footballList_, 30, 200); // 30: Initial Size 200: Final display size - } - footballList_->SetDefaultImage(footballDefaultImg_); - footballList_->SetPosition(0, 0, GetRootContainer()->GetWidth(), GetRootContainer()->GetHeight()); - enterAnimator_ = callback_->GetAnimator(); - AddViewToRootContainer(footballList_); - if (callback_ != nullptr) { - callback_->SetStartTime(HALTick::GetInstance().GetTime()); - } -} - -void ApplistView::HexagonsStyleOnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart "); - if (hexagonsList_ == nullptr) { - hexagonsList_ = new UICustomHexagonsList(); - } - hexagonsList_->SetPosition(0, 0, GetRootContainer()->GetWidth(), GetRootContainer()->GetHeight()); // 2, two - imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient - imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient - hexagonsList_->SetImageDistance(imgDistance_); - hexagonsList_->SetImageSizeInCenter(imgSize_); - int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? - hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half - hexagonsList_->SetScrollBlankSize(blankSize); - hexagonsList_->SetReboundSize(blankSize); - hexagonsList_->SetThrowDrag(true); - hexagonsList_->SetOnRotateListener(presenter_); - hexagonsList_->RequestFocus(); - AddViewToRootContainer(hexagonsList_); -} - -void ApplistView::WaterfallStyleOnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::WaterfallStyleOnStart "); - if (waterfallList_ == nullptr) { - waterfallList_ = new UIWaterfallList(); - } - waterfallList_->SetPosition(0, 0, GetRootContainer()->GetWidth(), GetRootContainer()->GetHeight()); - imgDistance_ = waterfallList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient - imgSize_ = waterfallList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient - waterfallList_->SetImageDistance(imgDistance_); - waterfallList_->SetImageSizeInCenter(imgSize_); - int16_t blankSize = waterfallList_->GetRelativeRect().GetWidth() > waterfallList_->GetRelativeRect().GetHeight() ? - waterfallList_->GetRelativeRect().GetWidth() / 2 : waterfallList_->GetRelativeRect().GetHeight() / 2; // 2, half - waterfallList_->SetThrowDrag(true); - uint16_t layoutHeight = static_cast(imgDistance_ * Sin(60)); - waterfallList_->SetReboundSize(layoutHeight); // 60: degree, row's layout height - waterfallList_->SetScrollBlankSize(layoutHeight, UIAbstractScroll::Direction::TOP); - waterfallList_->SetScrollBlankSize(Screen::GetInstance().GetHeight() / 2 - layoutHeight, // 2: half - UIAbstractScroll::Direction::BOTTOM); - waterfallList_->RequestFocus(); - waterfallList_->SetRotateFactor(10); // 10, empirical coefficient - waterfallList_->SetOnRotateListener(presenter_); - waterfallList_->SetTouchable(false); - waterfallList_->SetDraggable(false); // ensure that it can't be dragged during animation to avoid error display - AddViewToRootContainer(waterfallList_); -} - -void ApplistView::ListStyleOnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart"); - listAdapter_ = new ApplistAdapter(); - if (listAdapter_ == nullptr) { - return; - } - listAdapter_->SetItemClickListener(presenter_); - - contentList_ = new UIList(UIList::VERTICAL); - if (contentList_ == nullptr) { - return; - } - contentList_->SetPosition(0, 0); - contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2); - contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position - contentList_->SetDraggable(true); - contentList_->SetThrowDrag(true); - contentList_->EnableAutoAlign(true); - contentList_->SetScrollStateListener(presenter_); - contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); - contentList_->SetYScrollBarVisible(true); - - dragListener_ = new AppListOnDragListener(); - if (dragListener_ == nullptr) { - return; - } - contentList_->SetOnDragListener(dragListener_); - AddViewToRootContainer(contentList_); -} - -void ApplistView::ResumeWaterFallDraggable() -{ - if (waterfallList_ != nullptr) { - waterfallList_->SetTouchable(true); - waterfallList_->SetDraggable(true); // resume touchable after transition animation - } -} - -void ApplistView::StartFootBallAnimator() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::StartFootBallAnimator"); - if (enterAnimator_ != nullptr) { - enterAnimator_->Start(); + if (desktopFragment_ != nullptr) { + OnStop(); } + DesktopStyle style = SettingDesktopModel::GetInstance().GetDesktopStyle(); + desktopFragment_ = DesktopFactory::GetInstance().CreateDesktopStyle(style); + desktopFragment_->SetPosition(0, 0, GetRootContainer()->GetWidth(), GetRootContainer()->GetHeight()); + desktopFragment_->CreateView(); + AddViewToRootContainer(desktopFragment_->GetFragmentView()); } void ApplistView::OnStop() { - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - FootballStyleOnStop(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsStyleOnStop(); - } else if (style == AppListStyle::WATERFALL_STYLE) { - WaterfallStyleOnStop(); - } else { - ListStyleOnStop(); - } - return; -} - -void ApplistView::FootballStyleOnStop() -{ - if (enterAnimator_ != nullptr) { - enterAnimator_->Stop(); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::FootballStyleOnStop"); - if (footballDefaultImg_ != nullptr) { - ImageCacheManager::GetInstance().UnloadSingleRes(PNG_APPLIST_NOTSETUSE_IMG); - footballDefaultImg_ = nullptr; - } - if (footballList_ != nullptr) { - footballList_->RemoveAll(); - } - ListNode* viewNode = footballItemList_.Head(); - while (viewNode != footballItemList_.End()) { - delete(viewNode->data_); - viewNode = viewNode->next_; - } - footballItemList_.Clear(); -} - -void ApplistView::HexagonsStyleOnStop() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop"); - if (hexagonsList_ != nullptr) { - hexagonsList_->RemoveAll(); - } - ListNode* viewNode = listHexagonsView_.Head(); - while (viewNode != listHexagonsView_.End()) { - delete(viewNode->data_); - viewNode = viewNode->next_; - } - listHexagonsView_.Clear(); -} - -void ApplistView::WaterfallStyleOnStop() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::WaterfallStyleOnStop"); - if (waterfallList_ != nullptr) { - waterfallList_->RemoveAll(); - } - ListNode* viewNode = waterfallItemList_.Head(); - while (viewNode != waterfallItemList_.End()) { - delete(viewNode->data_); - viewNode = viewNode->next_; + if (desktopFragment_ == nullptr) { + return; } - waterfallItemList_.Clear(); + desktopFragment_->DestroyView(); + delete desktopFragment_; + desktopFragment_ = nullptr; } -void ApplistView::ListStyleOnStop() +void ApplistView::OnResume() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop"); - int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); - int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); - presenter_->SetHeadItemY(listHeadY); - presenter_->SetStartIndex(listHeadIndex); -} - -void ApplistView::LoadAppIconImage(UIImageView *view, const uint32_t id, const char *path) -{ - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(id, path); - if (image == nullptr) { - GRAPHIC_LOGE("Load App Icon path %s Image %x fail\n", path, id); + if (desktopFragment_ == nullptr) { return; } - view->SetSrc(image); + desktopFragment_->ResumeView(); } void ApplistView::AddAppItemToList(const AppItem &item) { - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - FootballItemView *itemView = new FootballItemView(); - itemView->SetItemInfo(item); - if (item.iconHexagon == nullptr && item.hexagonPath != nullptr) { - LoadAppIconImage(itemView, item.hexagonId, item.hexagonPath); - } else { - itemView->SetSrc(item.iconHexagon); - } - itemView->SetTouchable(true); - itemView->SetOnClickListener(presenter_); - footballList_->Add(itemView); - footballItemList_.PushBack(itemView); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsItemView *itemView = new HexagonsItemView(); - itemView->SetItemInfo(item); - if (item.iconSmall == nullptr && item.resPath != nullptr) { - LoadAppIconImage(itemView, item.resId, item.resPath); - } else { - itemView->SetSrc(item.iconSmall); - } - itemView->SetTouchable(true); - itemView->SetOnClickListener(presenter_); - hexagonsList_->Add(itemView); - listHexagonsView_.PushBack(itemView); - } else if (style == AppListStyle::WATERFALL_STYLE) { - WaterfallItemView *itemView = new WaterfallItemView(); - itemView->SetItemInfo(item); - if (item.iconSmall == nullptr && item.resPath != nullptr) { - LoadAppIconImage(itemView, item.resId, item.resPath); - } else { - itemView->SetSrc(item.iconSmall); - } - itemView->SetTouchable(true); - itemView->SetOnClickListener(presenter_); - waterfallList_->Add(itemView); - waterfallItemList_.PushBack(itemView); - } else { - listAdapter_->AddListItem(item); + if (desktopFragment_ == nullptr) { + return; } + desktopFragment_->AddAppItemToList(item); } void ApplistView::ClearAppItemToList() { - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == FOOTBALL_STYLE) { - FootballStyleOnStop(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsStyleOnStop(); - } else if (style == AppListStyle::WATERFALL_STYLE) { - WaterfallStyleOnStop(); - } else { - listAdapter_->ClearItem(); - } -} - -void ApplistView::RefreshAppList(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::RefreshAppList"); - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - footballList_->RefreshIcosahedron(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - hexagonsList_->LayoutChildren(true); - } else if (style == AppListStyle::WATERFALL_STYLE) { - waterfallList_->LayoutChildren(true); - } else { - uint16_t startIndex = 0; - int16_t headY = 0; - if (presenter_->GetStartIndex() >= presenter_->GetListItemNum()) { - startIndex = presenter_->GetListItemNum() - 1; - headY = VERTICAL_RESOLUTION / NUM_2; - } else { - startIndex = presenter_->GetStartIndex(); - headY = presenter_->GetHeadItemY(); - if (headY == 0) { - headY = VERTICAL_RESOLUTION / NUM_2; - } - } - contentList_->SetAdapter(listAdapter_); - contentList_->ScrollTo(startIndex); - contentList_->ScrollBy(headY); - contentList_->RefreshList(); + if (desktopFragment_ == nullptr) { + return; } + desktopFragment_->ClearAppItemToList(); } -void FootballAnimatorCallback::Callback(UIView *view) +void ApplistView::RefreshAppList() { - if (HALTick::GetInstance().GetElapseTime(startTime_) < 300) { // 300, empirical coefficient + if (desktopFragment_ == nullptr) { return; } - if (!isStartAnim_) { - animator_->Stop(); - animator_->Start(); - isStartAnim_ = true; - } - UIIcosahedronView* footView = dynamic_cast(view); - int16_t el = EasingEquation::LinearEaseNone(startPos_, endPos_, animator_->GetRunTime(), animator_->GetTime()); - footView->SetSideLength(el); - footView->RefreshIcosahedron(); - const Vector3 rotateStart(Screen::GetInstance().GetWidth() / 2.0, // 2.0: divisor - Screen::GetInstance().GetHeight() / 2.0, 0); // 2.0: divisor - const Vector3 rotateEnd(0, 0, 0); - // 270 : stop angle - int16_t angle = EasingEquation::LinearEaseNone(0, 270, animator_->GetRunTime(), animator_->GetTime()); - footView->RotatePlanes(angle, rotateStart, rotateEnd); + desktopFragment_->RefreshAppList(); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/DesktopFactory.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/DesktopFactory.cpp new file mode 100644 index 000000000..621ebccd4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/DesktopFactory.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: DesktopFactory + * Author: + * Create: 2025-07 + */ + +#include "applist/DesktopFactory.h" +#include "wearable_log.h" + +namespace OHOS { + +void DesktopFactory::RegisterDesktopStyle(const uint16_t style, DesktopInterface* desktop) +{ + if (desktop == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't register desktop using null proxy"); + return; + } + if (desktops_.find(style) != desktops_.end()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "desktop style %d has already been registered", style); + return; + } else { + desktops_.insert({style, desktop}); + } +} + +UIDesktopFragment* DesktopFactory::CreateDesktopStyle(uint16_t style) +{ + auto it = desktops_.find(style); + if (it != desktops_.end()) { + return it->second->CreateDesktop(); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Desktop style:%d was not registered", style); + return nullptr; + } +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/FootballDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/FootballDesktopFragment.cpp new file mode 100644 index 000000000..53dd8e9f5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/FootballDesktopFragment.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: FootballDesktopFragment.cpp + * Author: + * Create: 2025-07-04 + */ + +#include "applist/FootballDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "hal_tick.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(FOOTBALL_STYLE, FootballDesktopFragment); + +void FootballDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::OnCreateView "); + if (footballList_ == nullptr) { + footballList_ = new UIIcosahedronView(); + } + footballList_->SetThrowDrag(true); + if (footballDefaultImg_ == nullptr) { + footballDefaultImg_ = ImageCacheManager::GetInstance().LoadSingleRes(PNG_APPLIST_NOTSETUSE_IMG); + if (footballDefaultImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load res faild"); + return; + } + } + if (callback_ == nullptr) { + callback_ = new FootballAnimatorCallback(footballList_, 30, 200); // 30: Initial Size 200: Final display size + } + footballList_->SetDefaultImage(footballDefaultImg_); + footballList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + enterAnimator_ = callback_->GetAnimator(); + fragmentView_.Add(footballList_); + if (callback_ != nullptr) { + callback_->SetStartTime(HALTick::GetInstance().GetTime()); + } +} + +void FootballDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (footballList_ != nullptr) { + delete footballList_; + footballList_ = nullptr; + } + if (footballDefaultImg_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(PNG_APPLIST_NOTSETUSE_IMG); + footballDefaultImg_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + enterAnimator_ = nullptr; +} + +void FootballDesktopFragment::OnResumeView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::OnResumeView"); + if (enterAnimator_ != nullptr) { + enterAnimator_->Start(); + } +} + +bool FootballDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + FootballItemView *itemView = dynamic_cast(&view); + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_INVALID, FOOTBALL_STYLE); +} + +void FootballDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::AddAppItemToList"); + FootballItemView *itemView = new FootballItemView(); + if (!itemView->SetItemInfo(item)) { + delete itemView; + return; + } + itemView->SetTouchable(true); + itemView->SetOnClickListener(this); + footballList_->Add(itemView); + footballItemList_.PushBack(itemView); +} + +void FootballDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::ClearAppItemToList"); + if (enterAnimator_ != nullptr) { + enterAnimator_->Stop(); + } + if (footballList_ != nullptr) { + footballList_->RemoveAll(); + } + ListNode* viewNode = footballItemList_.Head(); + while (viewNode != footballItemList_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + footballItemList_.Clear(); +} + +void FootballDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FootballDesktopFragment::RefreshAppList"); + footballList_->RefreshIcosahedron(); +} + +void FootballAnimatorCallback::Callback(UIView *view) +{ + if (HALTick::GetInstance().GetElapseTime(startTime_) < 300) { // 300, empirical coefficient + return; + } + if (!isStartAnim_) { + animator_->Stop(); + animator_->Start(); + isStartAnim_ = true; + } + UIIcosahedronView* footView = dynamic_cast(view); + int16_t el = EasingEquation::LinearEaseNone(startPos_, endPos_, animator_->GetRunTime(), animator_->GetTime()); + footView->SetSideLength(el); + footView->RefreshIcosahedron(); + const Vector3 rotateStart(Screen::GetInstance().GetWidth() / 2.0, // 2.0: divisor + Screen::GetInstance().GetHeight() / 2.0, 0); // 2.0: divisor + const Vector3 rotateEnd(0, 0, 0); + // 270 : stop angle + int16_t angle = EasingEquation::LinearEaseNone(0, 270, animator_->GetRunTime(), animator_->GetTime()); + footView->RotatePlanes(angle, rotateStart, rotateEnd); +} + +FootballItemView::~FootballItemView() +{ + if (itemInfo_.iconHexagon == nullptr && itemInfo_.hexagonPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.hexagonId, itemInfo_.hexagonPath); + } +} + +bool FootballItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; + if (itemInfo.iconHexagon == nullptr && itemInfo.hexagonPath != nullptr) { + ImageInfo* image = + ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.hexagonId, itemInfo.hexagonPath); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", + itemInfo.hexagonId, itemInfo.hexagonPath); + return false; + } + SetSrc(image); + } else { + SetSrc(itemInfo.iconHexagon); + } + return true; +} + +AppViewId FootballItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} + +const char *FootballItemView::GetAppUid() +{ + return itemInfo_.uid; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp new file mode 100644 index 000000000..23e10139b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: HexagonsDesktopFragment.cpp + * Author: + * Create: 2025-07-04 + */ + +#include "applist/HexagonsDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "common/image_cache_manager.h" +#include "NativeAbility.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(HEXAGONS_STYLE, HexagonsDesktopFragment); + +void HexagonsDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnCreateView "); + if (hexagonsList_ == nullptr) { + hexagonsList_ = new UICustomHexagonsList(); + } + hexagonsList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); // 2, two + imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? + hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half + hexagonsList_->SetScrollBlankSize(blankSize); + hexagonsList_->SetReboundSize(blankSize); + hexagonsList_->SetThrowDrag(true); + hexagonsList_->SetOnRotateListener(this); + hexagonsList_->RequestFocus(); + fragmentView_.Add(hexagonsList_); +} + +void HexagonsDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (hexagonsList_ != nullptr) { + delete hexagonsList_; + hexagonsList_ = nullptr; + } +} + +bool HexagonsDesktopFragment::OnRotate(UIView& view, const RotateEvent& event) +{ + UICustomHexagonsList* hexagonsView = dynamic_cast(&view); + if (hexagonsView == nullptr) { + return false; + } + int8_t index = hexagonsView->GetFocusedImgIndex(); + uint8_t focusIndex_ = 0; + if (index >= 0) { + focusIndex_ = static_cast(index); + } + HexagonsItemView *itemView = dynamic_cast(hexagonsView->GetViewByIndex(focusIndex_)); + AppViewId viewId = itemView->GetViewId(); + if (FloatMore(hexagonsView->GetGlobalScale(), 2.0f)) { // 2.0 threshold for beginning transition + hexagonsView->StopRotateAnimator(); + NativeAbility::GetInstance().ChangeSlice(viewId, TransitionType::TRANSITION_HEXAGONS); + hexagonsView->ClearFocus(); + } + return true; +} + +bool HexagonsDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + HexagonsItemView *itemView = dynamic_cast(&view); + UIHexagonsList *hexagonsView = dynamic_cast(itemView->GetParent()); + if (hexagonsView == nullptr || itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hexagonsView or itemView is nullptr"); + return false; + } + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + hexagonsView->SetDraggable(false); + hexagonsView->Scale(1.0f, itemView->GetViewIndex()); // switch focus to click view + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_HEXAGONS, HEXAGONS_STYLE); +} + +void HexagonsDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::AddAppItemToList"); + HexagonsItemView *itemView = new HexagonsItemView(); + if (!itemView->SetItemInfo(item)) { + delete itemView; + return; + } + itemView->SetTouchable(true); + itemView->SetOnClickListener(this); + hexagonsList_->Add(itemView); + listHexagonsView_.PushBack(itemView); +} + +void HexagonsDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::ClearAppItemToList"); + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); + } + ListNode* viewNode = listHexagonsView_.Head(); + while (viewNode != listHexagonsView_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + listHexagonsView_.Clear(); +} + +void HexagonsDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::RefreshAppList"); + hexagonsList_->LayoutChildren(true); +} + +HexagonsItemView::~HexagonsItemView() +{ + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } +} + +bool HexagonsItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; + if (itemInfo.iconSmall == nullptr && itemInfo.resPath != nullptr) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", + itemInfo.resId, itemInfo.resPath); + return false; + } + SetSrc(image); + } else { + SetSrc(itemInfo.iconSmall); + } + return true; +} + +AppViewId HexagonsItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} + +const char *HexagonsItemView::GetAppUid() +{ + return itemInfo_.uid; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp new file mode 100644 index 000000000..15f446a12 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: ListDesktopFragment.cpp + * Author: + * Create: 2025-07-04 + */ + +#include "applist/ListDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "applist/ApplistModel.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(APPLIST_STYLE, ListDesktopFragment); + +static constexpr int16 NUM_2 = 2; +static constexpr int16 MAX_SCROLL_DIS = 1000; + +void ListDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::OnCreateView"); + listAdapter_ = new ApplistAdapter(); + if (listAdapter_ == nullptr) { + return; + } + listAdapter_->SetItemClickListener(this); + + contentList_ = new UIList(UIList::VERTICAL); + if (contentList_ == nullptr) { + return; + } + contentList_->SetPosition(0, 0); + contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2); + contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position + contentList_->SetDraggable(true); + contentList_->SetThrowDrag(true); + contentList_->EnableAutoAlign(true); + contentList_->SetScrollStateListener(this); + contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); + contentList_->SetYScrollBarVisible(true); + + dragListener_ = new AppListOnDragListener(); + if (dragListener_ == nullptr) { + return; + } + contentList_->SetOnDragListener(dragListener_); + fragmentView_.Add(contentList_); +} + + +void ListDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::OnDestroyView"); + int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); + int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); + ApplistModel *model = &ApplistModel::GetInstance(); + model->SetHeadItemY(listHeadY); + model->SetStartIndex(listHeadIndex); + + ClearAppItemToList(); + + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + if (contentList_ != nullptr) { + delete contentList_; + contentList_ = nullptr; + } + if (dragListener_ != nullptr) { + delete dragListener_; + dragListener_ = nullptr; + } +} + +bool ListDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + AppItemView *itemView = dynamic_cast(&view); + if (itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "itemView is nullptr"); + return false; + } + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_INVALID, APPLIST_STYLE); +} + +void ListDesktopFragment::OnItemSelected(int16 index, UIView *view) +{ + UNUSED(index); + if (view != nullptr) { + itemViewSele = static_cast(view); + itemViewSele->SelectedChange(); + + if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { + preItemViewSele->Reset(); + } + preItemViewSele = itemViewSele; + } +} + +void ListDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::AddAppItemToList"); + listAdapter_->AddListItem(item); +} + +void ListDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::ClearAppItemToList"); + listAdapter_->ClearItem(); +} + +void ListDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::RefreshAppList"); + uint16_t startIndex = 0; + int16_t headY = 0; + ApplistModel *model = &ApplistModel::GetInstance(); + if (model->GetStartIndex() >= model->GetAppListNum()) { + startIndex = model->GetAppListNum() - 1; + headY = VERTICAL_RESOLUTION / NUM_2; + } else { + startIndex = model->GetStartIndex(); + headY = model->GetHeadItemY(); + if (headY == 0) { + headY = VERTICAL_RESOLUTION / NUM_2; + } + } + contentList_->SetAdapter(listAdapter_); + contentList_->ScrollTo(startIndex); + contentList_->ScrollBy(headY); + contentList_->RefreshList(); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp new file mode 100644 index 000000000..c735620d7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlanetDesktop + * Created: 2025-07-29 + */ + +#include "applist/PlanetDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "applist/ApplistModel.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(PLANET_STYLE, PlanetDesktopFragment); + +static constexpr int16 LABEL_FONT_SIZE = 15; + +void PlanetDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnCreateView "); + imgSize_ = 100; // 100, size of item + int16_t imageDistance = 5; // 5, image distance + if (planetList_ == nullptr) { + planetList_ = new UICustomPlanetList(imgSize_, imageDistance); + } + planetList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + planetList_->SetDraggable(true); + planetList_->SetThrowDrag(true); + planetList_->SetItemClickListener(this); + planetList_->RequestFocus(); + fragmentView_.Add(planetList_); +} + +void PlanetDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (planetList_ != nullptr) { + delete planetList_; + planetList_ = nullptr; + } +} + +bool PlanetDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + PlanetItemView *itemView = dynamic_cast(&view); + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_INVALID, PLANET_STYLE); +} + +void PlanetDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::AddAppItemToList"); + PlanetItemView* itemView = new PlanetItemView(); + UILabel* label = new UILabel(); + itemView->SetItemInfo(item); + itemView->SetSrc(item.iconSmall); + itemView->SetTouchable(true); + itemView->SetAutoEnable(false); + itemView->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); + itemView->SetOnClickListener(this); + label->SetText(item.label); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetVisible(false); + label->SetHeight(30); // 30, label height + label->SetWidth(100); // 100, label width + planetList_->AddItemVIew(itemView); + planetList_->AddLabel(label); + pltItemList_.PushBack(itemView); + pltLabelList_.PushBack(label); +} + +void PlanetDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::ClearAppItemToList"); + int16_t offsetX = 0; + int16_t offsetY = 0; + ApplistModel *model = &ApplistModel::GetInstance(); + + planetList_->RestoreItemState(); + planetList_->GetLastOffset(offsetX, offsetY); + model->SetLastOffset(offsetX, offsetY); + if (planetList_ != nullptr) { + planetList_->RemoveAll(); + } + ListNode* viewNode = pltItemList_.Head(); + while (viewNode != pltItemList_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + pltItemList_.Clear(); + ListNode* labelNode = pltLabelList_.Head(); + while (labelNode != pltLabelList_.End()) { + delete(labelNode->data_); + labelNode = labelNode->next_; + } + pltLabelList_.Clear(); +} + +void PlanetDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::RefreshAppList"); + int16_t offsetX = 0; + int16_t offsetY = 0; + ApplistModel *model = &ApplistModel::GetInstance(); + model->GetLastOffset(offsetX, offsetY); + planetList_->SetLastOffset(offsetX, offsetY); + planetList_->LayoutChildren(true); + planetList_->AddClickListenerToAppItems(); +} + +void PlanetItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; +} + +AppViewId PlanetItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} + +const char *PlanetItemView::GetAppUid() +{ + return itemInfo_.uid; +} + +const char *PlanetItemView::GetAppLabel() +{ + return itemInfo_.label; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/SphereDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/SphereDesktopFragment.cpp new file mode 100644 index 000000000..844cb8be5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/SphereDesktopFragment.cpp @@ -0,0 +1,192 @@ + /* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: SphereDesktopFragment + * Author: Hisi Graphic Team + * Created: 2025-09 + */ + +#include +#include "applist/SphereDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "common/image_cache_manager.h" +#include "NativeAbility.h" +#include "hal_tick.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(SPHERE_STYLE, SphereDesktopFragment); + +void SphereDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::OnCreateView "); + if (sphereView_ == nullptr) { + sphereView_ = new UISphereView(1); + } + sphereView_->SetThrowDrag(true); + + if (callback_ == nullptr) { + callback_ = new SphereAnimatorCallback(sphereView_, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + } + + sphereView_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + enterAnimator_ = callback_->GetAnimator(); + sphereView_->SetVisible(false); + fragmentView_.Add(sphereView_); + if (callback_ != nullptr) { + callback_->SetStartTime(HALTick::GetInstance().GetTime()); + } +} + +void SphereDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (sphereView_ != nullptr) { + delete sphereView_; + sphereView_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + enterAnimator_ = nullptr; +} + +void SphereDesktopFragment::OnResumeView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::OnResumeView"); + if (enterAnimator_ != nullptr) { + enterAnimator_->Start(); + } +} + +bool SphereDesktopFragment::OnRotate(UIView& view, const RotateEvent& event) +{ + UISphereView *sphereView = dynamic_cast(&view); + if (sphereView == nullptr) { + return false; + } + sphereView->UpdateItemAngle(event.GetRotate()); + return true; +} + +bool SphereDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + SphereItemView *itemView = dynamic_cast(&view); + UISphereView *sphereView = dynamic_cast(itemView->GetParent()); + if (sphereView == nullptr || itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sphereView or itemView is nullptr"); + return false; + } + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + sphereView->SetDraggable(false); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_FADEINOUT, SPHERE_STYLE); +} + +void SphereDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::AddAppItemToList"); + SphereItemView *itemView = new SphereItemView(); + if (!itemView->SetItemInfo(item)) { + delete itemView; + return; + } + itemView->SetTouchable(true); + itemView->SetOnClickListener(this); + sphereView_->Add(itemView); + listSphereView_.PushBack(itemView); + sphereView_->SetNumberOfRow((listSphereView_.Size() + 2) / 3); // 控制在3排显示 +} + +void SphereDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::ClearAppItemToList"); + if (enterAnimator_ != nullptr) { + enterAnimator_->Stop(); + } + if (sphereView_ != nullptr) { + sphereView_->RemoveAll(); + } + ListNode* viewNode = listSphereView_.Head(); + while (viewNode != listSphereView_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + listSphereView_.Clear(); +} + +void SphereDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SphereDesktopFragment::RefreshAppList"); + sphereView_->LayoutChildren(true); +} + +void SphereAnimatorCallback::Callback(UIView *view) +{ + if (HALTick::GetInstance().GetElapseTime(startTime_) < 300) { // 300: 动画延迟显示时间,观感效果更好 + angle_=0; + return; + } + if (!view->IsVisible()) { + view->SetVisible(true); + } + if (!isStartAnim_) { + animator_->Stop(); + animator_->Start(); + isStartAnim_ = true; + } + UISphereView* sphereView = dynamic_cast(view); + const int16_t precision = 1000;// 1000: 精度 + int16_t el = EasingEquation::QuadEaseOut(0, precision, animator_->GetRunTime(), animator_->GetTime()); + int roateAngle = el * 360 / precision; // 360 : 一共旋转360度 + sphereView->UpdateItemAngle(roateAngle - angle_); + angle_ = roateAngle; +} + +SphereItemView::~SphereItemView() +{ + if (imageView_ != nullptr) { + delete imageView_; + imageView_ = nullptr; + } + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } +} + +bool SphereItemView::SetItemInfo(const AppItem &itemInfo) +{ + if (imageView_ == nullptr) { + imageView_ = new UIImageView(); + } + itemInfo_ = itemInfo; + if (itemInfo.iconSmall == nullptr && itemInfo.resPath != nullptr) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", + itemInfo.resId, itemInfo.resPath); + return false; + } + imageView_->SetSrc(image); + } else { + imageView_->SetSrc(itemInfo.iconSmall); + } + Add(imageView_); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + Resize(imageView_->GetWidth(), imageView_->GetHeight()); + return true; +} + +AppViewId SphereItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} + +const char *SphereItemView::GetAppUid() +{ + return itemInfo_.uid; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/UIDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/UIDesktopFragment.cpp new file mode 100644 index 000000000..f4861713a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/UIDesktopFragment.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: UIDesktopFragment.cpp + * Author: + * Create: 2025-07-07 + */ + +#include "applist/UIDesktopFragment.h" +#include "common/image_cache_manager.h" +#include "ability_manager.h" +#include "NativeAbility.h" + +namespace OHOS { +void UIDesktopFragment::SetPosition(int16_t x, int16_t y, int16_t width, int16_t height) +{ + fragmentView_.SetPosition(x, y, width, height); +} + +bool UIDesktopFragment::SwitchView(AppViewId viewId, char *uid, TransitionType type, DesktopStyle style) +{ + if (viewId < VIEW_MAX_INTER_APP) { + if (viewId == VIEW_SETTING && style == DesktopStyle::APPLIST_STYLE) { + NativeAbility::GetInstance().ChangeSlice(viewId, type, gSliceDefaultPriority, true); + } else { + NativeAbility::GetInstance().ChangeSlice(viewId, type); + } + return true; + } else if (viewId == VIEW_EXTERN_APP) { +#ifdef JS_ENABLE + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UIDesktopFragment::OnClick bundleName = %s", uid); + Want *want = new Want(); + memset_s(want, sizeof(Want), 0, sizeof(Want)); + ElementName startElement = {}; + startElement.abilityName = (char *)"default"; + startElement.bundleName = uid; + startElement.deviceId = nullptr; + SetWantElement(want, startElement); + if (viewId == VIEW_SETTING && style == DesktopStyle::APPLIST_STYLE) { + StartAbilityWithAnimation(want, static_cast(type), true); + } else { + StartAbilityWithAnimation(want, static_cast(type), false); + } + ClearWant(want); + delete want; + return true; +#endif + } + return false; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/WaterfallDesktopFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/WaterfallDesktopFragment.cpp new file mode 100644 index 000000000..0a0a7ee09 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/applist/src/WaterfallDesktopFragment.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: WaterfallDesktopFragment.cpp + * Author: + * Create: 2025-07-04 + */ + +#include "applist/WaterfallDesktopFragment.h" +#include "applist/DesktopFactory.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" + +namespace OHOS { +REGIST_DESKTOP_STYLE(WATERFALL_STYLE, WaterfallDesktopFragment); + +void WaterfallDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnCreateView "); + if (waterfallList_ == nullptr) { + waterfallList_ = new UIWaterfallList(); + } + waterfallList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + imgDistance_ = waterfallList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = waterfallList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + waterfallList_->SetImageDistance(imgDistance_); + waterfallList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = waterfallList_->GetRelativeRect().GetWidth() > waterfallList_->GetRelativeRect().GetHeight() ? + waterfallList_->GetRelativeRect().GetWidth() / 2 : waterfallList_->GetRelativeRect().GetHeight() / 2; // 2, half + waterfallList_->SetThrowDrag(true); + uint16_t layoutHeight = static_cast(imgDistance_ * Sin(60)); + waterfallList_->SetReboundSize(layoutHeight); // 60: degree, row's layout height + waterfallList_->SetScrollBlankSize(layoutHeight, UIAbstractScroll::Direction::TOP); + waterfallList_->SetScrollBlankSize(Screen::GetInstance().GetHeight() / 2 - layoutHeight, // 2: half + UIAbstractScroll::Direction::BOTTOM); + waterfallList_->RequestFocus(); + waterfallList_->SetRotateFactor(10); // 10, empirical coefficient + waterfallList_->SetOnRotateListener(this); + waterfallList_->SetTouchable(false); + waterfallList_->SetDraggable(false); // ensure that it can't be dragged during animation to avoid error display + fragmentView_.Add(waterfallList_); +} + +void WaterfallDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (waterfallList_ != nullptr) { + delete waterfallList_; + waterfallList_ = nullptr; + } +} + +void WaterfallDesktopFragment::OnResumeView() +{ + if (waterfallList_ != nullptr) { + waterfallList_->SetTouchable(true); + waterfallList_->SetDraggable(true); // resume touchable after transition animation + } +} + +bool WaterfallDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + WaterfallItemView *itemView = dynamic_cast(&view); + UIWaterfallList *waterfallView = dynamic_cast(itemView->GetParent()); + if (waterfallView == nullptr || itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "waterfallView or itemView is nullptr"); + return false; + } + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + waterfallView->SetDraggable(false); + waterfallView->Scale(1.0f, itemView->GetViewIndex()); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_WATERFALL, APPLIST_STYLE); +} + +void WaterfallDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::AddAppItemToList"); + WaterfallItemView *itemView = new WaterfallItemView(); + if (!itemView->SetItemInfo(item)) { + delete itemView; + return; + } + itemView->SetTouchable(true); + itemView->SetOnClickListener(this); + waterfallList_->Add(itemView); + waterfallItemList_.PushBack(itemView); +} + +void WaterfallDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::ClearAppItemToList"); + if (waterfallList_ != nullptr) { + waterfallList_->RemoveAll(); + } + ListNode* viewNode = waterfallItemList_.Head(); + while (viewNode != waterfallItemList_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + waterfallItemList_.Clear(); +} + +void WaterfallDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::RefreshAppList"); + waterfallList_->LayoutChildren(true); +} + +WaterfallItemView::~WaterfallItemView() +{ + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } +} + +bool WaterfallItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; + if (itemInfo.iconSmall == nullptr && itemInfo.resPath != nullptr) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", + itemInfo.resId, itemInfo.resPath); + return false; + } + SetSrc(image); + } else { + SetSrc(itemInfo.iconSmall); + } + return true; +} + +AppViewId WaterfallItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} + +const char *WaterfallItemView::GetAppUid() +{ + return itemInfo_.uid; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodChartPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodChartPage.cpp new file mode 100644 index 000000000..bc2a3f832 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodChartPage.cpp @@ -0,0 +1,350 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodChartPage + * Create: 2025-06 + */ + +#include +#include +#include +#include +#include "components/ui_list_nested.h" +#include "components/ui_chart.h" +#include "components/ui_scroll_view_nested.h" +#include "common/image_cache_manager.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "AppViewIDs.h" +#include "ui_resource_blood.h" +#include "blood/BloodModel.h" +#include "blood/BloodChartPage.h" + +namespace OHOS { +static constexpr uint16_t PERSEC_BLOOD_FONT_SIZE = 60; +static constexpr uint16_t PERSEC_BLOOD_X = 203; +static constexpr uint16_t PERSEC_BLOOD_Y = 40; +static constexpr uint16_t PERSEC_BLOOD_WIDTH = 260; +static constexpr uint16_t PERSEC_BLOOD_HEIGHT = 53; +static constexpr uint16_t PERSEC_BLOOD_TEXT_X = 188; +static constexpr uint16_t PERSEC_BLOOD_TEXT_Y = 96; +static constexpr uint16_t PERSEC_BLOOD_TEXT_HEIGHT = 64; +static constexpr uint16_t COORDINATE_POINT_X = 70; +static constexpr uint16_t COORDINATE_POINT_Y = 120; +static constexpr uint16_t COORDINATE_HEIGHT = 156; +static constexpr uint16_t COORDINATE_WIDTH = 330; +static constexpr uint16_t BLOOD_LIMIT_FONT_SIZE = 30; +static constexpr uint16_t TOP_TEXT_WIDTH = 232; +static constexpr uint16_t TOP_TEXT_HEIGHT = 76; +static constexpr uint16_t TOP_TEXT_X = 107; +static constexpr uint16_t TOP_TEXT_Y = 352; +static constexpr uint16_t BOTTOM_TEXT_WIDTH = 35; +static constexpr uint16_t BOTTOM_TEXT_HEIGHT = 36; +static constexpr uint16_t BLOOD_LIMIT_FONT_SIZE_ONE = 24; +static constexpr uint16_t BLOOD_LABLE_FONT_SIZE_ONE = 16; +static constexpr uint16_t BOTTOM_TEXT_WIDTH_ONE = 89; +static constexpr uint16_t BOTTOM_TEXT_HEIGHT_ONE = 29; +static constexpr uint16_t BOTTOM_TEXT_ONE_X = 188; +static constexpr uint16_t BOTTOM_TEXT_ONE_Y = 105; +static constexpr uint16_t LABLE_XAXIS1_POSION_X = 50; +static constexpr uint16_t LABLE_XAXIS2_POSION_X = 210; +static constexpr uint16_t LABLE_XAXIS3_POSION_X = 370; +static constexpr uint16_t LABLE_XAXIS_POSION_Y = 275; +static constexpr uint16_t BLOOD_XAXIS_SETMARKNUM = 40; +static constexpr uint16_t BLOOD_YAXIS_SETMARKNUM = 3; +static constexpr uint16_t BLOOD_XAXIS_RANGE_MAX = 4; +static constexpr uint16_t BLOOD_YAXIS_RANGE_MAX = 200; +static constexpr uint16_t BLOOD_STYLE_LINE_NUM = 3; +static constexpr uint16_t BLOOD_CHART_IMAGE_POSION_X = 15; +static constexpr uint16_t BLOOD_CHART_IMAGE_POSION_Y = 140; +static constexpr uint16_t BLOOD_BIND_IMAGE_X = 140; +static constexpr uint16_t BLOOD_BIND_IMAGE_Y = 50; +static constexpr uint16_t BLOOD_BIND_IMAGE_WIDTH = 50; +static constexpr uint16_t BLOOD_BIND_IMAGE_HEIGHT = 50; +static constexpr char *BLOOD_RETEST_BUTTON = "retestButton"; + +const int g_imageAnimatorInfo[BLOOD_ANIMATOR_IMAGE_NUM] = { + IMAGE_BLOOD_FRAME00, IMAGE_BLOOD_FRAME01, IMAGE_BLOOD_FRAME02, IMAGE_BLOOD_FRAME03, IMAGE_BLOOD_FRAME04, + IMAGE_BLOOD_FRAME05, IMAGE_BLOOD_FRAME06, IMAGE_BLOOD_FRAME07, IMAGE_BLOOD_FRAME08, IMAGE_BLOOD_FRAME09, + IMAGE_BLOOD_FRAME10, IMAGE_BLOOD_FRAME11, IMAGE_BLOOD_FRAME12, IMAGE_BLOOD_FRAME13, IMAGE_BLOOD_FRAME14, + IMAGE_BLOOD_FRAME15, IMAGE_BLOOD_FRAME16, IMAGE_BLOOD_FRAME17, IMAGE_BLOOD_FRAME18, IMAGE_BLOOD_FRAME19, + IMAGE_BLOOD_FRAME20, IMAGE_BLOOD_FRAME21, IMAGE_BLOOD_FRAME22, IMAGE_BLOOD_FRAME23, IMAGE_BLOOD_FRAME24, + IMAGE_BLOOD_FRAME25, IMAGE_BLOOD_FRAME26, IMAGE_BLOOD_FRAME27, IMAGE_BLOOD_FRAME28, IMAGE_BLOOD_FRAME29, +}; + +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_CHART_PAGE, BloodChartPage, false); + +BloodChartPage::BloodChartPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodChartPage::BloodChartPage"); +} + +void BloodChartPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIViewGroup fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + mainImg_ = new UIImageView(); + if (mainImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new mainImg_ fail"); + return; + } + mainImg_->SetPosition(0, 0); + mainImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(mainImg_, BLOOD_IMAGE, IMAGE_BLOOD_BG); + group_->Add(mainImg_); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(PERSEC_BLOOD_X, PERSEC_BLOOD_Y); + labelTitle_->Resize(PERSEC_BLOOD_WIDTH, PERSEC_BLOOD_HEIGHT); + labelTitle_->SetStyle(STYLE_TEXT_FONT, PERSEC_BLOOD_FONT_SIZE); + labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetRollSpeed(0); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, PERSEC_BLOOD_FONT_SIZE); + + labelTestTime_ = new UILabel(); + if (labelTestTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTestTime_ fail"); + return; + } + labelTestTime_->SetText("刚刚"); + labelTestTime_->SetPosition(BOTTOM_TEXT_ONE_X, BOTTOM_TEXT_ONE_Y, BOTTOM_TEXT_WIDTH_ONE, BOTTOM_TEXT_HEIGHT_ONE); + labelTestTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LIMIT_FONT_SIZE_ONE); + labelTestTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTestTime_->SetStyle(STYLE_TEXT_COLOR, 0xFFCCCCCC); + labelTestTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + bloodMeasurementInfo info = BloodModel::GetInstance().GetBlood(); + std::string strBlood = std::to_string(info.blood) + "%"; + labelTitle_->SetText(strBlood.c_str()); + + dataSerial_ = new UIChartDataSerial(); + if (dataSerial_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new dataSerial_ fail"); + return; + } + dataSerial_->SetMaxDataCount(BLOOD_XAXIS_RANGE_MAX); + // 打桩数据,真实测量数据的存储和更新需要客户自实现 + Point pointArray[BLOOD_XAXIS_RANGE_MAX] = {{0, info.blood}, {1, 75}, {2, 100}, {3, 80}}; + dataSerial_->AddPoints(pointArray, BLOOD_XAXIS_RANGE_MAX); + dataSerial_->SetLineColor(Color::Green()); + dataSerial_->SetFillColor(Color::Green()); + dataSerial_->EnableGradient(true); + + chartPillar_ = new UIChartPillar(); + if (chartPillar_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new chartPillar_ fail"); + return; + } + chartPillar_->SetPosition(COORDINATE_POINT_X, COORDINATE_POINT_Y); + chartPillar_->SetWidth(COORDINATE_WIDTH); + chartPillar_->SetHeight(COORDINATE_HEIGHT); + chartPillar_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + chartPillar_->SetStyle(STYLE_BACKGROUND_OPA, 0); + chartPillar_->SetStyle(STYLE_LINE_WIDTH, BLOOD_STYLE_LINE_NUM); + + chartPillar_->GetXAxis().SetDataRange(0, BLOOD_XAXIS_RANGE_MAX); + chartPillar_->GetXAxis().SetMarkNum(BLOOD_XAXIS_SETMARKNUM); + chartPillar_->GetYAxis().SetDataRange(0, BLOOD_YAXIS_RANGE_MAX); + chartPillar_->GetYAxis().SetMarkNum(BLOOD_YAXIS_SETMARKNUM); + chartPillar_->GetYAxis().SetVisible(false); + chartPillar_->AddDataSerial(dataSerial_); + group_->Add(chartPillar_); + + chartImg_ = new UIImageView(); + if (chartImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new chartImg_ fail"); + return; + } + chartImg_->SetPosition(BLOOD_CHART_IMAGE_POSION_X, BLOOD_CHART_IMAGE_POSION_Y); + LOADIMG::LoadImageViewImg(chartImg_, BLOOD_IMAGE, IMAGE_BLOOD_SCALE); + chartImg_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->Add(chartImg_); + + labelXAxisPointOne_ = new UILabel(); + if (labelXAxisPointOne_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointOne_ fail"); + return; + } + labelXAxisPointOne_->SetText("00:00"); + labelXAxisPointOne_->SetPosition(LABLE_XAXIS1_POSION_X, LABLE_XAXIS_POSION_Y, BOTTOM_TEXT_WIDTH_ONE, + BOTTOM_TEXT_HEIGHT_ONE); + labelXAxisPointOne_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLE_FONT_SIZE_ONE); + group_->Add(labelXAxisPointOne_); + + labelXAxisPointTwo_ = new UILabel(); + if (labelXAxisPointTwo_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointTwo_ fail"); + return; + } + labelXAxisPointTwo_->SetText("12:00"); + labelXAxisPointTwo_->SetPosition(LABLE_XAXIS2_POSION_X, LABLE_XAXIS_POSION_Y, BOTTOM_TEXT_WIDTH_ONE, + BOTTOM_TEXT_HEIGHT_ONE); + labelXAxisPointTwo_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLE_FONT_SIZE_ONE); + group_->Add(labelXAxisPointTwo_); + + labelXAxisPointThree_ = new UILabel(); + if (labelXAxisPointThree_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointThree_ fail"); + return; + } + labelXAxisPointThree_->SetText("24:00"); + labelXAxisPointThree_->SetPosition(LABLE_XAXIS3_POSION_X, LABLE_XAXIS_POSION_Y, BOTTOM_TEXT_WIDTH_ONE, + BOTTOM_TEXT_HEIGHT_ONE); + labelXAxisPointThree_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLE_FONT_SIZE_ONE); + group_->Add(labelXAxisPointThree_); + + labelButtonRetest_ = new UILabelButton(); + if (labelButtonRetest_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelButtonRetest_ fail"); + return; + } + labelButtonRetest_->SetPosition(TOP_TEXT_X, TOP_TEXT_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + LOADIMG::LoadBtnImage(labelButtonRetest_, BLOOD_IMAGE, IMAGE_BLOOD_AGAIN, IMAGE_BLOOD_AGAIN); + labelButtonRetest_->SetViewId(BLOOD_RETEST_BUTTON); + labelButtonRetest_->SetOnClickListener(this); + labelButtonRetest_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + labelButtonRetest_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + labelButtonRetest_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelButtonRetest_->SetVisible(true); + group_->Add(labelButtonRetest_); + + group_->Add(labelTitle_); + group_->Add(labelTestTime_); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + InitImageAnimator(); + + AddViewToPageContainer(group_); +} + +bool BloodChartPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_RESULT_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool BloodChartPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp (view.GetViewId(), BLOOD_RETEST_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_READY_PAGE, + TransitionType::TRANSITION_INVALID, true); + } + return true; +} + +void BloodChartPage::InitImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imageAnimator_ fail"); + return; + } + for (uint8_t i = 0; i < BLOOD_ANIMATOR_IMAGE_NUM; i++) { + imageAnimatorImageInfo_[i].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[i], BLOOD_IMAGE); + imageAnimatorImageInfo_[i].imageType = IMG_SRC_IMAGE_INFO; + imageAnimatorImageInfo_[i].pos.x = BLOOD_BIND_IMAGE_X; + imageAnimatorImageInfo_[i].pos.y = BLOOD_BIND_IMAGE_Y; + imageAnimatorImageInfo_[i].width = BLOOD_BIND_IMAGE_WIDTH; + imageAnimatorImageInfo_[i].height = BLOOD_BIND_IMAGE_HEIGHT; + } + + imageAnimator_->SetPosition(PERSEC_BLOOD_TEXT_X, PERSEC_BLOOD_TEXT_Y); + imageAnimator_->SetImageAnimatorSrc(imageAnimatorImageInfo_, + BLOOD_ANIMATOR_IMAGE_NUM, BLOOD_ANIMATOR_IMAGE_UPDATE); + imageAnimator_->SetRepeat(true); + imageAnimator_->SetAutoEnable(false); + imageAnimator_->SetResizeMode(UIImageView::FILL); + imageAnimator_->Start(); + imageAnimator_->LayoutCenterOfParent(); + imageAnimator_->SetDraggable(true); + group_->Add(imageAnimator_); +} + +BloodChartPage::~BloodChartPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelButtonRetest_ != nullptr) { + delete labelButtonRetest_; + labelButtonRetest_ = nullptr; + } + + if (labelTestTime_ != nullptr) { + delete labelTestTime_; + labelTestTime_ = nullptr; + } + + if (dataSerial_ != nullptr) { + delete dataSerial_; + dataSerial_ = nullptr; + } + + if (chartPillar_ != nullptr) { + delete chartPillar_; + chartPillar_ = nullptr; + } + + if (labelXAxisPointOne_ != nullptr) { + delete labelXAxisPointOne_; + labelXAxisPointOne_ = nullptr; + } + + if (labelXAxisPointTwo_ != nullptr) { + delete labelXAxisPointTwo_; + labelXAxisPointTwo_ = nullptr; + } + + if (labelXAxisPointThree_ != nullptr) { + delete labelXAxisPointThree_; + labelXAxisPointThree_ = nullptr; + } + + if (mainImg_ != nullptr) { + delete mainImg_; + mainImg_ = nullptr; + } + + if (chartImg_ != nullptr) { + delete chartImg_; + chartImg_ = nullptr; + } + + if (imageAnimator_ != nullptr) { + delete imageAnimator_; + imageAnimator_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodChartPage::~BloodChartPage"); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodExplainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodExplainPage.cpp new file mode 100644 index 000000000..25e8bd26f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodExplainPage.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodExplainPage + * Create: 2025-06 + */ + +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "ui_resource_blood.h" +#include "blood/BloodPresenter.h" +#include "blood/BloodView.h" +#include "blood/BloodExplainPage.h" + +namespace OHOS { +static BloodExplainPage *g_pBloodCalcPage = nullptr; +static const char *BLOOD_LABEL_ONE = (char *)"血氧饱和度"; +static const char *BLOOD_LABEL_TWO = + (char + *)"血氧饱和度(SpO2)是血液中氧和血红蛋白(HbO2)的容量占全部血红蛋白的百分比,是维持人体正常机制的重要生理参数。"; +static const char *BLOOD_LABEL_THREE = (char *)"测量须知"; +static const char *BLOOD_LABEL_FOUR = + (char *)"本设备支持血氧测量范围为70%~100%" + "。在穿戴设备上启动血氧测量后,为确保测量准确,须按佩戴指引进行操作。受外界因素影响(" + "血流灌注低、手臂毛发多、有纹身、低温等)影响,测量精度可能会下降,测量结果仅供参考,不作为医疗诊断依据。"; +static constexpr uint16_t BLOOD_FIRST_LABEL_FONT = 38; +static constexpr uint16_t BLOOD_LABEL_FIRST_X = 45; +static constexpr uint16_t BLOOD_LABEL_FIRST_Y = 40; +static constexpr uint16_t BLOOD_LABEL_SECOND_X = 45; +static constexpr uint16_t BLOOD_LABEL_SECOND_Y = 98; +static constexpr uint16_t BLOOD_LABEL_THIRD_X = 45; +static constexpr uint16_t BLOOD_LABEL_THIRD_Y = 514; +static constexpr uint16_t BLOOD_LABEL_FOUR_X = 45; +static constexpr uint16_t BLOOD_LABEL_FOUR_Y = 564; +static constexpr uint16_t BLOOD_LABEL_FIRST_WIDTH = 350; +static constexpr uint16_t BLOOD_LABEL_FIRST_HEIGHT = 400; +static constexpr uint16_t BLOOD_LABEL_POSITION_WIDTH = 200; +static constexpr uint16_t BLOOD_LABEL_POSITION_HEIGHT = 60; +static constexpr uint16_t BLOOD_LABEL2_POSITION_Y = 404; +static constexpr uint16_t BLOOD_BUTTONLEVEL_POSITION_X = 127; +static constexpr uint16_t BLOOD_BUTTONLABLE_POSITION_X = 217; +static constexpr uint16_t BLOOD_BUTTONLEVEL2_POSITION_Y = 440; +static constexpr uint16_t BLOOD_BUTTONLEVEL3_POSITION_Y = 474; +static constexpr uint16_t LIST_BLANK_SIZE = 50; +static constexpr uint16_t INDEX_0 = 0; +static constexpr uint16_t INDEX_1 = 1; +static constexpr uint16_t INDEX_2 = 2; +static constexpr uint16_t INDEX_3 = 3; +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_EXPLAIN_PAGE, BloodExplainPage, false); + +BloodExplainPage::BloodExplainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodExplainPage::BloodExplainPage"); +} + +BloodExplainPage::~BloodExplainPage() +{ + if (scrollGroup_ != nullptr) { + scrollGroup_->RemoveAll(); + delete scrollGroup_; + scrollGroup_ = nullptr; + } + + if (imgNormal_ != nullptr) { + delete imgNormal_; + imgNormal_ = nullptr; + } + + if (imgGeneral_ != nullptr) { + delete imgGeneral_; + imgGeneral_ = nullptr; + } + + if (imgAbnormal_ != nullptr) { + delete imgAbnormal_; + imgAbnormal_ = nullptr; + } + + if (labelNormal_ != nullptr) { + delete labelNormal_; + labelNormal_ = nullptr; + } + + if (labelGeneral_ != nullptr) { + delete labelGeneral_; + labelGeneral_ = nullptr; + } + + if (labelAbnormal_ != nullptr) { + delete labelAbnormal_; + labelAbnormal_ = nullptr; + } + + for (int i = 0; i < LABEL_DES_COUNT; i++) { + if (labelDes_[i] != nullptr) { + delete labelDes_[i]; + labelDes_[i] = nullptr; + } + } + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodExplainPage::~BloodExplainPage"); +} + +void BloodExplainPage::OnStart(void *data) +{ + scrollGroup_ = new UIScrollView(); + if (scrollGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollGroup_ fail"); + return; + } + scrollGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollGroup_->SetThrowDrag(true); + scrollGroup_->SetScrollBlankSize(LIST_BLANK_SIZE); + scrollGroup_->SetOnDragListener(this); + scrollGroup_->SetDraggable(true); + scrollGroup_->SetTouchable(true); + if (!InitSimilarLabel(INDEX_0, BLOOD_LABEL_FIRST_X, BLOOD_LABEL_FIRST_Y, BLOOD_LABEL_ONE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new InitSimilarLabel[INDEX_0] error"); + } + if (!InitSimilarLabel(INDEX_1, BLOOD_LABEL_SECOND_X, BLOOD_LABEL_SECOND_Y, BLOOD_LABEL_TWO)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new InitSimilarLabel[INDEX_1] error"); + } + if (!InitSimilarLabel(INDEX_2, BLOOD_LABEL_THIRD_X, BLOOD_LABEL_THIRD_Y, BLOOD_LABEL_THREE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new InitSimilarLabel[INDEX_2] error"); + } + if (!InitSimilarLabel(INDEX_3, BLOOD_LABEL_FOUR_X, BLOOD_LABEL_FOUR_Y, BLOOD_LABEL_FOUR)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new InitSimilarLabel[INDEX_3] error"); + } + + imgNormal_ = new UIImageView(); + if (imgNormal_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imgNormal_ fail"); + return; + } + imgNormal_->SetPosition(BLOOD_BUTTONLEVEL_POSITION_X, BLOOD_LABEL2_POSITION_Y); + LOADIMG::LoadImageViewImg(imgNormal_, BLOOD_IMAGE, IMAGE_BLOOD_NORMAL); + scrollGroup_->Add(imgNormal_); + + labelNormal_ = new UILabel(); + if (labelNormal_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelNormal_ fail"); + return; + } + labelNormal_->SetText(">=94%"); + labelNormal_->SetPosition(BLOOD_BUTTONLABLE_POSITION_X, BLOOD_LABEL2_POSITION_Y); + labelNormal_->Resize(BLOOD_LABEL_POSITION_WIDTH, BLOOD_LABEL_POSITION_HEIGHT); + labelNormal_->SetTextColor(Color::White()); + scrollGroup_->Add(labelNormal_); + + imgGeneral_ = new UIImageView(); + if (imgGeneral_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imgGeneral_ fail"); + return; + } + imgGeneral_->SetPosition(BLOOD_BUTTONLEVEL_POSITION_X, BLOOD_BUTTONLEVEL2_POSITION_Y); + LOADIMG::LoadImageViewImg(imgGeneral_, BLOOD_IMAGE, IMAGE_BLOOD_COMMON); + scrollGroup_->Add(imgGeneral_); + + labelGeneral_ = new UILabel(); + if (labelGeneral_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelGeneral_ fail"); + return; + } + labelGeneral_->SetText("70%~93%"); + labelGeneral_->SetPosition(BLOOD_BUTTONLABLE_POSITION_X, BLOOD_BUTTONLEVEL2_POSITION_Y); + labelGeneral_->Resize(BLOOD_LABEL_POSITION_WIDTH, BLOOD_LABEL_POSITION_HEIGHT); + labelGeneral_->SetTextColor(Color::White()); + scrollGroup_->Add(labelGeneral_); + + imgAbnormal_ = new UIImageView(); + if (imgAbnormal_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imgAbnormal_ fail"); + return; + } + imgAbnormal_->SetPosition(BLOOD_BUTTONLEVEL_POSITION_X, BLOOD_BUTTONLEVEL3_POSITION_Y); + LOADIMG::LoadImageViewImg(imgAbnormal_, BLOOD_IMAGE, IMAGE_BLOOD_ABNORMAL); + scrollGroup_->Add(imgAbnormal_); + + labelAbnormal_ = new UILabel(); + if (labelAbnormal_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelAbnormal_ fail"); + return; + } + labelAbnormal_->SetText("<70%"); + labelAbnormal_->SetPosition(BLOOD_BUTTONLABLE_POSITION_X, BLOOD_BUTTONLEVEL3_POSITION_Y); + labelAbnormal_->Resize(BLOOD_LABEL_POSITION_WIDTH, BLOOD_LABEL_POSITION_HEIGHT); + labelAbnormal_->SetTextColor(Color::White()); + scrollGroup_->Add(labelAbnormal_); + AddViewToPageContainer(scrollGroup_); +} + +bool BloodExplainPage::InitSimilarLabel(int16 num, int16 labelX, int16 labelY, const char *labelText) +{ + if (num < 0 || num >= LABEL_DES_COUNT) { + return false; + } + labelDes_[num] = new UILabel(); + if (labelDes_[num] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelDes_[%d] error", num); + return false; + } + labelDes_[num]->SetPosition(labelX, labelY, BLOOD_LABEL_FIRST_WIDTH, BLOOD_LABEL_FIRST_HEIGHT); + labelDes_[num]->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelDes_[num]->SetText(labelText); + if (num == INDEX_0) { + labelDes_[num]->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_FIRST_LABEL_FONT); + } else { + labelDes_[num]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_FIRST_LABEL_FONT); + } + labelDes_[num]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + scrollGroup_->Add(labelDes_[num]); + return true; +} + +bool BloodExplainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_RESULT_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMainPage.cpp new file mode 100644 index 000000000..07b8e3652 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMainPage.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodMainPage + * Create: 2025-06 + */ + +#include +#include +#include +#include +#include +#include "components/root_view.h" +#include "sys/time.h" +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "securec.h" +#include "ui_resource_blood.h" +#include "blood/BloodPresenter.h" +#include "blood/BloodMainPage.h" + +namespace OHOS { +static constexpr uint16_t BLOOD_BUTTON_POSITION_X = 110; +static constexpr uint16_t BLOOD_BUTTON_HEIGHT = 76; +static constexpr uint16_t BLOOD_TITLE_POSITION_X = 195; +static constexpr uint16_t BLOOD_TITLE_POSITION_Y = 40; +static constexpr uint16_t BLOOD_TITLE_WIDTH = 260; +static constexpr uint16_t BLOOD_TITLE_HEIGHT = 53; +static constexpr uint16_t BLOOD_TITLE_FONT_SIZE = 38; +static constexpr uint16_t BLOOD_BUTTON_TWO_POSITION_Y = 330; +static constexpr uint16_t BLOOD_BUTTON_TWO_WIDTH = 232; +static constexpr uint16_t BLOOD_LABLETEST_POSITION_X = 158; +static constexpr uint16_t BLOOD_LABLETEST_POSITION_Y = 281; +static constexpr uint16_t BLOOD_LABLETEST_WIDTH = 200; +static constexpr uint16_t BLOOD_LABLETEST_HEIGHT = 40; +static constexpr uint16_t BLOOD_LABLETEST_SIZE_FONT = 24; +static constexpr uint16_t VIDEO_WIDTH = 454; +static constexpr uint16_t VIDEO_HEIGHT = 454; +static constexpr uint16_t STRIDE_ALIGNMENT_VALUE = 128; +static constexpr uint16_t BUFFER_QUEUE_SIZE = 3; +static constexpr uint16_t JPEG_HEIGHT_DIVISOR = 2; +static constexpr uint16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128; +static constexpr uint16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; +static constexpr uint16_t BLOOD_BUTTON_FONT_SIZE = 35; +static constexpr uint16_t BLOOD_DATE_TIME_ONE = 90; +static constexpr uint16_t BLOOD_DATE_TIME_TWO = 3000; +static constexpr uint16_t BLOOD_DATE_TIME_THREE = 60; +static constexpr uint16_t BLOOD_DATE_TIME_FOUR = 3600; +static constexpr uint16_t BLOOD_OPA = 50; +static constexpr char *BLOOD_START_BUTTON = "startButton"; + +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_MAIN_PAGE, BloodMainPage, true); + +BloodMainPage::BloodMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodMainPage::BloodMainPage"); +} + +BloodMainPage::~BloodMainPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (buttonStart_ != nullptr) { + delete buttonStart_; + buttonStart_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelPreTest_ != nullptr) { + delete labelPreTest_; + labelPreTest_ = nullptr; + } + + if (videoPlay_ != nullptr) { + videoPlay_->StopVideoPlay(); + delete videoPlay_; + videoPlay_ = nullptr; + } + + if (surfaceView_ != nullptr) { + delete surfaceView_; + surfaceView_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodMainPage::~BloodMainPage"); +} + +void BloodMainPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + InitImageAnimator(); + + buttonStart_ = new UILabelButton(); + if (buttonStart_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonStart_ fail"); + return; + } + buttonStart_->SetPosition(BLOOD_BUTTON_POSITION_X, BLOOD_BUTTON_TWO_POSITION_Y); + buttonStart_->Resize(BLOOD_BUTTON_TWO_WIDTH, BLOOD_BUTTON_HEIGHT); + buttonStart_->SetViewId(BLOOD_START_BUTTON); + buttonStart_->SetOnClickListener(this); + buttonStart_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::RELEASED); + buttonStart_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::PRESSED); + buttonStart_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::INACTIVE); + buttonStart_->SetText("开始测量"); + buttonStart_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_BUTTON_FONT_SIZE); + buttonStart_->SetVisible(true); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(BLOOD_TITLE_POSITION_X, BLOOD_TITLE_POSITION_Y, BLOOD_TITLE_WIDTH, BLOOD_TITLE_HEIGHT); + labelTitle_->SetText("血氧"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_TITLE_FONT_SIZE); + SetTestTime(); + group_->Add(buttonStart_); + group_->Add(labelPreTest_); + group_->Add(labelTitle_); + + AddViewToPageContainer(group_); +} + +void BloodMainPage::OnResume() +{ + videoPlay_->StartVideoPlay(); +} + +void BloodMainPage::OnPause() +{ + videoPlay_->StopVideoPlay(); +} + +void BloodMainPage::SetTestTime() +{ + labelPreTest_ = new UILabel(); + if (labelPreTest_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelPreTest_ fail"); + return; + } + labelPreTest_->SetPosition(BLOOD_LABLETEST_POSITION_X, BLOOD_LABLETEST_POSITION_Y, BLOOD_LABLETEST_WIDTH, + BLOOD_LABLETEST_HEIGHT); + labelPreTest_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLETEST_SIZE_FONT); + labelPreTest_->SetStyle(STYLE_TEXT_COLOR, 0xFFCCCCCC); + labelPreTest_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelPreTest_->SetVisible(false); + bloodMeasurementInfo info = BloodModel::GetInstance().GetBlood(); + struct timeval current_time; + if (info.blood == 0) { + info.blood = BLOOD_DATE_TIME_ONE; + gettimeofday(¤t_time, nullptr); + int64_t now = current_time.tv_sec; + struct timeval time1; + time1.tv_sec = now - BLOOD_DATE_TIME_TWO; + info.time = time1; + } + if (info.blood != 0) { + struct timeval tv = info.time; + std::time_t time = tv.tv_sec; + std::tm *tm_info = std::localtime(&time); + std::stringstream ss; + if (IsToday(tv)) { + gettimeofday(¤t_time, nullptr); + int64_t now = current_time.tv_sec; + int64_t diff_seconds = now - tv.tv_sec; + if (diff_seconds < 0) { + ss << info.blood << "% " + << "刚刚"; + } else if (diff_seconds < BLOOD_DATE_TIME_THREE) { + ss << info.blood << "% (" << diff_seconds << "秒前)"; + } else if (diff_seconds < BLOOD_DATE_TIME_FOUR) { + int minutes = diff_seconds / BLOOD_DATE_TIME_THREE; + ss << info.blood << "% (" << minutes << "分钟前)"; + } else { + int hours = diff_seconds / BLOOD_DATE_TIME_FOUR; + ss << info.blood << "% (" << hours << "小时前)"; + } + } else { + ss << info.blood << "% " << (tm_info->tm_mon + 1) << "/" << tm_info->tm_mday; + } + labelPreTest_->SetText(ss.str().c_str()); + int textWidth = labelPreTest_->GetTextWidth(); + int posX = (HORIZONTAL_RESOLUTION - textWidth) / 2; + labelPreTest_->SetX(posX); + labelPreTest_->SetVisible(true); + } +} + +bool BloodMainPage::IsToday(const struct timeval &tv) +{ + time_t now = time(nullptr); + std::tm *now_tm = localtime(&now); + std::time_t given_time = tv.tv_sec; + std::tm *given_tm = std::localtime(&given_time); + + return (now_tm->tm_year == given_tm->tm_year) && (now_tm->tm_mon == given_tm->tm_mon) && + (now_tm->tm_mday == given_tm->tm_mday); +} + +bool BloodMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} + +bool BloodMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BLOOD_START_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_READY_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + UNUSED(event); + return true; +} + +void BloodMainPage::InitImageAnimator() +{ + surfaceView_ = new UILiteSurfaceView(); + if (surfaceView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImageAnimator new UILiteSurfaceView fail"); + return; + } + colorKey_.full = 0xff202020; + surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT); + surfaceView_->SetPreview(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_BLOOD_PREVIEW1, BLOOD_IMAGE)); + surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + surfaceView_->SetSurfaceColorkey(colorKey_); + group_->Add(surfaceView_); + + Surface *surface = surfaceView_->GetSurface(); + surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE); + surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT); + surface->SetQueueSize(BUFFER_QUEUE_SIZE); + surface->SetFormat(PIXEL_FMT_YCBCR_420_SP); + + int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT; + int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * + ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR; + int32_t bufferSize = ySize + uvSize; + surface->SetSize(bufferSize); + std::string uri("/user/res/video/bloodBackGround.mp4"); + videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, false); + if (videoPlay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new videoPlay_ fail"); + return; + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMeasurementPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMeasurementPage.cpp new file mode 100644 index 000000000..83b6c5eaa --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodMeasurementPage.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodMeasurementPage + * Create: 2025-06 + */ + +#include +#include +#include +#include "ui_test_group.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "surface.h" +#include "settings/model/SettingDisplayModel.h" +#include "ui_resource_blood.h" +#include "blood/BloodPresenter.h" +#include "blood/BloodMeasurementPage.h" + +namespace OHOS { +static constexpr uint16_t BLOOD_BUTTON_TWO_POSITION_X = 152; +static constexpr uint16_t BLOOD_BUTTON_TWO_POSITION_Y = 330; +static constexpr uint16_t BLOOD_LABEL_FRONT = 72; +static constexpr uint16_t BLOOD_LABEL_FRONT_BOTTOM = 36; +static constexpr uint16_t BLOOD_LABEL2_POSITION_X = 183; +static constexpr uint16_t BLOOD_LABEL2_POSITION_Y = 162; +static constexpr uint16_t BLOOD_LABEL2_WIDTH = 180; +static constexpr uint16_t BLOOD_LABEL2_HEIGHT = 42; +static constexpr uint16_t VIDEO_WIDTH = 454; +static constexpr uint16_t VIDEO_HEIGHT = 454; +static constexpr uint16_t STRIDE_ALIGNMENT_VALUE = 128; +static constexpr uint16_t BUFFER_QUEUE_SIZE = 3; +static constexpr uint16_t JPEG_HEIGHT_DIVISOR = 2; +static constexpr uint16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128; +static constexpr uint16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; +static constexpr uint16_t BLOOD_LABLETITLE_POSITION_X = 195; +static constexpr uint16_t BLOOD_LABLETITLE_POSITION_Y = 40; +static constexpr uint16_t BLOOD_LABLETITLE_WIDTH = 260; +static constexpr uint16_t BLOOD_LABLETITLE_HEIGHT = 53; +static constexpr uint16_t BLOOD_LABLETITLE_FONT_SIZE = 38; +static constexpr uint16_t BLOOD_TIME = 15; +static constexpr uint16_t BLOOD_NUM = 60; +static constexpr uint16_t BLOOD_NUM_ONE = 40; + +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_MEASUREMENT_PAGE, BloodMeasurementPage, false); + +BloodMeasurementPage::BloodMeasurementPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodMeasurementPage::BloodMeasurementPage"); +} + +BloodMeasurementPage::~BloodMeasurementPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelTime_ != nullptr) { + delete labelTime_; + labelTime_ = nullptr; + } + + if (labelTips_ != nullptr) { + delete labelTips_; + labelTips_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + if (videoPlay_ != nullptr) { + videoPlay_->StopVideoPlay(); + delete videoPlay_; + videoPlay_ = nullptr; + } + + if (surfaceView_ != nullptr) { + delete surfaceView_; + surfaceView_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodMeasurementPage::~BloodMeasurementPage"); +} + +void BloodMeasurementPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + InitImageAnimator(); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(BLOOD_LABLETITLE_POSITION_X, BLOOD_LABLETITLE_POSITION_Y, BLOOD_LABLETITLE_WIDTH, + BLOOD_LABLETITLE_HEIGHT); + labelTitle_->SetText("血氧"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_LABLETITLE_FONT_SIZE); + labelTitle_->SetVisible(false); + + InitAnimator(); + gettimeofday(&startTime_, nullptr); + StartAnimator(); + group_->Add(labelTitle_); + AddViewToPageContainer(group_); +} + +void BloodMeasurementPage::OnResume() +{ + videoPlay_->StartVideoPlay(); + SettingDisplayModel::GetInstance().EnableSteadyOn(); +} + +void BloodMeasurementPage::OnPause() +{ + videoPlay_->StopVideoPlay(); + SettingDisplayModel::GetInstance().DisableSteadyOn(); +} + +void BloodMeasurementPage::InitAnimator() +{ + labelTime_ = new UILabel(); + if (labelTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTime_ fail"); + return; + } + labelTime_->SetPosition(BLOOD_LABEL2_POSITION_X, BLOOD_LABEL2_POSITION_Y); + labelTime_->Resize(BLOOD_LABEL2_WIDTH, BLOOD_LABEL2_HEIGHT); + labelTime_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT); + + labelTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTime_->SetText("15s"); + labelTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTime_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT); + labelTime_->SetVisible(false); + + labelTips_ = new UILabel(); + if (labelTips_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTips_ fail"); + return; + } + labelTips_->SetPosition(BLOOD_BUTTON_TWO_POSITION_X, BLOOD_BUTTON_TWO_POSITION_Y); + labelTips_->Resize(BLOOD_LABEL2_WIDTH, BLOOD_LABEL2_HEIGHT); + labelTips_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT_BOTTOM); + labelTips_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTips_->SetText("正在测量"); + labelTips_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTips_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT_BOTTOM); + labelTips_->SetVisible(false); + group_->Add(labelTime_); + group_->Add(labelTips_); + + callBack_ = new BloodAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new callBack_ fail"); + return; + } + animator_ = new Animator(callBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ fail"); + return; + } +} + +void BloodMeasurementPage::BloodAnimatorCallback::Callback(UIView *view) +{ + (void)view; + static int count = 0; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + int time = current_time.tv_sec - page_->startTime_.tv_sec; + std::string strTime1 = std::to_string(BLOOD_TIME - time) + "s"; + page_->SetLabelTime(strTime1); + page_->ShowOnMeasurement(); + if (time >= BLOOD_TIME) { + page_->StopAnimator(); + int random_number = BLOOD_NUM + rand() % BLOOD_NUM_ONE; + struct timeval testTime; + gettimeofday(&testTime, nullptr); + bloodMeasurementInfo info; + info.blood = random_number; + info.time = testTime; + BloodModel::GetInstance().SetBlood(info); + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_RESULT_PAGE, + TransitionType::TRANSITION_INVALID, false); + } +} + +void BloodMeasurementPage::StopAnimator() +{ + animator_->Stop(); +} +void BloodMeasurementPage::StartAnimator() +{ + animator_->Start(); +} + +void BloodMeasurementPage::SetLabelTime(std::string str) +{ + labelTime_->SetText(str.c_str()); +} + +void BloodMeasurementPage::ShowOnMeasurement() +{ + labelTips_->SetVisible(true); + labelTitle_->SetVisible(true); + labelTime_->SetVisible(true); +} + +bool BloodMeasurementPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void BloodMeasurementPage::InitImageAnimator() +{ + surfaceView_ = new UILiteSurfaceView(); + if (surfaceView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new surfaceView_ fail"); + return; + } + colorKey_.full = 0xff202020; + surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT); + surfaceView_->SetPreview(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_BLOOD_PREVIEW2, BLOOD_IMAGE)); + surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + surfaceView_->SetSurfaceColorkey(colorKey_); + group_->Add(surfaceView_); + + Surface *surface = surfaceView_->GetSurface(); + surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE); + surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT); + surface->SetQueueSize(BUFFER_QUEUE_SIZE); + surface->SetFormat(PIXEL_FMT_YCBCR_420_SP); + + int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT; + int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * + ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR; + int32_t bufferSize = ySize + uvSize; + surface->SetSize(bufferSize); + std::string uri("/user/res/video/blood.mp4"); + videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, false); + if (videoPlay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new videoPlay_ fail"); + return; + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodModel.cpp index 692d2d93d..e948704cd 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodModel.cpp @@ -1,133 +1,24 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.cpp - * Author: + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodModel * Create: 2025-03-23 */ #include -#include "blood/BloodModel.h" -#include "blood/BloodView.h" #include "ohos_timer.h" #include "wearable_log.h" +#include "blood/BloodView.h" +#include "blood/BloodModel.h" namespace OHOS { -static constexpr uint64_t CENTI_SECOND_UNIT = 100; -static constexpr uint64_t MS_ONE_SECONDS = 1000; -static constexpr uint16_t NUM_TEN = 10; -static constexpr uint16_t NUM_TIME_MIN = 60; -static constexpr uint16_t NUM_TIME_HOUR = 3600; -static constexpr int32_t NUM_TIME_DAY = 86400; +BloodModel::BloodModel() {} -static constexpr int16_t MIN_TO_HOUR = 60; -static constexpr int16_t HOURLY_SYSTEM = 24; -BloodModel::BloodModel() -{ - InitCurrentTimeTimer(); -} - -BloodModel::~BloodModel() -{ - DisableCurrentTimeTimer(); -} +BloodModel::~BloodModel() {} BloodModel &BloodModel::GetInstance() { static BloodModel instance; return instance; } -void BloodModel::SetbuttonStatus(bool status) -{ - buttonStatus = status; -} - -bool BloodModel::GetbuttonStatus() -{ - return buttonStatus; -} - -/* 定时器回调函数 */ -static void CurrentTimeTimerCallback(void *data) -{ - (void)data; - BloodView *view = BloodView::GetInstance(); - if (view != nullptr && view->IsCurrentTimeLabelValid()) { - std::string currTime = BloodModel::GetInstance().GetCurrentTimeString(); - view->UpdateCurrentTimeLabel(currTime.c_str()); - } -} - -std::string BloodModel::GetCurrentTimeString() -{ - std::string strHours; - std::string strMinute; - struct timeval tv; - gettimeofday(&tv, NULL); - uint64_t second = tv.tv_sec; - uint64_t uSecond = tv.tv_usec; - uint64_t minute = second / MIN_TO_HOUR; - uint64_t hour = minute / MIN_TO_HOUR; - uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - - if (realHour >= 0 && realHour < NUM_TEN) { - strHours = "0" + std::to_string(realHour); - } else { - strHours = std::to_string(realHour); - } - if (realMinute >= 0 && realMinute < NUM_TEN) { - strMinute = "0" + std::to_string(realMinute); - } else { - strMinute = std::to_string(realMinute); - } - return strHours + ":" + strMinute; -} - -void BloodModel::InitCurrentTimeTimer() -{ - if (pCurrentTimeTimer_ != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchModel::InitCurrentTimeTimer GraphicTimer already exists!!"); - return; - } - uint32_t tick = GetOSTick(MS_ONE_SECONDS); - pCurrentTimeTimer_ = new GraphicTimer(tick, CurrentTimeTimerCallback, nullptr, true); - if (pCurrentTimeTimer_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchModel::InitCurrentTimeTimer new GraphicTimer failed!!"); - return; - } -} -void BloodModel::DisableCurrentTimeTimer() -{ - if (pCurrentTimeTimer_ != nullptr) { - pCurrentTimeTimer_->Stop(); - delete pCurrentTimeTimer_; - pCurrentTimeTimer_ = nullptr; - } -} - -void BloodModel::StartCurrentTimeTimer() -{ - if (pCurrentTimeTimer_ != nullptr) { - bool retTimer = pCurrentTimeTimer_->Start(); - if (!retTimer) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartStopwatchTimer GraphicTimer Start failed!!"); - if (pCurrentTimeTimer_ != nullptr) { - delete pCurrentTimeTimer_; - pCurrentTimeTimer_ = nullptr; - } - return; - } - } -} - -void BloodModel::PauseCurrentTimeTimer() -{ - if (pCurrentTimeTimer_ != nullptr) { - pCurrentTimeTimer_->Stop(); - } -} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodPresenter.cpp index 5e98671cc..7013d7a20 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodPresenter.cpp @@ -1,89 +1,15 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: SettingPresenter.cpp - * Author: - * Create: 2025-03-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodPresenter + * Create: 2025-06 */ -#include "blood/BloodPresenter.h" -#include "blood/BloodView.h" -#include "blood/BloodModel.h" #include "uiservice/ui_service.h" #include "NativeRegisterManager.h" -namespace OHOS { - -REGIST_MENU(VIEW_BLOOD, BloodView, BloodPresenter, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "血氧"); - -static BloodPresenter *g_pBloodPresenter = nullptr; - -BloodPresenter::BloodPresenter() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodPresenter::BloodPresenter"); - findPhoneModel = &BloodModel::GetInstance(); - g_pBloodPresenter = this; -} - -BloodPresenter::~BloodPresenter() -{ - g_pBloodPresenter = nullptr; -} - -void BloodPresenter::OnResume(void) -{ - Presenter::OnResume(); - SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); - BloodModel::GetInstance().StartCurrentTimeTimer(); -} - -void BloodPresenter::OnPause(void) -{ - Presenter::OnPause(); - SendMsgToUIService(UI_RM_SLEEP_VETO, 0, nullptr, 0); - BloodModel::GetInstance().PauseCurrentTimeTimer(); - return; -} - -BloodPresenter *BloodPresenter::GetInstance() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodPresenter GetInstance"); - return g_pBloodPresenter; -} - -bool BloodPresenter::ClickFuncId(const char *buttonName) -{ - if (buttonName == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempPresenter::ClickFuncId buttonName nullptr error!"); - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::ClickFuncId buttonName = %s", buttonName); - if (strcmp(buttonName, "button1") == 0) { - } else if (strcmp(buttonName, "button2") == 0) { - } - return false; -} - -bool BloodPresenter::OnClick(UIView &view, const ClickEvent &event) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnClick "); - UNUSED(event); - BloodView::GetInstance()->DropView(view, 1); - return true; -} - -bool BloodPresenter::OnDrag(UIView &view, const DragEvent &event) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherOnDragListener::OnDrag"); - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag %s", view.GetViewId()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag %s", event.GetDragDirection()); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); - BloodView::GetInstance()->DropView(view, 0); - } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag DIRECTION_RIGHT_TO_LEFT"); - BloodView::GetInstance()->DropView(view, 1); - } - return false; -} +#include "blood/BloodView.h" +#include "blood/BloodModel.h" +#include "blood/BloodPresenter.h" +namespace OHOS { +REGIST_MENU(VIEW_BLOOD, BloodView, BloodPresenter, BLOOD_ICON, BLOOD_ICON, "血氧"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodReadyPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodReadyPage.cpp new file mode 100644 index 000000000..e14eacdeb --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodReadyPage.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodReadyPage + * Create: 2025-06 + */ + +#include +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "surface.h" +#include "ui_resource_blood.h" +#include "blood/BloodPresenter.h" +#include "blood/BloodReadyPage.h" + +namespace OHOS { +static constexpr uint16_t BLOOD_BUTTON_POSITION_X = 188; +static constexpr uint16_t BLOOD_BUTTON_WIDTH = 96; +static constexpr uint16_t BLOOD_BUTTON_HEIGHT = 96; +static constexpr uint16_t BLOOD_BUTTON_TWO_POSITION_Y = 288; +static constexpr uint16_t BLOOD_LABEL3_POSITION_X = 65; +static constexpr uint16_t BLOOD_LABEL3_POSITION_Y = 150; +static constexpr uint16_t BLOOD_LABLETIPSSATRT_POSITION_X = 110; +static constexpr uint16_t BLOOD_LABLETIPSSATRT_POSITION_Y = 200; +static constexpr uint16_t BLOOD_LABLETIPSSATRT_WIDTH = 424; +static constexpr uint16_t BLOOD_LABLETIPSSATRT_HEIGHT = 424; +static constexpr uint16_t BLOOD_LABLETIPSSATRT_FONT_SIZE = 36; +static constexpr uint16_t BLOOD_LABLEBACK_POSITION_X = 218; +static constexpr uint16_t BLOOD_LABLEBACK_POSITION_Y = 318; +static constexpr uint16_t BLOOD_LABLEBACK_WIDTH = 50; +static constexpr uint16_t BLOOD_LABLEBACK_HEIGHT = 50; +static constexpr uint16_t BLOOD_LABLEBACK_FONT_SIZE = 30; +static constexpr uint16_t BLOOD_PLAYBACK_POSITION_X = 140; +static constexpr uint16_t BLOOD_PLAYBACK_POSITION_Y = 250; +static constexpr uint16_t BLOOD_PLAYBACK_WIDTH = 172; +static constexpr uint16_t BLOOD_PLAYBACK_HEIGHT = 172; +static constexpr uint16_t BLOOD_PLAYBACK_VENTER_POSITION = 86; +static constexpr uint32_t BLOOD_PLAYBACK_RANGE = 100000; +static constexpr uint16_t BLOOD_PLAYBACK_RADIUS = 48; +static constexpr uint16_t BLOOD_PLAYBACK_START_ANGLE = 360; +static constexpr uint16_t BLOOD_PLAYBACK_STYLE_LINE_WIDTH = 12; +static constexpr uint16_t BLOOD_TIME = 3; +static constexpr uint16_t BLOOD_PROGRESS_TIME = 3; +static constexpr uint16_t BLOOD_TIME_USEC = 1000; +static constexpr char *BLOOD_START_BUTTON = "startButton"; + +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_READY_PAGE, BloodReadyPage, false); + +BloodReadyPage::BloodReadyPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodReadyPage::BloodReadyPage"); +} + +BloodReadyPage::~BloodReadyPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (buttonStart_ != nullptr) { + delete buttonStart_; + buttonStart_ = nullptr; + } + + if (labelTips_ != nullptr) { + delete labelTips_; + labelTips_ = nullptr; + } + + if (timeProgress_ != nullptr) { + delete timeProgress_; + timeProgress_ = nullptr; + } + + if (labelProgressTime_ != nullptr) { + delete labelProgressTime_; + labelProgressTime_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodReadyPage::~BloodReadyPage"); +} + +void BloodReadyPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + buttonStart_ = new UILabelButton(); + if (buttonStart_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonStart_ fail"); + return; + } + buttonStart_->SetPosition(BLOOD_BUTTON_POSITION_X, BLOOD_BUTTON_TWO_POSITION_Y); + buttonStart_->Resize(BLOOD_BUTTON_WIDTH, BLOOD_BUTTON_HEIGHT); + LOADIMG::LoadBtnImage(buttonStart_, BLOOD_IMAGE, IMAGE_BLOOD_RESET, IMAGE_BLOOD_RESET); + buttonStart_->SetViewId(BLOOD_START_BUTTON); + buttonStart_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + buttonStart_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + buttonStart_->SetVisible(true); + buttonStart_->SetOnClickListener(this); + group_->Add(buttonStart_); + + labelTips_ = new UILabel(); + if (labelTips_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTips_ fail"); + return; + } + labelTips_->SetPosition(BLOOD_LABLETIPSSATRT_POSITION_X, BLOOD_LABLETIPSSATRT_POSITION_Y, + BLOOD_LABLETIPSSATRT_WIDTH, BLOOD_LABLETIPSSATRT_HEIGHT); + labelTips_->SetText("请佩戴手表测量"); + labelTips_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLETIPSSATRT_FONT_SIZE); + labelTips_->SetVisible(true); + group_->Add(labelTips_); + + InitCircleProgress(); + + InitAnimator(); + + AddViewToPageContainer(group_); +} + +void BloodReadyPage::InitAnimator() +{ + callBack_ = new BloodAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new callBack_ fail"); + return; + } + animator_ = new Animator(callBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ fail"); + return; + } +} + +int BloodReadyPage::InitCircleProgress() +{ + labelProgressTime_ = new UILabel(); + if (labelProgressTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelProgressTime_ fail"); + return OHOS_FAILURE; + } + labelProgressTime_->SetPosition(BLOOD_LABLEBACK_POSITION_X, BLOOD_LABLEBACK_POSITION_Y, BLOOD_LABLEBACK_WIDTH, + BLOOD_LABLEBACK_HEIGHT); + labelProgressTime_->SetText("3"); + labelProgressTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABLEBACK_FONT_SIZE); + labelProgressTime_->SetVisible(true); + labelProgressTime_->SetVisible(false); + group_->Add(labelProgressTime_); + timeProgress_ = new UICircleProgress(); + if (timeProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new timeProgress_ fail"); + return OHOS_FAILURE; + } + timeProgress_->SetPosition(BLOOD_PLAYBACK_POSITION_X, BLOOD_PLAYBACK_POSITION_Y, BLOOD_PLAYBACK_WIDTH, + BLOOD_PLAYBACK_HEIGHT); + timeProgress_->SetCenterPosition(BLOOD_PLAYBACK_VENTER_POSITION, BLOOD_PLAYBACK_VENTER_POSITION); + timeProgress_->SetRange(BLOOD_PLAYBACK_RANGE, 0); + timeProgress_->SetRadius(BLOOD_PLAYBACK_RADIUS); + timeProgress_->SetStartAngle(BLOOD_PLAYBACK_START_ANGLE); + timeProgress_->SetEndAngle(0); + timeProgress_->SetValue(0); + timeProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xFF491010); + timeProgress_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timeProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0xFFD72C2E); + timeProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, BLOOD_PLAYBACK_STYLE_LINE_WIDTH); + timeProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, BLOOD_PLAYBACK_STYLE_LINE_WIDTH); + timeProgress_->SetVisible(false); + group_->Add(timeProgress_); + return OHOS_SUCCESS; +} + +void BloodReadyPage::BloodAnimatorCallback::Callback(UIView *view) +{ + (void)view; + static int count = 0; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + long seconds = current_time.tv_sec - page_->startTime_.tv_sec; + long micros = current_time.tv_usec - page_->startTime_.tv_usec; + long time = (seconds * BLOOD_TIME_USEC) + (micros / BLOOD_TIME_USEC); + page_->SetLabelProgressTime(time); + if ((time / BLOOD_TIME_USEC) == BLOOD_TIME) { + page_->ShowOnMeasurement(); + page_->StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_MEASUREMENT_PAGE, + TransitionType::TRANSITION_INVALID, false); + } +} + +void BloodReadyPage::StopAnimator() +{ + animator_->Stop(); +} + +void BloodReadyPage::SetLabelProgressTime(int time) +{ + int progressTime = BLOOD_PROGRESS_TIME - (time / BLOOD_TIME_USEC); + std::string strTime = std::to_string(progressTime); + labelProgressTime_->SetText(strTime.c_str()); + double percentage = static_cast(time) / (BLOOD_TIME * BLOOD_TIME_USEC); + double value = round(percentage * BLOOD_PLAYBACK_RANGE); + timeProgress_->SetValue(value); +} + +void BloodReadyPage::ShowOnMeasurement() +{ + buttonStart_->SetVisible(false); + labelTips_->SetVisible(false); + timeProgress_->SetVisible(false); + labelProgressTime_->SetVisible(false); +} + +bool BloodReadyPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool BloodReadyPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), BLOOD_START_BUTTON) == 0) { + labelTips_->SetVisible(false); + labelTips_->SetPosition(BLOOD_LABEL3_POSITION_X, BLOOD_LABEL3_POSITION_Y); + labelTips_->SetText("请屏幕朝上偏紧佩戴, 保持静止"); + labelTips_->SetVisible(true); + buttonStart_->SetVisible(false); + animator_->Start(); + timeProgress_->SetVisible(true); + labelProgressTime_->SetVisible(true); + gettimeofday(&startTime_, nullptr); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodResultPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodResultPage.cpp new file mode 100644 index 000000000..a8cb0f1f1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/blood/src/BloodResultPage.cpp @@ -0,0 +1,235 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodResultPage + * Create: 2025-06 + */ + +#include +#include +#include +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "ui_resource_blood.h" +#include "msg_center_device.h" +#include "blood/BloodPresenter.h" +#include "blood/BloodView.h" +#include "blood/BloodResultPage.h" + +namespace OHOS { +static constexpr uint16_t BLOOD_BUTTON_POSITION_X = 120; +static constexpr uint16_t BLOOD_BUTTON_POSITION_Y = 320; +static constexpr uint16_t BLOOD_BUTTON_WIDTH = 232; +static constexpr uint16_t BLOOD_BUTTON_HEIGHT = 76; +static constexpr uint16_t BLOOD_BUTTON_FONT_SIZE = 35; +static constexpr uint16_t BLOOD_LABEL_FRONT = 30; +static constexpr uint16_t BLOOD_LABEL_ONE_POSITION_X = 170; +static constexpr uint16_t BLOOD_LABEL_ONE_POSITION_Y = 150; +static constexpr uint16_t BLOOD_LABEL_ONE_POSITION_WIDTH = 72; +static constexpr uint16_t BLOOD_LABEL_ONE_POSITION_HEIGHT = 32; +static constexpr uint16_t BLOOD_LABEL_ONE_WIDTH = 200; +static constexpr uint16_t BLOOD_LABEL_ONE_HEIGHT = 60; +static constexpr uint16_t BLOOD_LABEL_FRONT_ONE = 60; +static constexpr uint16_t BLOOD_LABEL2_POSITION_X = 117; +static constexpr uint16_t BLOOD_LABEL2_POSITION_Y = 212; +static constexpr uint16_t BLOOD_LABEL3_POSITION_Y = 212; +static constexpr uint16_t BLOOD_LABEL2_WIDTH = 200; +static constexpr uint16_t BLOOD_LABEL2_HEIGHT = 60; +static constexpr uint16_t BLOOD_TITLE_POSITION_X = 195; +static constexpr uint16_t BLOOD_TITLE_POSITION_Y = 40; +static constexpr uint16_t BLOOD_TITLE_WIDTH = 260; +static constexpr uint16_t BLOOD_TITLE_HEIGHT = 53; +static constexpr uint16_t BLOOD_TITLE_FONT_SIZE = 38; +static constexpr uint16_t BLOOD_BUTTONLEVEL_POSITION_X = 277; +static constexpr uint16_t BLOOD_RANDOM_NUMBER_HIGH = 90; +static constexpr uint16_t BLOOD_RANDOM_NUMBER_LOW = 70; +static constexpr uint16_t BLOOD_OPA = 50; +static constexpr char *BLOOD_BUTTON_MORE = "moreButton"; + +REGIST_SLICE_PAGE(VIEW_BLOOD, BLOOD_PAGES::BLOOD_RESULT_PAGE, BloodResultPage, false); + +BloodResultPage::BloodResultPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodResultPage::BloodResultPage"); +} + +BloodResultPage::~BloodResultPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (buttonMore_ != nullptr) { + delete buttonMore_; + buttonMore_ = nullptr; + } + + if (labelData_ != nullptr) { + delete labelData_; + labelData_ = nullptr; + } + + if (labelBloodOxygen_ != nullptr) { + delete labelBloodOxygen_; + labelBloodOxygen_ = nullptr; + } + + if (mainImg_ != nullptr) { + delete mainImg_; + mainImg_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (levelImg_ != nullptr) { + delete levelImg_; + levelImg_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadSingleRes(BLOOD_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodResultPage::~BloodResultPage"); +} + +void BloodResultPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + mainImg_ = new UIImageView(); + if (mainImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new mainImg_ fail"); + return; + } + mainImg_->SetPosition(0, 0); + mainImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(mainImg_, BLOOD_IMAGE, IMAGE_BLOOD_BG); + group_->Add(mainImg_); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(BLOOD_TITLE_POSITION_X, BLOOD_TITLE_POSITION_Y, BLOOD_TITLE_WIDTH, BLOOD_TITLE_HEIGHT); + labelTitle_->SetText("结果"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_TITLE_FONT_SIZE); + labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetRollSpeed(0); + + labelData_ = new UILabel(); + if (labelData_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelData_ fail"); + return; + } + labelData_->SetPosition(BLOOD_LABEL_ONE_POSITION_X, BLOOD_LABEL_ONE_POSITION_Y); + labelData_->Resize(BLOOD_LABEL_ONE_WIDTH, BLOOD_LABEL_ONE_HEIGHT); + labelData_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT_ONE); + labelData_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelData_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelData_->SetRollSpeed(0); + labelData_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT_ONE); + + labelBloodOxygen_ = new UILabel(); + if (labelBloodOxygen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelBloodOxygen_ fail"); + return; + } + labelBloodOxygen_->SetPosition(BLOOD_LABEL2_POSITION_X, BLOOD_LABEL2_POSITION_Y); + labelBloodOxygen_->Resize(BLOOD_LABEL2_WIDTH, BLOOD_LABEL2_HEIGHT); + labelBloodOxygen_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT); + labelBloodOxygen_->SetText("血氧饱和度"); + labelBloodOxygen_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelBloodOxygen_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelBloodOxygen_->SetRollSpeed(0); + labelBloodOxygen_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT); + labelBloodOxygen_->SetVisible(true); + + buttonMore_ = new UILabelButton(); + if (buttonMore_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonMore_ fail"); + return; + } + buttonMore_->SetPosition(BLOOD_BUTTON_POSITION_X, BLOOD_BUTTON_POSITION_Y); + buttonMore_->Resize(BLOOD_BUTTON_WIDTH, BLOOD_BUTTON_HEIGHT); + buttonMore_->SetViewId(BLOOD_BUTTON_MORE); + buttonMore_->SetOnClickListener(this); + buttonMore_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::RELEASED); + buttonMore_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::PRESSED); + buttonMore_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::INACTIVE); + buttonMore_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_BUTTON_FONT_SIZE); + buttonMore_->SetText("进一步了解"); + buttonMore_->SetStyle(STYLE_TEXT_COLOR, 0xFFCCCCCC); + buttonMore_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + buttonMore_->SetVisible(true); + + levelImg_ = new UIImageView(); + if (levelImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new levelImg_ fail"); + return; + } + levelImg_->SetPosition(BLOOD_BUTTONLEVEL_POSITION_X, BLOOD_LABEL3_POSITION_Y); + bloodMeasurementInfo info = BloodModel::GetInstance().GetBlood(); + std::string strBlood = std::to_string(info.blood) + "%"; + labelData_->SetText(strBlood.c_str()); + errcode_t result; +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN, &info.blood, + sizeof(info.blood)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "send blood result:%d ", result); +#endif + if (info.blood >= BLOOD_RANDOM_NUMBER_HIGH) { + LOADIMG::LoadImageViewImg(levelImg_, BLOOD_IMAGE, IMAGE_BLOOD_NORMAL); + } else if (info.blood >= BLOOD_RANDOM_NUMBER_LOW && info.blood < BLOOD_RANDOM_NUMBER_HIGH) { + LOADIMG::LoadImageViewImg(levelImg_, BLOOD_IMAGE, IMAGE_BLOOD_COMMON); + } else { + LOADIMG::LoadImageViewImg(levelImg_, BLOOD_IMAGE, IMAGE_BLOOD_ABNORMAL); + } + + group_->Add(labelTitle_); + group_->Add(labelData_); + group_->Add(labelBloodOxygen_); + group_->Add(buttonMore_); + group_->Add(levelImg_); + AddViewToPageContainer(group_); +} + +bool BloodResultPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_CHART_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool BloodResultPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BLOOD_BUTTON_MORE) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BLOOD_PAGES::BLOOD_EXPLAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + UNUSED(event); + return true; +} + +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp index 0e074c908..099cd2216 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp @@ -13,9 +13,12 @@ extern "C" { #endif static bool gatts_register_flag = false; +static bool gattc_register_flag = false; static uint8_t gatts_server_id = 0; +static uint8_t gattc_client_id = 0; std::list g_gap_ble_callback_list; std::list g_gatts_callback_list; +std::list g_gattc_callback_list; std::list g_uuid_list; std::list g_svr_handle_list; @@ -31,6 +34,12 @@ errcode_t wrapper_gatts_register_callbacks(gatts_callbacks_t *func) return ERRCODE_SUCC; } +errcode_t wrapper_gattc_register_callbacks(gattc_callbacks_t *func) +{ + g_gattc_callback_list.push_back(*func); + return ERRCODE_SUCC; +} + void wrapper_gap_ble_enable_callback(errcode_t status) { for (auto callback : g_gap_ble_callback_list) { @@ -219,7 +228,7 @@ void wrapper_gatts_delete_all_service_callback(uint8_t server_id, errcode_t stat if (callback.delete_service_cb) { callback.delete_service_cb(server_id, status); } - } + } } void wrapper_gatts_read_request_callback(uint8_t server_id, uint16_t conn_id, gatts_req_read_cb_t *read_cb_para, errcode_t status) { @@ -237,6 +246,7 @@ void wrapper_gatts_write_request_callback(uint8_t server_id, uint16_t conn_id, g } } } + void wrapper_gatts_mtu_changed_callback(uint8_t server_id, uint16_t conn_id, uint16_t mtu_size, errcode_t status) { for (auto callback : g_gatts_callback_list) { @@ -246,6 +256,124 @@ void wrapper_gatts_mtu_changed_callback(uint8_t server_id, uint16_t conn_id, uin } } +void wrapper_gattc_discovery_svc_callback(uint8_t client_id, uint16_t conn_id, + gattc_discovery_service_result_t *service, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_svc_cb) { + callback.discovery_svc_cb(client_id, conn_id, service, status); + } + } +} + +void wrapper_gattc_discovery_svc_cmp_callback(uint8_t client_id, uint16_t conn_id, + bt_uuid_t *uuid, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_svc_cmp_cb) { + callback.discovery_svc_cmp_cb(client_id, conn_id, uuid, status); + } + } +} + +void wrapper_gattc_discovery_chara_callback(uint8_t client_id, uint16_t conn_id, + gattc_discovery_character_result_t *character, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_chara_cb) { + callback.discovery_chara_cb(client_id, conn_id, character, status); + } + } +} + +void wrapper_gattc_discovery_chara_cmp_callback(uint8_t client_id, uint16_t conn_id, + gattc_discovery_character_param_t *param, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_chara_cmp_cb) { + callback.discovery_chara_cmp_cb(client_id, conn_id, param, status); + } + } +} + +void wrapper_gattc_discovery_desc_callback(uint8_t client_id, uint16_t conn_id, + gattc_discovery_descriptor_result_t *descriptor, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_desc_cb) { + callback.discovery_desc_cb(client_id, conn_id, descriptor, status); + } + } +} + +void wrapper_gattc_discovery_desc_cmp_callback(uint8_t client_id, uint16_t conn_id, + uint16_t character_handle, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.discovery_desc_cmp_cb) { + callback.discovery_desc_cmp_cb(client_id, conn_id, character_handle, status); + } + } +} + +void wrapper_gattc_read_callback(uint8_t client_id, uint16_t conn_id, + gattc_handle_value_t *read_result, gatt_status_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.read_cb) { + callback.read_cb(client_id, conn_id, read_result, status); + } + } +} + +void wrapper_gattc_read_cmp_callback(uint8_t client_id, uint16_t conn_id, + gattc_read_req_by_uuid_param_t *param, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.read_cmp_cb) { + callback.read_cmp_cb(client_id, conn_id, param, status); + } + } +} + +void wrapper_gattc_write_callback(uint8_t client_id, uint16_t conn_id, uint16_t handle, gatt_status_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.write_cb) { + callback.write_cb(client_id, conn_id, handle, status); + } + } +} + +void wrapper_gattc_mtu_changed_callback(uint8_t client_id, uint16_t conn_id, uint16_t mtu_size, errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.mtu_changed_cb) { + callback.mtu_changed_cb(client_id, conn_id, mtu_size, status); + } + } +} + +void wrapper_gattc_notification_callback(uint8_t client_id, uint16_t conn_id, gattc_handle_value_t *data, + errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.notification_cb) { + callback.notification_cb(client_id, conn_id, data, status); + } + } +} + +void wrapper_indication_callback(uint8_t client_id, uint16_t conn_id, gattc_handle_value_t *data, + errcode_t status) +{ + for (auto callback : g_gattc_callback_list) { + if (callback.indication_cb) { + callback.indication_cb(client_id, conn_id, data, status); + } + } +} + static gap_ble_callbacks_t g_wrapper_gap_ble_callbacks = { .ble_enable_cb = wrapper_gap_ble_enable_callback, .ble_disable_cb = wrapper_gap_ble_disable_callback, @@ -260,7 +388,7 @@ static gap_ble_callbacks_t g_wrapper_gap_ble_callbacks = { .read_rssi_cb = wrapper_gap_ble_read_rssi_callback, .terminate_adv_cb = wrapper_gap_ble_terminate_adv_callback, .auth_complete_cb = wrapper_gap_ble_auth_complete_callback, - .conn_param_update_cb = wrapper_gap_ble_connect_param_update_callback, + .conn_param_update_cb = wrapper_gap_ble_connect_param_update_callback, }; static gatts_callbacks_t g_wrapper_gatts_callbacks = { @@ -272,15 +400,44 @@ static gatts_callbacks_t g_wrapper_gatts_callbacks = { .delete_service_cb = wrapper_gatts_delete_all_service_callback, .read_request_cb = wrapper_gatts_read_request_callback, .write_request_cb = wrapper_gatts_write_request_callback, - .mtu_changed_cb = wrapper_gatts_mtu_changed_callback, + .mtu_changed_cb = wrapper_gatts_mtu_changed_callback, +}; + +static gattc_callbacks_t g_wrapper_gattc_callbacks = { + .discovery_svc_cb = wrapper_gattc_discovery_svc_callback, + .discovery_svc_cmp_cb = wrapper_gattc_discovery_svc_cmp_callback, + .discovery_chara_cb = wrapper_gattc_discovery_chara_callback, + .discovery_chara_cmp_cb = wrapper_gattc_discovery_chara_cmp_callback, + .discovery_desc_cb = wrapper_gattc_discovery_desc_callback, + .discovery_desc_cmp_cb = wrapper_gattc_discovery_desc_cmp_callback, + .read_cb = wrapper_gattc_read_callback, + .read_cmp_cb = wrapper_gattc_read_cmp_callback, + .write_cb = wrapper_gattc_write_callback, + .mtu_changed_cb = wrapper_gattc_mtu_changed_callback, + .notification_cb = wrapper_gattc_notification_callback, + .indication_cb = wrapper_indication_callback, }; void wrapper_ble_register(void) { gap_ble_register_callbacks(&g_wrapper_gap_ble_callbacks); gatts_register_callbacks(&g_wrapper_gatts_callbacks); + gattc_register_callbacks(&g_wrapper_gattc_callbacks); } +errcode_t wrapper_gattc_register_client(bt_uuid_t *uuid, uint8_t *clientId) +{ + errcode_t ret = ERRCODE_SUCC; + if (gattc_register_flag) { + *clientId = gattc_client_id; + ret = ERRCODE_SUCC; + } else { + gattc_register_flag = true; + ret = gattc_register_client(uuid, clientId); + gattc_client_id = *clientId; + } + return ret; +} errcode_t wrapper_gatts_register_server(bt_uuid_t *app_uuid, uint8_t *server_id) { diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathExerPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathExerPage.cpp new file mode 100644 index 000000000..eb41dc992 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathExerPage.cpp @@ -0,0 +1,311 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathExerPage + * Create: 2025-5-13 + */ +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "PageTransitionMgr.h" +#include "SlicePageFactory.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/root_view.h" +#include "components/ui_image_animator.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ohos_timer.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#include "settings/model/SettingDisplayModel.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathExerPage.h" + +namespace OHOS { +static constexpr int16_t BREATH_GROUP_SIZE = 454; +static constexpr int16_t BREATH_ZERO = 0; +static constexpr int16_t BREATH_ONE = 1; +static constexpr int16_t BREATH_TWO = 2; +static constexpr int16_t BREATH_THREE = 3; +static constexpr uint16_t IMAGEANIMATOERVIEW_SIZE = 80; +static constexpr uint16_t END_TIME = 20; +static constexpr int16_t BREATH_INHALE_POSITION_X = 180; +static constexpr int16_t BREATH_INHALE_POSITION_Y = 380; +static constexpr int16_t BREATH_INHALE_SIZE_WIDTH = 100; +static constexpr int16_t BREATH_INHALE_SIZE_HEIGHT = 50; +static constexpr int16_t BREATH_FRONT = 40; +static constexpr int16_t BREATH_HALF = 2; +static constexpr int16_t ONE_MINUTE = 60; +static constexpr float BREATH_DEFAULT_SCALE = 0.5f; +static constexpr float BREATH_DEFAULT_ANGLE = 30.0f; +static constexpr float BREATH_MID_ANGLE = 60.0f; +static constexpr float BREATH_MAX_ANGLE = 90.0f; +static constexpr float BREATH_MAX_FACTOR = 1.0f; +static constexpr float BREATH_MIN_FACTOR = 0.5f; +const Vector2 VIEW_CENTER = {227, 227}; +enum class State { FadingOutFirst, FadingInSecond, FadingOutSecond, FadingInFirst } currentState; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_EXER_VIEW, BreathExerPage, false); + +BreathExerPage::BreathExerPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathExerPage::BreathExerPage"); +} + +BreathExerPage::~BreathExerPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (mainImg_ != nullptr) { + delete mainImg_; + mainImg_ = nullptr; + } + + if (romataImg_ != nullptr) { + delete romataImg_; + romataImg_ = nullptr; + } + + if (romataImgVirtual_ != nullptr) { + delete romataImgVirtual_; + romataImgVirtual_ = nullptr; + } + + if (breathInhale_ != nullptr) { + delete breathInhale_; + breathInhale_ = nullptr; + } + + if (breathExhale_ != nullptr) { + delete breathExhale_; + breathExhale_ = nullptr; + } + + if (animatorCallBack_ != nullptr) { + delete animatorCallBack_; + animatorCallBack_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathExerPage::~BreathExerPage"); +} + +void BreathExerPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetTouchable(true); + group_->SetDraggable(true); + group_->SetOnDragListener(this); + + mainImg_ = new UIImageView(); + if (mainImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainImg_ new image fail"); + return; + } + mainImg_->SetPosition(0, 0); + mainImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(mainImg_, BREATH_IMAGE, IMAGE_BREATH_BG1); + group_->Add(mainImg_); + + romataImg_ = new UIImageView(); + if (romataImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainImg_ new romataImg_ fail"); + return; + } + romataImg_->SetPosition(0, 0); + romataImg_->SetStyle(STYLE_BACKGROUND_OPA, 0); + romataImg_->Rotate(0, VIEW_CENTER); + LOADIMG::LoadImageViewImg(romataImg_, BREATH_IMAGE, IMAGE_BREATH_ROMATA1); + group_->Add(romataImg_); + + romataImgVirtual_ = new UIImageView(); + if (romataImgVirtual_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainImg_ new romataImgVirtual_ fail"); + return; + } + romataImgVirtual_->SetPosition(0, 0); + romataImgVirtual_->SetStyle(STYLE_BACKGROUND_OPA, 0); + romataImgVirtual_->Rotate(0, VIEW_CENTER); + LOADIMG::LoadImageViewImg(romataImgVirtual_, BREATH_IMAGE, IMAGE_BREATH_ROMATA2); + group_->Add(romataImgVirtual_); + + breathInhale_ = new UILabel(); + breathInhale_->SetPosition(BREATH_INHALE_POSITION_X, BREATH_INHALE_POSITION_Y, BREATH_INHALE_SIZE_WIDTH, + BREATH_INHALE_SIZE_HEIGHT); + breathInhale_->SetText("吸气"); + breathInhale_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_FRONT); + breathInhale_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + breathInhale_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + group_->Add(breathInhale_); + + breathExhale_ = new UILabel(); + breathExhale_->SetPosition(BREATH_INHALE_POSITION_X, BREATH_INHALE_POSITION_Y, BREATH_INHALE_SIZE_WIDTH, + BREATH_INHALE_SIZE_HEIGHT); + breathExhale_->SetText("呼气"); + breathExhale_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_FRONT); + breathExhale_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + breathExhale_->SetStyle(STYLE_TEXT_OPA, OPA_TRANSPARENT); + group_->Add(breathExhale_); + + animatorCallBack_ = new BreathExerPageCallback(this); + if (animatorCallBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animatorCallBack_ ERROR"); + return; + } + animator_ = new Animator(animatorCallBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ ERROR"); + return; + } + + currentState = State::FadingOutFirst; + g_StartTime = BreathModel::GetInstance().GetBeginTime(); + rotateStep_ = BreathModel::GetInstance().GetRotateStep(); + flag_ = true; + scale_ = BREATH_DEFAULT_SCALE; + angle_ = BREATH_DEFAULT_ANGLE; + animator_->Start(); + SettingDisplayModel::GetInstance().EnableSteadyOn(); + AddViewToPageContainer(group_); +} + +void BreathExerPage::UpdateTextOpa() +{ + static float alpha = 0; + float totalRotationSteps = (BREATH_MAX_ANGLE - BREATH_DEFAULT_ANGLE) / rotateStep_; + float deltaAlpha = (float)OPA_OPAQUE / totalRotationSteps * BREATH_HALF; + switch (currentState) { + case State::FadingOutFirst: + if (angle_ < BREATH_MID_ANGLE) { + alpha += deltaAlpha; + alpha = (alpha > (float)OPA_OPAQUE) ? (float)OPA_OPAQUE : alpha; + breathInhale_->SetStyle(STYLE_TEXT_OPA, alpha); + breathInhale_->SetVisible(true); + breathExhale_->SetVisible(false); + } else { + currentState = State::FadingInSecond; + alpha = OPA_OPAQUE; + } + break; + case State::FadingInSecond: + if (angle_ < BREATH_MAX_ANGLE) { + alpha -= deltaAlpha; + alpha = (alpha < 0.0f) ? 0.0f : alpha; + breathInhale_->SetStyle(STYLE_TEXT_OPA, alpha); + breathInhale_->SetVisible(true); + breathExhale_->SetVisible(false); + } else { + currentState = State::FadingOutSecond; + alpha = 0; + } + break; + case State::FadingOutSecond: + if (angle_ > BREATH_MID_ANGLE) { + alpha += deltaAlpha; + alpha = (alpha > (float)OPA_OPAQUE) ? ((float)OPA_OPAQUE) : alpha; + breathExhale_->SetStyle(STYLE_TEXT_OPA, alpha); + breathInhale_->SetVisible(false); + breathExhale_->SetVisible(true); + } else { + currentState = State::FadingInFirst; + alpha = OPA_OPAQUE; + } + break; + case State::FadingInFirst: + if (angle_ > BREATH_DEFAULT_ANGLE) { + alpha -= deltaAlpha; + alpha = (alpha < 0.0f) ? 0.0f : alpha; + breathExhale_->SetStyle(STYLE_TEXT_OPA, alpha); + breathInhale_->SetVisible(false); + breathExhale_->SetVisible(true); + } else { + currentState = State::FadingOutFirst; + alpha = 0; + } + break; + } +} + +void BreathExerPage::UpdateImageRotate() +{ + if (flag_) { + angle_ += rotateStep_; + scale_ += (BREATH_MAX_FACTOR - BREATH_MIN_FACTOR) / ((BREATH_MAX_ANGLE - BREATH_DEFAULT_ANGLE) / rotateStep_); + } else { + angle_ -= rotateStep_; + scale_ -= (BREATH_MAX_FACTOR - BREATH_MIN_FACTOR) / ((BREATH_MAX_ANGLE - BREATH_DEFAULT_ANGLE) / rotateStep_); + } + scale_ = (scale_ > BREATH_MAX_FACTOR) ? BREATH_MAX_FACTOR : scale_; + scale_ = (scale_ < BREATH_MIN_FACTOR) ? BREATH_MIN_FACTOR : scale_; + + if (angle_ >= BREATH_MAX_ANGLE) { + angle_ = BREATH_MAX_ANGLE; + flag_ = false; + } else if (angle_ <= BREATH_DEFAULT_ANGLE) { + angle_ = BREATH_DEFAULT_ANGLE; + flag_ = true; + } + + romataImgVirtual_->Scale(Vector2{scale_, scale_}, VIEW_CENTER); + romataImgVirtual_->Rotate(angle_, VIEW_CENTER); + romataImgVirtual_->Invalidate(); + romataImg_->Scale(Vector2{scale_, scale_}, VIEW_CENTER); + romataImg_->Rotate(BREATH_MID_ANGLE - angle_, VIEW_CENTER); + romataImg_->Invalidate(); +} + +void BreathExerPage::OnPause() +{ + animator_->Stop(); + SettingDisplayModel::GetInstance().DisableSteadyOn(); +} + +bool BreathExerPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + animator_->Stop(); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void BreathExerPage::BreathExerPageCallback::Callback(UIView *view) +{ + UNUSED(view); + struct timeval currentTime; + gettimeofday(¤tTime, nullptr); + uint32_t breathingTime = (BreathModel::GetInstance().GetTrainTime() + 1) * ONE_MINUTE; + if (breathingTime <= currentTime.tv_sec - g_StartTime) { + BreathExerPage->animator_->Stop(); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_RESULT_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else { + BreathExerPage->UpdateImageRotate(); + BreathExerPage->UpdateTextOpa(); + } +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathMainPage.cpp new file mode 100644 index 000000000..bdd7df5d7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathMainPage.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathMainPage + * Create: 2025-5-13 + */ +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "PageTransitionMgr.h" +#include "SlicePageFactory.h" +#include "TransitionType.h" +#include "UiConfig.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "breathexercise/BreathModel.h" +#include "breathexercise/BreathMainPage.h" + +namespace OHOS { +static constexpr char *BREATH_MAIN_BTN_TIMEID = "timeButton"; +static constexpr char *BREATH_MAIN_BTN_RHYTHM_ID = "rhythmButton"; +static constexpr char *BREATH_MAIN_BTN_START_ID = "startButton"; +static constexpr int16_t BREATH_MAIN_TITLE_X = 97; +static constexpr int16_t BREATH_MAIN_TITLE_Y = 34; +static constexpr int16_t BREATH_MAIN_TITLE_W = 260; +static constexpr int16_t BREATH_MAIN_TITLE_H = 53; +static constexpr int16_t BREATH_MAIN_TITLE_FONT_SIZE = 38; +static constexpr int16_t BREATH_MAIN_DURBTN_X = 16; +static constexpr int16_t BREATH_MAIN_DURBTN_Y = 190; +static constexpr int16_t BREATH_MAIN_DURBTN_W = 74; +static constexpr int16_t BREATH_MAIN_DURBTN_H = 74; +static constexpr int16_t BREATH_MAIN_RHYBTN_X = 364; +static constexpr int16_t BREATH_MAIN_RHYBTN_Y = 190; +static constexpr int16_t BREATH_MAIN_RHYBTN_W = 74; +static constexpr int16_t BREATH_MAIN_RHYBTN_H = 74; +static constexpr int16_t BREATH_MAIN_STARTBTN_X = 60; +static constexpr int16_t BREATH_MAIN_STARTBTN_Y = 358; +static constexpr int16_t BREATH_MAIN_STARTBTN_W = 333; +static constexpr int16_t BREATH_MAIN_STARTBTN_H = 96; +static constexpr int16_t BREATH_MAIN_DURLAB_X = 20; +static constexpr int16_t BREATH_MAIN_DURLAB_Y = 275; +static constexpr int16_t BREATH_MAIN_DURLAB_W = 65; +static constexpr int16_t BREATH_MAIN_DURLAB_H = 30; +static constexpr int16_t BREATH_MAIN_RHYLAB_X = 376; +static constexpr int16_t BREATH_MAIN_RHYLAB_Y = 275; +static constexpr int16_t BREATH_MAIN_RHYLAB_W = 50; +static constexpr int16_t BREATH_MAIN_RHYLAB_H = 30; +static constexpr int16_t BREATH_MAIN_CENTER_XY = 127; +static constexpr int16_t BREATH_MAIN_CENTER_WH = 200; +static constexpr int16_t BREATH_MAIN_SETTING_FONT_SIZE = 24; +static constexpr int16_t BREATH_MAIN_TIME_FONT_SIZE = 20; +static constexpr int16_t BREATH_GROUP_SIZE = 466; +static constexpr uint16_t Y_OFFSET = 300; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_MAIN_VIEW, BreathMainPage, true); + +BreathMainPage::BreathMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathMainPage::BreathMainPage"); +} + +BreathMainPage::~BreathMainPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (lableSetting_ != nullptr) { + delete lableSetting_; + lableSetting_ = nullptr; + } + if (buttonStart_ != nullptr) { + delete buttonStart_; + buttonStart_ = nullptr; + } + if (buttonSetting_ != nullptr) { + delete buttonSetting_; + buttonSetting_ = nullptr; + } + if (buttonTime_ != nullptr) { + delete buttonTime_; + buttonTime_ = nullptr; + } + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + if (lableTime_ != nullptr) { + delete lableTime_; + lableTime_ = nullptr; + } + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + if (center_ != nullptr) { + delete center_; + center_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathMainPage::~BreathMainPage"); +} + +void BreathMainPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetTouchable(true); + group_->SetDraggable(true); + group_->SetOnDragListener(this); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Background ERROR"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + LOADIMG::LoadImageViewImg(bgImg_, BREATH_IMAGE, IMAGE_BREATH_BG3); + group_->Add(bgImg_); + + center_ = new UIImageView(); + if (center_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Center ERROR"); + return; + } + center_->SetPosition(BREATH_MAIN_CENTER_XY, BREATH_MAIN_CENTER_XY); + center_->Resize(BREATH_MAIN_CENTER_WH, BREATH_MAIN_CENTER_WH); + LOADIMG::LoadImageViewImg(center_, BREATH_IMAGE, IMAGE_BREATH_CENTER2); + group_->Add(center_); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ ERROR"); + return; + } + labelTitle_->SetPosition(BREATH_MAIN_TITLE_X, BREATH_MAIN_TITLE_Y); + labelTitle_->Resize(BREATH_MAIN_TITLE_W, BREATH_MAIN_TITLE_H); + labelTitle_->SetText("呼吸"); + labelTitle_->SetTextColor(Color::White()); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_MAIN_TITLE_FONT_SIZE); + group_->Add(labelTitle_); + + buttonTime_ = new UIButton(); + if (buttonTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonTime_ ERROR"); + return; + } + buttonTime_->SetPosition(BREATH_MAIN_DURBTN_X, BREATH_MAIN_DURBTN_Y); + buttonTime_->Resize(BREATH_MAIN_DURBTN_W, BREATH_MAIN_DURBTN_H); + buttonTime_->SetViewId(BREATH_MAIN_BTN_TIMEID); + buttonTime_->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonTime_, BREATH_IMAGE, IMAGE_BREATH_TIME, IMAGE_BREATH_TIME); + buttonTime_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(buttonTime_); + + buttonSetting_ = new UIButton(); + if (buttonSetting_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonSetting_ ERROR"); + return; + } + buttonSetting_->SetPosition(BREATH_MAIN_RHYBTN_X, BREATH_MAIN_RHYBTN_Y); + buttonSetting_->Resize(BREATH_MAIN_RHYBTN_W, BREATH_MAIN_RHYBTN_H); + buttonSetting_->SetViewId(BREATH_MAIN_BTN_RHYTHM_ID); + buttonSetting_->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonSetting_, BREATH_IMAGE, IMAGE_BREATH_SETTING, IMAGE_BREATH_SETTING); + buttonSetting_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonSetting_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(buttonSetting_); + + buttonStart_ = new UIButton(); + if (buttonStart_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonStart_ ERROR"); + return; + } + buttonStart_->SetPosition(BREATH_MAIN_STARTBTN_X, BREATH_MAIN_STARTBTN_Y); + buttonStart_->Resize(BREATH_MAIN_STARTBTN_W, BREATH_MAIN_STARTBTN_H); + buttonStart_->SetViewId(BREATH_MAIN_BTN_START_ID); + buttonStart_->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonStart_, BREATH_IMAGE, IMAGE_BREATH_START, IMAGE_BREATH_START); + buttonStart_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonStart_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(buttonStart_); + + lableSetting_ = new UILabel(); + if (lableSetting_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new lableSetting_ ERROR"); + return; + } + lableSetting_->SetPosition(BREATH_MAIN_RHYLAB_X, BREATH_MAIN_RHYLAB_Y); + lableSetting_->Resize(BREATH_MAIN_RHYLAB_W, BREATH_MAIN_RHYLAB_H); + lableSetting_->SetText("设置"); + lableSetting_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + lableSetting_->SetTextColor(Color::White()); + lableSetting_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableSetting_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_MAIN_SETTING_FONT_SIZE); + group_->Add(lableSetting_); + + lableTime_ = new UILabel(); + if (lableTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new lableTime_ ERROR"); + return; + } + lableTime_->SetPosition(BREATH_MAIN_DURLAB_X, BREATH_MAIN_DURLAB_Y); + lableTime_->Resize(BREATH_MAIN_DURLAB_W, BREATH_MAIN_DURLAB_H); + lableTime_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + lableTime_->SetTextColor(Color::White()); + lableTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_MAIN_TIME_FONT_SIZE); + group_->Add(lableTime_); + + AddViewToPageContainer(group_); +} + +void BreathMainPage::OnResume(void) +{ + int time = BreathModel::GetInstance().GetTrainTime() + 1; + std::ostringstream oss; + oss << time << " 分钟"; + std::string timeStr = oss.str(); + lableTime_->SetText(timeStr.c_str()); +} + +bool BreathMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BREATH_MAIN_BTN_TIMEID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_DUR_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), BREATH_MAIN_BTN_RHYTHM_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_RHY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), BREATH_MAIN_BTN_START_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_START_VIEW, + TransitionType::TRANSITION_INVALID, false); +#ifdef _WIN32 + struct timeval tv; + gettimeofday(&tv, NULL); +#else + struct timeval64 tv; + gettimeofday64(&tv, NULL); +#endif + uint32_t remTime = tv.tv_sec; + BreathModel::GetInstance().SetStartTime(remTime); + } else { + return false; + } + return true; +} + +bool BreathMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } else if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && + (event.GetStartPoint().y > Y_OFFSET)) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_TRAINING_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathModel.cpp new file mode 100644 index 000000000..aab4095b6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathModel.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathModel + * Create: 2025-5-13 + */ +#include "main/HealthModel.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "uiservice/ui_service.h" +#include "wearable_log.h" +#include "breathexercise/BreathTimeSetPage.h" +#include "breathexercise/BreathModel.h" + + +namespace OHOS { +static constexpr char *SPEED_FASTER_LITTLE = "稍快"; +static constexpr char *SPEED_SOOTHING = "舒缓"; +static constexpr char *SPEED_SLOWING = "缓慢"; +static constexpr uint16_t MINUTE_0_DATA = 0; +static constexpr uint16_t MINUTE_1_DATA = 1; +static constexpr uint16_t MINUTE_2_DATA = 2; +static constexpr uint16_t Frequency_Score_LOWER = 60; +static constexpr uint16_t Frequency_Score_RANGE = 40; +static constexpr uint16_t Heart_Rate_LOWER = 90; +static constexpr uint16_t Heart_Rate_RANGE = 10; +static constexpr uint16_t ONE_MINUTE = 60; +static constexpr uint16_t TWO_MINUTES = 120; +static constexpr uint16_t THREE_MINUTES = 180; +static constexpr uint8_t FREQUENCY_8 = 0; +static constexpr uint8_t FREQUENCY_7 = 1; +static constexpr uint8_t FREQUENCY_6 = 2; +static constexpr float BREATH_ROTETAESTEP_6 = 0.295f; +static constexpr float BREATH_ROTETAESTEP_7 = 0.347f; +static constexpr float BREATH_ROTETAESTEP_8 = 0.393f; + +BreathModel::BreathModel() {} + +BreathModel::~BreathModel() {} + +BreathModel &BreathModel::GetInstance() +{ + static BreathModel instance; + return instance; +} + +uint8_t BreathModel::GetTrainTime() +{ + return selectTrainTime_; +} + +void BreathModel::SetTrainTime(uint16_t value) +{ + selectTrainTime_ = value; +} + +uint8_t BreathModel::GetRhythm() +{ + return selectRhythm_; +} + +void BreathModel::SetRhythm(uint16_t value) +{ + selectRhythm_ = value; +} + +int32_t BreathModel::GetStartTime() +{ + return startTime_; +} + +void BreathModel::SetStartTime(int32_t value) +{ + startTime_ = value; +} + +int32_t BreathModel::GetBeginTime() +{ + return beginTime_; +} + +void BreathModel::SetBeginTime(int32_t value) +{ + beginTime_ = value; +} + +uint8_t BreathModel::GetFrequencyScore() +{ + if (frequencyScore_ == 0) { + BreathModel::GetInstance().SetFrequencyScore(); + return frequencyScore_; + } + return frequencyScore_; +} + +void BreathModel::SetFrequencyScore() +{ + frequencyScore_ = Frequency_Score_LOWER + rand() % Frequency_Score_RANGE; +} + +std::string BreathModel::GetTrainingDurationTime() +{ + return std::to_string(trainingDurationTime_); +} + +void BreathModel::SetTrainingDurationTime(uint16_t selectTrainTime) +{ + trainingDurationTime_ += selectTrainTime; +} + +std::string BreathModel::GetTrainingCount() +{ + return std::to_string(trainingCount_); +} + +void BreathModel::SetTrainingCount() +{ + trainingCount_++; +} + +uint8_t BreathModel::GetHeartRate() +{ + if (heartRate_ == 0) { + BreathModel::GetInstance().SetHeartRate(); + return heartRate_; + } + return heartRate_; +} + +void BreathModel::SetHeartRate() +{ + heartRate_ = Heart_Rate_LOWER + rand() % Heart_Rate_RANGE; +} + +float BreathModel::GetRotateStep() +{ + switch (selectRhythm_) { + case FREQUENCY_6: + return BREATH_ROTETAESTEP_6; + case FREQUENCY_7: + return BREATH_ROTETAESTEP_7; + case FREQUENCY_8: + return BREATH_ROTETAESTEP_8; + default: + return BREATH_ROTETAESTEP_6; + } +} + +char *BreathModel::GetRhythmText() +{ + if (selectRhythm_ == MINUTE_0_DATA) { + return SPEED_FASTER_LITTLE; + } else if (selectRhythm_ == MINUTE_1_DATA) { + return SPEED_SOOTHING; + } else if (selectRhythm_ == MINUTE_2_DATA) { + return SPEED_SLOWING; + } + return nullptr; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathPresenter.cpp new file mode 100644 index 000000000..faea9f9da --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathPresenter + * Create: 2025-5-13 + */ +#include "AppViewIDs.h" +#include "NativeRegisterManager.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_BREATH, BreathView, BreathPresenter, BREATH_ICON, BREATH_ICON, "呼吸训练"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathResultPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathResultPage.cpp new file mode 100644 index 000000000..1effbbdd3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathResultPage.cpp @@ -0,0 +1,407 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathReult + * Create: 2025-5-13 + */ +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "PageTransitionMgr.h" +#include "SlicePageFactory.h" +#include "TransitionType.h" +#include "UiConfig.h" +#include "components/root_view.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathResultPage.h" + +namespace OHOS { +static constexpr char *BREATH_BUTTON_COMPLETE_ID = "completeButton"; +static constexpr char *BREATH_BUTTON_RESTART_ID = "restartButton"; +static constexpr uint16_t BREATH_RESULTS_X = 97; +static constexpr uint16_t BREATH_RESULTS_Y = 34; +static constexpr uint16_t BREATH_RESULTS_W = 260; +static constexpr uint16_t BREATH_RESULTS_H = 53; +static constexpr uint16_t BREATH_MAX_FONT_SIZE = 38; +static constexpr uint16_t BREATH_MIN_FONT_SIZE = 28; +static constexpr uint16_t BREATH_SCOUT_FONT_SIZE = 40; +static constexpr uint16_t BREATH_RHYTHM_X = 77; +static constexpr uint16_t BREATH_RHYTHM_Y = 83; +static constexpr uint16_t BREATH_RHYTHM_W = 300; +static constexpr uint16_t BREATH_RHYTHM_H = 30; +static constexpr uint16_t BREATH_SCORES_X = 241; +static constexpr uint16_t BREATH_SCORES_Y = 190; +static constexpr uint16_t BREATH_SCORES_W = 72; +static constexpr uint16_t BREATH_SCORES_H = 32; +static constexpr uint16_t BREATH_COMPLETE_X = 111; +static constexpr uint16_t BREATH_COMPLETE_Y = 730; +static constexpr uint16_t BREATH_RESTART_Y = 815; +static constexpr uint16_t BREATH_COMPLETE_W = 232; +static constexpr uint16_t BREATH_COMPLETE_H = 76; +static constexpr uint16_t BREATH_GUINEAS_SIZE = 100; +static constexpr uint16_t BREATH_NINETY_SIZE = 90; +static constexpr uint16_t BREATH_EIGHTY_NINE_SIZE = 89; +static constexpr uint16_t BREATH_EIGHTY_SIZE = 80; +static constexpr uint16_t BREATH_SEVENTY_NINE_SIZE = 79; +static constexpr uint16_t BREATH_SEVENTY_SIZE = 70; +static constexpr uint16_t BREATH_SIXTY_NINE_SIZE = 69; +static constexpr uint16_t BREATH_SIXTY_SIZE = 60; +static constexpr uint16_t TEXT_OPACITY = 147; +static constexpr uint16_t TEXT_OPACITY_TWO = 220; +static constexpr uint16_t INDEX_0 = 0; +static constexpr uint16_t INDEX_1 = 1; +static constexpr uint16_t INDEX_2 = 2; +static constexpr uint16_t INDEX_3 = 3; +static constexpr uint16_t INDEX_4 = 4; +static constexpr uint16_t BREATH_RESULT_POSY_OFFSET = 118; +static constexpr uint16_t BREATH_RESULT_BUTTON_BG_POSITION_X = 92; +static constexpr uint16_t BREATH_RESULT_BUTTON_BG_POSITION_Y = 132; +static constexpr uint16_t BREATH_RESULT_BUTTON_BG_WIDTH = 270; +static constexpr uint16_t BREATH_RESULT_BUTTON_BG_HEIGHT = 108; +static constexpr uint16_t BREATH_RESULT_LABEL_DES_POSITION_X = 112; +static constexpr uint16_t BREATH_RESULT_LABEL_DES_POSITION_Y = 142; +static constexpr uint16_t BREATH_RESULT_LABEL_DES_WIDTH = 200; +static constexpr uint16_t BREATH_RESULT_LABEL_DES_HEIGHT = 30; +static constexpr uint16_t BREATH_RESULT_LABEL_COUNT_POSITION_X = 112; +static constexpr uint16_t BREATH_RESULT_LABEL_COUNT_POSITION_Y = 182; +static constexpr uint16_t BREATH_RESULT_LABEL_COUNT_WIDTH = 50; +static constexpr uint16_t BREATH_RESULT_LABEL_COUNT_HEIGHT = 44; +static constexpr uint16_t BREATH_RESULT_LABEL_UNIT_POSITION_X = 112; +static constexpr uint16_t BREATH_RESULT_LABEL_UNIT_POSITION_Y = 192; +static constexpr uint16_t BREATH_RESULT_LABEL_UNIT_WIDTH = 70; +static constexpr uint16_t BREATH_RESULT_LABEL_UNIT_HEIGHT = 34; +static constexpr uint16_t BREATH_RESULT_BORDER_RADIUS = 8; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_RESULT_VIEW, BreathResultPage, false); + +BreathResultPage::BreathResultPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathResultPage::BreathResultPage"); +} + +BreathResultPage::~BreathResultPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelTimeAndRhythmTitle_ != nullptr) { + delete labelTimeAndRhythmTitle_; + labelTimeAndRhythmTitle_ = nullptr; + } + + if (scores_ != nullptr) { + delete scores_; + scores_ = nullptr; + } + + if (pageBgImg_ != nullptr) { + delete pageBgImg_; + pageBgImg_ = nullptr; + } + + if (buttonComplete_ != nullptr) { + delete buttonComplete_; + buttonComplete_ = nullptr; + } + + if (buttonRestart_ != nullptr) { + delete buttonRestart_; + buttonRestart_ = nullptr; + } + + for (int i = 0; i < LABEL_COUNT; i++) { + if (buttonBg_[i] != nullptr) { + delete buttonBg_[i]; + buttonBg_[i] = nullptr; + } + } + + for (int i = 0; i < LABEL_COUNT; i++) { + if (labelDes_[i] != nullptr) { + delete labelDes_[i]; + labelDes_[i] = nullptr; + } + } + + for (int i = 0; i < LABEL_COUNT; i++) { + if (labelValue_[i] != nullptr) { + delete labelValue_[i]; + labelValue_[i] = nullptr; + } + } + + for (int i = 0; i < LABEL_COUNT; i++) { + if (labelUnit_[i] != nullptr) { + delete labelUnit_[i]; + labelUnit_[i] = nullptr; + } + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathResultPage::~BreathResultPage"); +} + +void BreathResultPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetThrowDrag(true); + group_->SetScrollBlankSize(BREATH_RESULTS_Y); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ ERROR"); + return; + } + labelTitle_->SetPosition(BREATH_RESULTS_X, BREATH_RESULTS_Y); + labelTitle_->Resize(BREATH_RESULTS_W, BREATH_RESULTS_H); + labelTitle_->SetText("训练结果"); + labelTitle_->SetTextColor(Color::White()); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_MAX_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(labelTitle_); + + labelTimeAndRhythmTitle_ = new UILabel(); + if (labelTimeAndRhythmTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Rhythm ERROR"); + return; + } + labelTimeAndRhythmTitle_->SetPosition(BREATH_RHYTHM_X, BREATH_RHYTHM_Y); + labelTimeAndRhythmTitle_->Resize(BREATH_RHYTHM_W, BREATH_RHYTHM_H); + labelTimeAndRhythmTitle_->SetTextColor(Color::Green()); + labelTimeAndRhythmTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_MIN_FONT_SIZE); + labelTimeAndRhythmTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + uint8_t durationTime = BreathModel::GetInstance().GetTrainTime() + 1; + std::ostringstream oss; + oss << std::to_string(durationTime) << " 分钟" << " | "; + if (const char* rhythm = BreathModel::GetInstance().GetRhythmText()) { + oss << rhythm; + } else { + oss << "缓慢"; // 默认值 + } + + std::string weatherHumidity = oss.str(); + labelTimeAndRhythmTitle_->SetText(weatherHumidity.c_str()); + group_->Add(labelTimeAndRhythmTitle_); + + BreathModel::GetInstance().SetFrequencyScore(); + BreathModel::GetInstance().SetHeartRate(); + BreathModel::GetInstance().SetTrainingDurationTime(BreathModel::GetInstance().GetTrainTime() + 1); + BreathModel::GetInstance().SetTrainingCount(); + InitBtnBg(); + InitLabelDes(); + InitLabelCount(); + InitLabelUnit(); + InitBtn(); + pageBgImg_ = new UIImageView(); + if (pageBgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new pageBgImg_ ERROR"); + return; + } + pageBgImg_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(pageBgImg_, BREATH_IMAGE, IMAGE_BREATH_BG2); + AddViewToPageContainer(pageBgImg_); + AddViewToPageContainer(group_); +} + +void BreathResultPage::InitBtn() +{ + buttonComplete_ = new UIButton(); + if (buttonComplete_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonComplete_ ERROR"); + return; + } + buttonComplete_->SetPosition(BREATH_COMPLETE_X, BREATH_COMPLETE_Y); + buttonComplete_->Resize(BREATH_COMPLETE_W, BREATH_COMPLETE_H); + buttonComplete_->SetViewId(BREATH_BUTTON_COMPLETE_ID); + buttonComplete_->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonComplete_, BREATH_IMAGE, IMAGE_BREATH_COMPLETE, IMAGE_BREATH_COMPLETE); + buttonComplete_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonComplete_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(buttonComplete_); + + buttonRestart_ = new UIButton(); + if (buttonRestart_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonRestart_ ERROR"); + return; + } + buttonRestart_->SetPosition(BREATH_COMPLETE_X, BREATH_RESTART_Y); + buttonRestart_->Resize(BREATH_COMPLETE_W, BREATH_COMPLETE_H); + buttonRestart_->SetViewId(BREATH_BUTTON_RESTART_ID); + buttonRestart_->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonRestart_, BREATH_IMAGE, IMAGE_BREATH_RETEST, IMAGE_BREATH_RETEST); + buttonRestart_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonRestart_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(buttonRestart_); +} + +void BreathResultPage::InitBtnBg() +{ + for (int i = 0; i < LABEL_COUNT; i++) { + buttonBg_[i] = new UIButton(); + if (buttonBg_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button ERROR"); + return; + } + + int posY = BREATH_RESULT_BUTTON_BG_POSITION_Y + BREATH_RESULT_POSY_OFFSET * i; + buttonBg_[i]->SetPosition(BREATH_RESULT_BUTTON_BG_POSITION_X, posY, BREATH_RESULT_BUTTON_BG_WIDTH, + BREATH_RESULT_BUTTON_BG_HEIGHT); + buttonBg_[i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::PRESSED); + buttonBg_[i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::INACTIVE); + buttonBg_[i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::RELEASED); + buttonBg_[i]->SetStyleForState(STYLE_BORDER_RADIUS, BREATH_RESULT_BORDER_RADIUS, UIButton::PRESSED); + buttonBg_[i]->SetStyleForState(STYLE_BORDER_RADIUS, BREATH_RESULT_BORDER_RADIUS, UIButton::INACTIVE); + buttonBg_[i]->SetStyleForState(STYLE_BORDER_RADIUS, BREATH_RESULT_BORDER_RADIUS, UIButton::RELEASED); + group_->Add(buttonBg_[i]); + } +} + +void BreathResultPage::InitLabelDes() +{ + std::string strDes[LABEL_COUNT] = {"呼吸频率", "呼吸前心率", "训练时长", "今日累计时长", "今日累计次数"}; + for (int i = 0; i < LABEL_COUNT; i++) { + labelDes_[i] = new UILabel(); + if (labelDes_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button ERROR"); + return; + } + + int posY = BREATH_RESULT_LABEL_DES_POSITION_Y + BREATH_RESULT_POSY_OFFSET * i; + labelDes_[i]->SetPosition(BREATH_RESULT_LABEL_DES_POSITION_X, posY, BREATH_RESULT_LABEL_DES_WIDTH, + BREATH_RESULT_LABEL_DES_HEIGHT); + labelDes_[i]->SetText(strDes[i].c_str()); + labelDes_[i]->SetTextColor(Color::White()); + labelDes_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_MIN_FONT_SIZE); + labelDes_[i]->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + labelDes_[i]->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(labelDes_[i]); + } +} + +void BreathResultPage::InitLabelCount() +{ + for (int i = 0; i < LABEL_COUNT; i++) { + labelValue_[i] = new UILabel(); + if (labelValue_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button ERROR"); + return; + } + + int posY = BREATH_RESULT_LABEL_COUNT_POSITION_Y + BREATH_RESULT_POSY_OFFSET * i; + labelValue_[i]->SetPosition(BREATH_RESULT_LABEL_COUNT_POSITION_X, posY, BREATH_RESULT_LABEL_COUNT_WIDTH, + BREATH_RESULT_LABEL_COUNT_HEIGHT); + labelValue_[i]->SetText("20"); + labelValue_[i]->SetTextColor(Color::White()); + labelValue_[i]->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_SCOUT_FONT_SIZE); + labelValue_[i]->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(labelValue_[i]); + } + scores_ = new UIImageView(); + if (scores_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Scores ERROR"); + return; + } + scores_->SetPosition(BREATH_SCORES_X, BREATH_SCORES_Y); + scores_->Resize(BREATH_SCORES_W, BREATH_SCORES_H); + group_->Add(scores_); + uint8_t heartRate_ = BreathModel::GetInstance().GetHeartRate(); + uint8_t frequencyScore_ = BreathModel::GetInstance().GetFrequencyScore(); + if (frequencyScore_ >= BREATH_NINETY_SIZE && frequencyScore_ <= BREATH_GUINEAS_SIZE) { + LOADIMG::LoadImageViewImg(scores_, BREATH_IMAGE, IMAGE_BREATH_EXCELLENT); + } else if (frequencyScore_ >= BREATH_EIGHTY_SIZE && frequencyScore_ <= BREATH_EIGHTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores_, BREATH_IMAGE, IMAGE_BREATH_GOOD); + } else if (frequencyScore_ >= BREATH_SEVENTY_SIZE && frequencyScore_ <= BREATH_SEVENTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores_, BREATH_IMAGE, IMAGE_BREATH_NORMAL); + } else if (frequencyScore_ >= BREATH_SIXTY_SIZE && frequencyScore_ <= BREATH_SIXTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores_, BREATH_IMAGE, IMAGE_BREATH_PASS); + } else { + LOADIMG::LoadImageViewImg(scores_, BREATH_IMAGE, IMAGE_BREATH_BAD); + } + labelValue_[INDEX_0]->SetText(std::to_string(heartRate_).c_str()); + labelValue_[INDEX_1]->SetText(std::to_string(frequencyScore_).c_str()); + int selectTime = BreathModel::GetInstance().GetTrainTime() + 1; + labelValue_[INDEX_2]->SetText(std::to_string(selectTime).c_str()); + labelValue_[INDEX_3]->SetText(BreathModel::GetInstance().GetTrainingDurationTime().c_str()); + labelValue_[INDEX_4]->SetText(BreathModel::GetInstance().GetTrainingCount().c_str()); +} + +void BreathResultPage::InitLabelUnit() +{ + std::string strDes[LABEL_COUNT] = {"次/分", "次/分", "分", "分钟", "次"}; + for (int i = 0; i < LABEL_COUNT; i++) { + labelUnit_[i] = new UILabel(); + if (labelUnit_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button ERROR"); + return; + } + + int offset = 10; + int posY = BREATH_RESULT_LABEL_UNIT_POSITION_Y + BREATH_RESULT_POSY_OFFSET * i; + int posX = BREATH_RESULT_LABEL_UNIT_POSITION_X + labelValue_[i]->GetTextWidth() + offset; + labelUnit_[i]->SetPosition(posX, posY, BREATH_RESULT_LABEL_UNIT_WIDTH, BREATH_RESULT_LABEL_UNIT_HEIGHT); + labelUnit_[i]->SetText(strDes[i].c_str()); + labelUnit_[i]->SetTextColor(Color::White()); + labelUnit_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_MIN_FONT_SIZE); + labelUnit_[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelUnit_[i]->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY_TWO); + labelUnit_[i]->SetWidth(labelUnit_[i]->GetTextWidth()); + group_->Add(labelUnit_[i]); + } +} + +bool BreathResultPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BREATH_BUTTON_COMPLETE_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), BREATH_BUTTON_RESTART_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_START_VIEW, + TransitionType::TRANSITION_INVALID, false); +#ifdef _WIN32 + struct timeval tv; + gettimeofday(&tv, NULL); +#else + struct timeval64 tv; + gettimeofday64(&tv, NULL); +#endif + uint32_t remTime = tv.tv_sec; + BreathModel::GetInstance().SetStartTime(remTime); + } + return true; +} + +bool BreathResultPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathRhythmSetPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathRhythmSetPage.cpp new file mode 100644 index 000000000..b508a1e73 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathRhythmSetPage.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathRhythmSetPage + * Create: 2025-5-13 + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "UiConfig.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#include "breathexercise/BreathModel.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathRhythmSetPage.h" + +namespace OHOS { +static constexpr char *BREATH_RHYTHM_BUTTON_OK_ID = "okButton"; +static constexpr uint16_t BREATH_RHYTHM_TITLE_X = 100; +static constexpr uint16_t BREATH_RHYTHM_TITLE_Y = 38; +static constexpr uint16_t BREATH_RHYTHM_TITLE_W = 253; +static constexpr uint16_t BREATH_RHYTHM_TITLE_H = 53; +static constexpr uint16_t BREATH_RHYTHM_TITLE_FONT_SIZE = 38; +static constexpr uint16_t BREATH_RHYTHM_PICKER_X = 64; +static constexpr uint16_t BREATH_RHYTHM_PICKER_Y = 109; +static constexpr uint16_t BREATH_RHYTHM_PICKER_W = 321; +static constexpr uint16_t BREATH_RHYTHM_PICKER_H = 218; +static constexpr uint16_t BREATH_RHYTHM_PICKER_FONT_SIZE = 44; +static constexpr uint16_t BREATH_RHYTHM_PICKER_ITEM_H = 80; +static constexpr uint16_t BREATH_RHYTHM_OK_X = 61; +static constexpr uint16_t BREATH_RHYTHM_OK_Y = 362; +static constexpr uint16_t BREATH_RHYTHM_OK_W = 331; +static constexpr uint16_t BREATH_RHYTHM_OK_H = 98; +static constexpr uint16_t BREATH_GROUP_SIZE = 466; +static constexpr uint8_t PICKER_SIZE = 3; +const char *g_rhythmListData[PICKER_SIZE] = {"稍快 8次/分", "舒缓 7次/分", "缓慢 6次/分"}; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_RHY_VIEW, BreathRhythmSetPage, false); + +BreathRhythmSetPage::BreathRhythmSetPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathRhythmSetPage::BreathRhythmSetPage"); +} + +BreathRhythmSetPage::~BreathRhythmSetPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (lableRhythm_ != nullptr) { + delete lableRhythm_; + lableRhythm_ = nullptr; + } + if (pickerRhythm_ != nullptr) { + delete pickerRhythm_; + pickerRhythm_ = nullptr; + } + if (buttonOk_ != nullptr) { + delete buttonOk_; + buttonOk_ = nullptr; + } + if (pickerImg_ != nullptr) { + delete pickerImg_; + pickerImg_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathRhythmSetPage::~BreathRhythmSetPage"); +} + +void BreathRhythmSetPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetTouchable(false); + group_->SetDraggable(false); + + lableRhythm_ = new UILabel(); + if (lableRhythm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new lableRhythm_ ERROR"); + return; + } + lableRhythm_->SetPosition(BREATH_RHYTHM_TITLE_X, BREATH_RHYTHM_TITLE_Y); + lableRhythm_->Resize(BREATH_RHYTHM_TITLE_W, BREATH_RHYTHM_TITLE_H); + lableRhythm_->SetText("节奏设置"); + lableRhythm_->SetTextColor(Color::White()); + lableRhythm_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableRhythm_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_RHYTHM_TITLE_FONT_SIZE); + group_->Add(lableRhythm_); + + pickerRhythm_ = new UIPicker(); + if (pickerRhythm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new pickerRhythm_ ERROR"); + return; + } + pickerRhythm_->SetPosition(BREATH_RHYTHM_PICKER_X, BREATH_RHYTHM_PICKER_Y); + pickerRhythm_->Resize(BREATH_RHYTHM_PICKER_W, BREATH_RHYTHM_PICKER_H); + pickerRhythm_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_RHYTHM_PICKER_FONT_SIZE); + pickerRhythm_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_RHYTHM_PICKER_FONT_SIZE); + pickerRhythm_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + pickerRhythm_->SetItemHeight(BREATH_RHYTHM_PICKER_ITEM_H); + pickerRhythm_->SetTextColor(Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff), + Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff)); + uint8_t selectPick = BreathModel::GetInstance().GetRhythm(); + pickerRhythm_->SetSelected(selectPick); + pickerRhythm_->RegisterSelectedListener(this); + pickerRhythm_->SetVisible(true); + pickerRhythm_->SetOnDragListener(this); + pickerRhythm_->SetLoopState(false); + group_->Add(pickerRhythm_); + + pickerImg_ = new UIImageView(); + if (pickerImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Center ERROR"); + return; + } + pickerImg_->SetPosition(BREATH_RHYTHM_PICKER_X, BREATH_RHYTHM_PICKER_Y); + pickerImg_->Resize(BREATH_RHYTHM_PICKER_W, BREATH_RHYTHM_PICKER_H); + LOADIMG::LoadImageViewImg(pickerImg_, BREATH_IMAGE, IMAGE_BREATH_CENTER); + group_->Add(pickerImg_); + + buttonOk_ = new UIButton(); + if (buttonOk_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonOk_ ERROR"); + return; + } + buttonOk_->SetPosition(BREATH_RHYTHM_OK_X, BREATH_RHYTHM_OK_Y); + buttonOk_->Resize(BREATH_RHYTHM_OK_W, BREATH_RHYTHM_OK_H); + buttonOk_->SetViewId(BREATH_RHYTHM_BUTTON_OK_ID); + buttonOk_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + LOADIMG::LoadBtnImage(buttonOk_, BREATH_IMAGE, IMAGE_BREATH_OK, IMAGE_BREATH_OK); + buttonOk_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonOk_->SetOnClickListener(this); + group_->Add(buttonOk_); + + AddViewToPageContainer(group_); +} + +void BreathRhythmSetPage::OnResume() +{ + pickerRhythm_->SetValues(g_rhythmListData, PICKER_SIZE); + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); +} + +bool BreathRhythmSetPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BREATH_RHYTHM_BUTTON_OK_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + BreathModel::GetInstance().SetRhythm(pickerRhythm_->GetSelected()); + } + return true; +} + +bool BreathRhythmSetPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathStartPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathStartPage.cpp new file mode 100644 index 000000000..4c8b35734 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathStartPage.cpp @@ -0,0 +1,223 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathStartPage + * Create: 2025-5-13 + */ +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "PageTransitionMgr.h" +#include "SlicePageFactory.h" +#include "TransitionType.h" +#include "UiConfig.h" +#include "components/root_view.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ohos_timer.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "breathexercise/BreathModel.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathStartPage.h" + +namespace OHOS { +static constexpr uint16_t BREATH_START_TITLE_X = 97; +static constexpr uint16_t BREATH_START_TITLE_Y = 40; +static constexpr uint16_t BREATH_START_TITLE_W = 260; +static constexpr uint16_t BREATH_START_TITLE_H = 53; +static constexpr uint16_t BREATH_START_TITLE_FONT_SIZE = 36; +static constexpr uint16_t BREATH_START_CENTERIMG_X = 88; +static constexpr uint16_t BREATH_START_CENTERIMG_Y = 88; +static constexpr uint16_t BREATH_START_CENTERIMG_W = 279; +static constexpr uint16_t BREATH_START_CENTERIMG_H = 280; +static constexpr uint16_t BREATH_START_GUIDE_X = 126; +static constexpr uint16_t BREATH_START_GUIDE_Y = 354; +static constexpr uint16_t BREATH_START_GUIDE_W = 202; +static constexpr uint16_t BREATH_START_GUIDE_H = 68; +static constexpr uint16_t BREATH_START_GUIDE_FONT_SIZE = 24; +static constexpr uint16_t BREATH_GROUP_SIZE = 466; +static constexpr uint16_t TEXT_OPACITY = 147; +static constexpr uint16_t COUNTDOWN = 5; +static constexpr uint16_t SIZE = 64; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_START_VIEW, BreathStartPage, false); + +BreathStartPage::BreathStartPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathStartPage::BreathStartPage"); +} + +BreathStartPage::~BreathStartPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (titleLable_ != nullptr) { + delete titleLable_; + titleLable_ = nullptr; + } + + if (guideLable_ != nullptr) { + delete guideLable_; + guideLable_ = nullptr; + } + + if (centerImg_ != nullptr) { + delete centerImg_; + centerImg_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (animatorCallBack_ != nullptr) { + delete animatorCallBack_; + animatorCallBack_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathStartPage::~BreathStartPage"); +} + +void BreathStartPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetTouchable(true); + group_->SetDraggable(true); + group_->SetOnDragListener(this); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new bgImg_ ERROR"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + LOADIMG::LoadImageViewImg(bgImg_, BREATH_IMAGE, IMAGE_BREATH_BG3); + group_->Add(bgImg_); + + titleLable_ = new UILabel(); + if (titleLable_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new titleLable_ ERROR"); + return; + } + titleLable_->SetPosition(BREATH_START_TITLE_X, BREATH_START_TITLE_Y); + titleLable_->Resize(BREATH_START_TITLE_W, BREATH_START_TITLE_H); + titleLable_->SetText("请保持静止"); + titleLable_->SetTextColor(Color::White()); + titleLable_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLable_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_START_TITLE_FONT_SIZE); + group_->Add(titleLable_); + + centerImg_ = new UIImageView(); + if (centerImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new centerImg ERROR"); + return; + } + centerImg_->SetPosition(BREATH_START_CENTERIMG_X, BREATH_START_CENTERIMG_Y); + centerImg_->Resize(BREATH_START_CENTERIMG_W, BREATH_START_CENTERIMG_H); + LOADIMG::LoadImageViewImg(centerImg_, BREATH_IMAGE, IMAGE_BREATH_CENTER1); + group_->Add(centerImg_); + + guideLable_ = new UILabel(); + if (guideLable_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new guideLable_ ERROR"); + return; + } + guideLable_->SetPosition(BREATH_START_GUIDE_X, BREATH_START_GUIDE_Y); + guideLable_->Resize(BREATH_START_GUIDE_W, BREATH_START_GUIDE_H); + guideLable_->SetTextColor(Color::White()); + guideLable_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + guideLable_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_START_GUIDE_FONT_SIZE); + guideLable_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + guideLable_->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(guideLable_); + + animatorCallBack_ = new BreathStartCallback(this); + if (animatorCallBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animatorCallBack_ ERROR"); + return; + } + animator_ = new Animator(animatorCallBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ ERROR"); + return; + } + animator_->Start(); + AddViewToPageContainer(group_); +} + +void BreathStartPage::BreathStartCallback::Callback(UIView *view) +{ + UNUSED(view); +#ifdef _WIN32 + struct timeval tv; + gettimeofday(&tv, NULL); +#else + struct timeval64 tv; + gettimeofday64(&tv, NULL); +#endif + int32_t start_time = BreathModel::GetInstance().GetStartTime(); + int32_t remTime = COUNTDOWN - (tv.tv_sec - start_time); + if (remTime <= 0) { + BreathStartPage->animator_->Stop(); +#ifdef _WIN32 + struct timeval time; + gettimeofday(&time, NULL); +#else + struct timeval64 time; + gettimeofday64(&time, NULL); +#endif + uint32_t breathing_time = time.tv_sec; + BreathModel::GetInstance().SetBeginTime(breathing_time); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_EXER_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else { + char szText[SIZE] = ""; + sprintf_s(szText, sizeof(szText), "%d秒后跟随训练指引开始吸气和呼气", remTime); + BreathStartPage->guideLable_->SetText(szText); + } +} + +void BreathStartPage::OnPause() +{ + animator_->Stop(); +} + +bool BreathStartPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void BreathStartPage::OnTimer() {} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTimeSetPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTimeSetPage.cpp new file mode 100644 index 000000000..a622c5baf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTimeSetPage.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathTimeSetPage + * Create: 2025-5-13 + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "TransitionType.h" +#include "UiConfig.h" +#include "components/root_view.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathTimeSetPage.h" + +namespace OHOS { +static constexpr char *BREATH_TIME_BUTTON_OK_ID = "okButton"; +static constexpr uint16_t BREATH_TIME_TITLE_X = 100; +static constexpr uint16_t BREATH_TIME_TITLE_Y = 38; +static constexpr uint16_t BREATH_TIME_TITLE_W = 253; +static constexpr uint16_t BREATH_TIME_TITLE_H = 53; +static constexpr uint16_t BREATH_TIME_TITLE_FONT_SIZE = 38; +static constexpr uint16_t BREATH_TIME_PICKER_X = 64; +static constexpr uint16_t BREATH_TIME_PICKER_Y = 109; +static constexpr uint16_t BREATH_TIME_PICKER_W = 321; +static constexpr uint16_t BREATH_TIME_PICKER_H = 218; +static constexpr uint16_t BREATH_TIME_PICKER_FONT_SIZE = 44; +static constexpr uint16_t BREATH_TIME_PICKER_ITEM_H = 80; +static constexpr uint16_t BREATH_TIME_OK_X = 61; +static constexpr uint16_t BREATH_TIME_OK_Y = 362; +static constexpr uint16_t BREATH_TIME_OK_W = 331; +static constexpr uint16_t BREATH_TIME_OK_H = 98; +static constexpr uint16_t BREATH_GROUP_SIZE = 466; +static constexpr uint8_t PICKER_SIZE = 3; +const char *g_timeList[PICKER_SIZE] = {"1 分钟", "2 分钟", "3 分钟"}; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_DUR_VIEW, BreathTimeSetPage, false); + +BreathTimeSetPage::BreathTimeSetPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathTimeSetPage::BreathTimeSetPage"); +} + +BreathTimeSetPage::~BreathTimeSetPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + if (pickerTime_ != nullptr) { + delete pickerTime_; + pickerTime_ = nullptr; + } + if (buttonOk_ != nullptr) { + delete buttonOk_; + buttonOk_ = nullptr; + } + if (pickerImg_ != nullptr) { + delete pickerImg_; + pickerImg_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathTimeSetPage::~BreathTimeSetPage"); +} + +void BreathTimeSetPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new Group ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ ERROR"); + return; + } + labelTitle_->SetPosition(BREATH_TIME_TITLE_X, BREATH_TIME_TITLE_Y); + labelTitle_->Resize(BREATH_TIME_TITLE_W, BREATH_TIME_TITLE_H); + labelTitle_->SetText("时间设置"); + labelTitle_->SetTextColor(Color::White()); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_TIME_TITLE_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(labelTitle_); + + pickerTime_ = new UIPicker(); + if (pickerTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new pickerTime_ ERROR"); + return; + } + pickerTime_->SetPosition(BREATH_TIME_PICKER_X, BREATH_TIME_PICKER_Y); + pickerTime_->Resize(BREATH_TIME_PICKER_W, BREATH_TIME_PICKER_H); + pickerTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + pickerTime_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TIME_PICKER_FONT_SIZE); + pickerTime_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TIME_PICKER_FONT_SIZE); + pickerTime_->SetItemHeight(BREATH_TIME_PICKER_ITEM_H); + pickerTime_->SetTextColor(Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff), + Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff)); + uint8_t selectTime = BreathModel::GetInstance().GetTrainTime(); + pickerTime_->SetSelected(selectTime); + pickerTime_->SetOnDragListener(this); + pickerTime_->SetLoopState(false); + group_->Add(pickerTime_); + + pickerImg_ = new UIImageView(); + if (pickerImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new pickerImg_ ERROR"); + return; + } + pickerImg_->SetPosition(BREATH_TIME_PICKER_X, BREATH_TIME_PICKER_Y); + pickerImg_->Resize(BREATH_TIME_PICKER_W, BREATH_TIME_PICKER_H); + LOADIMG::LoadImageViewImg(pickerImg_, BREATH_IMAGE, IMAGE_BREATH_CENTER); + group_->Add(pickerImg_); + + buttonOk_ = new UIButton(); + if (buttonOk_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonOk_ ERROR"); + return; + } + buttonOk_->SetPosition(BREATH_TIME_OK_X, BREATH_TIME_OK_Y); + buttonOk_->Resize(BREATH_TIME_OK_W, BREATH_TIME_OK_H); + buttonOk_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + buttonOk_->SetViewId(BREATH_TIME_BUTTON_OK_ID); + LOADIMG::LoadBtnImage(buttonOk_, BREATH_IMAGE, IMAGE_BREATH_OK, IMAGE_BREATH_OK); + buttonOk_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonOk_->SetOnClickListener(this); + group_->Add(buttonOk_); + + AddViewToPageContainer(group_); +} + +void BreathTimeSetPage::OnResume() +{ + pickerTime_->SetValues(g_timeList, PICKER_SIZE); + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); +} + +bool BreathTimeSetPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), BREATH_TIME_BUTTON_OK_ID) == 0) { + BreathModel::GetInstance().SetTrainTime(pickerTime_->GetSelected()); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool BreathTimeSetPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTrainingRecordsPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTrainingRecordsPage.cpp new file mode 100644 index 000000000..fa622d25c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/breathexercise/src/BreathTrainingRecordsPage.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathTrainingRecordsPage + * Create: 2025-5-13 + */ +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "TransitionType.h" +#include "UiConfig.h" +#include "components/root_view.h" +#include "gfx_utils/graphic_math.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "wearable_log.h" +#include "breathexercise/BreathView.h" +#include "breathexercise/BreathTrainingRecordsPage.h" + +namespace OHOS { +static constexpr uint16_t BREATH_TRAINING_RECORDS_X = 97; +static constexpr uint16_t BREATH_TRAINING_RECORDS_Y = 34; +static constexpr uint16_t BREATH_TRAINING_RECORDS_W = 260; +static constexpr uint16_t BREATH_TRAINING_RECORDS_H = 53; +static constexpr uint16_t BREATH_TRAINING_RECORDS_FONT_SIZE = 38; +static constexpr uint16_t BREATH_TRAINING_TOTALDURATION_X = 236; +static constexpr uint16_t BREATH_TRAINING_TOTALDURATION_Y = 139; +static constexpr uint16_t BREATH_TRAINING_TOTALDURATION_W = 96; +static constexpr uint16_t BREATH_TRAINING_TOTALDURATION_H = 30; +static constexpr uint16_t BREATH_TRAINING_FONT_SIZE = 24; +static constexpr uint16_t BREATH_TRAINING_DURATION_MINUTE_X = 290; +static constexpr uint16_t BREATH_TRAINING_DURATION_MINUTE_Y = 185; +static constexpr uint16_t BREATH_TRAINING_DURATION_MINUTE_W = 48; +static constexpr uint16_t BREATH_TRAINING_DURATION_MINUTE_H = 29; +static constexpr uint16_t BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_X = 236; +static constexpr uint16_t BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_Y = 268; +static constexpr uint16_t BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_W = 96; +static constexpr uint16_t BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_H = 30; +static constexpr uint16_t BREATH_TRAINING_NUMBER_OF_TIMES_X = 290; +static constexpr uint16_t BREATH_TRAINING_NUMBER_OF_TIMES_Y = 315; +static constexpr uint16_t BREATH_TRAINING_NUMBER_OF_TIMES_W = 29; +static constexpr uint16_t BREATH_TRAINING_NUMBER_OF_TIMES_H = 29; +static constexpr uint16_t BREATH_TRAINING_TIME_X = 236; +static constexpr uint16_t BREATH_TRAINING_TIME_Y = 171; +static constexpr uint16_t BREATH_TRAINING_TIME_W = 49; +static constexpr uint16_t BREATH_TRAINING_TIME_H = 49; +static constexpr uint16_t BREATH_TRAINING_FONT_MAX_SIZE = 40; +static constexpr uint16_t BREATH_TRAINING_SCOUR_X = 236; +static constexpr uint16_t BREATH_TRAINING_SCOUR_Y = 303; +static constexpr uint16_t BREATH_TRAINING_SCOUR_W = 49; +static constexpr uint16_t BREATH_TRAINING_SCOUR_H = 49; +static constexpr uint16_t BREATH_TRAINING_SIZE = 454; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND2_X = 65; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND2_Y = 174; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND2_W = 119; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND2_H = 120; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND3_X = 215; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND3_Y = 123; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND3_W = 171; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND3_H = 108; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND4_X = 215; +static constexpr uint16_t BREATH_TRAINING_BACKGROUND4_Y = 252; +static constexpr uint16_t TEXT_OPACITY = 147; +static constexpr uint16_t TEXT_OPACITY_BACK = 27; +static constexpr uint16_t Y_OFFSET = 50; + +REGIST_SLICE_PAGE(VIEW_BREATH, BREATH_PAGE::BREATH_TRAINING_VIEW, BreathTrainingRecordsPage, false); + +BreathTrainingRecordsPage::BreathTrainingRecordsPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathTrainingRecordsPage::BreathTrainingRecordsPage"); +} + +BreathTrainingRecordsPage::~BreathTrainingRecordsPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (labelTimeDes_ != nullptr) { + delete labelTimeDes_; + labelTimeDes_ = nullptr; + } + if (labelTimeUnit_ != nullptr) { + delete labelTimeUnit_; + labelTimeUnit_ = nullptr; + } + if (labelCountDes_ != nullptr) { + delete labelCountDes_; + labelCountDes_ = nullptr; + } + if (labelCountUnit_ != nullptr) { + delete labelCountUnit_; + labelCountUnit_ = nullptr; + } + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + if (labelTimeValue_ != nullptr) { + delete labelTimeValue_; + labelTimeValue_ = nullptr; + } + if (labelCountValue_ != nullptr) { + delete labelCountValue_; + labelCountValue_ = nullptr; + } + if (bgImg1_ != nullptr) { + delete bgImg1_; + bgImg1_ = nullptr; + } + if (bgImg2_ != nullptr) { + delete bgImg2_; + bgImg2_ = nullptr; + } + if (bgImg3_ != nullptr) { + delete bgImg3_; + bgImg3_ = nullptr; + } + if (bgImg4_ != nullptr) { + delete bgImg4_; + bgImg4_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathTrainingRecordsPage::~BreathTrainingRecordsPage"); +} + +void BreathTrainingRecordsPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ ERROR"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetTouchable(true); + group_->SetDraggable(true); + group_->SetOnDragListener(this); + + bgImg1_ = new UIImageView(); + if (bgImg1_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new bgImg1_ ERROR"); + return; + } + bgImg1_->SetPosition(0, 0); + bgImg1_->Resize(BREATH_TRAINING_SIZE, BREATH_TRAINING_SIZE); + LOADIMG::LoadImageViewImg(bgImg1_, BREATH_IMAGE, IMAGE_BREATH_BG3); + group_->Add(bgImg1_); + + bgImg2_ = new UIImageView(); + if (bgImg2_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new bgImg2_ ERROR"); + return; + } + bgImg2_->SetPosition(BREATH_TRAINING_BACKGROUND2_X, BREATH_TRAINING_BACKGROUND2_Y); + bgImg2_->Resize(BREATH_TRAINING_BACKGROUND2_W, BREATH_TRAINING_BACKGROUND2_H); + LOADIMG::LoadImageViewImg(bgImg2_, BREATH_IMAGE, IMAGE_BREATH_RESULT); + group_->Add(bgImg2_); + + bgImg3_ = new UIImageView(); + if (bgImg3_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new bgImg3_ ERROR"); + return; + } + bgImg3_->SetPosition(BREATH_TRAINING_BACKGROUND3_X, BREATH_TRAINING_BACKGROUND3_Y); + bgImg3_->Resize(BREATH_TRAINING_BACKGROUND3_W, BREATH_TRAINING_BACKGROUND3_H); + LOADIMG::LoadImageViewImg(bgImg3_, BREATH_IMAGE, IMAGE_BREATH_BG4); + bgImg3_->SetStyle(STYLE_BACKGROUND_OPA, TEXT_OPACITY_BACK); + group_->Add(bgImg3_); + + bgImg4_ = new UIImageView(); + if (bgImg4_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new bgImg4_ ERROR"); + return; + } + bgImg4_->SetPosition(BREATH_TRAINING_BACKGROUND4_X, BREATH_TRAINING_BACKGROUND4_Y); + bgImg4_->Resize(BREATH_TRAINING_BACKGROUND3_W, BREATH_TRAINING_BACKGROUND3_H); + LOADIMG::LoadImageViewImg(bgImg4_, BREATH_IMAGE, IMAGE_BREATH_BG4); + bgImg4_->SetStyle(STYLE_BACKGROUND_OPA, TEXT_OPACITY_BACK); + group_->Add(bgImg4_); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ ERROR"); + return; + } + labelTitle_->SetPosition(BREATH_TRAINING_RECORDS_X, BREATH_TRAINING_RECORDS_Y); + labelTitle_->Resize(BREATH_TRAINING_RECORDS_W, BREATH_TRAINING_RECORDS_H); + labelTitle_->SetText("训练记录"); + labelTitle_->SetTextColor(Color::White()); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_TRAINING_RECORDS_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(labelTitle_); + + labelTimeDes_ = new UILabel(); + if (labelTimeDes_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTimeDes_ ERROR"); + return; + } + labelTimeDes_->SetPosition(BREATH_TRAINING_TOTALDURATION_X, BREATH_TRAINING_TOTALDURATION_Y); + labelTimeDes_->Resize(BREATH_TRAINING_TOTALDURATION_W, BREATH_TRAINING_TOTALDURATION_H); + labelTimeDes_->SetText("累计时长"); + labelTimeDes_->SetTextColor(Color::White()); + labelTimeDes_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_SIZE); + labelTimeDes_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTimeDes_->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(labelTimeDes_); + + labelTimeUnit_ = new UILabel(); + if (labelTimeUnit_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTimeUnit_ ERROR"); + return; + } + labelTimeUnit_->SetPosition(BREATH_TRAINING_DURATION_MINUTE_X, BREATH_TRAINING_DURATION_MINUTE_Y); + labelTimeUnit_->Resize(BREATH_TRAINING_DURATION_MINUTE_W, BREATH_TRAINING_DURATION_MINUTE_H); + labelTimeUnit_->SetText("分钟"); + labelTimeUnit_->SetTextColor(Color::White()); + labelTimeUnit_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_SIZE); + labelTimeUnit_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTimeUnit_->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(labelTimeUnit_); + + labelCountDes_ = new UILabel(); + if (labelCountDes_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelCountDes_ ERROR"); + return; + } + labelCountDes_->SetPosition(BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_X, BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_Y); + labelCountDes_->Resize(BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_W, BREATH_TRAINING_TOTAL_NUMBLE_OF_TIMES_H); + labelCountDes_->SetText("累计次数"); + labelCountDes_->SetTextColor(Color::White()); + labelCountDes_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_SIZE); + labelCountDes_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelCountDes_->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(labelCountDes_); + + labelCountUnit_ = new UILabel(); + if (labelCountUnit_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelCountUnit_ ERROR"); + return; + } + labelCountUnit_->SetPosition(BREATH_TRAINING_NUMBER_OF_TIMES_X, BREATH_TRAINING_NUMBER_OF_TIMES_Y); + labelCountUnit_->Resize(BREATH_TRAINING_NUMBER_OF_TIMES_W, BREATH_TRAINING_NUMBER_OF_TIMES_H); + labelCountUnit_->SetText("次"); + labelCountUnit_->SetTextColor(Color::White()); + labelCountUnit_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_SIZE); + labelCountUnit_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelCountUnit_->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group_->Add(labelCountUnit_); + + labelTimeValue_ = new UILabel(); + if (labelTimeValue_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTimeValue_ ERROR"); + return; + } + labelTimeValue_->SetPosition(BREATH_TRAINING_TIME_X, BREATH_TRAINING_TIME_Y); + labelTimeValue_->Resize(BREATH_TRAINING_TIME_W, BREATH_TRAINING_TIME_H); + labelTimeValue_->SetTextColor(Color::White()); + labelTimeValue_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_MAX_SIZE); + labelTimeValue_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTimeValue_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + group_->Add(labelTimeValue_); + + labelCountValue_ = new UILabel(); + if (labelCountValue_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelCountValue_ ERROR"); + return; + } + labelCountValue_->SetPosition(BREATH_TRAINING_SCOUR_X, BREATH_TRAINING_SCOUR_Y); + labelCountValue_->Resize(BREATH_TRAINING_SCOUR_W, BREATH_TRAINING_SCOUR_H); + labelCountValue_->SetTextColor(Color::White()); + labelCountValue_->SetFont(BOLD_VECTOR_FONT_FILENAME, BREATH_TRAINING_FONT_MAX_SIZE); + labelCountValue_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelCountValue_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + group_->Add(labelCountValue_); + + AddViewToPageContainer(group_); +} + +void BreathTrainingRecordsPage::OnResume() +{ + labelTimeValue_->SetText((BreathModel::GetInstance().GetTrainingDurationTime().c_str())); + labelCountValue_->SetText((BreathModel::GetInstance().GetTrainingCount().c_str())); +} + +bool BreathTrainingRecordsPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) && (event.GetStartPoint().y > Y_OFFSET)) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_PAGE::BREATH_MAIN_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraMainPage.cpp index 6aca1160c..aea7204eb 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraMainPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraMainPage.cpp @@ -14,12 +14,11 @@ #include "bts_spp.h" #include "ui_resource_camera.h" #include "camera/CameraView.h" -#include "camera/CameraMainPage.h" #include "camera/CameraPresenter.h" +#include "camera/CameraMainPage.h" namespace OHOS { static CameraMainPage *g_pCameraMainPage = nullptr; - static constexpr uint16_t BLUETOOTH_XPOS = 158; static constexpr uint16_t BLUETOOTH_XPOY = 154; static constexpr uint16_t TITLE_XPOS = 15; @@ -33,19 +32,19 @@ static constexpr uint16_t CAMERATITLE_XPOY = 37; static constexpr uint16_t CAMERATITLE_WIDTH = 260; static constexpr uint16_t CAMERATITLE_HIGHT = 53; static constexpr uint16_t CAMERAFIND_XPOS = 123; -static constexpr uint16_t CAMERAFIND_XPOY = 200; +static constexpr uint16_t CAMERAFIND_XPOY = 192; static constexpr uint16_t CAMERAFIND_WIDTH = 250; static constexpr uint16_t CAMERAFIND_HIGHT = 42; -static constexpr uint16_t CAMERATIME_XPOS = 200; +static constexpr uint16_t CAMERATIME_XPOS = 102; static constexpr uint16_t BUTTON_WIDTH = 171; static constexpr uint16_t BUTTON_HIGHT = 171; static constexpr uint16_t COUNTDOWN_TIME = 5; static constexpr uint16_t CAMERA_SIZE = 466; static constexpr uint16_t CAMERA_BUTTON_POSITION_X = 144; static constexpr uint16_t CAMERA_BUTTON_POSITION_Y = 154; -static constexpr uint16_t TIME_FONT_SIZE = 50; -static constexpr uint16_t CAMERATIME_HIGHT = 55; -static constexpr uint16_t ERROR_NUM = 2; +static constexpr uint16_t TIME_FONT_SIZE = 72; +static constexpr uint16_t CAMERATIME_HIGHT = 70; +static constexpr char *TAKEPHOTO_BUTTON = "takePhotoButton"; REGIST_SLICE_PAGE(VIEW_CAMERA, CAMERA_PAGES::CAMERA_MAIN_PAGE, CameraMainPage, true); @@ -65,45 +64,45 @@ CameraMainPage::~CameraMainPage() container_ = nullptr; } - if (title != nullptr) { - delete title; - title = nullptr; + if (disconnectTitle_ != nullptr) { + delete disconnectTitle_; + disconnectTitle_ = nullptr; } - if (bluetoothDisconnected != nullptr) { - delete bluetoothDisconnected; - bluetoothDisconnected = nullptr; + if (btDisconnected_ != nullptr) { + delete btDisconnected_; + btDisconnected_ = nullptr; } - if (cameraFind != nullptr) { - delete cameraFind; - cameraFind = nullptr; + if (cameraFind_ != nullptr) { + delete cameraFind_; + cameraFind_ = nullptr; } - if (cameraTitle != nullptr) { - delete cameraTitle; - cameraTitle = nullptr; + if (cameraTitle_ != nullptr) { + delete cameraTitle_; + cameraTitle_ = nullptr; } - if (cameraTime != nullptr) { - delete cameraTime; - cameraTime = nullptr; + if (cameraTime_ != nullptr) { + delete cameraTime_; + cameraTime_ = nullptr; } - if (button != nullptr) { - delete button; - button = nullptr; - } - - if (animator_ != nullptr) { - delete animator_; - animator_ = nullptr; + if (takePhotoButton_ != nullptr) { + delete takePhotoButton_; + takePhotoButton_ = nullptr; } if (callBack_ != nullptr) { delete callBack_; callBack_ = nullptr; } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } ImageCacheManager::GetInstance().UnloadAllInMultiRes(CAMERA_IMAGE); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraMainPage::~CameraMainPage"); } @@ -115,76 +114,85 @@ CameraMainPage *CameraMainPage::GetInstance() void CameraMainPage::OnStart(void *data) { + container_ = new UIScrollView(); if (container_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CameraMainPage::new container fail"); - container_ = new UIScrollView(); - container_->SetPosition(0, 0, CAMERA_SIZE, CAMERA_SIZE); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ is nullptr"); + return; } + container_->SetPosition(0, 0, CAMERA_SIZE, CAMERA_SIZE); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); container_->SetTouchable(true); container_->SetDraggable(true); container_->SetOnDragListener(this); - bluetoothDisconnected = new UIImageView(); - if (bluetoothDisconnected == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDisconnected is nullptr"); + btDisconnected_ = new UIImageView(); + if (btDisconnected_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btDisconnected_ is nullptr"); return; } - LOADIMG::LoadImageViewImg(bluetoothDisconnected, CAMERA_IMAGE, IMAGE_CONVERTER_TOOL_CAMERA_2); - bluetoothDisconnected->SetPosition(BLUETOOTH_XPOS, BLUETOOTH_XPOY); - bluetoothDisconnected->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - bluetoothDisconnected->SetVisible(false); - container_->Add(bluetoothDisconnected); - - title = new UILabel(); - if (title == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title is nullptr"); + LOADIMG::LoadImageViewImg(btDisconnected_, CAMERA_IMAGE, IMAGE_CAMERA_DISCONNECT); + btDisconnected_->SetPosition(BLUETOOTH_XPOS, BLUETOOTH_XPOY); + btDisconnected_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + btDisconnected_->SetVisible(false); + container_->Add(btDisconnected_); + + disconnectTitle_ = new UILabel(); + if (disconnectTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "disconnectTitle_ is nullptr"); return; } - title->SetText("蓝牙已断开"); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); - title->SetPosition(TITLE_XPOS, TITLE_XPOY, TITLE_WIDTH, TITLE_HIGHT); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetVisible(false); - container_->Add(title); - - cameraTitle = new UILabel(); - if (cameraTitle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTitle is nullptr"); + disconnectTitle_->SetText("蓝牙已断开"); + disconnectTitle_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); + disconnectTitle_->SetPosition(TITLE_XPOS, TITLE_XPOY, TITLE_WIDTH, TITLE_HIGHT); + disconnectTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + disconnectTitle_->SetVisible(false); + container_->Add(disconnectTitle_); + + cameraTitle_ = new UILabel(); + if (cameraTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTitle_ is nullptr"); return; } - cameraTitle->SetText("相机"); - cameraTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CAMERATITLE_FONT_SIZE); - cameraTitle->SetPosition(CAMERATITLE_XPOS, CAMERATITLE_XPOY, CAMERATITLE_WIDTH, CAMERATITLE_HIGHT); - cameraTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - cameraTitle->SetVisible(false); - container_->Add(cameraTitle); - - cameraFind = new UILabel(); - if (cameraFind == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraFind is nullptr"); + cameraTitle_->SetText("相机"); + cameraTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, CAMERATITLE_FONT_SIZE); + cameraTitle_->SetPosition(CAMERATITLE_XPOS, CAMERATITLE_XPOY, CAMERATITLE_WIDTH, CAMERATITLE_HIGHT); + cameraTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + cameraTitle_->SetVisible(false); + container_->Add(cameraTitle_); + + cameraFind_ = new UILabel(); + if (cameraFind_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraFind_ is nullptr"); return; } - cameraFind->SetText("正在连接手机..."); - cameraFind->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); - cameraFind->SetPosition(CAMERAFIND_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERAFIND_HIGHT); - cameraFind->SetVisible(false); - container_->Add(cameraFind); - - cameraTime = new UILabel(); - if (cameraTime == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTime is nullptr"); + cameraFind_->SetText("正在连接手机..."); + cameraFind_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); + cameraFind_->SetPosition(CAMERAFIND_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERAFIND_HIGHT); + cameraFind_->SetVisible(false); + container_->Add(cameraFind_); + + cameraTime_ = new UILabel(); + if (cameraTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTime_ is nullptr"); return; } - cameraTime->SetText("5s"); - cameraTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_FONT_SIZE); - cameraTime->SetPosition(CAMERATIME_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERATIME_HIGHT); - cameraTime->SetVisible(false); - container_->Add(cameraTime); + cameraTime_->SetText("5s"); + cameraTime_->SetFont(BOLD_VECTOR_FONT_FILENAME, TIME_FONT_SIZE); + cameraTime_->SetPosition(CAMERATIME_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERATIME_HIGHT); + cameraTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + cameraTime_->SetVisible(false); + container_->Add(cameraTime_); SetUpButton(); callBack_ = new CameraAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack_ is nullptr"); + return; + } animator_ = new Animator(callBack_, nullptr, 0, true); - + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "animator_ is nullptr"); + return; + } AddViewToPageContainer(container_); InitCameraView(); } @@ -208,13 +216,14 @@ uint8_t CameraMainPage::GetConnectStatus() void CameraMainPage::InitCameraView() { if (GetConnectStatus() == 1) { - cameraTitle->SetVisible(true); - cameraFind->SetVisible(true); - title->SetVisible(false); - bluetoothDisconnected->SetVisible(false); - cameraTime->SetVisible(false); - button->SetVisible(false); - button->SetTouchable(false); + cameraTitle_->SetVisible(true); + cameraFind_->SetVisible(true); + disconnectTitle_->SetVisible(false); + btDisconnected_->SetVisible(false); + cameraTime_->SetVisible(false); + takePhotoButton_->SetVisible(false); + takePhotoButton_->Disable(); + takePhotoButton_->SetTouchable(false); container_->Invalidate(); uint8_t value = 1; errcode_t ret; @@ -222,52 +231,55 @@ void CameraMainPage::InitCameraView() ret = 0; #else ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, - MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE, &value, sizeof(value)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE ret = %d", ret); + MSGCENTER_TYPE_ID_CAMERA_CONNECTING_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "connecting phoneCamera ret = %d", ret); #endif } else { - title->SetVisible(true); - bluetoothDisconnected->SetVisible(true); - cameraTitle->SetVisible(false); - cameraFind->SetVisible(false); - cameraTime->SetVisible(false); - button->SetVisible(false); - button->SetTouchable(false); + disconnectTitle_->SetVisible(true); + btDisconnected_->SetVisible(true); + cameraTitle_->SetVisible(false); + cameraFind_->SetVisible(false); + cameraTime_->SetVisible(false); + takePhotoButton_->SetVisible(false); + takePhotoButton_->Disable(); + takePhotoButton_->SetTouchable(false); container_->Invalidate(); } } void CameraMainPage::Refresh_page() { - cameraTitle->SetVisible(true); - button->SetVisible(true); - button->SetTouchable(true); - cameraFind->SetVisible(false); - title->SetVisible(false); - bluetoothDisconnected->SetVisible(false); - cameraTime->SetVisible(false); + cameraTitle_->SetVisible(true); + takePhotoButton_->SetVisible(true); + takePhotoButton_->Enable(); + takePhotoButton_->SetTouchable(true); + cameraFind_->SetVisible(false); + disconnectTitle_->SetVisible(false); + btDisconnected_->SetVisible(false); + cameraTime_->SetVisible(false); container_->Invalidate(); } void CameraMainPage::SetUpButton() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraMainPage::SetupButton new Label"); - if (button == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button is nullptr"); - button = new UILabelButton(); + takePhotoButton_ = new UILabelButton(); + if (takePhotoButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "takePhotoButton_ is nullptr"); + return; } - button->SetPosition(CAMERA_BUTTON_POSITION_X, CAMERA_BUTTON_POSITION_Y); - button->Resize(BUTTON_WIDTH, BUTTON_HIGHT); - button->SetViewId("button1"); - button->SetOnClickListener(this); - button->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); - button->SetVisible(false); - button->SetTouchable(false); - LOADIMG::LoadBtnImage(button, CAMERA_IMAGE, IMAGE_CONVERTER_TOOL_CAMERA_1, IMAGE_CONVERTER_TOOL_CAMERA_1); - container_->Add(button); + takePhotoButton_->SetPosition(CAMERA_BUTTON_POSITION_X, CAMERA_BUTTON_POSITION_Y); + takePhotoButton_->Resize(BUTTON_WIDTH, BUTTON_HIGHT); + takePhotoButton_->SetViewId(TAKEPHOTO_BUTTON); + takePhotoButton_->SetOnClickListener(this); + takePhotoButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + takePhotoButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + takePhotoButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + takePhotoButton_->SetVisible(false); + takePhotoButton_->Disable(); + takePhotoButton_->SetTouchable(false); + LOADIMG::LoadBtnImage(takePhotoButton_, CAMERA_IMAGE, IMAGE_CAMERA_TAKEPHOTO, IMAGE_CAMERA_TAKEPHOTO); + container_->Add(takePhotoButton_); } void CameraMainPage::OnPause() @@ -278,20 +290,22 @@ void CameraMainPage::OnPause() bool CameraMainPage::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - if (view.GetViewId() == "button1") { + if (strcmp(view.GetViewId(), TAKEPHOTO_BUTTON) == 0) { if (GetConnectStatus() == 1) { - button->SetVisible(false); - cameraTime->SetVisible(true); - SetFirstFlag(true); + takePhotoButton_->SetVisible(false); + takePhotoButton_->Disable(); + cameraTime_->SetVisible(true); + SetFirstClickFlag(true); animator_->Start(); } else { - title->SetVisible(true); - bluetoothDisconnected->SetVisible(true); - cameraTitle->SetVisible(false); - cameraFind->SetVisible(false); - cameraTime->SetVisible(false); - button->SetVisible(false); - button->SetTouchable(false); + disconnectTitle_->SetVisible(true); + btDisconnected_->SetVisible(true); + cameraTitle_->SetVisible(false); + cameraFind_->SetVisible(false); + cameraTime_->SetVisible(false); + takePhotoButton_->SetVisible(false); + takePhotoButton_->Disable(); + takePhotoButton_->SetTouchable(false); container_->Invalidate(); } } @@ -300,21 +314,19 @@ bool CameraMainPage::OnClick(UIView &view, const ClickEvent &event) bool CameraMainPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraPresenter::OnDrag"); UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); uint8_t value = 1; errcode_t ret; #ifdef _WIN32 ret = 0; #else ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, - MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT, &value, sizeof(value)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT ret = %d", ret); + MSGCENTER_TYPE_ID_PHONE_EXIT_CAMERA, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "notify phone exit camera, ret = %d", ret); #endif - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } return true; } @@ -325,13 +337,12 @@ void CameraMainPage::CameraAnimatorCallback::Callback(UIView *view) static int count = 0; static struct timeval start_time; struct timeval current_time; - if (page_->GetFirstFlag()) { + if (page_->GetFirstClickFlag()) { gettimeofday(&start_time, nullptr); - page_->SetFirstFlag(false); + page_->SetFirstClickFlag(false); } gettimeofday(¤t_time, nullptr); int time = current_time.tv_sec - start_time.tv_sec; - std::string strTime1 = std::to_string(COUNTDOWN_TIME - time) + "s"; page_->SetCameraTime(time); if (time == COUNTDOWN_TIME) { page_->StopAnimator(); @@ -341,18 +352,18 @@ void CameraMainPage::CameraAnimatorCallback::Callback(UIView *view) void CameraMainPage::StopAnimator() { animator_->Stop(); - button->SetVisible(true); - cameraTime->SetVisible(false); - cameraTime->SetText("5s"); - SetFirstFlag(false); + takePhotoButton_->SetVisible(true); + takePhotoButton_->Enable(); + cameraTime_->SetVisible(false); + cameraTime_->SetText("5s"); + SetFirstClickFlag(false); uint8_t value = 1; errcode_t ret; #ifdef _WIN32 - ret = 0; + ret = 0; #else - ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, - MSGCENTER_TYPE_ID_ON_CAMERA, &value, sizeof(value)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_ON_CAMERA ret = %d", ret); + ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_ON_CAMERA, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "notify phone take photo ret = %d", ret); #endif } @@ -361,16 +372,16 @@ void CameraMainPage::SetCameraTime(int time) int progressTime = COUNTDOWN_TIME - time; int progressValue = 0; std::string strTime = std::to_string(COUNTDOWN_TIME - time) + "s"; - cameraTime->SetText(strTime.c_str()); + cameraTime_->SetText(strTime.c_str()); } -bool CameraMainPage::GetFirstFlag() +bool CameraMainPage::GetFirstClickFlag() { - return isFirst; + return isFirstClick_; } -void CameraMainPage::SetFirstFlag(bool value) +void CameraMainPage::SetFirstClickFlag(bool value) { - isFirst = value; + isFirstClick_ = value; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraModel.cpp index 669c55b3d..bc0796f69 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraModel.cpp @@ -7,11 +7,10 @@ #include #include "ohos_timer.h" #include "wearable_log.h" -#include "camera/CameraModel.h" #include "camera/CameraView.h" +#include "camera/CameraModel.h" namespace OHOS { - CameraModel::CameraModel() {} CameraModel::~CameraModel() {} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraPresenter.cpp index 4d94013c8..78a576f1e 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/camera/src/CameraPresenter.cpp @@ -11,5 +11,5 @@ #include "camera/CameraPresenter.h" namespace OHOS { -REGIST_MENU(VIEW_CAMERA, CameraView, CameraPresenter, CAMERA_MAIN_ICON, PNG_APPLIST_SETTING_IMAGE, "相机"); +REGIST_MENU(VIEW_CAMERA, CameraView, CameraPresenter, CAMERA_ICON, CAMERA_ICON, "相机"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/AmbientClockView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/AmbientClockView.cpp index c0e50762d..21f615166 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/AmbientClockView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/AmbientClockView.cpp @@ -11,11 +11,14 @@ #include "wearable_log.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" -#include "UICardPageFactory.h" +#include "UIWatchDialFactory.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif namespace OHOS { -REGIST_WATCH_DIAL(DIAL_DISPLAY_MODE_AOD, DIAL_CLOCK, AmbientClockView); +REGIST_WATCH_DIAL(DIAL_DISPLAY_SUPPORT_AOD, DIAL_CLOCK, AmbientClockView, nullptr); static constexpr uint16_t POINT_POSITION_X = 202; static constexpr uint16_t POINT_POSITION_Y = 16; @@ -36,33 +39,11 @@ static constexpr int16_t HOURLY_SYSTEM = 24; AmbientClockView::AmbientClockView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AmbientClockView::AmbientClockView"); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - PreLoad(); } AmbientClockView::~AmbientClockView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AmbientClockView::~AmbientClockView"); - if (viewiInitStatus_) { - mainSweepClock_->RemoveAll(); - delete secondHand_; - secondHand_ = nullptr; - delete minuteHand_; - minuteHand_ = nullptr; - delete hourHand_; - hourHand_ = nullptr; - delete hand24Hour_; - hand24Hour_ = nullptr; - delete bigCircle_; - bigCircle_ = nullptr; - delete medCircle_; - medCircle_ = nullptr; - delete smallCircle_; - smallCircle_ = nullptr; - Remove(mainSweepClock_); - delete mainSweepClock_; - mainSweepClock_ = nullptr; - } } bool AmbientClockView::InitCenterCircleView(void) @@ -162,28 +143,45 @@ bool AmbientClockView::InitSweepClock(void) return true; } -void AmbientClockView::PreLoad(void) +void AmbientClockView::InitDateTime(void) { - if (!viewiInitStatus_) { - InitView(); - viewiInitStatus_ = true; - } + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + mainSweepClock_->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); +} + +void AmbientClockView::Update(void) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * + SEC_TO_MILLI + uSecond / USEC_TO_MILLI); + mainSweepClock_->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); } -bool AmbientClockView::InitView(void) +void AmbientClockView::OnCreateView(void* data) { + fragmentView_.SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AmbientClockView::InitView"); mainSweepClock_ = new UISweepClock(); if (mainSweepClock_ == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); - return false; + return; } if (!InitSweepClock()) { - return false; + return; } - Add(mainSweepClock_); + fragmentView_.Add(mainSweepClock_); mainSweepClock_->SetDragParentInstead(true); mainSweepClock_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -205,32 +203,31 @@ bool AmbientClockView::InitView(void) mainSweepClock_->SetInitTime24Hour(0, 0, 0); mainSweepClock_->SetWorkMode(UISweepClock::WorkMode::NORMAL); InitDateTime(); - SetCoverable(true); - return true; -} - -void AmbientClockView::InitDateTime(void) -{ - struct tm pTM; - time_t seconds; - time(&seconds); - localtime_r(&seconds, &pTM); - mainSweepClock_->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); } -void AmbientClockView::UpdateTime(void) +void AmbientClockView::OnDestroyView() { - struct timeval tv; - gettimeofday(&tv, nullptr); - uint64_t second = tv.tv_sec; - uint64_t uSecond = tv.tv_usec; - uint64_t minute = second / MIN_TO_HOUR; - uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); - uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * - SEC_TO_MILLI + uSecond / USEC_TO_MILLI); - mainSweepClock_->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AmbientClockView::OnDestroyView"); + if (mainSweepClock_ != nullptr) { + mainSweepClock_->RemoveAll(); + delete secondHand_; + secondHand_ = nullptr; + delete minuteHand_; + minuteHand_ = nullptr; + delete hourHand_; + hourHand_ = nullptr; + delete hand24Hour_; + hand24Hour_ = nullptr; + delete bigCircle_; + bigCircle_ = nullptr; + delete medCircle_; + medCircle_ = nullptr; + delete smallCircle_; + smallCircle_ = nullptr; + fragmentView_.Remove(mainSweepClock_); + delete mainSweepClock_; + mainSweepClock_ = nullptr; + } } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientAodView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientAodView.cpp new file mode 100644 index 000000000..db6da99a0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientAodView.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientAodView + * Create: 2025-04 + */ + +#include "clock/GradientAodView.h" +#include "wearable_log.h" +#include "UIWatchDialFactory.h" + +namespace OHOS { + +REGIST_WATCH_DIAL(DIAL_DISPLAY_SUPPORT_AOD, GRADIENT_CLOCK, GradientAodView, nullptr); + +static GradientAodView* g_pGradientAodView = nullptr; + +GradientAodView::GradientAodView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientAodView::GradientAodView"); + g_pGradientAodView = this; +} + +GradientAodView::~GradientAodView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientAodView::~GradientAodView"); +} + +GradientAodView *GradientAodView::GetInstance(void) +{ + return g_pGradientAodView; +} + +void GradientAodView::Update(void) +{ + if (gradientDateView_ != nullptr) { + gradientDateView_->UpdateTime(); + } +} + +void GradientAodView::OnCreateView(void* data) +{ + fragmentView_.SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientAodView::OnCreateView"); + gradientDateView_ = new GradientDateView(); + if (!gradientDateView_) { + GRAPHIC_LOGE("gradientDateView_ malloc memory Failed\n"); + return; + } + fragmentView_.Add(gradientDateView_); + gradientDateView_->InitView(); + Update(); +} + +void GradientAodView::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientAodView::OnDestroyView"); + if (gradientDateView_) { + gradientDateView_->RemoveAll(); + fragmentView_.Remove(gradientDateView_); + delete gradientDateView_; + gradientDateView_ = nullptr; + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientClockView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientClockView.cpp new file mode 100644 index 000000000..31fdb2040 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientClockView.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientClockView + * Create: 2025-04 + */ + +#include "clock/GradientClockView.h" +#include "wearable_log.h" +#include "clock/ClockResourceImage.h" +#include "common/screen.h" +#include "sys/time.h" +#include "UIWatchDialFactory.h" +#include "main/DialBinTypesV2.h" + +namespace OHOS { + +const DialInfo dialInfoConfig = { + GRADIENT_CLOCK, "½¥±ä±íÅÌ", PNG_SET_GRADIENT_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY + }; + +REGIST_WATCH_DIAL(DIAL_DISPLAY_SUPPORT_NORMAL, GRADIENT_CLOCK, GradientClockView, &dialInfoConfig); +static GradientClockView *g_pGradientClockView = nullptr; + +static constexpr float SEC_TO_MILLI = 1000.0f; +static constexpr int16_t USEC_TO_MILLI = 1000; +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr float SEC_TO_MIN = 60.0f; +static constexpr float SECOND_HAND_RANGE = 160.0f; +static constexpr float MINUTE_HAND_RANGE = 120.0f; +static constexpr float SECOND_START_ANGLE = 200.0f; +static constexpr float MINUTE_START_ANGLE = 240.0f; +static constexpr int16_t ANGLE_DETAL = 3; +static constexpr int16_t USEC_TO_SEC = 60; +static constexpr float ANGEL_MINUTE_STEPS = 6.0f; +static constexpr int16_t CLOCK_RADIUS = HORIZONTAL_RESOLUTION / 2; +static constexpr int16_t CLOCK_RADIUS_RECTANGLE = (VERTICAL_RESOLUTION > HORIZONTAL_RESOLUTION) ?\ + VERTICAL_RESOLUTION / 2 + 75 : HORIZONTAL_RESOLUTION / 2; +static constexpr int16_t MINUTE_RADIUS = CLOCK_RADIUS - static_cast(0.103524 * HORIZONTAL_RESOLUTION); +static constexpr int16_t MINUTE_RADIUS_RECTANGLE = CLOCK_RADIUS_RECTANGLE; +static constexpr int16_t MARGIN_BG = 10; +static constexpr int16_t CENTER_X = HORIZONTAL_RESOLUTION / 2; +static constexpr int16_t CENTER_Y = VERTICAL_RESOLUTION/ 2; +static constexpr int16_t MINUTE_COUNT = 2; +static ColorStop minutestops[MINUTE_COUNT] = {{0, 0x00FFFAEF}, {0.333, 0xFFFFD383}}; // Alaph 00~FF +static constexpr int16_t SECOND_COUNT = 2; +static ColorStop secondstops[SECOND_COUNT] = {{0, 0x0AF8F5FD}, {0.444, 0xFF7948EA}}; // Alaph 0A~FF +static constexpr int16_t BACKGROUD_COUNT = 3; +ColorStop backgroudstops[BACKGROUD_COUNT] = {{0, 0xFF994EDE}, {0.50974, 0xFFFC62BA}, {1, 0xFFFEC45E}}; + +void GradientClockView::SafeDelete(UIView* ptr) +{ + if (ptr != nullptr) { + Remove(ptr); + delete ptr; + ptr = nullptr; + } +} + +GradientClockView *GradientClockView::GetInstance(void) +{ + return g_pGradientClockView; +} + +GradientClockView::GradientClockView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientClockView::GradientClockView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + secondAngle_ = SECOND_START_ANGLE; + PreLoad(); + g_pGradientClockView = this; +} + +GradientClockView::~GradientClockView() +{ + if (!viewiInitStatus_) { + return; + } + SafeDelete(backgroudCanvas_); + SafeDelete(secondHandCanvas_); + SafeDelete(minuteHandCanvas_); + if (gradientDateView_) { + gradientDateView_->RemoveAll(); + Remove(gradientDateView_); + delete gradientDateView_; + gradientDateView_ = nullptr; + } + g_pGradientClockView = nullptr; +} + +bool GradientClockView::InitView(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientClockView::InitView"); + + backgroudCanvas_ = new UICanvasExt(); + if (backgroudCanvas_ != nullptr) { + PaintExt backPaint; + backPaint.SetStyle(Paint::PaintStyle::FILL_STYLE); + backPaint.SetLinearGradient({-MARGIN_BG, VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION + MARGIN_BG, + VERTICAL_RESOLUTION}, backgroudstops, BACKGROUD_COUNT); + backPaint.SetAntialiased(true); + backgroudCanvas_->SetStyle(STYLE_BACKGROUND_OPA, 0); + backgroudCanvas_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + uint16_t radius = (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE) ?\ + CLOCK_RADIUS_RECTANGLE : CLOCK_RADIUS; + backgroudCanvas_->DrawCircle({CENTER_X, CENTER_Y}, radius, backPaint); + Add(backgroudCanvas_); + } + + secondHandCanvas_ = new UICanvasExt(); + if (secondHandCanvas_ != nullptr) { + Add(secondHandCanvas_); + } + + minuteHandCanvas_ = new UICanvasExt(); + if (minuteHandCanvas_ != nullptr) { + Add(minuteHandCanvas_); + } + + gradientDateView_ = new GradientDateView(); + if (gradientDateView_ != nullptr) { + Add(gradientDateView_); + gradientDateView_->InitView(); + } + + SetCoverable(true); + Update(); + viewiInitStatus_ = true; + return true; +} + +void GradientClockView::PreLoad(void) +{ + if (!viewiInitStatus_) { + InitView(); + viewiInitStatus_ = true; + } +} + +void GradientClockView::Update(void) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + uint64_t realMilliSecond = static_cast(uSecond / USEC_TO_MILLI); + uint8_t realSecond = second % USEC_TO_SEC; + + if (gradientDateView_ != nullptr) { + gradientDateView_->UpdateTime(); + } + + // update all canvas + UpdateHands(realMinute, realSecond, realMilliSecond); +} + +void GradientClockView::UpdateHands(uint8_t minute, uint8_t second, uint64_t milliSecond) +{ + if (second !=second_) { + secondAngle_ = second % USEC_TO_SEC * ANGEL_MINUTE_STEPS; + second_ = second; + } + + // update second hand + float secondAngle = SECOND_START_ANGLE + secondAngle_ + milliSecond / SEC_TO_MILLI * ANGEL_MINUTE_STEPS; + uint16_t colckRadius = (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE) ?\ + CLOCK_RADIUS_RECTANGLE :CLOCK_RADIUS; + sectorInfo sectorStru(secondAngle, SECOND_HAND_RANGE, colckRadius, SECOND_COUNT, secondstops); + UpdateCanvas(secondHandCanvas_, sectorStru); + + // update minute hand + float minuteAngle = MINUTE_START_ANGLE + minute % USEC_TO_SEC * ANGEL_MINUTE_STEPS + + second / SEC_TO_MIN * ANGEL_MINUTE_STEPS; + uint16_t minuteRadius = (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE) ?\ + MINUTE_RADIUS_RECTANGLE : MINUTE_RADIUS; + sectorInfo minuteStru(minuteAngle, MINUTE_HAND_RANGE, minuteRadius, MINUTE_COUNT, minutestops); + UpdateCanvas(minuteHandCanvas_, minuteStru); +} + +void GradientClockView::UpdateCanvas(UICanvasExt *canvas, const sectorInfo& sectorInfo) +{ + if (canvas == nullptr) { + GRAPHIC_LOGE("callback view is not UICanvasExt"); + return; + } + + canvas->Clear(); + float sectorEnd = sectorInfo.startAngle + sectorInfo.angleRange; + PaintExt secPaint; + secPaint.SetStyle(Paint::PaintStyle::FILL_STYLE); + secPaint.SetStrokeWidth(1); + SweepGradient sweep = {CENTER_X, CENTER_Y, sectorInfo.startAngle}; + secPaint.SetSweepGradient(sweep, sectorInfo.colorStop, sectorInfo.stopCount); + secPaint.SetOpacity(OPA_OPAQUE); + secPaint.SetAntialiased(true); + canvas->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + canvas->DrawSector({CENTER_X, CENTER_Y}, sectorInfo.sectorRadius, sectorInfo.startAngle + ANGLE_DETAL, + sectorEnd, secPaint); + canvas->SetStyle(STYLE_BACKGROUND_OPA, 0); +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientDateView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientDateView.cpp new file mode 100644 index 000000000..09adb4214 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/GradientDateView.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientDateView + * Create: 2025-04 + */ + +#include +#include "sys/time.h" +#include "clock/GradientDateView.h" +#include "wearable_log.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "clock/ClockResourceImage.h" + +namespace OHOS { +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +static constexpr int16_t NUM2 = 2; +static constexpr int16_t SCREEN_HALF_W = HORIZONTAL_RESOLUTION / NUM2; +static constexpr int16_t SCREEN_HALF_H = VERTICAL_RESOLUTION / NUM2; +static constexpr int16_t TIME_SPLIT_X_DANCE = static_cast(0.015419 * HORIZONTAL_RESOLUTION); +static constexpr int16_t TIME_SPLIT_Y_DANCE = static_cast(0.096916 * VERTICAL_RESOLUTION); +static constexpr int16_t TIME_SPLIT_X = SCREEN_HALF_W - TIME_SPLIT_X_DANCE; +static constexpr int16_t TIME_SPLIT_Y = SCREEN_HALF_H - TIME_SPLIT_Y_DANCE; +static constexpr int16_t TIME_X_DANCE = static_cast(0.145374 * HORIZONTAL_RESOLUTION); +static constexpr int16_t TIME_Y_DANCE = static_cast(0.132159 * VERTICAL_RESOLUTION); +static constexpr int16_t TIME_POINT_Y = SCREEN_HALF_H - TIME_Y_DANCE; +static constexpr int16_t HOUR_POINT_X = SCREEN_HALF_W - TIME_X_DANCE; +static constexpr int16_t MINUTE_POINT_X = SCREEN_HALF_W + TIME_X_DANCE; +static constexpr int16_t WEEK_POINT_X_DANCE = static_cast(0.066079 * HORIZONTAL_RESOLUTION); +static constexpr int16_t WEEK_POINT_Y_DANCE = static_cast(0.127753 * VERTICAL_RESOLUTION); +static constexpr int16_t WEEK_POINT_X = SCREEN_HALF_W - WEEK_POINT_X_DANCE; +static constexpr int16_t WEEK_POINT_Y = SCREEN_HALF_H + WEEK_POINT_Y_DANCE; +static constexpr int16_t WEEK_POINT_Y_RECTANGLE = SCREEN_HALF_H + WEEK_POINT_Y_DANCE\ + - static_cast(0.025974 * VERTICAL_RESOLUTION); +static constexpr int16_t DATE_POINT_Y_DANCE = WEEK_POINT_X_DANCE; +static constexpr int16_t DATE_POINT_Y = SCREEN_HALF_H + DATE_POINT_Y_DANCE; +static constexpr int16_t YEAR_POINT_X = SCREEN_HALF_W - static_cast(0.07489 * HORIZONTAL_RESOLUTION); +static constexpr int16_t MONTH_POINT_X = SCREEN_HALF_W + static_cast(0.024229 * HORIZONTAL_RESOLUTION); +static constexpr int16_t DAY_POINT_X = SCREEN_HALF_W + static_cast(0.101322 * HORIZONTAL_RESOLUTION); +static constexpr int16_t DATE_LEFT_SPLIT_X = SCREEN_HALF_W - static_cast(0.028634 * HORIZONTAL_RESOLUTION); +static constexpr int16_t DATE_RIGHT_SPLIT_X = SCREEN_HALF_W + static_cast(0.048458 * HORIZONTAL_RESOLUTION); +static constexpr int16_t NUM4 = 4; +static constexpr int16_t SPACE = 0; + +template +void SafeDelete(T*& ptr) +{ + if (ptr != nullptr) { + delete ptr; + ptr = nullptr; + } +} + +static const std::vector g_weekVector = { + PNG_WEEK_SUN, + PNG_WEEK_MON, + PNG_WEEK_TUE, + PNG_WEEK_WED, + PNG_WEEK_THU, + PNG_WEEK_FRI, + PNG_WEEK_SAT, +}; + +static const std::vector g_dateVector = { + PNG_DATA_0, + PNG_DATA_1, + PNG_DATA_2, + PNG_DATA_3, + PNG_DATA_4, + PNG_DATA_5, + PNG_DATA_6, + PNG_DATA_7, + PNG_DATA_8, + PNG_DATA_9, +}; + +static const std::vector g_timeVector = { + PNG_TIME_0, + PNG_TIME_1, + PNG_TIME_2, + PNG_TIME_3, + PNG_TIME_4, + PNG_TIME_5, + PNG_TIME_6, + PNG_TIME_7, + PNG_TIME_8, + PNG_TIME_9, +}; + +GradientDateView::GradientDateView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientDateView::GradientDateView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, 0); +} + +GradientDateView::~GradientDateView() +{ + if (!viewiInitStatus_) { + return; + } + + RemoveAll(); + SafeDelete(yearImgView_); + SafeDelete(monthImgView_); + SafeDelete(dayImgView_); + SafeDelete(hourImgView_); + SafeDelete(minuteImgView_); + SafeDelete(backgroudImage_); + ImageCacheManager::GetInstance().UnloadSingleRes(PNG_GRADIENT_CLOCK_RESOURCE); + for (auto weekImg : weekInfo_) { + if (weekImg != nullptr) { + ImageCacheFree(*weekImg); + delete weekImg; + weekImg = nullptr; + } + } + for (auto dateImg : dateNumImgInfo_) { + if (dateImg != nullptr) { + ImageCacheFree(*dateImg); + delete dateImg; + dateImg = nullptr; + } + } +} + +bool GradientDateView::InitView(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GradientDateView::InitView"); + backgroudImage_ = new UIImageView(); + if (backgroudImage_) { + backgroudImage_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + backgroudImage_->SetResizeMode(UIImageView::FILL); + LoadClockImageById(backgroudImage_, PNG_TIME_SCALE); + Add(backgroudImage_); + } + InitWeekImgView(); + InitDateImgViews(); + InitTimeImgViews(); + viewiInitStatus_ = true; + return true; +} + +void GradientDateView::InitWeekImgView(void) +{ + uint16_t length = g_weekVector.size(); + int16_t y = (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE) ?\ + WEEK_POINT_Y_RECTANGLE : WEEK_POINT_Y; + weekImgView_.SetPosition(WEEK_POINT_X, y); + if (!LoadGradientDateImages(weekInfo_, g_weekVector, length)) { + return; + } + Add(&weekImgView_); +} + +void GradientDateView::InitDateImgViews(void) +{ + uint16_t length = g_dateVector.size(); + if (!LoadGradientDateImages(dateNumImgInfo_, g_dateVector, length)) { + return; + } + InitDigitalImgView(yearImgView_, {YEAR_POINT_X, DATE_POINT_Y}, NUM4, dateNumImgInfo_); + InitDigitalImgView(monthImgView_, {MONTH_POINT_X, DATE_POINT_Y}, NUM2, dateNumImgInfo_); + InitDigitalImgView(dayImgView_, {DAY_POINT_X, DATE_POINT_Y}, NUM2, dateNumImgInfo_); + + if (LoadClockImageById(&dateSplitLeft_, PNG_DATA_SPLIT)) { + dateSplitLeft_.SetPosition(DATE_LEFT_SPLIT_X, DATE_POINT_Y); + Add(&dateSplitLeft_); + } + + if (LoadClockImageById(&dateSplitRight_, PNG_DATA_SPLIT)) { + dateSplitRight_.SetPosition(DATE_RIGHT_SPLIT_X, DATE_POINT_Y); + Add(&dateSplitRight_); + } +} + +void GradientDateView::InitTimeImgViews(void) +{ + uint16_t length = g_timeVector.size(); + if (!LoadGradientDateImages(timeNumImgInfo_, g_timeVector, length)) { + return; + } + InitDigitalImgView(hourImgView_, {HOUR_POINT_X, TIME_POINT_Y}, NUM2, timeNumImgInfo_); + InitDigitalImgView(minuteImgView_, {MINUTE_POINT_X, TIME_POINT_Y}, NUM2, timeNumImgInfo_); + if (LoadClockImageById(&timeSplit_, PNG_TIME_SPLIT)) { + timeSplit_.SetPosition(TIME_SPLIT_X, TIME_SPLIT_Y); + Add(&timeSplit_); + } +} + +void GradientDateView::InitDigitalImgView(DialDigitalImgView* &dialView, Point pos, + uint16_t integerLength, std::vector &numImgInfo) +{ + if (dialView != nullptr) { + delete dialView; + dialView = nullptr; + } + uint16_t numImgLength = numImgInfo.size(); + if (numImgLength == 0) { + return; + } + dialView = new DialDigitalImgView(); + if (!dialView) { + GRAPHIC_LOGE("dialView malloc memory Failed\n"); + return; + } + + const OHOS::ImageInfo **dataArray = new const OHOS::ImageInfo *[numImgLength]; + if (!dataArray) { + GRAPHIC_LOGE("dataArray malloc memory Failed\n"); + return; + } + + for (size_t i = 0; i < numImgLength; ++i) { + dataArray[i] = numImgInfo[i]; + } + + dialView->SetNumRes(dataArray, numImgLength); + + delete[] dataArray; + dialView->SetIntegerLength(integerLength); + dialView->SetParent(this); + dialView->SetAlignPos(pos); + dialView->SetAlign(ImgAlign::CENTER); + dialView->SetSpace(SPACE); + Add(dialView); +} + +void GradientDateView::UpdateTime(void) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + + time_t time_struct = second; + struct tm *local_time = localtime(&time_struct); + uint16_t year = local_time->tm_year + 1900; // tm_year begin 1900 + uint16_t month = local_time->tm_mon + 1; // tm_mon is 0-11, need + 1 + uint16_t day = local_time->tm_mday; + uint16_t weekDay = local_time->tm_wday; + realHour = local_time->tm_hour; + realMinute = local_time->tm_min; + + if (weekInfo_.size() > 0) { + weekImgView_.SetSrc(weekInfo_.at(weekDay)); + } + + HandleDigitalData(yearImgView_, static_cast(year)); + HandleDigitalData(monthImgView_, static_cast(month)); + HandleDigitalData(dayImgView_, static_cast(day)); + HandleDigitalData(hourImgView_, static_cast(realHour)); + HandleDigitalData(minuteImgView_, static_cast(realMinute)); +} + +void GradientDateView::HandleDigitalData(DialDigitalImgView* digitalView, float data) +{ + if (digitalView != nullptr) { + digitalView->HandleFloatData(data); + } +} + +bool GradientDateView::LoadClockImageById(UIImageView* view, uint32_t resId) +{ + if (view == nullptr) { + GRAPHIC_LOGE("view == nullptr, Please check!"); + return false; + } + FILE* fp = fopen(PNG_GRADIENT_CLOCK_RESOURCE, "rb"); + if (fp == nullptr) { + GRAPHIC_LOGE("cannot open file: %s", PNG_GRADIENT_CLOCK_RESOURCE); + return false; + } + ImageInfo* imgInfo = ImageCacheManager::GetInstance(). + LoadOneInMultiRes(resId, PNG_GRADIENT_CLOCK_RESOURCE, fp); + view->SetSrc(imgInfo); + fclose(fp); + return true; +} + +bool GradientDateView::LoadGradientDateImages(std::vector &imgInfos, + std::vector resIds, uint16_t length) +{ + FILE* fp = fopen(PNG_GRADIENT_CLOCK_RESOURCE, "rb"); + if (fp == nullptr) { + GRAPHIC_LOGE("cannot open file: %s", PNG_GRADIENT_CLOCK_RESOURCE); + return false; + } + + uint32_t imgSize = sizeof(ImageInfo); + for (uint16_t i = 0; i < length; i++) { + ImageInfo* imgInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(resIds[i], PNG_GRADIENT_CLOCK_RESOURCE, fp); + if (!imgInfo) { + GRAPHIC_LOGE("LoadOneInMultiRes Failed: resId = %d\n", resIds[i]); + imgInfos.clear(); + break; + } + imgInfos.push_back(imgInfo); + } + fclose(fp); + return true; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/MainClockView.cpp index 1fdfcf4da..d6c405e29 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -11,12 +11,17 @@ #include "wearable_log.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" -#include "UICardPageFactory.h" +#include "UIWatchDialFactory.h" +#include "main/DialBinTypesV2.h" #include namespace OHOS { -REGIST_WATCH_DIAL(DIAL_DISPLAY_MODE_MAIN, DIAL_CLOCK, MainClockView); +const DialInfo dialInfoConfig = { + DIAL_CLOCK, "ɨÃë±íÅÌ", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY + }; + +REGIST_WATCH_DIAL(DIAL_DISPLAY_SUPPORT_NORMAL, DIAL_CLOCK, MainClockView, &dialInfoConfig); static MainClockView *g_pMainClockView = nullptr; @@ -418,10 +423,10 @@ void MainClockView::RefreshHeartRate(int value) void MainClockView::InitDateTime(void) { - UpdateTime(); + Update(); } -void MainClockView::UpdateTime(void) +void MainClockView::Update(void) { struct timeval tv; gettimeofday(&tv, nullptr); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassControlView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassControlView.cpp index d4139a5b9..6708d71d4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassControlView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassControlView.cpp @@ -13,6 +13,11 @@ CompassControlView::CompassControlView() SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); } +CompassControlView::~CompassControlView() +{ + UnLoad(); +} + void CompassControlView::PreLoad(void) { if (compassFragment_ == nullptr) { @@ -64,4 +69,11 @@ void CompassControlView::ScrollEnd(bool isActive) compassFragment_->ResumeView(); } } + +void CompassControlView::Update(void) +{ + if (compassFragment_ != nullptr) { + compassFragment_->Update(); + } +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassFragment.cpp index cca744b26..0ef34a963 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassFragment.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/CompassFragment.cpp @@ -55,7 +55,7 @@ const CompassItem g_compassList[] = { {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, "西北"} }; -void CompassFragment::Callback(void) +void CompassFragment::Update(void) { if (!initialized_) { return; @@ -177,17 +177,14 @@ void CompassFragment::OnCreateView(void* data) void CompassFragment::OnPauseView() { - Deinit(); } void CompassFragment::OnResumeView() { - Init(); } void CompassFragment::OnDestroyView() { - Deinit(); fragmentView_.RemoveAll(); if (directionLabel_ != nullptr) { delete directionLabel_; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp index 11a3b45cd..46229bb33 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp @@ -18,13 +18,14 @@ bool MainCompassPresenter::OnDrag(UIView& view, const DragEvent& event) UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } return true; } void MainCompassPresenter::OnResume() { + Init(); if ((view_ != nullptr) && (view_->compassFragment_ != nullptr)) { view_->compassFragment_->ResumeView(); } @@ -32,8 +33,16 @@ void MainCompassPresenter::OnResume() void MainCompassPresenter::OnPause() { + Deinit(); if ((view_ != nullptr) && (view_->compassFragment_ != nullptr)) { view_->compassFragment_->PauseView(); } } + +void MainCompassPresenter::Callback() +{ + if ((view_ != nullptr) && (view_->compassFragment_ != nullptr)) { + view_->compassFragment_->Update(); + } +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateButtonItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateButtonItemView.cpp index 210f188bc..2039c7c78 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateButtonItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateButtonItemView.cpp @@ -1,96 +1,68 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: DateButtonItemView * Create: 2025-03-23 */ -#include "date/DateButtonItemView.h" #include "UiConfig.h" #include "common/image_cache_manager.h" #include "ui_resource_date.h" #include "wearable_log.h" +#include "date/DateButtonItemView.h" namespace OHOS { static constexpr int16_t DATE_ITEM_BUTTON_POSITION_X = 0; -static constexpr int16_t DATE_ITEM_BUTTON_POSITION_Y = 20; +static constexpr int16_t DATE_ITEM_BUTTON_POSITION_Y = 0; static constexpr int16_t DATE_ITEM_BUTTON_WIDTH = 80; static constexpr int16_t DATE_ITEM_BUTTON_HEIGHT = 55; static constexpr int16 DATE_ITEM_FONT_SIZE = 36; -static constexpr int16_t DATE_ITEM_WIDTH = 95; -static constexpr int16_t DATE_ITEM_HEIGHT = 60; DateButtonItemView::DateButtonItemView() { - SetPosition(0, 0, DATE_ITEM_WIDTH, DATE_ITEM_HEIGHT); - SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - SetTouchable(true); - SetUpChild(); - - Add(&sLabelButton); + labelButton_.SetPosition(DATE_ITEM_BUTTON_POSITION_X, DATE_ITEM_BUTTON_POSITION_Y); + labelButton_.Resize(DATE_ITEM_BUTTON_WIDTH, DATE_ITEM_BUTTON_HEIGHT); + labelButton_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + labelButton_.SetAlign(TEXT_ALIGNMENT_CENTER); + labelButton_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelButton_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + labelButton_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + Add(&labelButton_); } DateButtonItemView::~DateButtonItemView() { - Remove(&sLabelButton); + Remove(&labelButton_); } void DateButtonItemView::SetItemInfo(const DateButtonItem itemInfo) { - sItemInfo = itemInfo; - sLabelButton.SetText(sItemInfo.button_day); - ImageInfo *image1; - ImageInfo *image2; - if (sItemInfo.isFirst) { - if (sItemInfo.isSelect) { - image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE6, DATE_IMAGE); - sLabelButton.SetTextColor(Color::White()); + itemInfo_ = itemInfo; + labelButton_.SetText(itemInfo_.buttonDay); + int imageSrc1; + int imageSrc2; + if (itemInfo_.isFirst) { + if (itemInfo_.isSelect) { + imageSrc1 = IMAGE_DATE_RED; + labelButton_.SetTextColor(Color::White()); } else { - sLabelButton.SetTextColor(Color::GetColorFromRGBA(0xe0, 0x2d, 0x2f, 0xff)); - image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE3, DATE_IMAGE); - } - if (image1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); - return; - } - image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE6, DATE_IMAGE); - if (image2 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); - return; + imageSrc1 = IMAGE_DATE_WHITE; + labelButton_.SetTextColor(Color::GetColorFromRGBA(0xe0, 0x2d, 0x2f, 0xff)); } + imageSrc2 = IMAGE_DATE_RED; } else { - if (sItemInfo.isSelect) { - image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE4, DATE_IMAGE); + if (itemInfo_.isSelect) { + imageSrc1 = IMAGE_DATE_SELECT; } else { - image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE2, DATE_IMAGE); - } - if (image1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); - return; + imageSrc1 = IMAGE_DATE_GRAY; } - image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE4, DATE_IMAGE); - if (image2 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); - return; - } - sLabelButton.SetTextColor(Color::White()); + imageSrc2 = IMAGE_DATE_SELECT; + labelButton_.SetTextColor(Color::White()); } - sLabelButton.SetImageSrc(image1, image2); + LOADIMG::LoadBtnImage(&labelButton_, DATE_IMAGE, imageSrc1, imageSrc2); } -void DateButtonItemView::SetUpChild() +DateButtonItem DateButtonItemView::GetItem() { - sLabelButton.SetPosition(DATE_ITEM_BUTTON_POSITION_X, 0); - sLabelButton.Resize(DATE_ITEM_BUTTON_WIDTH, DATE_ITEM_BUTTON_HEIGHT); - sLabelButton.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); - sLabelButton.SetAlign(TEXT_ALIGNMENT_CENTER); - sLabelButton.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabelButton.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - sLabelButton.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + return itemInfo_; } - -DateButtonItem DateButtonItemView ::GetItem() -{ - return sItemInfo; -} - } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateContentItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateContentItemView.cpp new file mode 100644 index 000000000..683d79f0d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateContentItemView.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateItemView + * Create: 2025-03-23 + */ + +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "wearable_log.h" +#include "date/DateContentItemView.h" + +namespace OHOS { +static constexpr int16_t DATE_ITEM_LABEL_POSITION_X = 43; +static constexpr int16_t DATE_ITEM_LABEL_POSITION_Y = 22; +static constexpr int16_t DATE_ITEM_LABEL_DES_POSITION_X = 23; +static constexpr int16_t DATE_ITEM_LABEL_DES_POSITION_Y = 60; +static constexpr int16_t DATE_ITEM_LABEL_ADDRESS_POSITION_X = 23; +static constexpr int16_t DATE_ITEM_LABEL_ADDRESS_POSITION_Y = 110; +static constexpr int16_t DATE_ITEM_LABEL_WIDTH = 200; +static constexpr int16_t DATE_ITEM_LABEL_HEIGHT = 40; +static constexpr int16_t DATE_ITEM_LABEL_DES_WIDTH = 314; +static constexpr int16_t DATE_ITEM_LABEL_DES_HEIGHT = 40; +static constexpr int16_t DATE_ITEM_LABEL_ADDRESS_WIDTH = 314; +static constexpr int16_t DATE_ITEM_LABEL_ADDRESS_HEIGHT = 40; +static constexpr int16_t DATE_ITEM_FONT_SIZE = 24; +static constexpr int16_t DATE_ITEM_FONT2_SIZE = 32; +static constexpr int16_t DATE_ITEM_WIDTH = 376; +static constexpr int16_t DATE_ITEM_HEIGHT = 170; +static constexpr int16_t DATE_ITEM_HEIGHT_BORDER = 10; +static constexpr int16_t DATE_ITEM_BORDER_RADIUS = 15; + +DateContentItemView::DateContentItemView() +{ + labelTitle_.Resize(DATE_ITEM_LABEL_WIDTH, DATE_ITEM_LABEL_HEIGHT); + labelTitle_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + labelTitle_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + labelTitle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelDes_.Resize(DATE_ITEM_LABEL_DES_WIDTH, DATE_ITEM_LABEL_DES_POSITION_Y); + labelDes_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + labelDes_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelDes_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + labelDes_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelAddress_.Resize(DATE_ITEM_LABEL_ADDRESS_WIDTH, DATE_ITEM_LABEL_ADDRESS_HEIGHT); + labelAddress_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + labelAddress_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelAddress_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + labelAddress_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + signs_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(&signs_, DATE_IMAGE, IMAGE_DATE_SIGNS); + + backGround_.Disable(); + backGround_.SetPosition(0, 0, DATE_ITEM_WIDTH, DATE_ITEM_HEIGHT - DATE_ITEM_HEIGHT_BORDER); + backGround_.SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::PRESSED); + backGround_.SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::INACTIVE); + backGround_.SetStyleForState(STYLE_BACKGROUND_COLOR, 0X36FFFFFF, UIButton::RELEASED); + backGround_.SetStyleForState(STYLE_BORDER_RADIUS, DATE_ITEM_BORDER_RADIUS, UIButton::PRESSED); + backGround_.SetStyleForState(STYLE_BORDER_RADIUS, DATE_ITEM_BORDER_RADIUS, UIButton::INACTIVE); + backGround_.SetStyleForState(STYLE_BORDER_RADIUS, DATE_ITEM_BORDER_RADIUS, UIButton::RELEASED); + + Add(&backGround_); + Add(&labelTitle_); + Add(&labelDes_); + Add(&labelAddress_); + Add(&signs_); +} + +DateContentItemView::~DateContentItemView() +{ + Remove(&backGround_); + Remove(&labelTitle_); + Remove(&labelDes_); + Remove(&labelAddress_); + Remove(&signs_); +} + +void DateContentItemView::SetItemInfo(const DateItem itemInfo) +{ + itemInfo_ = itemInfo; + int offsetX1 = 95; + int offsetY1 = 10; + int offsetX2 = 30; + int offsetY2 = 40; + labelTitle_.SetText(itemInfo.title); + labelDes_.SetText(itemInfo.describetion); + + if (!strcmp(itemInfo.address, "no location")) { + labelAddress_.SetVisible(false); + backGround_.SetHeight(DATE_ITEM_HEIGHT - offsetY2 - offsetY1); + SetHeight(DATE_ITEM_HEIGHT - offsetY2); + } else { + labelAddress_.SetVisible(true); + labelAddress_.SetText(itemInfo.address); + backGround_.SetHeight(DATE_ITEM_HEIGHT - offsetY1); + SetHeight(DATE_ITEM_HEIGHT); + } + + if (itemInfo.visiable) { + labelTitle_.SetPosition(DATE_ITEM_LABEL_POSITION_X + offsetX1, DATE_ITEM_LABEL_POSITION_Y + offsetY1); + labelTitle_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT2_SIZE); + labelDes_.SetPosition(DATE_ITEM_LABEL_DES_POSITION_X + offsetX2, DATE_ITEM_LABEL_DES_POSITION_Y + offsetY2); + labelDes_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelDes_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + labelAddress_.SetVisible(false); + } else { + labelTitle_.SetPosition(DATE_ITEM_LABEL_POSITION_X, DATE_ITEM_LABEL_POSITION_Y); + labelTitle_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelTitle_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + labelDes_.SetPosition(DATE_ITEM_LABEL_DES_POSITION_X, DATE_ITEM_LABEL_DES_POSITION_Y); + labelDes_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelDes_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT2_SIZE); + labelAddress_.SetPosition(DATE_ITEM_LABEL_DES_POSITION_X, DATE_ITEM_LABEL_ADDRESS_POSITION_Y); + labelAddress_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelAddress_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + signs_.SetPosition(DATE_ITEM_LABEL_DES_POSITION_X, DATE_ITEM_FONT_SIZE); + } + signs_.SetVisible(!itemInfo.visiable); +} + +const char *DateContentItemView ::GetViewId() +{ + return itemInfo_.index; +} +bool DateContentItemView::GetVisiable() +{ + return itemInfo_.visiable; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMainPage.cpp index 5072468de..9ca30421b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMainPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMainPage.cpp @@ -1,12 +1,9 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: DateMainPage * Created: 2025-4 */ -#include "date/DateMainPage.h" -#include "date/DateModel.h" -#include "date/DatePresenter.h" #include "NativeAbility.h" #include "SlicePageFactory.h" #include "UiConfig.h" @@ -15,6 +12,12 @@ #include "components/ui_list_nested.h" #include "components/ui_scroll_view_nested.h" #include "ui_resource_date.h" +#include "bts_br_gap.h" +#include "bts_spp.h" +#include "msg_center_device.h" +#include "date/DateModel.h" +#include "date/DatePresenter.h" +#include "date/DateMainPage.h" static constexpr int16_t DOWNSELECTPOSITION = 100; static constexpr int16_t DOWNCONTENTLIST_POSITION_X = 39; @@ -27,232 +30,338 @@ static constexpr int16_t BUTTONCONTENTLIST_WIDTH = 410; static constexpr int16_t BUTTONCONTENTLIST_HEIGHT = 55; static constexpr int16_t BUTTONCONTENTLIST_SELECT_POSITON = 90; static constexpr uint16_t DATE_MONTH_FONT = 25; -static constexpr uint16_t DATE_MONTH_POS_X = 129; -static constexpr uint16_t DATE_MONTH_POS_Y = 31; +static constexpr uint16_t DATE_MONTH_POS_X = 117; +static constexpr uint16_t DATE_MONTH_POS_Y = 30; static constexpr uint16_t DATE_MONTH_WIDTH = 196; static constexpr uint16_t LIST_POSITION_Y = 155; +static constexpr uint16_t LIST_BLANK_SIZE = 60; static constexpr uint16_t DATE_MONTH_HEIGHT = 50; static constexpr uint8_t FONT_FORTY_SIZE = 36; +static constexpr uint8_t MONTH_ADJUST_THRESHOLD = 3; +static constexpr uint8_t MONTHS_IN_YEAR = 12; +static constexpr uint8_t CENTURY = 100; +static constexpr uint8_t ZELLER_MONTH_FACTOR = 13; +static constexpr uint8_t ZELLER_DIVISOR = 5; +static constexpr uint8_t LEAP_YEAR_INTERVAL = 4; +static constexpr uint8_t DAYS_IN_WEEK = 7; +static constexpr uint8_t CENTURY_OFFSET = 5; +static constexpr int16 INDEX_0 = 0; +static constexpr int16 INDEX_1 = 1; +static constexpr int16 INDEX_2 = 2; +static constexpr int16 INDEX_3 = 3; +static constexpr int16 INDEX_4 = 4; +static constexpr int16 INDEX_5 = 5; +static constexpr int16_t DATE_ITEM_WIDTH = 95; +static constexpr int16_t DATE_ITEM_HEIGHT = 60; +static constexpr int16_t DATE_DOWN_LIST_ITEM_WIDTH = 376; +static constexpr int16_t DATE_DOWN_LIST_ITEM_HEIGHT = 170; +static constexpr char *DATE_LIST = "dateList"; +static constexpr char *DETAIL_LIST = "detailList"; namespace OHOS { REGIST_SLICE_PAGE(VIEW_DATE, DATE_PAGES::DATE_MAIN_PAGE, DateMainPage, true); +static DateMainPage *g_pDateMainPage = nullptr; DateMainPage::DateMainPage() { + g_pDateMainPage = this; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::DateMainPage"); } DateMainPage::~DateMainPage() { - if (uiScrollView != nullptr) { - uiScrollView->RemoveAll(); - delete uiScrollView; - uiScrollView = nullptr; + g_pDateMainPage = nullptr; + if (uiScrollView_ != nullptr) { + uiScrollView_->RemoveAll(); + delete uiScrollView_; + uiScrollView_ = nullptr; } - if (listAdapter != nullptr) { - delete listAdapter; - listAdapter = nullptr; + dateList_->ClearAll(); + if (dateList_ != nullptr) { + delete dateList_; + dateList_ = nullptr; } - if (buttonAdapter != nullptr) { - delete buttonAdapter; - buttonAdapter = nullptr; + detailList_->ClearAll(); + if (detailList_ != nullptr) { + delete detailList_; + detailList_ = nullptr; } - if (buttonContentList != nullptr) { - delete buttonContentList; - buttonContentList = nullptr; + if (titlLabel_ != nullptr) { + delete titlLabel_; + titlLabel_ = nullptr; } - if (downContentList != nullptr) { - delete downContentList; - downContentList = nullptr; + if (bgImage_ != nullptr) { + delete bgImage_; + bgImage_ = nullptr; } - if (title != nullptr) { - delete title; - title = nullptr; - } - - if (image1 != nullptr) { - delete image1; - image1 = nullptr; + int reset = DateModel::GetInstance().resetPage_; + if (reset == PAGE_STATUS_0 || reset == PAGE_STATUS_2) { + DateModel::GetInstance().selectButton_ = ""; } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(DATE_IMAGE); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::~DateMainPage"); } +DateMainPage *DateMainPage::GetInstance() +{ + return g_pDateMainPage; +} + void DateMainPage::OnStart(void *data) { - uiScrollView = new UIScrollView(); - if (uiScrollView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::scrollView is nullptr"); - return; - } - uiScrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - uiScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - uiScrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - uiScrollView->SetThrowDrag(true); - uiScrollView->SetOnDragListener(this); - uiScrollView->SetThrowDrag(true); - image1 = new UIImageView(); - if (image1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::image1 is nullptr"); + uiScrollView_ = new UIScrollView(); + if (uiScrollView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is nullptr"); return; } - image1->SetPosition(0, 0); - image1->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - ImageInfo *imgSrc = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE7, DATE_IMAGE); - if (imgSrc == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DateMainPage::OnStart LoadOneInMultiRes IMAGE_CONVERTER_TOOL_DATE8 fail"); + uiScrollView_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + uiScrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + uiScrollView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + uiScrollView_->SetThrowDrag(true); + uiScrollView_->SetOnDragListener(this); + uiScrollView_->SetThrowDrag(true); + bgImage_ = new UIImageView(); + if (bgImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImage_ is nullptr"); return; } - image1->SetSrc(imgSrc); - uiScrollView->Add(image1); + bgImage_->SetPosition(0, 0); + bgImage_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(bgImage_, DATE_IMAGE, IMAGE_DATE_BG1); + uiScrollView_->Add(bgImage_); DateModel::GetInstance().InitDate(); - title = new UILabel(); - if (title == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::title is nullptr"); + titlLabel_ = new UILabel(); + if (titlLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titlLabel_ is nullptr"); return; } - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MONTH_FONT); std::stringstream ss; - title->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT, UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); - title->SetPosition(DATE_MONTH_POS_X, DATE_MONTH_POS_Y, DATE_MONTH_WIDTH, DATE_MONTH_HEIGHT); - uiScrollView->Add(title); - InitDownList(); - AddViewToPageContainer(uiScrollView); + titlLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT, UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT); + titlLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); + titlLabel_->SetPosition(DATE_MONTH_POS_X, DATE_MONTH_POS_Y, DATE_MONTH_WIDTH, DATE_MONTH_HEIGHT); + uiScrollView_->Add(titlLabel_); + InitList(); + if (DateModel::GetInstance().GetConnectStatus()) { + errcode_t result; + uint8_t value = 1; +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SYNC_DATE_REQ, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "sync data request result:%d ", result); +#endif + } + AddViewToPageContainer(uiScrollView_); +} + +void DateMainPage::ReloadPage() +{ + DateModel::GetInstance().InitDate(); + RefreshListData(); } -void DateMainPage::InitDownList() +void DateMainPage::RefreshListData() { - if (buttonContentList == nullptr) { - buttonContentList = new UIList(0); + std::string strSelect = DateModel::GetInstance().selectButton_; + if (strSelect == "") { + SetDateButtonList(listTop_[0].buttonViewId); + RefreshDateMsg(listTop_[0].buttonViewId); + } else { + for (int i = 0; i < listTop_.Size(); i++) { + if (listTop_[i].buttonViewId == strSelect) { + SetDateButtonList(listTop_[i].buttonViewId); + RefreshDateMsg(listTop_[i].buttonViewId); + break; + } + } } - buttonAdapter = new DateButtonAdapter(); - if (buttonAdapter == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::listAdapter is nullptr"); +} + +void DateMainPage::InitList() +{ + dateList_ = new UISimpleList(); + if (dateList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dateList_ is nullptr"); return; } - buttonAdapter->SetItemClickListener(this); - buttonContentList->SetViewId("buttonList"); - buttonContentList->SetPosition(BUTTONCONTENTLIST_POSITION_X, BUTTONCONTENTLIST_POSITION_Y, BUTTONCONTENTLIST_WIDTH, + dateList_->SetViewId(DATE_LIST); + dateList_->SetPosition(BUTTONCONTENTLIST_POSITION_X, BUTTONCONTENTLIST_POSITION_Y, BUTTONCONTENTLIST_WIDTH, BUTTONCONTENTLIST_HEIGHT); - buttonContentList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - buttonContentList->SetSelectPosition(BUTTONCONTENTLIST_SELECT_POSITON); - buttonContentList->SetDraggable(true); - buttonContentList->SetThrowDrag(true); - buttonContentList->EnableAutoAlign(true); - buttonContentList->ScrollTo(0); - buttonContentList->SetAdapter(buttonAdapter); - buttonContentList->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); - InitDateTop(); - RefreshButtonListDate(0); - if (downContentList == nullptr) { - downContentList = new UIList(); - } + dateList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + dateList_->SetSelectPosition(BUTTONCONTENTLIST_SELECT_POSITON); + dateList_->SetDraggable(true); + dateList_->SetThrowDrag(true); + dateList_->EnableAutoAlign(true); + dateList_->SetIntercept(true); + dateList_->ScrollTo(0); + dateList_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + dateList_->SetDirection(0); + InitListTopDate(); - listAdapter = new DateAdapter(); - if (listAdapter == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::listAdapter is nullptr"); + detailList_ = new UISimpleList(); + if (detailList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "detailList_ is nullptr"); return; } - listAdapter->SetItemClickListener(this); - SetDownListAdapter(); - downContentList->SetViewId("downList"); - downContentList->SetPosition(DOWNCONTENTLIST_POSITION_X, DOWNCONTENTLIST_POSITION_Y); - downContentList->Resize(DOWNCONTENTLIST_WIDTH, DOWNCONTENTLIST_HEIGHT); // 364: height - downContentList->SetSelectPosition(DOWNSELECTPOSITION); - downContentList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - downContentList->SetDraggable(true); - downContentList->SetThrowDrag(true); - downContentList->EnableAutoAlign(true); - downContentList->SetElastic(true); - downContentList->ScrollTo(0); - downContentList->SetAdapter(listAdapter); - UpdateMsg(listTop.front().button_viewId); - uiScrollView->Add(downContentList); - uiScrollView->Add(buttonContentList); + + detailList_->SetViewId(DETAIL_LIST); + detailList_->SetPosition(DOWNCONTENTLIST_POSITION_X, DOWNCONTENTLIST_POSITION_Y); + detailList_->Resize(DOWNCONTENTLIST_WIDTH, DOWNCONTENTLIST_HEIGHT); + detailList_->SetSelectPosition(DOWNSELECTPOSITION); + detailList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + detailList_->SetDraggable(true); + detailList_->SetThrowDrag(true); + detailList_->EnableAutoAlign(true); + detailList_->SetElastic(true); + detailList_->ScrollTo(0); + detailList_->SetScrollBlankSize(LIST_BLANK_SIZE); + SetContentListDate(); + RefreshListData(); + uiScrollView_->Add(detailList_); + uiScrollView_->Add(dateList_); } -int calculateWeekday(int year, int month, int day) +int CalculateWeekday(int year, int month, int day) { - if (month < SET_THREE) { - month += SET_TWELVE; + if (month < MONTH_ADJUST_THRESHOLD) { + month += MONTHS_IN_YEAR; year--; } - int K = year % SET_HUNDRED; - int J = year / SET_HUNDRED; - int h = (day + SET_THIRTEEN * (month + SET_ONE) / SET_FIVE + K + K / SET_FOUR + J / SET_FOUR + SET_FIVE * J) % - SET_SEVEN; - return h; + int lastTwoDigitsOfYear = year % CENTURY; + int century = year / CENTURY; + int dayOfWeek = + (day + ZELLER_MONTH_FACTOR * (month + 1) / ZELLER_DIVISOR + lastTwoDigitsOfYear + + lastTwoDigitsOfYear / LEAP_YEAR_INTERVAL + century / LEAP_YEAR_INTERVAL + CENTURY_OFFSET * century) % + DAYS_IN_WEEK; + return dayOfWeek; } // 刷新List数据 -void DateMainPage::UpdateMsg(std::string dateMsg) +void DateMainPage::RefreshDateMsg(std::string dateMsg) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateView::UpdateMsg:%s", dateMsg.c_str()); - listAdapter->ClearListItem(); // 清空list数据 DateModel::GetInstance().InitDateVec(dateMsg); - SetDownListAdapter(); // 将设置的数据写入list + SetContentListDate(); // 将设置的数据写入list int year; int month; int day; int ret = sscanf_s(dateMsg.c_str(), "%d-%d-%d", &year, &month, &day); - if (ret != SET_THREE) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateMainPage::OnStart strDate"); + if (ret != DATE_UNIT_COUNT) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateMainPage strDate_ error"); return; } std::string weekDay[] = {"星期六", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五"}; - int today = calculateWeekday(year, month, day); + int today = CalculateWeekday(year, month, day); std::string titleDay; - if (dateMsg == listTop.front().button_viewId) { + if (dateMsg == listTop_.Front().buttonViewId) { titleDay = "今天 "; } else { titleDay = std::to_string(month) + "月 "; } titleDay += weekDay[today]; - DateModel::GetInstance().titleName = titleDay; - title->SetText(titleDay.c_str()); - downContentList->ScrollTo(SET_ZERO); - downContentList->RefreshList(); + DateModel::GetInstance().titleName_ = titleDay; + titlLabel_->SetText(titleDay.c_str()); + detailList_->ScrollTo(0); + detailList_->RefreshList(); +} + +static UIView* CreateContetListViewCb(uint8_t type) +{ + DateContentItemView* item = new DateContentItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, DATE_DOWN_LIST_ITEM_WIDTH, DATE_DOWN_LIST_ITEM_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_pDateMainPage); + return item; +} + +static void UpdateContentListViewCb(UIView* view, void* data, uint8_t type) +{ + DateContentItemView* item = dynamic_cast(view); + if (view == nullptr || data == nullptr || item == nullptr) { + return; + } + DateItem* content = static_cast(data); + item->SetItemInfo(*content); } -void DateMainPage::SetDownListAdapter() +void DateMainPage::SetContentListDate() { - for (const auto &item : DateModel::GetInstance().listDate) { - listAdapter->AddListItem(item); + detailList_->ClearAll(); + int count = DateModel::GetInstance().listDate_.size(); + for (int i = 0; i < count; i++) { + Contents content; + content.createFunc = CreateContetListViewCb; + content.updateFunc = UpdateContentListViewCb; + content.type = 0; + content.data = reinterpret_cast(&DateModel::GetInstance().listDate_[i]); + detailList_->AddContent(content); } + detailList_->RefreshList(); } -void DateMainPage::RefreshButtonListDate(int value) +static UIView* CreateViewCb(uint8_t type) { - buttonAdapter->ClearListItem(); - for (auto &item : listTop) { - if (item.index == value) { - item.isSelect = true; + DateButtonItemView* item = new DateButtonItemView(); + if (item == nullptr) { + return nullptr; + } + + item->SetPosition(0, 0, DATE_ITEM_WIDTH, DATE_ITEM_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_pDateMainPage); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + DateButtonItemView* item = dynamic_cast(view); + if (view == nullptr || data == nullptr || item == nullptr) { + return; + } + DateButtonItem* content = static_cast(data); + item->SetItemInfo(*content); +} + +void DateMainPage::SetDateButtonList(std::string viewId) +{ + dateList_->ClearAll(); + int count = listTop_.Size(); + for (int i = 0;i < count; i++) { + if (listTop_[i].buttonViewId == viewId) { + listTop_[i].isSelect = true; } else { - item.isSelect = false; + listTop_[i].isSelect = false; } - buttonAdapter->AddListItem(item); + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&listTop_[i]); + dateList_->AddContent(content); } - buttonContentList->RefreshList(); + dateList_->RefreshList(); } -bool DateMainPage::InitDateTop() +bool DateMainPage::InitListTopDate() { - listTop.clear(); - for (int i = 0; i < SET_SEVEN; ++i) { - strDate[i] = GetFutureDate(i); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::OnStart strDate[%d]:%s", i, strDate[i].c_str()); - strDay[i] = strDate[i].substr(strDate[i].length() - SET_TWO); + listTop_.Clear(); + for (int i = 0; i < WEEK_DYAS; ++i) { + strDate_[i] = GetFutureDate(i); + strDay_[i] = strDate_[i].substr(strDate_[i].length() - INDEX_2); if (i == 0) { - listTop.push_back({strDate[i].c_str(), strDay[i].c_str(), i, true, true}); + listTop_.PushBack({strDate_[i].c_str(), strDay_[i].c_str(), true, true}); } else { - listTop.push_back({strDate[i].c_str(), strDay[i].c_str(), i, false, false}); + listTop_.PushBack({strDate_[i].c_str(), strDay_[i].c_str(), false, false}); } } return true; @@ -262,8 +371,8 @@ std::string DateMainPage::GetFutureDate(int days_ahead) { time_t now = time(nullptr); time_t future_time = now + (days_ahead * HOUR_COUNT * NUM_TIME_MIN * NUM_TIME_MIN); - tm *tm = localtime(&future_time); - char buffer[80]; // 存储格式化后的日期字符串 + tm *tm = localtime(&future_time); // 检查返回值长度 + char buffer[11]; // 11:2025-08-14字符串长度 strftime(buffer, sizeof(buffer), "%Y-%m-%d", tm); return std::string(buffer); } @@ -273,29 +382,30 @@ bool DateMainPage::OnDrag(UIView &view, const DragEvent &event) UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + DateModel::GetInstance().resetPage_ = PAGE_STATUS_0; + NativeAbility::GetInstance().ChangeSliceToApplist(); } return true; } bool DateMainPage::OnClick(UIView &view, const ClickEvent &event) { - int posY = event.GetCurrentPos().y; - if (posY > LIST_POSITION_Y) { - DateItemView *dateItemView = static_cast(&view); - std::string view_id = dateItemView->GetViewId(); + if(strcmp(view.GetParent()->GetViewId(), DATE_LIST) == 0) { + DateButtonItemView *dateButtonItemView = dynamic_cast(&view); + DateButtonItem item = dateButtonItemView->GetItem(); + DateModel::GetInstance().selectButton_ = item.buttonViewId; + SetDateButtonList(item.buttonViewId); + RefreshDateMsg(item.buttonViewId); + } else if (strcmp(view.GetParent()->GetViewId(), DETAIL_LIST) == 0) { + DateContentItemView *dateItemView = dynamic_cast(&view); bool visiable = dateItemView->GetVisiable(); if (visiable) { return false; } - DateModel::GetInstance().messageIndex = view_id; - NativeAbility::GetInstance().SwitchPageInSlice(DATE_PAGES::DATE_MESSAGE_PAGE, nullptr, - TransitionType::TRANSITION_INVALID, true); - } else { - DateButtonItemView *dateButtonItemView = static_cast(&view); - DateButtonItem item = dateButtonItemView->GetItem(); - RefreshButtonListDate(item.index); - UpdateMsg(item.button_viewId); + DateModel::GetInstance().messageIndex_ = dateItemView->GetViewId(); + DateModel::GetInstance().resetPage_ = PAGE_STATUS_1; + NativeAbility::GetInstance().SwitchPageInSlice(DATE_PAGES::DATE_MESSAGE_PAGE, + TransitionType::TRANSITION_INVALID, false); } UNUSED(event); return true; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMessagePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMessagePage.cpp index 277e65596..2f4085cb1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMessagePage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateMessagePage.cpp @@ -1,13 +1,9 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: DateMessagePage * Create: 2025-03-15 */ -#include "date/DateMessagePage.h" -#include "date/DateModel.h" -#include "date/DatePresenter.h" -#include "date/DateView.h" #include "NativeAbility.h" #include "SlicePageFactory.h" #include "UiConfig.h" @@ -15,21 +11,29 @@ #include "components/ui_list_nested.h" #include "components/ui_scroll_view_nested.h" #include "ui_resource_date.h" +#include "date/DateModel.h" +#include "date/DatePresenter.h" +#include "date/DateView.h" +#include "date/DateMessagePage.h" namespace OHOS { static constexpr uint16_t DATE_MONTH_WIDTH = 221; static constexpr uint16_t DATE_MESSAGE_WIDTH = 180; static constexpr uint16_t DATE_MESSAGE_HEIGHT = 50; static constexpr uint16_t DATE_MESSAGE_POSITON_X = 117; -static constexpr uint16_t DATE_MESSAGE_POSITON_Y = 20; +static constexpr uint16_t DATE_MESSAGE_POSITON_Y = 30; static constexpr uint16_t DATE_MESSAGE_POSITON_X1 = 137; static constexpr uint16_t DATE_MESSAGE_FRONT_SIZE_ONE = 36; static constexpr uint16_t DATE_MESSAGE_FRONT_SIZE_TWO = 32; static constexpr uint16_t DATE_MESSAGE_TWO_POSITION_X = 31; -static constexpr uint16_t DATE_MESSAGE_TWO_POSITION_Y = 100; +static constexpr uint16_t DATE_MESSAGE_TWO_POSITION_Y = 120; static constexpr uint16_t DATE_MESSAGE_TWO_WIDTH = 392; static constexpr uint16_t DATE_MESSAGE_TWO_HEIGHT = 120; static constexpr uint16_t DATE_MESSAGE_MAX_LINE_HEIGHT = 140; +static constexpr uint16_t DATE_MESSAGE_ADDRESS_WIDTH = 392; +static constexpr uint16_t DATE_MESSAGE_ADDRESS_HEIGHT = 120; +static constexpr uint16_t DATE_MESSAGE_TIME_POS_Y = 400; +static constexpr uint16_t DATE_MESSAGE_BLANK_SIZE = 30; REGIST_SLICE_PAGE(VIEW_DATE, DATE_PAGES::DATE_MESSAGE_PAGE, DateMessagePage, false); @@ -40,119 +44,170 @@ DateMessagePage::DateMessagePage() DateMessagePage::~DateMessagePage() { - if (group != nullptr) { - group->RemoveAll(); - delete group; - group = nullptr; + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImage_ != nullptr) { + delete bgImage_; + bgImage_ = nullptr; } - if (image1 != nullptr) { - delete image1; - image1 = nullptr; + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; } - if (labelTitle != nullptr) { - delete labelTitle; - labelTitle = nullptr; + if (labelMessage_ != nullptr) { + delete labelMessage_; + labelMessage_ = nullptr; } - if (labelMessage != nullptr) { - delete labelMessage; - labelMessage = nullptr; + if (labelTime_ != nullptr) { + delete labelTime_; + labelTime_ = nullptr; } - if (labelTime != nullptr) { - delete labelTime; - labelTime = nullptr; + if (labelAddress_ != nullptr) { + delete labelAddress_; + labelAddress_ = nullptr; } + + if (DateModel::GetInstance().resetPage_ == PAGE_STATUS_0) { + DateModel::GetInstance().selectButton_ = ""; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(DATE_IMAGE); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMessagePage::~DateMessagePage"); } void DateMessagePage::OnStart(void *data) { - group = new UIViewGroup(); - group->SetPosition(0, 0); - group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - image1 = new UIImageView; - if (image1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + DateModel::GetInstance().resetPage_ = PAGE_STATUS_0; + group_ = new UIScrollView(); + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetThrowDrag(true); + group_->SetScrollBlankSize(DATE_MESSAGE_BLANK_SIZE); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetStyle(STYLE_BACKGROUND_OPA, 0); + bgImage_ = new UIImageView; + if (bgImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImage_ is nullptr"); return; } - image1->SetPosition(0, 0); - image1->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - ImageInfo *imgSrc = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE8, DATE_IMAGE); + bgImage_->SetPosition(0, 0); + bgImage_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ImageInfo *imgSrc = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DATE_BG2, DATE_IMAGE); if (imgSrc == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::LoadOneInMultiRes fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imgSrc fail"); + return; } - image1->SetSrc(imgSrc); - group->Add(image1); + bgImage_->SetSrc(imgSrc); + InitLabel(); + AddViewToPageContainer(bgImage_); + AddViewToPageContainer(group_); +} - labelTitle = new UILabel(); - if (labelTitle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); +void DateMessagePage::InitLabel() +{ + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title is nullptr"); return; } - labelTitle->SetPosition(DATE_MESSAGE_POSITON_X, DATE_MESSAGE_POSITON_Y, DATE_MONTH_WIDTH, DATE_MESSAGE_HEIGHT); - labelTitle->SetStyle(STYLE_TEXT_COLOR, Color::Purple().full); - labelTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); - labelTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelTitle->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelTitle->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - group->Add(labelTitle); - - labelMessage = new UILabel(); - if (labelMessage == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + labelTitle_->SetPosition(DATE_MESSAGE_POSITON_X, DATE_MESSAGE_POSITON_Y, DATE_MONTH_WIDTH, DATE_MESSAGE_HEIGHT); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::Purple().full); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + std::string strTitle = DateModel::GetInstance().titleName_; + labelTitle_->SetText(strTitle.c_str()); + group_->Add(labelTitle_); + + labelMessage_ = new UILabel(); + if (labelMessage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelMessage_ is nullptr"); return; } - labelMessage->SetPosition(DATE_MESSAGE_TWO_POSITION_X, DATE_MESSAGE_TWO_POSITION_Y, DATE_MESSAGE_TWO_WIDTH, + labelMessage_->SetPosition(DATE_MESSAGE_TWO_POSITION_X, DATE_MESSAGE_TWO_POSITION_Y, DATE_MESSAGE_TWO_WIDTH, DATE_MESSAGE_TWO_HEIGHT); - labelMessage->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelMessage->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelMessage->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelMessage->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - labelMessage->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); - labelMessage->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - labelMessage->SetRollSpeed(0); - group->Add(labelMessage); - - labelTime = new UILabel(); - if (labelTime == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + labelMessage_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelMessage_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelMessage_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelMessage_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelMessage_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); + labelMessage_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelMessage_->SetRollSpeed(0); + group_->Add(labelMessage_); + + labelTime_ = new UILabel(); + if (labelTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTime_ is nullptr"); return; } - labelTime->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelTime->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelTime->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelTime->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); - labelTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_TWO); - group->Add(labelTime); - - std::string strTitle = DateModel::GetInstance().titleName; - labelTitle->SetText(strTitle.c_str()); - for (const auto &item : DateModel::GetInstance().listDate) { - std::string strIndex = DateModel::GetInstance().messageIndex; - if (strIndex == item.index) { - labelTime->SetText(item.label_1); - labelMessage->SetText(item.label_2); + labelTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTime_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelTime_->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_TWO); + group_->Add(labelTime_); + + labelAddress_ = new UILabel(); + if (labelAddress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTime_ is nullptr"); + return; + } + labelAddress_->SetPosition(DATE_MESSAGE_TWO_POSITION_X, DATE_MESSAGE_TWO_POSITION_Y, DATE_MESSAGE_ADDRESS_WIDTH, + DATE_MESSAGE_ADDRESS_HEIGHT); + labelAddress_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelAddress_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelAddress_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelAddress_->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelAddress_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_TWO); + group_->Add(labelAddress_); + + for (const auto &item : DateModel::GetInstance().listDate_) { + std::string index = DateModel::GetInstance().messageIndex_; + if (!strcmp(index.c_str(), item.index)) { + labelTime_->SetText(item.title); + labelMessage_->SetText(item.describetion); + labelAddress_->SetText(item.address); + break; } } - int posTextHeight = labelMessage->GetTextHeight(); + int posTextHeight = labelMessage_->GetTextHeight(); int posHeight = DATE_MESSAGE_TWO_POSITION_Y; + labelMessage_->SetY(DATE_MESSAGE_TWO_POSITION_Y); + labelMessage_->SetHeight(posTextHeight); int pos = 0; - if (posTextHeight < DATE_MESSAGE_MAX_LINE_HEIGHT) { - int offsetY = 50; - pos = DATE_MESSAGE_TWO_POSITION_Y + posTextHeight + offsetY; - labelMessage->SetY(DATE_MESSAGE_TWO_POSITION_Y + offsetY); + int offset = 10; + int pageHeight; + pos = DATE_MESSAGE_TWO_POSITION_Y + posTextHeight + offset; + if (labelAddress_->GetText() != nullptr && (!strcmp(labelAddress_->GetText(), "no location"))) { + labelAddress_->SetVisible(false); + int pageH = 454; + int half = 2; + int posY = (pageH - posTextHeight) / half; + labelMessage_->SetY(posY); + labelTime_->SetPosition(DATE_MESSAGE_POSITON_X1, pos, DATE_MESSAGE_WIDTH, DATE_MESSAGE_HEIGHT); + pageHeight = labelMessage_->GetY() + labelMessage_->GetHeight(); } else { - pos = DATE_MESSAGE_TWO_POSITION_Y + posTextHeight; - labelMessage->SetY(DATE_MESSAGE_TWO_POSITION_Y); - } - labelMessage->SetHeight(posTextHeight); - labelTime->SetPosition(DATE_MESSAGE_POSITON_X1, pos, DATE_MESSAGE_WIDTH, DATE_MESSAGE_HEIGHT); - group->SetOnDragListener(this); - group->SetDraggable(true); - AddViewToPageContainer(group); + int addressHeight = labelAddress_->GetTextHeight(); + labelAddress_->SetY(pos); + labelAddress_->SetHeight(labelAddress_->GetTextHeight()); + pos = labelAddress_->GetY() + labelAddress_->GetHeight() + offset; + labelTime_->SetPosition(DATE_MESSAGE_POSITON_X1, pos, DATE_MESSAGE_WIDTH, DATE_MESSAGE_HEIGHT); + pageHeight = labelAddress_->GetY() + labelAddress_->GetHeight(); + } + if (pageHeight <= DATE_MESSAGE_TIME_POS_Y) { + int timeOffsetY = 364; + labelTime_->SetY(timeOffsetY); + } } bool DateMessagePage::OnDrag(UIView &view, const DragEvent &event) @@ -160,7 +215,9 @@ bool DateMessagePage::OnDrag(UIView &view, const DragEvent &event) UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DatePresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); + DateModel::GetInstance().resetPage_ = PAGE_STATUS_2; + NativeAbility::GetInstance().SwitchPageInSlice(DATE_PAGES::DATE_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); } return true; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateModel.cpp index 4792289fa..f5e8c5890 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DateModel.cpp @@ -1,18 +1,26 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: DateModel * Create: 2025-03-23 */ -#include "date/DateModel.h" -#include "date/DatePresenter.h" -#include "phoneservice/PhoneService.h" +#include "bts_br_gap.h" +#include "bts_spp.h" +#include "msg_center_customer.h" +#include "msg_center_device.h" #include "ohos_timer.h" -#include "wearable_log.h" +#include "phone_msg_notification.h" +#include "date/DatePresenter.h" +#include "date/DateModel.h" namespace OHOS { -static constexpr int16 DATE_COUNT = 24; -static constexpr int16 DATE_HOUR = 12; +static constexpr int16 INDEX_0 = 0; +static constexpr int16 INDEX_1 = 1; +static constexpr int16 INDEX_2 = 2; +static constexpr int16 INDEX_3 = 3; +static constexpr int16 INDEX_4 = 4; +static constexpr int16 INDEX_5 = 5; +static const char *DATE_FILE = DATE_PATH "/calendar.json"; DateModel::DateModel() {} @@ -27,30 +35,47 @@ DateModel &DateModel::GetInstance() bool DateModel::InitDateVec(std::string dateStr) { int index = 0; - listDate.clear(); - if (GetBtConnectStatus() != PROFILE_STATE_CONNECTED) { - listDate.push_back({"无日程", "请连接手机,同步日程信息", "0", true}); + listDate_.clear(); + if (GetConnectStatus() == 0) { + listDate_.push_back({"无日程", "请连接手机,同步日程信息", "0", "0", true}); } else { - for (const auto &msg : keyValues) { + for (const auto &msg : keyValues_) { + if (msg.first != dateStr) { + continue; + } for (const auto &item : msg.second) { - if (msg.first == dateStr) { - index++; - strIndex = std::to_string(index); - listDate.push_back({item.hour.c_str(), item.eventTitle.c_str(), strIndex.c_str(), false}); - } + listDate_.push_back( + {item.hour.c_str(), item.eventTitle.c_str(), item.address.c_str(), item.index.c_str(), false}); } } - if (listDate.size() == 0) { - listDate.push_back({"无日程", "请前往手机日历创建日程", "0", true}); + + if (listDate_.size() == 0) { + listDate_.push_back({"无日程", "请前往手机日历创建日程", "0", "0", true}); } } return true; } +uint8_t DateModel::GetConnectStatus() +{ + uint8_t conn_status = 0; +#ifdef _WIN32 + conn_status = 1; +#else + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_PHONE) { + conn_status = is_spp_connected(0) == true ? 1 : 0; + } else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + conn_status = msg_center_get_ble_conn_state(); + } +#endif + return conn_status; +} + bool DateModel::InitDate() { - keyValues.clear(); - std::ifstream file("/user/app/user/ace/data/com.vendor.Weather/calendar.json"); + keyValues_.clear(); + dateClockVec_.clear(); + std::ifstream file(DATE_FILE); if (!file.is_open()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cannot open file"); return false; @@ -78,16 +103,219 @@ bool DateModel::InitDate() cJSON *date = cJSON_GetObjectItemCaseSensitive(dateSum, std::to_string(i).c_str()); if (!cJSON_IsObject(date)) { cJSON_Delete(root); - continue; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error date"); + return false; } - std::string hour = cJSON_GetObjectItemCaseSensitive(date, "hour")->valuestring; - std::string eventTitle = cJSON_GetObjectItemCaseSensitive(date, "eventTitle")->valuestring; - std::string startTime = cJSON_GetObjectItemCaseSensitive(date, "startTime")->valuestring; - std::string time = cJSON_GetObjectItemCaseSensitive(date, "time")->valuestring; - std::string week = cJSON_GetObjectItemCaseSensitive(date, "week")->valuestring; - DateMsg item = {hour, eventTitle, startTime, week}; - keyValues[time].push_back(item); + + std::string time = "测试time"; + if (!cJSON_GetObjectItemCaseSensitive(date, "time")) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error time:"); + } else { + time = cJSON_GetObjectItemCaseSensitive(date, "time")->valuestring; + } + + std::string hour = "测试hour"; + if (!cJSON_GetObjectItemCaseSensitive(date, "hour")) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error hour:"); + } else { + hour = cJSON_GetObjectItemCaseSensitive(date, "hour")->valuestring; + } + + std::string eventTitle = "测试eventTitle"; + if (!cJSON_GetObjectItemCaseSensitive(date, "eventTitle")) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error eventTitle:"); + } else { + eventTitle = cJSON_GetObjectItemCaseSensitive(date, "eventTitle")->valuestring; + } + + std::string address = "no location"; + if (!cJSON_GetObjectItemCaseSensitive(date, "location")) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error location:"); + } else { + address = cJSON_GetObjectItemCaseSensitive(date, "location")->valuestring; + } + std::string index = std::to_string(i); + DateMsg item = {hour, eventTitle, address, index}; + keyValues_[time].push_back(item); + std::string start_time = hour.substr(0, INDEX_5); + std::string result_time = time + " " + start_time; + eventTitle = hour + "\r\n" + eventTitle; + CalcClockTime(result_time, eventTitle); + } + cJSON_Delete(root); + return true; +} + +void DateModel::CalcClockTime(std::string result_time, std::string eventTitle) +{ + std::tm tm = {}; + std::istringstream ss("2025-06-18 15:20"); + ss >> std::get_time(&tm, "%Y-%m-%d %H:%M"); + if (ss.fail()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CalcClockTime cannot open file"); + return; + } + DateToMessage item; + item.time = result_time; + item.eventTitle = eventTitle; + dateClockVec_.push_back(item); +} + +void DateModel::Init() +{ + InitDateTimer(); +} + +bool HasFileChanged(const std::string &filePath, time_t &lastModTime, std::string &lastContent) +{ + struct stat fileStat; + if (stat(filePath.c_str(), &fileStat) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cat file fail"); + return false; + } + + if (fileStat.st_mtime == lastModTime) { + return false; + } + + std::ifstream file(filePath); + if (!file.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cannot open file"); + return false; + } + + std::string currentContent((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + if (currentContent == lastContent) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "updateLastModTime"); + lastModTime = fileStat.st_mtime; + return false; } + + lastModTime = fileStat.st_mtime; + lastContent = currentContent; return true; } + +std::vector parseTime(const std::string &s) +{ + int year = 0; + int month = 0; + int day = 0; + int hour = 0; + int minute = 0; + int second = 0; + char sep; + std::istringstream ss(s); + ss >> year >> sep >> month >> sep >> day >> hour >> sep >> minute; + if (s.size() > TIME_END) { + ss >> sep >> second; + } + return {year, month, day, hour, minute, second}; +} + +void CmpClock() +{ + std::time_t now = std::time(nullptr); + std::tm *local = std::localtime(&now); + char buffer[20]; + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", local); + std::string time_str(buffer); + for (auto item = DateModel::GetInstance().dateClockVec_.begin(); + item != DateModel::GetInstance().dateClockVec_.end();) { + auto vsec = parseTime(item->time); + auto localtime = parseTime(time_str); + if (vsec[INDEX_0] < localtime[INDEX_0]) { + item = DateModel::GetInstance().dateClockVec_.erase(item); + continue; + } else if (vsec[INDEX_0] > localtime[INDEX_0]) { + ++item; + continue; + } + + if (vsec[INDEX_1] < localtime[INDEX_1]) { + item = DateModel::GetInstance().dateClockVec_.erase(item); + continue; + } else if (vsec[INDEX_1] > localtime[INDEX_1]) { + ++item; + continue; + } + + if (vsec[INDEX_2] < localtime[INDEX_2]) { + item = DateModel::GetInstance().dateClockVec_.erase(item); + continue; + } else if (vsec[INDEX_2] > localtime[INDEX_2]) { + ++item; + continue; + } + auto diff = (vsec[INDEX_3] - localtime[INDEX_3]) * NUM_TIME_HOUR + + (vsec[INDEX_4] - localtime[INDEX_4]) * NUM_TIME_MIN + (vsec[INDEX_5] - localtime[INDEX_5]); + if (diff <= NUM_TIME_MIN && diff > 0) { +#ifdef _WIN32 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PostGraphicEvent date msg"); +#else + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&PhoneMsgView::ShowDateMsg, "日历", "日历通知", item->eventTitle)); + item = DateModel::GetInstance().dateClockVec_.erase(item); +#endif + } else if (diff < 0) { + item = DateModel::GetInstance().dateClockVec_.erase(item); + } else { + ++item; + } + } +} + +void DateModel::ClearData() +{ + std::remove(DATE_FILE); +} + +/* 定时器回调函数 */ +void DateTimerCallback(void *data) +{ + (void)data; + static time_t lastModTime = 0; + static std::string lastContent; + bool change = HasFileChanged(DATE_FILE, lastModTime, lastContent); + if (change) { + DateModel::GetInstance().InitDate(); + } + if (DateModel::GetInstance().dateClockVec_.size() > 0) { + CmpClock(); + } +} + +/* 开启定时器 */ +void DateModel::InitDateTimer() +{ + if (startCount_ != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DatePhoneMenuPhoneMainPage already exists!!"); + return; + } + uint32 tick = GetOSTick(NUM_THIRTY * MS_ONE_SECONDS); + startCount_ = new GraphicTimer(tick, DateTimerCallback, nullptr, true); + if (startCount_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DatePhoneMenuPhoneMainPage new GraphicTimer failed!!"); + return; + } + bool retTimer = startCount_->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DatePhoneMenuPhoneMainPage osTimerStart failed!!"); + if (startCount_ != nullptr) { + delete startCount_; + startCount_ = nullptr; + } + return; + } +} + +/* 关闭定时器 */ +void DateModel::DisableDatePhoneTimer() +{ + if (startCount_ != nullptr) { + startCount_->Stop(); + delete startCount_; + startCount_ = nullptr; + } +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DatePresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DatePresenter.cpp index 64ba20fee..d6cecdee2 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DatePresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/date/src/DatePresenter.cpp @@ -1,16 +1,16 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: DatePresenter * Create: 2025-03-23 */ -#include "date/DatePresenter.h" -#include "date/DateModel.h" -#include "date/DateView.h" #include "NativeRegisterManager.h" #include "uiservice/ui_service.h" #include "wearable_log.h" +#include "date/DatePresenter.h" +#include "date/DateModel.h" +#include "date/DateView.h" namespace OHOS { -REGIST_MENU(VIEW_DATE, DateView, DatePresenter, DATE_MAIN_ICON, DATE_MAIN_ICON, "日程"); +REGIST_MENU(VIEW_DATE, DateView, DatePresenter, DATE_ICON, DATE_ICON, "日历"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPage.cpp index 6860eaec8..c43ecaba3 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPage.cpp @@ -1,67 +1,120 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: EmptyPage - * Create: 2025-04-24 + * Create: 2025-06-06 */ -#include "emptypage/EmptyPage.h" -#include "emptypage/EmptyPresenter.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_empty.h" #include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" #include "wearable_log.h" #include "AppViewIDs.h" #include "NativeAbility.h" +#include "emptypage/EmptyPresenter.h" +#include "emptypage/EmptyPage.h" namespace OHOS { -static const uint16_t MEM_LABEL_FONT_SIZE = 40; -static uint32_t EMPTY_PAGE = 1; +static constexpr uint16_t EMPTY_PAGE = 1; +static constexpr uint16_t MEM_LABEL_X = 121; +static constexpr uint16_t MEM_LABEL_W = 193; +static constexpr uint16_t MEM_LABEL_H = 40; +static constexpr uint16_t MEM_LABEL_FONT = 32; +static constexpr uint16_t MEM_USED_LABEL_Y = 161; +static constexpr uint16_t MEM_FREE_LABEL_Y = 272; + REGIST_SLICE_PAGE(VIEW_EMPTY, EMPTY_PAGE, EmptyPage, true); + void EmptyPage::OnStart(void *data) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmptyPage OnStart"); + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(EMPTY_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadEmptyImage fail"); + return; + } + container_ = new UIViewGroup(); if (container_ == nullptr) { - container_ = new UIScrollView(); - container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - // 设置界面组件回调函数 - container_->SetOnDragListener(this); - container_->SetOnClickListener(this); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmptyPage container_ new fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetOnDragListener(this); + container_->SetDraggable(true); + container_->SetTouchable(true); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmptyPage bgImg_ new fail"); + return; } + bgImg_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(bgImg_, EMPTY_IMAGE, IMAGE_EMPTY_BG); + container_->Add(bgImg_); + + uint32_t memUsed = 0; + uint32_t memFree = 0; #if !defined(_WIN32) - test_get_mem_info(1, &used_, &free_); + test_get_mem_info(&memUsed, &memFree); #endif - // Add Label to App - if (memLabel_ == nullptr) { - memLabel_ = new UILabel(); + memUsedLabel_ = new UILabel(); + if (memUsedLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmptyPage memUsedLabel_ new fail"); + return; + } + memUsedLabel_->SetPosition(MEM_LABEL_X, MEM_USED_LABEL_Y, MEM_LABEL_W, MEM_LABEL_H); + memUsedLabel_->SetText(std::to_string(memUsed).c_str()); + memUsedLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + memUsedLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MEM_LABEL_FONT); + container_->Add(memUsedLabel_); + + memFreeLabel_ = new UILabel(); + if (memFreeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmptyPage memFreeLabel_ new fail"); + return; } - memLabel_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - std::string memInfo = "Used : " + std::to_string(used_) + "\n" + "Free : " + std::to_string(free_); - memLabel_->SetText(memInfo.c_str()); - memLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - memLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MEM_LABEL_FONT_SIZE); - container_->Add(memLabel_); + memFreeLabel_->SetPosition(MEM_LABEL_X, MEM_FREE_LABEL_Y, MEM_LABEL_W, MEM_LABEL_H); + memFreeLabel_->SetText(std::to_string(memFree).c_str()); + memFreeLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + memFreeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MEM_LABEL_FONT); + container_->Add(memFreeLabel_); AddViewToPageContainer(container_); } +EmptyPage::EmptyPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmptyPage::EmptyPage"); +} + EmptyPage::~EmptyPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmptyPage::~EmptyPage"); if (container_ != nullptr) { container_->RemoveAll(); delete container_; container_ = nullptr; } - if (memLabel_ != nullptr) { - delete memLabel_; - memLabel_ = nullptr; + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + if (memUsedLabel_ != nullptr) { + delete memUsedLabel_; + memUsedLabel_ = nullptr; + } + if (memFreeLabel_ != nullptr) { + delete memFreeLabel_; + memFreeLabel_ = nullptr; } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(EMPTY_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmptyPage::~EmptyPage"); } bool EmptyPage::OnDrag(UIView &view, const DragEvent &event) { + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } return false; } - -bool EmptyPage::OnClick(UIView &view, const ClickEvent &event) -{ - return false; } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp index 1a429dfa6..797a5bce2 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp @@ -1,13 +1,13 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: EmptyPresenter - * Create: 2025-04-24 + * Create: 2025-06-06 */ +#include "NativeRegisterManager.h" #include "emptypage/EmptyView.h" #include "emptypage/EmptyPresenter.h" -#include "NativeRegisterManager.h" namespace OHOS { -REGIST_MENU(VIEW_EMPTY, EmptyView, EmptyPresenter, FLASHLIGHT_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, "空页面"); +REGIST_MENU(VIEW_EMPTY, EmptyView, EmptyPresenter, EMPTY_ICON, EMPTY_ICON, "空页面"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp index 54396d287..fefb06995 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp @@ -4,24 +4,21 @@ * Create: 2025-03-23 */ -#include "phoneservice/PhoneService.h" #include "UiConfig.h" +#include "bts_br_gap.h" #include "bts_spp.h" #include "common/image_cache_manager.h" #include "main/LoadImg.h" +#include "msg_center_device.h" #include "ui_resource_findPhone.h" #include "uiservice/ui_service.h" #include "ui_test_group.h" -#include "wearable_onlinelog.h" -#include "msg_center_protocol.h" -#include "msg_center_device.h" -#include "findphone/FindPhoneMainPage.h" +#include "settings/model/SettingDisplayModel.h" #include "findphone/FindPhonePresenter.h" #include "findphone/FindPhoneView.h" +#include "findphone/FindPhoneMainPage.h" -static uint8_t data = 0; namespace OHOS { - static FindPhoneMainPage *g_pFindPhoneMainPage = nullptr; static constexpr uint16_t FIND_PHONE_IMAGE_WIDTH = 500; static constexpr uint16_t FIND_PHONE_IMAGE_HEIGHT = 500; @@ -33,57 +30,48 @@ static constexpr uint16_t FIND_PHONE_RTYBUTTON_POSITION_X = 179; static constexpr uint16_t FIND_PHONE_RTYBUTTON_POSITION_Y = 289; static constexpr uint16_t FIND_PHONE_RTYBUTTON = 96; static constexpr uint16_t FIND_PHONE_SIZE = 466; -static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_POSITION_X = 170; -static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_POSITION_Y = 170; -static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_WIDTH = 100; -static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_HEIGHT = 100; static constexpr uint16_t FONT_DEFAULT_SIZE_1 = 36; static constexpr uint16_t FONT_DEFAULT_SIZE_2 = 38; static constexpr uint16_t FIND_PHONE_INITIAL = 0; -static constexpr uint16_t FIND_PHONE_TITLDE_X = 140; -static constexpr uint16_t FIND_PHONE_TITLDE_Y = 345; -static constexpr uint16_t FIND_PHONE_TITLDE_WIDTH = 314; +static constexpr uint16_t FIND_PHONE_TITLE_X = 140; +static constexpr uint16_t FIND_PHONE_TITLE_Y = 345; +static constexpr uint16_t FIND_PHONE_TITLE_WIDTH = 314; +static constexpr uint16_t FIND_PHONE_TITLE_HEIGHT = 100; static constexpr uint16_t FIND_PHONE_FINDTITLE_X = 150; static constexpr uint16_t FIND_PHONE_FINDTITLE_Y = 31; static constexpr uint16_t FIND_PHONE_FINDTITLE_WIDTH = 253; static constexpr uint16_t FIND_PHONE_FINDTITLE_HEIGHT = 53; -static constexpr uint16_t FIND_PHONE_RINGING_X = 200; -static constexpr uint16_t FIND_PHONE_RINGING2_X = 156; static constexpr uint16_t FIND_PHONE_RINGING_Y = 353; -static constexpr uint16_t FIND_PHONE_RINGING_WIDTH = 93; -static constexpr uint16_t FIND_PHONE_RINGING2_WIDTH = 144; +static constexpr uint16_t FIND_PHONE_RINGING_WIDTH = 454; static constexpr uint16_t FIND_PHONE_RINGING_HEIGHT = 42; static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_X = 50; static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_Y = 185; static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_WIDTH = 424; static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_HEIGHT = 50; -static constexpr uint16_t FIND_PHONE_DURATION_TIME = 60; static constexpr uint16_t IMAGE_SIZE = 500; -static constexpr uint16_t IMAGEANIMATOERVIEW_SIZE = 28; +static constexpr uint16_t IMAGE_OPA = 100; static constexpr uint16_t IMAGEANIMATOERVIEW_TIME = 60; static constexpr uint16_t FIND_PHONE_IMAGE_X = 5; -static constexpr uint16_t FIND_PHONE_IMAGE_y = 1; -static constexpr uint16_t FIND_PHONE_PIXELBYTE_SIZE = 4; -static constexpr uint16_t FIND_PHONE_PIXELBYTEH = 100; +static constexpr uint16_t FIND_PHONE_IMAGE_Y = 1; +static constexpr uint16_t FINDPHONE_TIMEOUT = 60; +static constexpr uint16_t MS_ONE_SECONDS = 1000; +static constexpr char *FIND_BUTTON = "findButton"; +static constexpr char *RETRY_BUTTON = "retryButton"; +static constexpr uint32_t g_imageAnimatorInfo[FINDPHONE_IMAGE_COUNT] = { + IMAGE_FINDPHONE_FRAME01, IMAGE_FINDPHONE_FRAME02, IMAGE_FINDPHONE_FRAME03, IMAGE_FINDPHONE_FRAME04, + IMAGE_FINDPHONE_FRAME05, IMAGE_FINDPHONE_FRAME06, IMAGE_FINDPHONE_FRAME07, IMAGE_FINDPHONE_FRAME08, + IMAGE_FINDPHONE_FRAME09, IMAGE_FINDPHONE_FRAME10, IMAGE_FINDPHONE_FRAME11, IMAGE_FINDPHONE_FRAME12, + IMAGE_FINDPHONE_FRAME13, IMAGE_FINDPHONE_FRAME14, IMAGE_FINDPHONE_FRAME15, IMAGE_FINDPHONE_FRAME16, + IMAGE_FINDPHONE_FRAME17, IMAGE_FINDPHONE_FRAME18, IMAGE_FINDPHONE_FRAME19, IMAGE_FINDPHONE_FRAME20, + IMAGE_FINDPHONE_FRAME21, IMAGE_FINDPHONE_FRAME22, IMAGE_FINDPHONE_FRAME23, IMAGE_FINDPHONE_FRAME24, + IMAGE_FINDPHONE_FRAME25, IMAGE_FINDPHONE_FRAME26, IMAGE_FINDPHONE_FRAME27, IMAGE_FINDPHONE_FRAME28, +}; REGIST_SLICE_PAGE(VIEW_FIND_PHONE, FIND_PHONE_PAGES::FIND_PHONE_MAIN_PAGE, FindPhoneMainPage, true); -const int g_imageAnimatorInfo[IMAGEANIMATOERVIEW_SIZE] = { - IMAGE_CONVERTER_TOOL_FINDPHONE001, IMAGE_CONVERTER_TOOL_FINDPHONE002, IMAGE_CONVERTER_TOOL_FINDPHONE003, - IMAGE_CONVERTER_TOOL_FINDPHONE004, IMAGE_CONVERTER_TOOL_FINDPHONE005, IMAGE_CONVERTER_TOOL_FINDPHONE006, - IMAGE_CONVERTER_TOOL_FINDPHONE007, IMAGE_CONVERTER_TOOL_FINDPHONE008, IMAGE_CONVERTER_TOOL_FINDPHONE009, - IMAGE_CONVERTER_TOOL_FINDPHONE010, IMAGE_CONVERTER_TOOL_FINDPHONE011, IMAGE_CONVERTER_TOOL_FINDPHONE012, - IMAGE_CONVERTER_TOOL_FINDPHONE013, IMAGE_CONVERTER_TOOL_FINDPHONE014, IMAGE_CONVERTER_TOOL_FINDPHONE015, - IMAGE_CONVERTER_TOOL_FINDPHONE016, IMAGE_CONVERTER_TOOL_FINDPHONE017, IMAGE_CONVERTER_TOOL_FINDPHONE018, - IMAGE_CONVERTER_TOOL_FINDPHONE019, IMAGE_CONVERTER_TOOL_FINDPHONE020, IMAGE_CONVERTER_TOOL_FINDPHONE021, - IMAGE_CONVERTER_TOOL_FINDPHONE022, IMAGE_CONVERTER_TOOL_FINDPHONE023, IMAGE_CONVERTER_TOOL_FINDPHONE024, - IMAGE_CONVERTER_TOOL_FINDPHONE025, IMAGE_CONVERTER_TOOL_FINDPHONE026, IMAGE_CONVERTER_TOOL_FINDPHONE027, - IMAGE_CONVERTER_TOOL_FINDPHONE028, -}; - FindPhoneMainPage::FindPhoneMainPage() { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::FindPhoneMainPage"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::FindPhoneMainPage"); g_pFindPhoneMainPage = this; } @@ -96,36 +84,42 @@ FindPhoneMainPage::~FindPhoneMainPage() container_ = nullptr; } - if (buttonFind != nullptr) { - delete buttonFind; - buttonFind = nullptr; + if (buttonFind_ != nullptr) { + delete buttonFind_; + buttonFind_ = nullptr; } - if (mainImage != nullptr) { - delete mainImage; - mainImage = nullptr; + if (labelDisconnect_ != nullptr) { + delete labelDisconnect_; + labelDisconnect_ = nullptr; } - if (labelUnder != nullptr) { - delete labelUnder; - labelUnder = nullptr; + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; } - if (labelFindTitle != nullptr) { - delete labelFindTitle; - labelFindTitle = nullptr; + if (labelRing_ != nullptr) { + delete labelRing_; + labelRing_ = nullptr; } - if (labelRing != nullptr) { - delete labelRing; - labelRing = nullptr; + if (buttonRetry_ != nullptr) { + delete buttonRetry_; + buttonRetry_ = nullptr; } - if (buttonRty != nullptr) { - delete buttonRty; - buttonRty = nullptr; + if (startCount_ != nullptr) { + delete startCount_; + startCount_ = nullptr; } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::~FindPhoneMainPage"); + + if (imageAnimator_ != nullptr) { + delete imageAnimator_; + imageAnimator_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(FINDPHONE_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::~FindPhoneMainPage"); } FindPhoneMainPage *FindPhoneMainPage::GetInstance() @@ -137,217 +131,198 @@ void FindPhoneMainPage::OnStop() { if (imageAnimator_->GetState() == true) { DisableFindPhoneTimer(); -#ifndef _WIN32 - errcode_t result = - uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnStop::uapi_diag_service_send_log OFF result:%d ", result); + uint8_t value = 1; + errcode_t result; +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_STOP_FIND_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnStop stop find phone result:%d ", result); #endif - ImageCacheManager::GetInstance().UnloadAllInMultiRes(FINDPHONE_IMAGE); } - data = 0; } void FindPhoneMainPage::OnStart(void *data) { + container_ = new UIViewGroup(); if (container_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new container_ fail"); - container_ = new UIViewGroup(); - container_->SetPosition(FIND_PHONE_INITIAL, FIND_PHONE_INITIAL, FIND_PHONE_SIZE, FIND_PHONE_SIZE); - container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new container_ fail"); + return; } + container_->SetPosition(FIND_PHONE_INITIAL, FIND_PHONE_INITIAL, FIND_PHONE_SIZE, FIND_PHONE_SIZE); + container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); container_->SetTouchable(true); container_->SetDraggable(true); container_->SetOnDragListener(this); - if (mainImage == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new mainImage fail"); - mainImage = new UIImageView(); - } - mainImage->SetPosition(FIND_PHONE_INITIAL, FIND_PHONE_INITIAL); - LOADIMG::LoadImageViewImg(mainImage, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_2); - container_->Add(mainImage); - - SetUpImageAnimator(); - SetupButton(); + InitImageAnimator(); + InitButton(); - labelUnder = new UILabel(); - if (labelUnder == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelUnder fail"); + labelDisconnect_ = new UILabel(); + if (labelDisconnect_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelDisconnect_ fail"); return; } - labelUnder->SetText("蓝牙已断开"); - labelUnder->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); - labelUnder->SetPosition(FIND_PHONE_TITLDE_X, FIND_PHONE_TITLDE_Y, FIND_PHONE_TITLDE_WIDTH, - FIND_PHONE_IMAGEANIMATOR_HEIGHT); - container_->Add(labelUnder); - labelFindTitle = new UILabel(); - if (labelFindTitle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelFindTitle fail"); + labelDisconnect_->SetText("蓝牙已断开"); + labelDisconnect_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + labelDisconnect_->SetPosition(FIND_PHONE_TITLE_X, FIND_PHONE_TITLE_Y, FIND_PHONE_TITLE_WIDTH, + FIND_PHONE_TITLE_HEIGHT); + container_->Add(labelDisconnect_); + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); return; } - labelFindTitle->SetText("查找手机"); - labelFindTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_2); - labelFindTitle->SetPosition(FIND_PHONE_FINDTITLE_X, FIND_PHONE_FINDTITLE_Y, FIND_PHONE_FINDTITLE_WIDTH, - FIND_PHONE_FINDTITLE_HEIGHT); - container_->Add(labelFindTitle); + labelTitle_->SetText("查找手机"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_2); + labelTitle_->SetPosition(FIND_PHONE_FINDTITLE_X, FIND_PHONE_FINDTITLE_Y, FIND_PHONE_FINDTITLE_WIDTH, + FIND_PHONE_FINDTITLE_HEIGHT); + container_->Add(labelTitle_); - labelRing = new UILabel(); - if (labelRing == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelRing fail"); + labelRing_ = new UILabel(); + if (labelRing_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelRing_ fail"); return; } - labelRing->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); - container_->Add(labelRing); + labelRing_->SetText("响铃"); + labelRing_->SetPosition(0, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING_WIDTH, FIND_PHONE_RINGING_HEIGHT); + labelRing_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + labelRing_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelRing_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + container_->Add(labelRing_); if (GetConnectStatus() == 1) { - labelRing->SetVisible(true); - labelUnder->SetVisible(false); - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); - buttonFind->Enable(); + labelRing_->SetVisible(true); + labelDisconnect_->SetVisible(false); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_CONNECT, IMAGE_FINDPHONE_CONNECT); + buttonFind_->Enable(); } else { - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4); - buttonFind->Disable(); - labelUnder->SetVisible(true); - labelRing->SetVisible(false); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_DISCONNECT, IMAGE_FINDPHONE_DISCONNECT); + buttonFind_->Disable(); + labelDisconnect_->SetVisible(true); + labelRing_->SetVisible(false); } imageAnimator_->Stop(); imageAnimator_->SetVisible(false); AddViewToPageContainer(container_); } -void FindPhoneMainPage::SetUpImageAnimator() +void FindPhoneMainPage::InitImageAnimator() { imageAnimator_ = new UIImageAnimatorView(); if (imageAnimator_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "FindPhoneMainPage::UIImageAnimatorView new Label SetUpImageAnimator fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imageAnimator_ new fail"); return; } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::SetUpImageAnimator "); - imageAnimator_ = new UIImageAnimatorView(); - for (data; data < IMAGEANIMATOERVIEW_SIZE; data++) { - searchImageInfo[data].imageInfo = - ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[data], FINDPHONE_IMAGE); - ; - searchImageInfo[data].imageType = IMG_SRC_IMAGE_INFO; - searchImageInfo[data].pos.x = FIND_PHONE_IMAGE_X; - searchImageInfo[data].pos.y = FIND_PHONE_IMAGE_y; - searchImageInfo[data].width = IMAGE_SIZE; - searchImageInfo[data].height = IMAGE_SIZE; - } - imageAnimator_->SetPosition(FIND_PHONE_IMAGE_X, FIND_PHONE_IMAGE_y, FIND_PHONE_IMAGE_WIDTH, - FIND_PHONE_IMAGE_HEIGHT); // 50 : offset 50 : offset 200 : offset 200: offset - int imageNumber = IMAGEANIMATOERVIEW_SIZE; - int ImageUpdate = IMAGEANIMATOERVIEW_TIME; - imageAnimator_->SetImageAnimatorSrc(searchImageInfo, imageNumber, - ImageUpdate); // 4: the number of images, 100: updating time + for (int i = 0; i < FINDPHONE_IMAGE_COUNT; i++) { + searchImageInfo_[i].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[i], FINDPHONE_IMAGE); + searchImageInfo_[i].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo_[i].pos.x = FIND_PHONE_IMAGE_X; + searchImageInfo_[i].pos.y = FIND_PHONE_IMAGE_Y; + searchImageInfo_[i].width = IMAGE_SIZE; + searchImageInfo_[i].height = IMAGE_SIZE; + } + imageAnimator_->SetPosition(FIND_PHONE_IMAGE_X, FIND_PHONE_IMAGE_Y, FIND_PHONE_IMAGE_WIDTH, + FIND_PHONE_IMAGE_HEIGHT); + imageAnimator_->SetImageAnimatorSrc(searchImageInfo_, FINDPHONE_IMAGE_COUNT, IMAGEANIMATOERVIEW_TIME); imageAnimator_->Stop(); imageAnimator_->LayoutCenterOfParent(); imageAnimator_->SetDraggable(true); imageAnimator_->SetOnDragListener(this); container_->Add(imageAnimator_); - InitImageInfo(); } -void FindPhoneMainPage::SetupButton() +void FindPhoneMainPage::InitButton() { - // Add Button to App - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::SetupButton new Label"); - if (buttonFind == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new buttonFind fail"); - buttonFind = new UIButton(); + buttonFind_ = new UIButton(); + if (buttonFind_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonFind_ fail"); + return; } - buttonFind->SetPosition(FIND_PHONE_BUTTON_POSITION_X, FIND_PHONE_BUTTON_POSITION_Y); - buttonFind->Resize(FIND_PHONE_BUTTON_WIDTH, FIND_PHONE_BUTTON_HEIGHT); - buttonFind->SetViewId("button1"); - buttonFind->SetOnClickListener(this); - buttonFind->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); - buttonFind->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - buttonFind->SetVisible(true); - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); - if (buttonRty == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new buttonRty fail"); - buttonRty = new UIButton(); + buttonFind_->SetPosition(FIND_PHONE_BUTTON_POSITION_X, FIND_PHONE_BUTTON_POSITION_Y); + buttonFind_->Resize(FIND_PHONE_BUTTON_WIDTH, FIND_PHONE_BUTTON_HEIGHT); + buttonFind_->SetViewId(FIND_BUTTON); + buttonFind_->SetOnClickListener(this); + buttonFind_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonFind_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonFind_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonFind_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_CONNECT, IMAGE_FINDPHONE_CONNECT); + buttonRetry_ = new UIButton(); + if (buttonRetry_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new buttonRetry_ fail"); + return; } - buttonRty->SetPosition(FIND_PHONE_RTYBUTTON_POSITION_X, FIND_PHONE_RTYBUTTON_POSITION_Y); - buttonRty->Resize(FIND_PHONE_RTYBUTTON, FIND_PHONE_RTYBUTTON); - buttonRty->SetViewId("buttonRty"); - buttonRty->SetOnClickListener(this); - buttonRty->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); - buttonRty->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - LOADIMG::LoadBtnImage(buttonRty, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7); - buttonRty->SetVisible(false); - // Add to rootView - container_->Add(buttonRty); - container_->Add(buttonFind); + buttonRetry_->SetPosition(FIND_PHONE_RTYBUTTON_POSITION_X, FIND_PHONE_RTYBUTTON_POSITION_Y); + buttonRetry_->Resize(FIND_PHONE_RTYBUTTON, FIND_PHONE_RTYBUTTON); + buttonRetry_->SetViewId(RETRY_BUTTON); + buttonRetry_->SetOnClickListener(this); + buttonRetry_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + buttonRetry_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadBtnImage(buttonRetry_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_RESET, IMAGE_FINDPHONE_RESET); + buttonRetry_->SetVisible(false); + container_->Add(buttonRetry_); + container_->Add(buttonFind_); } bool FindPhoneMainPage::ClickButtonChange() { -#ifndef _WIN32 errcode_t result; + uint8_t value = 1; if (imageAnimator_->GetState() == true) { - // 关闭定时器 - result = - uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log OFF result:%d ", result); +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_STOP_FIND_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ClickButtonChange stop find phone result:%d ", result); +#endif if (result == 0) { DisableFindPhoneTimer(); - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_CONNECT, IMAGE_FINDPHONE_CONNECT); imageAnimator_->Stop(); imageAnimator_->SetVisible(false); - buttonFind->SetOpaScale(OPA_OPAQUE); - mainImage->SetVisible(true); - labelRing->SetText("响铃"); - labelRing->SetPosition(FIND_PHONE_RINGING_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING_WIDTH, - FIND_PHONE_RINGING_HEIGHT); + buttonFind_->SetOpaScale(OPA_OPAQUE); + labelRing_->SetText("响铃"); return true; - } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OFF send to phone fail:%d ", result); - return false; } } else { - // 开启定时器 - result = - uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_ON_FIND_PHONE, nullptr, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log ON result:%d ", result); +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_START_FIND_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ClickButtonChange start find phone result:%d ", result); +#endif if (result == 0) { InitFindPhoneTimer(); - g_startCount->Start(); imageAnimator_->Start(); imageAnimator_->SetVisible(true); - buttonFind->SetOpaScale(OPA_TRANSPARENT); - mainImage->SetVisible(false); - labelRing->SetText("停止响铃"); - labelRing->SetPosition(FIND_PHONE_RINGING2_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING2_WIDTH, - FIND_PHONE_RINGING_HEIGHT); + buttonFind_->SetOpaScale(OPA_TRANSPARENT); + labelRing_->SetText("停止响铃"); return true; - } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ON send to phone fail:%d ", result); - return false; } } -#endif return true; } void FindPhoneMainPage::ShowReset() { // rtybutton、title显示,findTitle、button隐藏,imageAnimator停止 - labelUnder->SetText("查找手机超时,请重试"); - labelUnder->SetPosition(FIND_PHONE_SEARCHTIMEOUT_X, FIND_PHONE_SEARCHTIMEOUT_Y, FIND_PHONE_SEARCHTIMEOUT_WIDTH, - FIND_PHONE_SEARCHTIMEOUT_HEIGHT); - labelUnder->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); - labelUnder->SetVisible(true); - buttonRty->SetVisible(true); - labelFindTitle->SetVisible(false); - labelRing->SetVisible(false); - buttonFind->SetVisible(false); - mainImage->SetVisible(false); +#ifdef _WIN32 +#else + uint8_t value = 1; + uint8_t result = 0; + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_STOP_FIND_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ShowReset stop find phone result:%d ", result); +#endif + labelDisconnect_->SetText("查找手机超时,请重试"); + labelDisconnect_->SetPosition(FIND_PHONE_SEARCHTIMEOUT_X, FIND_PHONE_SEARCHTIMEOUT_Y, + FIND_PHONE_SEARCHTIMEOUT_WIDTH, FIND_PHONE_SEARCHTIMEOUT_HEIGHT); + labelDisconnect_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + labelDisconnect_->SetVisible(true); + buttonRetry_->SetVisible(true); + labelTitle_->SetVisible(false); + labelRing_->SetVisible(false); + buttonFind_->SetVisible(false); imageAnimator_->Stop(); imageAnimator_->SetVisible(false); DisableFindPhoneTimer(); @@ -355,88 +330,66 @@ void FindPhoneMainPage::ShowReset() bool FindPhoneMainPage::StopFindPhone() { -#ifndef _WIN32 - errcode_t result; if (imageAnimator_->GetState() == true) { - // 关闭定时器 - result = - uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log OFF result:%d ", result); - if (result == 0) { - DisableFindPhoneTimer(); - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); - imageAnimator_->Stop(); - imageAnimator_->SetVisible(false); - buttonFind->SetOpaScale(OPA_OPAQUE); - mainImage->SetVisible(true); - labelRing->SetText("响铃"); - labelRing->SetPosition(FIND_PHONE_RINGING_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING_WIDTH, - FIND_PHONE_RINGING_HEIGHT); - return true; - } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OFF send to phone fail:%d ", result); - return false; - } - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::imageAnimator is stop"); + DisableFindPhoneTimer(); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_CONNECT, IMAGE_FINDPHONE_CONNECT); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + buttonFind_->SetOpaScale(OPA_OPAQUE); + labelRing_->SetText("响铃"); + return true; } -#endif return true; } bool FindPhoneMainPage::OnClick(UIView &view, const ClickEvent &event) { -#ifndef _WIN32 UNUSED(event); - if (view.GetViewId() == "buttonRty") { + if (strcmp(view.GetViewId(), RETRY_BUTTON) == 0) { // rtybutton、title隐藏,findTitle、button显示,imageAnimator播放 - InitFindPhoneTimer(); - static uint8_t buffer[1024] = {16}; - errcode_t result = - uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_ON_FIND_PHONE, buffer, 16); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log ON result:%d ", result); + uint8_t value = 1; + errcode_t result; +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_START_FIND_PHONE, &value, sizeof(value)); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnClick start find phone result:%d ", result); +#endif if (result == 0) { - buttonRty->SetVisible(false); - labelUnder->SetVisible(false); - mainImage->SetVisible(false); - buttonFind->SetVisible(true); - labelFindTitle->SetVisible(true); + buttonRetry_->SetVisible(false); + labelDisconnect_->SetVisible(false); + buttonFind_->SetVisible(true); + labelTitle_->SetVisible(true); + InitFindPhoneTimer(); imageAnimator_->Start(); imageAnimator_->SetVisible(true); - buttonFind->SetOpaScale(OPA_TRANSPARENT); - labelRing->SetVisible(true); - labelRing->SetText("停止响铃"); - labelRing->SetPosition(FIND_PHONE_RINGING2_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING2_WIDTH, - FIND_PHONE_RINGING_HEIGHT); + buttonFind_->SetOpaScale(OPA_TRANSPARENT); + labelRing_->SetVisible(true); + labelRing_->SetText("停止响铃"); return true; - } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "try send to phone fail:%d ", result); - return false; } - } else { + } else if (strcmp(view.GetViewId(), FIND_BUTTON) == 0) { ClickButtonChange(); } -#endif return true; } bool FindPhoneMainPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnDrag"); UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } - return false; + return true; } uint8_t FindPhoneMainPage::GetConnectStatus() { uint8_t conn_status = 0; -#ifndef _WIN32 +#ifdef _WIN32 + conn_status = 1; +#else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_PHONE) { conn_status = is_spp_connected(0) == true ? 1 : 0; } else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { @@ -448,52 +401,43 @@ uint8_t FindPhoneMainPage::GetConnectStatus() void FindPhoneMainPage::ChangeToDisConnect() { - LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4, - IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4); + LOADIMG::LoadBtnImage(buttonFind_, FINDPHONE_IMAGE, IMAGE_FINDPHONE_DISCONNECT, IMAGE_FINDPHONE_DISCONNECT); + DisableFindPhoneTimer(); imageAnimator_->Stop(); imageAnimator_->SetVisible(false); - buttonFind->SetOpaScale(OPA_OPAQUE); - buttonFind->Disable(); - labelFindTitle->SetVisible(false); - labelUnder->SetVisible(true); - labelRing->SetVisible(false); + buttonFind_->SetOpaScale(OPA_OPAQUE); + buttonFind_->Disable(); + labelDisconnect_->SetVisible(true); + labelRing_->SetVisible(false); } /* 定时器回调函数 */ void FindPhoneTimerCallback(void *data) { (void)data; - timeCount++; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::timeCount:%d", timeCount); - if (timeCount == FIND_PHONE_DURATION_TIME) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Searching for phone timed out!!"); - FindPhoneMainPage::GetInstance()->ShowReset(); - timeCount = 0; - } - if (FindPhoneMainPage::GetInstance()->GetConnectStatus() != 1) { - FindPhoneMainPage::GetInstance()->ChangeToDisConnect(); - } + FindPhoneMainPage::GetInstance()->ShowReset(); } /* 开启定时器 */ void FindPhoneMainPage::InitFindPhoneTimer() { - if (g_startCount != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage already exists!!"); + if (startCount_ != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "already exists!!"); return; } - uint32 tick = GetOSTick(MS_ONE_SECONDS); - g_startCount = new GraphicTimer(tick, FindPhoneTimerCallback, nullptr, true); - if (g_startCount == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage new GraphicTimer failed!!"); + uint32 tick = GetOSTick(FINDPHONE_TIMEOUT * MS_ONE_SECONDS); + startCount_ = new GraphicTimer(tick, FindPhoneTimerCallback, nullptr, true); + if (startCount_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new GraphicTimer failed!!"); return; } - bool retTimer = g_startCount->Start(); + SettingDisplayModel::GetInstance().EnableSteadyOn(); + bool retTimer = startCount_->Start(); if (!retTimer) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage osTimerStart failed!!"); - if (g_startCount != nullptr) { - delete g_startCount; - g_startCount = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerStart failed!!"); + if (startCount_ != nullptr) { + delete startCount_; + startCount_ = nullptr; } return; } @@ -502,122 +446,11 @@ void FindPhoneMainPage::InitFindPhoneTimer() /* 关闭定时器 */ void FindPhoneMainPage::DisableFindPhoneTimer() { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CameraModel::DisableFindPhoneTimer!!"); - if (g_startCount != nullptr) { - g_startCount->Stop(); - delete g_startCount; - g_startCount = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraModel::DisableFindPhoneTimer delete g_startCount!!"); - } - timeCount = 0; -} - -void FindPhoneMainPage::InitImageInfo() -{ - const uint16_t pixelByteSize = FIND_PHONE_PIXELBYTE_SIZE; // 4: bytes per pixel - const uint16_t width = FIND_PHONE_PIXELBYTEH; // 100: image's width - const uint16_t height = FIND_PHONE_PIXELBYTEH; // 100: image's height - uint32_t dataSize = width * height * pixelByteSize; - uint8_t *srcData1 = static_cast(UIMalloc(dataSize)); - if (srcData1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData1 fail"); - return; - } - for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { - srcData1[i] = SET_INT_MAX; // 255: pixel value - srcData1[i + 1] = 0; // 1: set green channel - srcData1[i + SET_TWO] = 0; // 2: set red channel - srcData1[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel - } - imageInfo1_ = static_cast(UIMalloc(sizeof(ImageInfo))); - if (imageInfo1_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo1_ fail"); - UIFree(srcData1); - return; - } - - imageInfo1_->header.width = width; - imageInfo1_->header.height = height; - imageInfo1_->header.colorMode = ColorMode::ARGB8888; - imageInfo1_->dataSize = dataSize; - imageInfo1_->data = srcData1; - - uint8_t *srcData2 = static_cast(UIMalloc(dataSize)); - if (srcData2 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData2 fail"); - UIFree(imageInfo1_); - UIFree(srcData1); - return; - } - for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { - srcData2[i] = 0; // set blue channel - srcData2[i + 1] = SET_INT_MAX; // 1: set green channel 255: pixel value - srcData2[i + SET_TWO] = 0; // 2: set red channel - srcData2[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel - } - - imageInfo2_ = static_cast(UIMalloc(sizeof(ImageInfo))); - if (imageInfo2_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo2_ fail"); - UIFree(srcData2); - UIFree(imageInfo1_); - UIFree(srcData1); - return; - } - imageInfo2_->header.width = width; - imageInfo2_->header.height = height; - imageInfo2_->header.colorMode = ARGB8888; - imageInfo2_->dataSize = dataSize; - imageInfo2_->data = srcData2; - - uint8_t *srcData3 = static_cast(UIMalloc(dataSize)); - if (srcData3 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData3 fail"); - UIFree(imageInfo2_); - UIFree(srcData2); - UIFree(imageInfo1_); - UIFree(srcData1); - return; - } - for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { - srcData3[i] = 0; // set blue channel - srcData3[i + 1] = 0; // 1: set green channel - srcData3[i + SET_TWO] = SET_INT_MAX; // 2: set red channel 255: pixel value - srcData3[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel - } - - imageInfo3_ = static_cast(UIMalloc(sizeof(ImageInfo))); - if (imageInfo3_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo3_ fail"); - UIFree(srcData3); - UIFree(imageInfo2_); - UIFree(srcData2); - UIFree(imageInfo1_); - UIFree(srcData1); - return; + SettingDisplayModel::GetInstance().DisableSteadyOn(); + if (startCount_ != nullptr) { + startCount_->Stop(); + delete startCount_; + startCount_ = nullptr; } - imageInfo3_->header.width = width; - imageInfo3_->header.height = height; - imageInfo3_->header.colorMode = ARGB8888; - imageInfo3_->dataSize = dataSize; - imageInfo3_->data = srcData3; - - imageAnimatorImageInfo_[0].imageInfo = imageInfo1_; - imageAnimatorImageInfo_[0].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; - imageAnimatorImageInfo_[0].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 100: width value - imageAnimatorImageInfo_[0].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 100: height value - imageAnimatorImageInfo_[0].imageType = IMG_SRC_IMAGE_INFO; - - imageAnimatorImageInfo_[1].imageInfo = imageInfo2_; - imageAnimatorImageInfo_[1].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; - imageAnimatorImageInfo_[1].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 100: width value - imageAnimatorImageInfo_[1].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 100: height value - imageAnimatorImageInfo_[1].imageType = IMG_SRC_IMAGE_INFO; - - imageAnimatorImageInfo_[SET_TWO].imageInfo = imageInfo3_; // 2: image index - imageAnimatorImageInfo_[SET_TWO].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; - imageAnimatorImageInfo_[SET_TWO].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 2: image index, 100: width value - imageAnimatorImageInfo_[SET_TWO].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 2: image index, 100: height value - imageAnimatorImageInfo_[SET_TWO].imageType = IMG_SRC_IMAGE_INFO; // 2: image index } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp index c4784a692..762fab518 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp @@ -6,18 +6,10 @@ #include "ohos_timer.h" #include "wearable_log.h" -#include "findphone/FindPhoneModel.h" #include "findphone/FindPhoneView.h" +#include "findphone/FindPhoneModel.h" namespace OHOS { -static constexpr uint64_t CENTI_SECOND_UNIT = 100; -static constexpr uint64_t MS_ONE_SECONDS = 1000; -static constexpr uint16_t NUM_TEN = 10; -static constexpr uint16_t NUM_TIME_MIN = 60; -static constexpr uint16_t NUM_TIME_HOUR = 3600; -static constexpr int32_t NUM_TIME_DAY = 86400; -static constexpr int16_t MIN_TO_HOUR = 60; -static constexpr int16_t HOURLY_SYSTEM = 24; FindPhoneModel::FindPhoneModel() {} FindPhoneModel::~FindPhoneModel() {} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp index 96f909c52..53b73361c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp @@ -6,10 +6,10 @@ #include "NativeRegisterManager.h" #include "uiservice/ui_service.h" -#include "findphone/FindPhonePresenter.h" #include "findphone/FindPhoneModel.h" #include "findphone/FindPhoneView.h" +#include "findphone/FindPhonePresenter.h" namespace OHOS { -REGIST_MENU(VIEW_FIND_PHONE, FindPhoneView, FindPhonePresenter, FINDPHONE_MAIN_ICON, FINDPHONE_MAIN_ICON, "查找手机"); +REGIST_MENU(VIEW_FIND_PHONE, FindPhoneView, FindPhonePresenter, FINDPHONE_ICON, FINDPHONE_ICON, "查找手机"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp index 521673522..9bb5e9ea2 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp @@ -1,43 +1,43 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightBlinkPage * Create: 2025-04-24 */ -#include "flashlight/FlashLightBlinkPage.h" -#include "flashlight/FlashLightPresenter.h" #include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" #include "AppViewIDs.h" #include "wearable_log.h" #include "NativeAbility.h" -#include "flashlight/FlashLightModel.h" #include "main/LoadImg.h" -#include "flashlight/FlashlightUiResourceImage.h" +#include "ui_resource_flashlight.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightBlinkPage.h" + namespace OHOS { -static const uint16_t BLINK_PICKER_POS_X = 106; -static const uint16_t BLINK_PICKER_POS_Y = 113; -static const uint16_t BLINK_PICKER_WIDTH = 254; -static const uint16_t BLINK_PICKER_HEIGHT = 218; -static const uint16_t BLINK_PICKER_BACKGROUND_FONT_SIZE = 38; -static const uint16_t BLINK_PICKER_HIGHLIGHT_FONT_SIZE = 44; -static const uint16_t BLINK_PICKER_ITEM_HEIGHT = 73; -static const uint16_t BLINK_PICKER_NUM = 3; -static const uint16_t BLINK_BUTTON_POS_X = 59; -static const uint16_t BLINK_BUTTON_POS_Y = 358; -static const uint16_t BLINK_BUTTON_WIDTH = 337; -static const uint16_t BLINK_BUTTON_HEIGHT = 96; -static const uint16_t BLINK_TEXT_POS_X = 100; -static const uint16_t BLINK_TEXT_POS_Y = 38; -static const uint16_t BLINK_TEXT_WIDTH = 253; -static const uint16_t BLINK_TEXT_HEIGHT = 53; -static const uint16_t BLINK_TEXT_FONT_SIZE = 38; -static const std::string START_BLINK_BUTTON_ID = "startBlink"; +static constexpr uint16_t BLINK_PICKER_POS_X = 106; +static constexpr uint16_t BLINK_PICKER_POS_Y = 113; +static constexpr uint16_t BLINK_PICKER_WIDTH = 254; +static constexpr uint16_t BLINK_PICKER_HEIGHT = 218; +static constexpr uint16_t BLINK_PICKER_BACKGROUND_FONT_SIZE = 38; +static constexpr uint16_t BLINK_PICKER_HIGHLIGHT_FONT_SIZE = 44; +static constexpr uint16_t BLINK_PICKER_ITEM_HEIGHT = 73; +static constexpr uint16_t BLINK_PICKER_NUM = 3; +static constexpr uint16_t BLINK_BUTTON_POS_X = 59; +static constexpr uint16_t BLINK_BUTTON_POS_Y = 358; +static constexpr uint16_t BLINK_BUTTON_WIDTH = 337; +static constexpr uint16_t BLINK_BUTTON_HEIGHT = 96; +static constexpr uint16_t BLINK_TEXT_POS_X = 100; +static constexpr uint16_t BLINK_TEXT_POS_Y = 38; +static constexpr uint16_t BLINK_TEXT_WIDTH = 253; +static constexpr uint16_t BLINK_TEXT_HEIGHT = 53; +static constexpr uint16_t BLINK_TEXT_FONT_SIZE = 38; +static constexpr char *START_BLINK_BUTTON_ID = "startBlink"; REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_BLINK_VIEW, FlashLightBlinkPage, false); void FlashLightBlinkPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnStart"); if (container_ == nullptr) { container_ = new UIScrollView(); container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -51,11 +51,10 @@ void FlashLightBlinkPage::OnStart(void *data) blinkLabel_->SetText("闪烁频率"); blinkLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); blinkLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - blinkLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLINK_TEXT_FONT_SIZE); + blinkLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, BLINK_TEXT_FONT_SIZE); container_->Add(blinkLabel_); blinkLabel_->SetVisible(true); - // Add Picker to App if (blinkPicker_ == nullptr) { blinkPicker_ = new UIPicker(); } @@ -73,14 +72,12 @@ void FlashLightBlinkPage::OnStart(void *data) container_->Add(blinkPicker_); blinkPicker_->SetVisible(true); - // Add LabelButtonExt to App if (blinkButton_ == nullptr) { blinkButton_ = new UILabelButtonExt(); } blinkButton_->SetPosition(BLINK_BUTTON_POS_X, BLINK_BUTTON_POS_Y, BLINK_BUTTON_WIDTH, BLINK_BUTTON_HEIGHT); - blinkButton_->SetViewId(START_BLINK_BUTTON_ID.c_str()); - LOADIMG::LoadBtnImage(blinkButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_BLINKBUTTON, - IMAGE_CONVERTER_TOOL_BLINKBUTTON); + blinkButton_->SetViewId(START_BLINK_BUTTON_ID); + LOADIMG::LoadBtnImage(blinkButton_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_BLINKBUTTON, IMAGE_FLASHLIGHT_BLINKBUTTON); blinkButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); blinkButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); container_->Add(blinkButton_); @@ -91,9 +88,13 @@ void FlashLightBlinkPage::OnStart(void *data) AddViewToPageContainer(container_); } +FlashLightBlinkPage::FlashLightBlinkPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::FlashLightBlinkPage"); +} + FlashLightBlinkPage::~FlashLightBlinkPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::~FlashLightBlinkPage"); if (container_ != nullptr) { container_->RemoveAll(); delete container_; @@ -112,30 +113,27 @@ FlashLightBlinkPage::~FlashLightBlinkPage() blinkButton_ = nullptr; } ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::~FlashLightBlinkPage"); } bool FlashLightBlinkPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnDrag"); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_SET_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } bool FlashLightBlinkPage::OnClick(UIView &view, const ClickEvent &event) { - std::string viewId = view.GetViewId(); uint16_t itemIndex = blinkPicker_->GetSelected(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnClick [%s], itemIndex : [%d] ", viewId.c_str(), - itemIndex); - if (viewId == START_BLINK_BUTTON_ID) { + if (strcmp(view.GetViewId(), START_BLINK_BUTTON_ID) == 0) { FlashLightModel::GetInstance().SetBlinkFrequency((FlashLightBlinkFrequency)itemIndex); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnClick [Invalid]"); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp index 20ae1c068..1740e6083 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp @@ -1,76 +1,80 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightColorPage * Create: 2025-04-24 */ -#include "flashlight/FlashLightColorPage.h" -#include "flashlight/FlashLightPresenter.h" #include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" #include "AppViewIDs.h" #include "wearable_log.h" #include "NativeAbility.h" -#include "flashlight/FlashLightModel.h" #include "main/LoadImg.h" -#include "flashlight/FlashlightUiResourceImage.h" +#include "ui_resource_flashlight.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightColorPage.h" + namespace OHOS { -static const uint16_t COLOR_LABEL_POS_X = 100; -static const uint16_t COLOR_LABEL_POS_Y = 38; -static const uint16_t COLOR_LABEL_WIDTH = 253; -static const uint16_t COLOR_LABEL_HEIGHT = 53; -static const uint16_t COLOR_LABEL_FONT_SIZE = 38; -static const uint16_t CONTAINER_BLANK_SIZE = 100; +static constexpr uint16_t COLOR_LABEL_POS_X = 100; +static constexpr uint16_t COLOR_LABEL_POS_Y = 38; +static constexpr uint16_t COLOR_LABEL_WIDTH = 253; +static constexpr uint16_t COLOR_LABEL_HEIGHT = 53; +static constexpr uint16_t COLOR_LABEL_FONT_SIZE = 38; +static constexpr uint16_t CONTAINER_BLANK_SIZE = 100; // 行坐标 -const uint16_t FIRST_ROW_COLOR_BUTTON_POS_Y = 104; -const uint16_t SECOND_ROW_COLOR_BUTTON_POS_Y = 225; -const uint16_t THIRD_ROW_COLOR_BUTTON_POS_Y = 346; +static constexpr uint16_t FIRST_ROW_COLOR_BUTTON_POS_Y = 104; +static constexpr uint16_t SECOND_ROW_COLOR_BUTTON_POS_Y = 225; +static constexpr uint16_t THIRD_ROW_COLOR_BUTTON_POS_Y = 346; // 列坐标 -const uint16_t FIRST_COLUMN_COLOR_BUTTON_POS_X = 46; -const uint16_t SECOND_COLUMN_COLOR_BUTTON_POS_X = 169; -const uint16_t THIRD_COLUMN_COLOR_BUTTON_POS_X = 290; +static constexpr uint16_t FIRST_COLUMN_COLOR_BUTTON_POS_X = 46; +static constexpr uint16_t SECOND_COLUMN_COLOR_BUTTON_POS_X = 169; +static constexpr uint16_t THIRD_COLUMN_COLOR_BUTTON_POS_X = 290; // 按钮大小 -const uint16_t COLOR_BUTTON_WIDTH = 117; -const uint16_t COLOR_BUTTON_HEIGHT = 117; -static const uint32_t SELECT_COLOR_BUTTON_RES[10] = { +static constexpr uint16_t COLOR_BUTTON_WIDTH = 117; +static constexpr uint16_t COLOR_BUTTON_HEIGHT = 117; +// 选中按钮偏移值 +static constexpr uint16_t COLOR_BUTTON_OFFSET = 8; +static constexpr uint32_t g_selectColorButtonRes[] = { 0, - IMAGE_CONVERTER_TOOL_COLOR1PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR2PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR3PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR4PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR5PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR6PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR7PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR8PRESSBUTTON, - IMAGE_CONVERTER_TOOL_COLOR9PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_WHITE_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_RED_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_ORANGE_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_YELLOW_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_GREEN_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_LIGHT_BLUE_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_DARK_BLUE_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_PURPLE_PRESSBUTTON, + IMAGE_FLASHLIGHT_COLOR_MULTI_PRESSBUTTON, }; -static const std::string COLOR1_BUTTON_ID = "color1Button"; -static const std::string COLOR2_BUTTON_ID = "color2Button"; -static const std::string COLOR3_BUTTON_ID = "color3Button"; -static const std::string COLOR4_BUTTON_ID = "color4Button"; -static const std::string COLOR5_BUTTON_ID = "color5Button"; -static const std::string COLOR6_BUTTON_ID = "color6Button"; -static const std::string COLOR7_BUTTON_ID = "color7Button"; -static const std::string COLOR8_BUTTON_ID = "color8Button"; -static const std::string COLOR9_BUTTON_ID = "color9Button"; +static constexpr char *COLOR_WHITE_BUTTON_ID = "colorWhiteButton"; +static constexpr char *COLOR_RED_BUTTON_ID = "colorRedButton"; +static constexpr char *COLOR_ORANGE_BUTTON_ID = "colorOrangeButton"; +static constexpr char *COLOR_YELLOW_BUTTON_ID = "colorYellowButton"; +static constexpr char *COLOR_GREEN_BUTTON_ID = "colorGreenButton"; +static constexpr char *COLOR_LIGHT_BLUE_BUTTON_ID = "colorLightBlueButton"; +static constexpr char *COLOR_DARK_BLUE_BUTTON_ID = "colorDarkBlueButton"; +static constexpr char *COLOR_PURPLE_BUTTON_ID = "colorPurpleButton"; +static constexpr char *COLOR_MULTI_BUTTON_ID = "colorMultiButton"; + REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_COLOR_VIEW, FlashLightColorPage, false); void FlashLightColorPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnStart"); - uint32_t COLOR_BUTTON_RES[10] = { + uint32_t colorButtonRes[] = { 0, - IMAGE_CONVERTER_TOOL_COLOR1BUTTON, - IMAGE_CONVERTER_TOOL_COLOR2BUTTON, - IMAGE_CONVERTER_TOOL_COLOR3BUTTON, - IMAGE_CONVERTER_TOOL_COLOR4BUTTON, - IMAGE_CONVERTER_TOOL_COLOR5BUTTON, - IMAGE_CONVERTER_TOOL_COLOR6BUTTON, - IMAGE_CONVERTER_TOOL_COLOR7BUTTON, - IMAGE_CONVERTER_TOOL_COLOR8BUTTON, - IMAGE_CONVERTER_TOOL_COLOR9BUTTON, + IMAGE_FLASHLIGHT_COLOR_WHITE_BUTTON, + IMAGE_FLASHLIGHT_COLOR_RED_BUTTON, + IMAGE_FLASHLIGHT_COLOR_ORANGE_BUTTON, + IMAGE_FLASHLIGHT_COLOR_YELLOW_BUTTON, + IMAGE_FLASHLIGHT_COLOR_GREEN_BUTTON, + IMAGE_FLASHLIGHT_COLOR_LIGHT_BLUE_BUTTON, + IMAGE_FLASHLIGHT_COLOR_DARK_BLUE_BUTTON, + IMAGE_FLASHLIGHT_COLOR_PURPLE_BUTTON, + IMAGE_FLASHLIGHT_COLOR_MULTI_BUTTON, }; - uint16_t selectColor = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); - COLOR_BUTTON_RES[selectColor] = SELECT_COLOR_BUTTON_RES[selectColor]; + + uint16_t selectColor = (uint16_t)FlashLightModel::GetInstance().GetViewColorId(); + colorButtonRes[selectColor] = g_selectColorButtonRes[selectColor]; if (container_ == nullptr) { container_ = new UIScrollView(); container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -86,153 +90,215 @@ void FlashLightColorPage::OnStart(void *data) colorLabel_->SetText("灯光颜色"); colorLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); colorLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - colorLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, COLOR_LABEL_FONT_SIZE); + colorLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, COLOR_LABEL_FONT_SIZE); container_->Add(colorLabel_); colorLabel_->SetVisible(true); // 第一行颜色按钮 - if (color1Button_ == nullptr) { - color1Button_ = new UILabelButtonExt(); - } - color1Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color1Button_->SetViewId(COLOR1_BUTTON_ID.c_str()); - color1Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color1Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color1Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color1Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[WHITE_COLOR], COLOR_BUTTON_RES[WHITE_COLOR]); - container_->Add(color1Button_); - color1Button_->SetVisible(true); + if (colorWhiteButton_ == nullptr) { + colorWhiteButton_ = new UILabelButtonExt(); + } + if (selectColor == WHITE_COLOR) { + colorWhiteButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + FIRST_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorWhiteButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorWhiteButton_->SetViewId(COLOR_WHITE_BUTTON_ID); + colorWhiteButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorWhiteButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorWhiteButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorWhiteButton_, FLASHLIGHT_IMAGE, colorButtonRes[WHITE_COLOR], + colorButtonRes[WHITE_COLOR]); + container_->Add(colorWhiteButton_); + colorWhiteButton_->SetVisible(true); - if (color2Button_ == nullptr) { - color2Button_ = new UILabelButtonExt(); - } - color2Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color2Button_->SetViewId(COLOR2_BUTTON_ID.c_str()); - color2Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color2Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color2Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color2Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[RED_COLOR], COLOR_BUTTON_RES[RED_COLOR]); - container_->Add(color2Button_); - color2Button_->SetVisible(true); + if (colorRedButton_ == nullptr) { + colorRedButton_ = new UILabelButtonExt(); + } + if (selectColor == RED_COLOR) { + colorRedButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + FIRST_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorRedButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } + colorRedButton_->SetViewId(COLOR_RED_BUTTON_ID); + colorRedButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorRedButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorRedButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorRedButton_, FLASHLIGHT_IMAGE, colorButtonRes[RED_COLOR], colorButtonRes[RED_COLOR]); + container_->Add(colorRedButton_); + colorRedButton_->SetVisible(true); - if (color3Button_ == nullptr) { - color3Button_ = new UILabelButtonExt(); - } - color3Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color3Button_->SetViewId(COLOR3_BUTTON_ID.c_str()); - color3Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color3Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color3Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color3Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[ORANGE_COLOR], - COLOR_BUTTON_RES[ORANGE_COLOR]); - container_->Add(color3Button_); - color3Button_->SetVisible(true); + if (colorOrangeButton_ == nullptr) { + colorOrangeButton_ = new UILabelButtonExt(); + } + if (selectColor == ORANGE_COLOR) { + colorOrangeButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + FIRST_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorOrangeButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorOrangeButton_->SetViewId(COLOR_ORANGE_BUTTON_ID); + colorOrangeButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorOrangeButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorOrangeButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorOrangeButton_, FLASHLIGHT_IMAGE, colorButtonRes[ORANGE_COLOR], + colorButtonRes[ORANGE_COLOR]); + container_->Add(colorOrangeButton_); + colorOrangeButton_->SetVisible(true); // 第二行颜色按钮 - if (color4Button_ == nullptr) { - color4Button_ = new UILabelButtonExt(); - } - color4Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color4Button_->SetViewId(COLOR4_BUTTON_ID.c_str()); - color4Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color4Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color4Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color4Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[YELLOW_COLOR], - COLOR_BUTTON_RES[YELLOW_COLOR]); - container_->Add(color4Button_); - color4Button_->SetVisible(true); + if (colorYellowButton_ == nullptr) { + colorYellowButton_ = new UILabelButtonExt(); + } + if (selectColor == YELLOW_COLOR) { + colorYellowButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + SECOND_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorYellowButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorYellowButton_->SetViewId(COLOR_YELLOW_BUTTON_ID); + colorYellowButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorYellowButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorYellowButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorYellowButton_, FLASHLIGHT_IMAGE, colorButtonRes[YELLOW_COLOR], + colorButtonRes[YELLOW_COLOR]); + container_->Add(colorYellowButton_); + colorYellowButton_->SetVisible(true); - if (color5Button_ == nullptr) { - color5Button_ = new UILabelButtonExt(); - } - color5Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color5Button_->SetViewId(COLOR5_BUTTON_ID.c_str()); - color5Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color5Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color5Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color5Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[GREEN_COLOR], COLOR_BUTTON_RES[GREEN_COLOR]); - container_->Add(color5Button_); - color5Button_->SetVisible(true); + if (colorGreenButton_ == nullptr) { + colorGreenButton_ = new UILabelButtonExt(); + } + if (selectColor == GREEN_COLOR) { + colorGreenButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + SECOND_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorGreenButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } - if (color6Button_ == nullptr) { - color6Button_ = new UILabelButtonExt(); - } - color6Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color6Button_->SetViewId(COLOR6_BUTTON_ID.c_str()); - color6Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color6Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color6Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color6Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[LIGHT_BLUE_COLOR], - COLOR_BUTTON_RES[LIGHT_BLUE_COLOR]); + colorGreenButton_->SetViewId(COLOR_GREEN_BUTTON_ID); + colorGreenButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorGreenButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorGreenButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorGreenButton_, FLASHLIGHT_IMAGE, colorButtonRes[GREEN_COLOR], + colorButtonRes[GREEN_COLOR]); + container_->Add(colorGreenButton_); + colorGreenButton_->SetVisible(true); - container_->Add(color6Button_); - color6Button_->SetVisible(true); + if (colorLightBlueButton_ == nullptr) { + colorLightBlueButton_ = new UILabelButtonExt(); + } + if (selectColor == LIGHT_BLUE_COLOR) { + colorLightBlueButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + SECOND_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorLightBlueButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorLightBlueButton_->SetViewId(COLOR_LIGHT_BLUE_BUTTON_ID); + colorLightBlueButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorLightBlueButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorLightBlueButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorLightBlueButton_, FLASHLIGHT_IMAGE, colorButtonRes[LIGHT_BLUE_COLOR], + colorButtonRes[LIGHT_BLUE_COLOR]); + + container_->Add(colorLightBlueButton_); + colorLightBlueButton_->SetVisible(true); // 第三行颜色按钮 - if (color7Button_ == nullptr) { - color7Button_ = new UILabelButtonExt(); - } - color7Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color7Button_->SetViewId(COLOR7_BUTTON_ID.c_str()); - color7Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color7Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color7Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color7Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[DARK_BLUE_COLOR], - COLOR_BUTTON_RES[DARK_BLUE_COLOR]); - container_->Add(color7Button_); - color7Button_->SetVisible(true); + if (colorDarkBlueButton_ == nullptr) { + colorDarkBlueButton_ = new UILabelButtonExt(); + } + if (selectColor == DARK_BLUE_COLOR) { + colorDarkBlueButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + THIRD_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorDarkBlueButton_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorDarkBlueButton_->SetViewId(COLOR_DARK_BLUE_BUTTON_ID); + colorDarkBlueButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorDarkBlueButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorDarkBlueButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorDarkBlueButton_, FLASHLIGHT_IMAGE, colorButtonRes[DARK_BLUE_COLOR], + colorButtonRes[DARK_BLUE_COLOR]); + container_->Add(colorDarkBlueButton_); + colorDarkBlueButton_->SetVisible(true); - if (color8Button_ == nullptr) { - color8Button_ = new UILabelButtonExt(); - } - color8Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color8Button_->SetViewId(COLOR8_BUTTON_ID.c_str()); - color8Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color8Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color8Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color8Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[PURPLE_COLOR], - COLOR_BUTTON_RES[PURPLE_COLOR]); - container_->Add(color8Button_); - color8Button_->SetVisible(true); + if (colorPurpleButton_ == nullptr) { + colorPurpleButton_ = new UILabelButtonExt(); + } + if (selectColor == PURPLE_COLOR) { + colorPurpleButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + THIRD_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorPurpleButton_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorPurpleButton_->SetViewId(COLOR_PURPLE_BUTTON_ID); + colorPurpleButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorPurpleButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorPurpleButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorPurpleButton_, FLASHLIGHT_IMAGE, colorButtonRes[PURPLE_COLOR], + colorButtonRes[PURPLE_COLOR]); + container_->Add(colorPurpleButton_); + colorPurpleButton_->SetVisible(true); - if (color9Button_ == nullptr) { - color9Button_ = new UILabelButtonExt(); - } - color9Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - color9Button_->SetViewId(COLOR9_BUTTON_ID.c_str()); - color9Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - color9Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - color9Button_->SetAlign(TEXT_ALIGNMENT_CENTER); - LOADIMG::LoadBtnImage(color9Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[MULTI_COLOR], COLOR_BUTTON_RES[MULTI_COLOR]); - container_->Add(color9Button_); - color9Button_->SetVisible(true); + if (colorMultiButton_ == nullptr) { + colorMultiButton_ = new UILabelButtonExt(); + } + if (selectColor == MULTI_COLOR) { + colorMultiButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X - COLOR_BUTTON_OFFSET, + THIRD_ROW_COLOR_BUTTON_POS_Y - COLOR_BUTTON_OFFSET, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + } else { + colorMultiButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, + COLOR_BUTTON_WIDTH, COLOR_BUTTON_HEIGHT); + } + colorMultiButton_->SetViewId(COLOR_MULTI_BUTTON_ID); + colorMultiButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + colorMultiButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + colorMultiButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(colorMultiButton_, FLASHLIGHT_IMAGE, colorButtonRes[MULTI_COLOR], + colorButtonRes[MULTI_COLOR]); + container_->Add(colorMultiButton_); + colorMultiButton_->SetVisible(true); // 设置界面组件回调函数 container_->SetOnDragListener(this); // 设置手电筒多个颜色按钮回调函数 - color3Button_->SetOnClickListener(this); - color1Button_->SetOnClickListener(this); - color2Button_->SetOnClickListener(this); - color6Button_->SetOnClickListener(this); - color5Button_->SetOnClickListener(this); - color4Button_->SetOnClickListener(this); - color9Button_->SetOnClickListener(this); - color8Button_->SetOnClickListener(this); - color7Button_->SetOnClickListener(this); + colorOrangeButton_->SetOnClickListener(this); + colorWhiteButton_->SetOnClickListener(this); + colorRedButton_->SetOnClickListener(this); + colorLightBlueButton_->SetOnClickListener(this); + colorGreenButton_->SetOnClickListener(this); + colorYellowButton_->SetOnClickListener(this); + colorMultiButton_->SetOnClickListener(this); + colorPurpleButton_->SetOnClickListener(this); + colorDarkBlueButton_->SetOnClickListener(this); AddViewToPageContainer(container_); } +FlashLightColorPage::FlashLightColorPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::FlashLightColorPage"); +} + FlashLightColorPage::~FlashLightColorPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::~FlashLightColorPage"); if (container_ != nullptr) { container_->RemoveAll(); delete container_; @@ -242,89 +308,95 @@ FlashLightColorPage::~FlashLightColorPage() delete colorLabel_; colorLabel_ = nullptr; } - if (color1Button_ != nullptr) { - delete color1Button_; - color1Button_ = nullptr; + if (colorWhiteButton_ != nullptr) { + delete colorWhiteButton_; + colorWhiteButton_ = nullptr; } - if (color2Button_ != nullptr) { - delete color2Button_; - color2Button_ = nullptr; + if (colorRedButton_ != nullptr) { + delete colorRedButton_; + colorRedButton_ = nullptr; } - if (color3Button_ != nullptr) { - delete color3Button_; - color3Button_ = nullptr; + if (colorOrangeButton_ != nullptr) { + delete colorOrangeButton_; + colorOrangeButton_ = nullptr; } - if (color4Button_ != nullptr) { - delete color4Button_; - color4Button_ = nullptr; + if (colorYellowButton_ != nullptr) { + delete colorYellowButton_; + colorYellowButton_ = nullptr; } - if (color5Button_ != nullptr) { - delete color5Button_; - color5Button_ = nullptr; + if (colorGreenButton_ != nullptr) { + delete colorGreenButton_; + colorGreenButton_ = nullptr; } - if (color6Button_ != nullptr) { - delete color6Button_; - color6Button_ = nullptr; + if (colorLightBlueButton_ != nullptr) { + delete colorLightBlueButton_; + colorLightBlueButton_ = nullptr; } - if (color7Button_ != nullptr) { - delete color7Button_; - color7Button_ = nullptr; + if (colorDarkBlueButton_ != nullptr) { + delete colorDarkBlueButton_; + colorDarkBlueButton_ = nullptr; } - if (color8Button_ != nullptr) { - delete color8Button_; - color8Button_ = nullptr; + if (colorPurpleButton_ != nullptr) { + delete colorPurpleButton_; + colorPurpleButton_ = nullptr; } - if (color9Button_ != nullptr) { - delete color9Button_; - color9Button_ = nullptr; + if (colorMultiButton_ != nullptr) { + delete colorMultiButton_; + colorMultiButton_ = nullptr; } ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::~FlashLightColorPage"); } bool FlashLightColorPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_SET_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } bool FlashLightColorPage::OnClick(UIView &view, const ClickEvent &event) { - std::string viewId = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnClick [%s]", viewId.c_str()); - if (viewId == COLOR1_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::WHITE_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR2_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::RED_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR3_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::ORANGE_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR4_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::YELLOW_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR5_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::GREEN_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR6_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::LIGHT_BLUE_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR7_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::DARK_BLUE_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR8_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::PURPLE_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else if (viewId == COLOR9_BUTTON_ID) { - FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::MULTI_COLOR); - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnClick [Invalid]"); + if (strcmp(view.GetViewId(), COLOR_WHITE_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::WHITE_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_RED_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::RED_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_ORANGE_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::ORANGE_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_YELLOW_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::YELLOW_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_GREEN_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::GREEN_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_LIGHT_BLUE_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::LIGHT_BLUE_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_DARK_BLUE_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::DARK_BLUE_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_PURPLE_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::PURPLE_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), COLOR_MULTI_BUTTON_ID) == 0) { + FlashLightModel::GetInstance().SetViewColorId(FlashLightColorAttribute::MULTI_COLOR); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp index 273a4641a..269ddfe97 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightModel * Create: 2025-04-24 */ -#include "flashlight/FlashLightModel.h" + #ifdef BUILD_IN_LINUX #include "localtime.h" #endif +#include "flashlight/FlashLightModel.h" namespace OHOS { -static const uint32_t TIME_DISPLAY_NUM = 10; +static constexpr uint32_t TIME_DISPLAY_NUM = 10; FlashLightModel::FlashLightModel(FlashLightColorAttribute color, FlashLightBlinkFrequency blinkFrequency) { color_ = color; @@ -24,12 +25,12 @@ FlashLightModel &FlashLightModel::GetInstance() return instance; } -FlashLightColorAttribute FlashLightModel::GetViewColor() +FlashLightColorAttribute FlashLightModel::GetViewColorId() { return color_; } -void FlashLightModel::SetViewColor(FlashLightColorAttribute color) +void FlashLightModel::SetViewColorId(FlashLightColorAttribute color) { color_ = color; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp index ba91d99ce..33792e280 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp @@ -1,71 +1,72 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightPage * Create: 2025-04-24 */ + #include -#include "flashlight/FlashLightPage.h" -#include "flashlight/FlashLightPresenter.h" -#include "flashlight/FlashLightModel.h" #include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" #include "AppViewIDs.h" #include "wearable_log.h" #include "main/LoadImg.h" -#include "flashlight/FlashlightUiResourceImage.h" +#include "ui_resource_flashlight.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightPage.h" namespace OHOS { -static const uint16_t SWITCH_BUTTON_POS_X = 168; -static const uint16_t SWITCH_BUTTON_POS_Y = 168; -static const uint16_t SWITCH_BUTTON_WIDTH = 119; -static const uint16_t SWITCH_BUTTON_HEIGHT = 119; -static const uint16_t SWITCH_LABEL_POS_X = 168; -static const uint16_t SWITCH_LABEL_POS_Y = 308; -static const uint16_t SWITCH_LABEL_WIDTH = 128; -static const uint16_t SWITCH_LABEL_HEIGHT = 46; -static const uint16_t SWITCH_LABEL_FONT_SIZE = 32; -static const uint16_t TIME_LABEL_FONT_SIZE = 38; -static const uint16_t IMAGE_VIEW_POS_X = 213; -static const uint16_t IMAGE_VIEW_POS_Y = 414; -static const uint16_t TIME_TEXT_POS_X = 151; -static const uint16_t TIME_TEXT_POS_Y = 31; -static const uint16_t TIME_TEXT_WIDTH = 153; -static const uint16_t TIME_TEXT_HEIGHT = 53; -static const uint16_t Y_OFFSET = 300; -static const std::string SWITCH_BUTTON_ID = "switch"; +static constexpr uint16_t SWITCH_BUTTON_POS_X = 168; +static constexpr uint16_t SWITCH_BUTTON_POS_Y = 168; +static constexpr uint16_t SWITCH_BUTTON_WIDTH = 119; +static constexpr uint16_t SWITCH_BUTTON_HEIGHT = 119; +static constexpr uint16_t SWITCH_LABEL_POS_X = 168; +static constexpr uint16_t SWITCH_LABEL_POS_Y = 308; +static constexpr uint16_t SWITCH_LABEL_WIDTH = 128; +static constexpr uint16_t SWITCH_LABEL_HEIGHT = 46; +static constexpr uint16_t SWITCH_LABEL_FONT_SIZE = 32; +static constexpr uint16_t TIME_LABEL_FONT_SIZE = 38; +static constexpr uint16_t IMAGE_VIEW_POS_X = 213; +static constexpr uint16_t IMAGE_VIEW_POS_Y = 414; +static constexpr uint16_t TIME_TEXT_POS_X = 151; +static constexpr uint16_t TIME_TEXT_POS_Y = 31; +static constexpr uint16_t TIME_TEXT_WIDTH = 153; +static constexpr uint16_t TIME_TEXT_HEIGHT = 53; +static constexpr uint16_t Y_OFFSET = 300; +static constexpr char *SWITCH_BUTTON_ID = "switch"; -REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW, FlashLightPage, true); +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_VIEW, FlashLightPage, true); void FlashLightPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnStart"); if (container_ == nullptr) { container_ = new UIScrollView(); container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); } - if (OnLabel_ == nullptr) { - OnLabel_ = new UILabel(); - } - OnLabel_->SetPosition(SWITCH_LABEL_POS_X, SWITCH_LABEL_POS_Y, SWITCH_LABEL_WIDTH, SWITCH_LABEL_HEIGHT); - OnLabel_->SetText("点击照明"); - OnLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - OnLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SWITCH_LABEL_FONT_SIZE); - OnLabel_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - OnLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - OnLabel_->SetVisible(true); - container_->Add(OnLabel_); + if (tipsLabel_ == nullptr) { + tipsLabel_ = new UILabel(); + } + tipsLabel_->SetPosition(SWITCH_LABEL_POS_X, SWITCH_LABEL_POS_Y, SWITCH_LABEL_WIDTH, SWITCH_LABEL_HEIGHT); + tipsLabel_->SetText("点击照明"); + tipsLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + tipsLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SWITCH_LABEL_FONT_SIZE); + tipsLabel_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + tipsLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + tipsLabel_->SetVisible(true); + container_->Add(tipsLabel_); - if (flashLightOn_ == nullptr) { - flashLightOn_ = new UILabelButton(); - } - flashLightOn_->SetPosition(SWITCH_BUTTON_POS_X, SWITCH_BUTTON_POS_Y, SWITCH_BUTTON_WIDTH, SWITCH_BUTTON_HEIGHT); - flashLightOn_->SetViewId(SWITCH_BUTTON_ID.c_str()); - flashLightOn_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - flashLightOn_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); - LOADIMG::LoadBtnImage(flashLightOn_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_FLASHLIGHTON, - IMAGE_CONVERTER_TOOL_FLASHLIGHTON); - flashLightOn_->SetVisible(true); - container_->Add(flashLightOn_); + if (flashLightButtonOn_ == nullptr) { + flashLightButtonOn_ = new UILabelButton(); + } + flashLightButtonOn_->SetPosition(SWITCH_BUTTON_POS_X, SWITCH_BUTTON_POS_Y, + SWITCH_BUTTON_WIDTH, SWITCH_BUTTON_HEIGHT); + flashLightButtonOn_->SetViewId(SWITCH_BUTTON_ID); + flashLightButtonOn_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + flashLightButtonOn_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + LOADIMG::LoadBtnImage(flashLightButtonOn_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_FLASHLIGHTON, + IMAGE_FLASHLIGHT_FLASHLIGHTON); + flashLightButtonOn_->SetVisible(true); + container_->Add(flashLightButtonOn_); // 创建时间显示组件 if (systemTime_ == nullptr) { @@ -87,77 +88,79 @@ void FlashLightPage::OnStart(void *data) } timeAnimator_->Start(); - // Add ImageView to App if (imageArrow_ == nullptr) { imageArrow_ = new UIImageView(); } imageArrow_->SetPosition(IMAGE_VIEW_POS_X, IMAGE_VIEW_POS_Y); container_->Add(imageArrow_); imageArrow_->SetVisible(true); - LOADIMG::LoadImageViewImg(imageArrow_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_DOWNARROW); + LOADIMG::LoadImageViewImg(imageArrow_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_DOWNARROW); - flashLightOn_->SetOnClickListener(this); + flashLightButtonOn_->SetOnClickListener(this); container_->SetOnDragListener(this); AddViewToPageContainer(container_); } +FlashLightPage::FlashLightPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::FlashLightPage"); +} + FlashLightPage::~FlashLightPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::~FlashLightPage"); - if (timeAnimator_ != nullptr) { - timeAnimator_->Stop(); - } if (container_ != nullptr) { container_->RemoveAll(); delete container_; container_ = nullptr; } - if (flashLightOn_ != nullptr) { - delete flashLightOn_; - flashLightOn_ = nullptr; + if (flashLightButtonOn_ != nullptr) { + delete flashLightButtonOn_; + flashLightButtonOn_ = nullptr; } if (systemTime_ != nullptr) { delete systemTime_; systemTime_ = nullptr; } + if (tipsLabel_ != nullptr) { + delete tipsLabel_; + tipsLabel_ = nullptr; + } if (imageArrow_ != nullptr) { delete imageArrow_; imageArrow_ = nullptr; } - if (timeAnimator_ != nullptr) { - delete timeAnimator_; - timeAnimator_ = nullptr; - } if (timeCallback_ != nullptr) { delete timeCallback_; timeCallback_ = nullptr; } + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::~FlashLightPage"); } bool FlashLightPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } else if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > Y_OFFSET)) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_SET_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } bool FlashLightPage::OnClick(UIView &view, const ClickEvent &event) { - std::string viewId = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnClick [%s]", viewId.c_str()); - if (viewId == SWITCH_BUTTON_ID) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnClick [Invalid]"); - } - return false; + if (strcmp(view.GetViewId(), SWITCH_BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; } void FlashLightPage::TimeAnimatorCallback::Callback(UIView *view) diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp index fdf35dccc..86502858b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp @@ -1,104 +1,104 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightPlayPage * Create: 2025-04-24 */ -#include "flashlight/FlashLightPlayPage.h" -#include "flashlight/FlashLightPresenter.h" #include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" #include "wearable_log.h" #include "AppViewIDs.h" #include "NativeAbility.h" #include "main/LoadImg.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightPlayPage.h" namespace OHOS { -static const uint32_t FLASHLIGHT_PAGE_RES[10] = { - IMAGE_CONVERTER_TOOL_PLAYBLACKPAGE, IMAGE_CONVERTER_TOOL_PLAY1PAGE, IMAGE_CONVERTER_TOOL_PLAY2PAGE, - IMAGE_CONVERTER_TOOL_PLAY3PAGE, IMAGE_CONVERTER_TOOL_PLAY4PAGE, IMAGE_CONVERTER_TOOL_PLAY5PAGE, - IMAGE_CONVERTER_TOOL_PLAY6PAGE, IMAGE_CONVERTER_TOOL_PLAY7PAGE, IMAGE_CONVERTER_TOOL_PLAY8PAGE, - IMAGE_CONVERTER_TOOL_PLAY9PAGE, +static constexpr uint32_t g_flashLightPageRes[] = { + IMAGE_FLASHLIGHT_PLAY_BLACK_PAGE, IMAGE_FLASHLIGHT_PLAY_WHITE_PAGE, IMAGE_FLASHLIGHT_PLAY_RED_PAGE, + IMAGE_FLASHLIGHT_PLAY_ORANGE_PAGE, IMAGE_FLASHLIGHT_PLAY_YELLOW_PAGE, IMAGE_FLASHLIGHT_PLAY_GREEN_PAGE, + IMAGE_FLASHLIGHT_PLAY_LIGHT_BLUE_PAGE, IMAGE_FLASHLIGHT_PLAY_DARK_BLUE_PAGE, IMAGE_FLASHLIGHT_PLAY_PURPLE_PAGE, + IMAGE_FLASHLIGHT_PLAY_MULTI_PAGE, }; -static const uint32_t FLASHLIGHT_BLINK_FREQ[3] = {500, 100, 0}; -static const uint32_t IMAGE_NUM = 2; -static const std::string PLAY_VIEW_ID = "flashLightPlayPage"; +static constexpr uint32_t g_flashLightBlinkFreq[] = {500, 100, 0}; +static constexpr char *PLAY_VIEW_ID = "flashLightPlayPage"; REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, FlashLightPlayPage, false); void FlashLightPlayPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::OnStart"); if (container_ == nullptr) { container_ = new UIScrollView(); container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - container_->SetViewId(PLAY_VIEW_ID.c_str()); + container_->SetViewId(PLAY_VIEW_ID); } - uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); + uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColorId(); uint16_t blinkIndex = (uint16_t)FlashLightModel::GetInstance().GetBlinkFrequency(); - if (playImageAnimal == nullptr) { - playImageAnimal = new UIImageAnimatorView(); + if (playImageAnimal_ == nullptr) { + playImageAnimal_ = new UIImageAnimatorView(); } - playImageInfo[0].imageInfo = - ImageCacheManager::GetInstance().LoadOneInMultiRes(FLASHLIGHT_PAGE_RES[colorIndex], FLASHLIGHT_IMAGE); - playImageInfo[0].imageType = IMG_SRC_IMAGE_INFO; - playImageInfo[0].pos.x = 0; - playImageInfo[0].pos.y = 0; - playImageInfo[0].width = HORIZONTAL_RESOLUTION; - playImageInfo[0].height = VERTICAL_RESOLUTION; - playImageInfo[1].imageInfo = - ImageCacheManager::GetInstance().LoadOneInMultiRes(FLASHLIGHT_PAGE_RES[0], FLASHLIGHT_IMAGE); - playImageInfo[1].imageType = IMG_SRC_IMAGE_INFO; - playImageInfo[1].pos.x = 0; - playImageInfo[1].pos.y = 0; - playImageInfo[1].width = HORIZONTAL_RESOLUTION; - playImageInfo[1].height = VERTICAL_RESOLUTION; - playImageAnimal->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - playImageAnimal->SetImageAnimatorSrc(playImageInfo, IMAGE_NUM, FLASHLIGHT_BLINK_FREQ[blinkIndex]); - playImageAnimal->SetRepeat(true); - playImageAnimal->SetAutoEnable(false); - playImageAnimal->SetResizeMode(UIImageView::FILL); - container_->Add(playImageAnimal); + playImageInfo_[0].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_flashLightPageRes[colorIndex], FLASHLIGHT_IMAGE); + playImageInfo_[0].imageType = IMG_SRC_IMAGE_INFO; + playImageInfo_[0].pos.x = 0; + playImageInfo_[0].pos.y = 0; + playImageInfo_[0].width = HORIZONTAL_RESOLUTION; + playImageInfo_[0].height = VERTICAL_RESOLUTION; + playImageInfo_[1].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_flashLightPageRes[0], FLASHLIGHT_IMAGE); + playImageInfo_[1].imageType = IMG_SRC_IMAGE_INFO; + playImageInfo_[1].pos.x = 0; + playImageInfo_[1].pos.y = 0; + playImageInfo_[1].width = HORIZONTAL_RESOLUTION; + playImageInfo_[1].height = VERTICAL_RESOLUTION; + playImageAnimal_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + playImageAnimal_->SetImageAnimatorSrc(playImageInfo_, IMAGE_NUM, g_flashLightBlinkFreq[blinkIndex]); + playImageAnimal_->SetRepeat(true); + playImageAnimal_->SetAutoEnable(false); + playImageAnimal_->SetResizeMode(UIImageView::FILL); + container_->Add(playImageAnimal_); - playImageAnimal->Start(); + playImageAnimal_->Start(); container_->SetOnDragListener(this); container_->SetOnClickListener(this); AddViewToPageContainer(container_); } +FlashLightPlayPage::FlashLightPlayPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::FlashLightPlayPage"); +} + FlashLightPlayPage::~FlashLightPlayPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::~FlashLightPlayPage"); if (container_ != nullptr) { container_->RemoveAll(); delete container_; container_ = nullptr; } - if (playImageAnimal != nullptr) { - playImageAnimal->Stop(); - delete playImageAnimal; - playImageAnimal = nullptr; + if (playImageAnimal_ != nullptr) { + playImageAnimal_->Stop(); + delete playImageAnimal_; + playImageAnimal_ = nullptr; } ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::~FlashLightPlayPage"); } bool FlashLightPlayPage::OnDrag(UIView &view, const DragEvent &event) { - std::string id = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag [%s]", id.c_str()); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } - return false; + return true; } bool FlashLightPlayPage::OnClick(UIView &view, const ClickEvent &event) { - std::string viewId = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::OnClick [%s]", viewId.c_str()); - if (viewId == PLAY_VIEW_ID) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW); + if (strcmp(view.GetViewId(), PLAY_VIEW_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp index 57bb513b2..df1b8ba0f 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightPresenter * Create: 2025-04-24 */ @@ -9,6 +9,5 @@ #include "NativeRegisterManager.h" namespace OHOS { -REGIST_MENU(VIEW_FLASHLIGHT, FlashLightView, FlashLightPresenter, FLASHLIGHT_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, - "手电筒"); +REGIST_MENU(VIEW_FLASHLIGHT, FlashLightView, FlashLightPresenter, FLASHLIGHT_ICON, FLASHLIGHT_ICON, "手电筒"); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightRecoverPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightRecoverPage.cpp new file mode 100644 index 000000000..7813e4302 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightRecoverPage.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightRecoverPage + * Create: 2025-04-24 + */ + +#include "SlicePageFactory.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "main/LoadImg.h" +#include "ui_resource_flashlight.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightRecoverPage.h" + +namespace OHOS { +static constexpr uint16_t RECOVER_LABEL_POS_X = 15; +static constexpr uint16_t RECOVER_LABEL_POS_Y = 185; +static constexpr uint16_t RECOVER_LABEL_WIDTH = 424; +static constexpr uint16_t RECOVER_LABEL_HEIGHT = 50; +static constexpr uint16_t RECOVER_LABEL_FONT_SIZE = 36; +static constexpr uint16_t CANCLE_BUTTON_POS_X = 115; +static constexpr uint16_t CANCLE_BUTTON_POS_Y = 300; +static constexpr uint16_t CONFIRM_BUTTON_POS_X = 255; +static constexpr uint16_t CONFIRM_BUTTON_POS_Y = 300; +static constexpr uint16_t CANCLE_BUTTON_WIDTH = 85; +static constexpr uint16_t CANCLE_BUTTON_HEIGHT = 85; +static constexpr char *CANCLE_BUTTON_ID = "cancle"; +static constexpr char *CONFIRM_BUTTON_ID = "confirm"; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_RECOVER_VIEW, FlashLightRecoverPage, false); +void FlashLightRecoverPage::OnStart(void *data) +{ + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + if (recoverLabel_ == nullptr) { + recoverLabel_ = new UILabel(); + } + recoverLabel_->SetPosition(RECOVER_LABEL_POS_X, RECOVER_LABEL_POS_Y, RECOVER_LABEL_WIDTH, RECOVER_LABEL_HEIGHT); + recoverLabel_->SetText("是否恢复默认设置"); + recoverLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + recoverLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + recoverLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, RECOVER_LABEL_FONT_SIZE); + // Add to rootView + container_->Add(recoverLabel_); + recoverLabel_->SetVisible(true); + + if (cancelButton_ == nullptr) { + cancelButton_ = new UILabelButtonExt(); + } + cancelButton_->SetPosition(CANCLE_BUTTON_POS_X, CANCLE_BUTTON_POS_Y, CANCLE_BUTTON_WIDTH, CANCLE_BUTTON_HEIGHT); + cancelButton_->SetViewId(CANCLE_BUTTON_ID); + LOADIMG::LoadBtnImage(cancelButton_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_RECOVERCANCLE, + IMAGE_FLASHLIGHT_RECOVERCANCLE); + cancelButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + cancelButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(cancelButton_); + cancelButton_->SetVisible(true); + + if (confirmButton_ == nullptr) { + confirmButton_ = new UILabelButtonExt(); + } + confirmButton_->SetPosition(CONFIRM_BUTTON_POS_X, CONFIRM_BUTTON_POS_Y, CANCLE_BUTTON_WIDTH, CANCLE_BUTTON_HEIGHT); + confirmButton_->SetViewId(CONFIRM_BUTTON_ID); + LOADIMG::LoadBtnImage(confirmButton_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_RECOVERCONFIRM, + IMAGE_FLASHLIGHT_RECOVERCONFIRM); + confirmButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(confirmButton_); + confirmButton_->SetVisible(true); + + // 设置界面组件回调函数 + container_->SetOnDragListener(this); + cancelButton_->SetOnClickListener(this); + confirmButton_->SetOnClickListener(this); + AddViewToPageContainer(container_); +} + +FlashLightRecoverPage::FlashLightRecoverPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightRecoverPage::FlashLightRecoverPage"); +} + +FlashLightRecoverPage::~FlashLightRecoverPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightRecoverPage::~FlashLightRecoverPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (recoverLabel_ != nullptr) { + delete recoverLabel_; + recoverLabel_ = nullptr; + } + if (cancelButton_ != nullptr) { + delete cancelButton_; + cancelButton_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightRecoverPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_SET_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool FlashLightRecoverPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), CONFIRM_BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_VIEW, + TransitionType::TRANSITION_INVALID, false); + FlashLightModel::GetInstance().SetDefault(); + } else if (strcmp(view.GetViewId(), CANCLE_BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_SET_VIEW, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp index 32f330bf3..9b06a98d8 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightSetItemView * Create: 2025-02-15 */ #include "wearable_log.h" #include "UiConfig.h" -#include "flashlight/FlashLightSetItemView.h" #include "screensetting/ScreenModels.h" #include "main/LoadImg.h" #include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightSetItemView.h" namespace OHOS { static constexpr uint16_t ITEM_X = 0; @@ -34,62 +34,52 @@ static constexpr uint16_t ITEM_LABEL_FONT = 32; FlashLightSetItemView::FlashLightSetItemView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetItemView"); - SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - SetTouchable(true); - - sIcon.SetPosition(ICON_X, ICON_Y); - sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + sIcon_.SetPosition(ICON_X, ICON_Y); + sIcon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - sLabel.SetPosition(LABEL_X, LABEL_Y); - sLabel.Resize(LABEL_W, LABEL_H); - sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); - sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); - sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + sLabel_.SetPosition(LABEL_X, LABEL_Y); + sLabel_.Resize(LABEL_W, LABEL_H); + sLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + sLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + sLabel_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - itemLabel.SetPosition(ITEM_LABEL_X, ITEM_LABEL_Y); - itemLabel.Resize(ITEM_LABEL_W, ITEM_LABEL_H); - itemLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_LABEL_FONT); - itemLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); - itemLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - itemLabel.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); - itemLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - itemLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + itemLabel_.SetPosition(ITEM_LABEL_X, ITEM_LABEL_Y); + itemLabel_.Resize(ITEM_LABEL_W, ITEM_LABEL_H); + itemLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_LABEL_FONT); + itemLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + itemLabel_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + itemLabel_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + itemLabel_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + itemLabel_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - sNextImage.SetPosition(IMAGE_X, IMAGE_Y); - sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - LOADIMG::LoadImageViewImg(&sNextImage, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RIGHTARROW); + sNextImage_.SetPosition(IMAGE_X, IMAGE_Y); + sNextImage_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(&sNextImage_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_RIGHTARROW); - Add(&sIcon); - Add(&sLabel); - Add(&itemLabel); - Add(&sNextImage); + Add(&sIcon_); + Add(&sLabel_); + Add(&itemLabel_); + Add(&sNextImage_); } FlashLightSetItemView::~FlashLightSetItemView() { - Remove(&sIcon); - Remove(&sLabel); - Remove(&itemLabel); - Remove(&sNextImage); + Remove(&sIcon_); + Remove(&sLabel_); + Remove(&itemLabel_); + Remove(&sNextImage_); ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); } void FlashLightSetItemView::SetItemInfo(const FlashLightSetItem itemInfo) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetItemView::SetItemInfo %[s]", itemInfo.viewId.c_str()); - sItemInfo = itemInfo; - sLabel.SetText(itemInfo.label.c_str()); - itemLabel.SetText(itemInfo.itemLabel.c_str()); - LOADIMG::LoadImageViewImg(&sIcon, FLASHLIGHT_IMAGE, itemInfo.resId); -} - -const char *FlashLightSetItemView::GetViewId() const -{ - return sItemInfo.viewId.c_str(); + itemInfo_ = itemInfo; + sLabel_.SetText(itemInfo.label.c_str()); + itemLabel_.SetText(itemInfo.itemLabel.c_str()); + SetViewId(itemInfo_.viewId.c_str()); + LOADIMG::LoadImageViewImg(&sIcon_, FLASHLIGHT_IMAGE, itemInfo.resId); } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp index 7a2361a61..6d99afb98 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp @@ -1,48 +1,80 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: FlashLightSetPage * Create: 2025-04-24 */ -#include "flashlight/FlashLightSetPage.h" -#include "flashlight/FlashLightPresenter.h" -#include "SlicePageFactory.h" -#include "flashlight/FlashLightView.h" -#include "flashlight/FlashLightModel.h" #include "AppViewIDs.h" #include "wearable_log.h" #include "NativeAbility.h" -#include #include "main/LoadImg.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightModel.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightSetPage.h" namespace OHOS { +static constexpr uint16_t SET_LABEL_POS_X = 117; +static constexpr uint16_t SET_LABEL_POS_Y = 31; +static constexpr uint16_t SET_LABEL_WIDTH = 220; +static constexpr uint16_t SET_LABEL_HEIGHT = 53; +static constexpr uint16_t SET_LABEL_FONT_SIZE = 38; +static constexpr uint16_t SET_LIST_POS_X = 59; +static constexpr uint16_t SET_LIST_POS_Y = 127; +static constexpr uint16_t SET_LIST_WIDTH = 340; +static constexpr uint16_t SET_LIST_HEIGHT = 244; +static constexpr uint16_t RECOVER_BUTTON_POS_X = 120; +static constexpr uint16_t RECOVER_BUTTON_POS_Y = 408; +static constexpr uint16_t RECOVER_BUTTON_WIDTH = 220; +static constexpr uint16_t RECOVER_BUTTON_HEIGHT = 80; +static constexpr uint16_t RECOVER_BUTTON_FONT_SIZE = 36; +static constexpr uint16_t CONTAINER_BLANK_SIZE = 100; +static constexpr uint16_t ITEM_X = 0; +static constexpr uint16_t ITEM_Y = 0; +static constexpr uint16_t ITEM_W = 340; +static constexpr uint16_t ITEM_H = 122; +static constexpr char *COLOR__BUTTON_ID = "setColorItem"; +static constexpr char *BLINK_BUTTON_ID = "setBlinkItem"; +static constexpr char *RECOVER_BUTTON_ID = "recoverDefault"; +static std::string g_blinkItemContent[] = {"慢", "å¿«", "不闪烁"}; +static std::string g_colorItemContent[] = {"黑色", "白色", "红色", "橙色", "黄色", + "绿色", "浅蓝色", "深蓝色", "紫色", "彩色"}; +static FlashLightSetItem g_listItem[] = { + {IMAGE_FLASHLIGHT_COLORITEM, "灯光颜色", "", ""}, + {IMAGE_FLASHLIGHT_BLINKITEM, "闪烁频率", "", ""} +}; +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW, FlashLightSetPage, false); +static FlashLightSetPage *g_pFlashLightSetPage = nullptr; + +static UIView* CreateViewCb(uint8_t type) +{ + FlashLightSetItemView* item = new FlashLightSetItemView(); + if (item == nullptr) { + return nullptr; + } -static const uint16_t SET_LABEL_POS_X = 117; -static const uint16_t SET_LABEL_POS_Y = 31; -static const uint16_t SET_LABEL_WIDTH = 220; -static const uint16_t SET_LABEL_HEIGHT = 53; -static const uint16_t SET_LABEL_FONT_SIZE = 38; -static const uint16_t SET_LIST_POS_X = 59; -static const uint16_t SET_LIST_POS_Y = 127; -static const uint16_t SET_LIST_WIDTH = 340; -static const uint16_t SET_LIST_HEIGHT = 244; -static const uint16_t RECOVER_BUTTON_POS_X = 120; -static const uint16_t RECOVER_BUTTON_POS_Y = 408; -static const uint16_t RECOVER_BUTTON_WIDTH = 220; -static const uint16_t RECOVER_BUTTON_HEIGHT = 80; -static const uint16_t RECOVER_BUTTON_FONT_SIZE = 36; -static const uint16_t CONTAINER_BLANK_SIZE = 100; -static const std::string COLOR__BUTTON_ID = "setColorItem"; -static const std::string BLINK_BUTTON_ID = "setBlinkItem"; -static const std::string RECOVER_BUTTON_ID = "recoverDefault"; -static std::string BLINK_ITEM_CONTENT[3] = {"慢", "å¿«", "不闪烁"}; -static std::string COLOR_ITEM_CONTENT[10] = {"黑色", "白色", "红色", "橙色", "黄色", - "绿色", "浅蓝色", "深蓝色", "紫色", "彩色"}; + item->SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); + item->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + item->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + item->SetTouchable(true); + item->SetOnClickListener(g_pFlashLightSetPage); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + FlashLightSetItemView* item = dynamic_cast(view); + if (view == nullptr || data == nullptr || item == nullptr) { + return; + } + FlashLightSetItem* content = static_cast(data); + item->SetItemInfo(*content); +} -REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW, FlashLightSetPage, false); void FlashLightSetPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnStart"); + g_pFlashLightSetPage = this; if (container_ == nullptr) { container_ = new UIScrollView(); container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -51,36 +83,43 @@ void FlashLightSetPage::OnStart(void *data) container_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); } - if (setLabel_ == nullptr) { - setLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + titleLabel_ = new UILabel(); } - setLabel_->SetPosition(SET_LABEL_POS_X, SET_LABEL_POS_Y, SET_LABEL_WIDTH, SET_LABEL_HEIGHT); - setLabel_->SetText("手电筒设置"); - setLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - setLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - setLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SET_LABEL_FONT_SIZE); - container_->Add(setLabel_); - setLabel_->SetVisible(true); + titleLabel_->SetPosition(SET_LABEL_POS_X, SET_LABEL_POS_Y, SET_LABEL_WIDTH, SET_LABEL_HEIGHT); + titleLabel_->SetText("手电筒设置"); + titleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SET_LABEL_FONT_SIZE); + container_->Add(titleLabel_); + titleLabel_->SetVisible(true); if (setItemList_ == nullptr) { - setItemList_ = new UIList(); + setItemList_ = new UISimpleList(); } setItemList_->SetPosition(SET_LIST_POS_X, SET_LIST_POS_Y, SET_LIST_WIDTH, SET_LIST_HEIGHT); setItemList_->SetLoopState(false); setItemList_->EnableAutoAlign(true); - if (setItemAdapter_ == nullptr) { - setItemAdapter_ = new FlashLightSetItemAdapter(); - } - uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); + setItemList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + setItemList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColorId(); uint16_t blinkIndex = (uint16_t)FlashLightModel::GetInstance().GetBlinkFrequency(); - colorItem_.itemLabel = COLOR_ITEM_CONTENT[colorIndex]; - colorItem_.viewId = COLOR__BUTTON_ID; - blinkItem_.itemLabel = BLINK_ITEM_CONTENT[blinkIndex]; - blinkItem_.viewId = BLINK_BUTTON_ID; - setItemAdapter_->AddListItem(colorItem_); - setItemAdapter_->AddListItem(blinkItem_); - setItemAdapter_->SetItemClickListener(this); - setItemList_->SetAdapter(setItemAdapter_); + + g_listItem[0].itemLabel = g_colorItemContent[colorIndex]; + g_listItem[0].viewId = COLOR__BUTTON_ID; + g_listItem[1].itemLabel = g_blinkItemContent[blinkIndex]; + g_listItem[1].viewId = BLINK_BUTTON_ID; + + for (uint8_t i = 0; i < (sizeof(g_listItem) / sizeof(FlashLightSetItem)); ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.data = reinterpret_cast(&g_listItem[i]); + setItemList_->AddContent(content); + } + setItemList_->RefreshList(); + container_->Add(setItemList_); setItemList_->SetVisible(true); @@ -89,13 +128,13 @@ void FlashLightSetPage::OnStart(void *data) } recoverButton_->SetPosition(RECOVER_BUTTON_POS_X, RECOVER_BUTTON_POS_Y, RECOVER_BUTTON_WIDTH, RECOVER_BUTTON_HEIGHT); - recoverButton_->SetViewId(RECOVER_BUTTON_ID.c_str()); + recoverButton_->SetViewId(RECOVER_BUTTON_ID); recoverButton_->SetText("恢复默认\n"); recoverButton_->SetTextColor(Color::Red()); recoverButton_->SetAlign(TEXT_ALIGNMENT_CENTER); recoverButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, RECOVER_BUTTON_FONT_SIZE); - LOADIMG::LoadBtnImage(recoverButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RECOVERBUTTON, - IMAGE_CONVERTER_TOOL_RECOVERBUTTON); + LOADIMG::LoadBtnImage(recoverButton_, FLASHLIGHT_IMAGE, IMAGE_FLASHLIGHT_RECOVERBUTTON, + IMAGE_FLASHLIGHT_RECOVERBUTTON); recoverButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); recoverButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); container_->Add(recoverButton_); @@ -107,6 +146,11 @@ void FlashLightSetPage::OnStart(void *data) AddViewToPageContainer(container_); } +FlashLightSetPage::FlashLightSetPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::FlashLightSetPage"); +} + FlashLightSetPage::~FlashLightSetPage() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::~FlashLightSetPage"); @@ -115,52 +159,44 @@ FlashLightSetPage::~FlashLightSetPage() delete container_; container_ = nullptr; } - if (setLabel_ != nullptr) { - delete setLabel_; - setLabel_ = nullptr; + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; } if (recoverButton_ != nullptr) { delete recoverButton_; recoverButton_ = nullptr; } if (setItemList_ != nullptr) { + setItemList_->ClearAll(); delete setItemList_; setItemList_ = nullptr; } - if (setItemAdapter_ != nullptr) { - delete setItemAdapter_; - setItemAdapter_ = nullptr; - } ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); } bool FlashLightSetPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW); + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } bool FlashLightSetPage::OnClick(UIView &view, const ClickEvent &event) { - uint8_t viewType = view.GetViewType(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnClick [%d]", viewType); - if (viewType == UIViewType::UI_VIEW_GROUP) { - FlashLightSetItemView *itemView = static_cast(&view); - std::string viewId = itemView->GetViewId(); - if (viewId == COLOR__BUTTON_ID) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_COLOR_VIEW); - } else if (viewId == BLINK_BUTTON_ID) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_BLINK_VIEW); - } - } else if (viewType == UIViewType::UI_LABEL_BUTTON_EXT && view.GetViewId() == RECOVER_BUTTON_ID) { - NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_DEFAULT_VIEW); - } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnClick [Invalid]"); + if (strcmp(view.GetViewId(), COLOR__BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_COLOR_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), BLINK_BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_BLINK_VIEW, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), RECOVER_BUTTON_ID) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(FlashLightAllView::FLASH_LIGHT_RECOVER_VIEW, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; +} } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMainPage.cpp new file mode 100644 index 000000000..d5cba8ac0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMainPage.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateMainPage + * Create: 2025-06 + */ + +#include +#include +#include +#include +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "ui_resource_heartRate.h" +#include "heartrate/HeartRatePresenter.h" +#include "heartrate/HeartRateView.h" +#include "heartrate/HeartRateModel.h" +#include "heartrate/HeartRateMainPage.h" + +namespace OHOS { +static constexpr uint16_t HEART_BUTTON_POSITION_X = 116; +static constexpr uint16_t HEART_BUTTON_HEIGHT = 76; +static constexpr uint16_t HEART_TITLE_POSITION_X = 195; +static constexpr uint16_t HEART_TITLE_POSITION_Y = 40; +static constexpr uint16_t HEART_TITLE_WIDTH = 260; +static constexpr uint16_t HEART_TITLE_HEIGHT = 53; +static constexpr uint16_t HEART_TITLE_FONT_SIZE = 38; +static constexpr uint16_t HEART_BUTTON_TWO_POSITION_Y = 330; +static constexpr uint16_t HEART_BUTTON_TWO_WIDTH = 232; +static constexpr uint16_t BOTTOM_TEXT_ONE_X = 138; +static constexpr uint16_t BOTTOM_TEXT_ONE_Y = 281; +static constexpr uint16_t BOTTOM_TEXT_WIDTH_ONE = 250; +static constexpr uint16_t BOTTOM_TEXT_HEIGHT_ONE = 36; +static constexpr uint16_t HEART_RATE_LIMIT_FONT_SIZE_TWO = 24; +static constexpr uint16_t VIDEO_WIDTH = 454; +static constexpr uint16_t VIDEO_HEIGHT = 454; +static constexpr uint16_t STRIDE_ALIGNMENT_VALUE = 128; +static constexpr uint16_t BUFFER_QUEUE_SIZE = 3; +static constexpr uint16_t JPEG_HEIGHT_DIVISOR = 2; +static constexpr uint16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128; +static constexpr uint16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; +static constexpr uint16_t HEART_BUTTON_FONT_SIZE = 35; +static constexpr uint16_t HEART_DATE_TIME_ONE = 90; +static constexpr uint16_t HEART_DATE_TIME_TWO = 3000; +static constexpr uint16_t HEART_DATE_TIME_THREE = 60; +static constexpr uint16_t HEART_DATE_TIME_FOUR = 3600; +static constexpr uint16_t HEART_DATE_MAX = 454; +static constexpr uint16_t HEART_DATE_WIDTH = 2; +static constexpr char *HEART_START_BUTTON = "startButton"; + +REGIST_SLICE_PAGE(VIEW_HEARTRATE, HeartRateAllView::HEARTRATE_MAIN_PAGE, HeartRateMainPage, true); + +HeartRateMainPage::HeartRateMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateMainPage::HeartRateMainPage"); +} + +HeartRateMainPage::~HeartRateMainPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (button_ != nullptr) { + delete button_; + button_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelPreTest_ != nullptr) { + delete labelPreTest_; + labelPreTest_ = nullptr; + } + + if (videoPlay_ != nullptr) { + videoPlay_->StopVideoPlay(); + delete videoPlay_; + videoPlay_ = nullptr; + } + + if (surfaceView_ != nullptr) { + delete surfaceView_; + surfaceView_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(HEART_RATE_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateMainPage::~HeartRateMainPage"); +} + +void HeartRateMainPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + InitImageAnimator(); + + button_ = new UILabelButton(); + if (button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button_ fail"); + return; + } + button_->SetPosition(HEART_BUTTON_POSITION_X, HEART_BUTTON_TWO_POSITION_Y); + button_->Resize(HEART_BUTTON_TWO_WIDTH, HEART_BUTTON_HEIGHT); + button_->SetViewId(HEART_START_BUTTON); + button_->SetOnClickListener(this); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::PRESSED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x14FFFFFF, UIButton::INACTIVE); + button_->SetText("开始测量"); + button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_BUTTON_FONT_SIZE); + button_->SetVisible(true); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(HEART_TITLE_POSITION_X, HEART_TITLE_POSITION_Y, HEART_TITLE_WIDTH, HEART_TITLE_HEIGHT); + labelTitle_->SetText("心率"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, HEART_TITLE_FONT_SIZE); + SetTestTime(); + group_->Add(button_); + group_->Add(labelPreTest_); + group_->Add(labelTitle_); + AddViewToPageContainer(group_); +} + +void HeartRateMainPage::OnResume() +{ + videoPlay_->StartVideoPlay(); +} + +void HeartRateMainPage::OnPause() +{ + videoPlay_->StopVideoPlay(); +} + +void HeartRateMainPage::SetTestTime() +{ + labelPreTest_ = new UILabel(); + if (labelPreTest_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelPreTest_ fail"); + return; + } + labelPreTest_->SetPosition(BOTTOM_TEXT_ONE_X, BOTTOM_TEXT_ONE_Y, BOTTOM_TEXT_WIDTH_ONE, BOTTOM_TEXT_HEIGHT_ONE); + labelPreTest_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_LIMIT_FONT_SIZE_TWO); + labelPreTest_->SetStyle(STYLE_TEXT_COLOR, 0xFFCCCCCC); + labelPreTest_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelPreTest_->SetVisible(false); + heartRateMeasurementInfo info = HeartRateModel::GetInstance().GetHeartRate(); + struct timeval current_time; + if (info.heartRate == 0) { + info.heartRate = HEART_DATE_TIME_ONE; + gettimeofday(¤t_time, nullptr); + int64_t now = current_time.tv_sec; + struct timeval time1; + time1.tv_sec = now - HEART_DATE_TIME_TWO; + info.time = time1; + } + if (info.heartRate != 0) { + struct timeval tv = info.time; + std::time_t time = tv.tv_sec; + std::tm *tm_info = std::localtime(&time); + std::stringstream ss; + if (IsToday(tv)) { + gettimeofday(¤t_time, nullptr); + int64_t now = current_time.tv_sec; + int64_t diff_seconds = now - tv.tv_sec; + if (diff_seconds < 0) { + ss << info.heartRate << "次/分 (" + << "刚刚)"; + } else if (diff_seconds < HEART_DATE_TIME_THREE) { + ss << info.heartRate << "次/分 (" + << "刚刚)"; + } else if (diff_seconds < HEART_DATE_TIME_FOUR) { + int minutes = diff_seconds / HEART_DATE_TIME_THREE; + ss << info.heartRate << "次/分 (" << minutes << "分钟前)"; + } else { + int hours = diff_seconds / HEART_DATE_TIME_FOUR; + ss << info.heartRate << "次/分 (" << hours << "小时前)"; + } + } else { + ss << info.heartRate << "次/分 " << (tm_info->tm_mon + 1) << "/" << tm_info->tm_mday; + } + labelPreTest_->SetText(ss.str().c_str()); + labelPreTest_->SetText(ss.str().c_str()); + int textWidth = labelPreTest_->GetTextWidth(); + int posX = (HEART_DATE_MAX - textWidth) / HEART_DATE_WIDTH; + labelPreTest_->SetX(posX); + labelPreTest_->SetVisible(true); + } +} + +bool HeartRateMainPage::IsToday(const struct timeval &tv) +{ + time_t now = time(nullptr); + std::tm *now_tm = localtime(&now); + std::time_t given_time = tv.tv_sec; + std::tm *given_tm = std::localtime(&given_time); + + return (now_tm->tm_year == given_tm->tm_year) && (now_tm->tm_mon == given_tm->tm_mon) && + (now_tm->tm_mday == given_tm->tm_mday); +} + +bool HeartRateMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} + +bool HeartRateMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), HEART_START_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(HeartRateAllView::HEARTRATE_READY_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + UNUSED(event); + return true; +} + +void HeartRateMainPage::InitImageAnimator() +{ + surfaceView_ = new UILiteSurfaceView(); + if (surfaceView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new surfaceView_ fail"); + return; + } + colorKey_.full = 0xff202020; + surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT); + surfaceView_->SetPreview( + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_HEART_RATE_PREVIEW1, HEART_RATE_IMAGE)); + surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + surfaceView_->SetSurfaceColorkey(colorKey_); + group_->Add(surfaceView_); + + Surface *surface = surfaceView_->GetSurface(); + surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE); + surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT); + surface->SetQueueSize(BUFFER_QUEUE_SIZE); + surface->SetFormat(PIXEL_FMT_YCBCR_420_SP); + + int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT; + int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * + ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR; + int32_t bufferSize = ySize + uvSize; + surface->SetSize(bufferSize); + std::string uri("/user/res/video/heartBackGround.mp4"); + videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, false); + if (videoPlay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new videoPlay_ fail"); + return; + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMeasurePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMeasurePage.cpp new file mode 100644 index 000000000..1b8ba61da --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateMeasurePage.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateMeasurePage + * Create: 2025-06 + */ + +#include +#include +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "settings/model/SettingDisplayModel.h" +#include "ui_resource_heartRate.h" +#include "heartrate/HeartRatePresenter.h" +#include "heartrate/HeartRateModel.h" +#include "heartrate/HeartRateMeasurePage.h" + +namespace OHOS { +static constexpr uint16_t HEARTRATE_BUTTON_TWO_POSITION_X = 142; +static constexpr uint16_t HEARTRATE_BUTTON_TWO_POSITION_Y = 370; +static constexpr uint16_t HEARTRATE_LABEL_FRONT = 40; +static constexpr uint16_t HEARTRATE_LABEL_FRONT_BOTTOM = 36; +static constexpr uint16_t HEARTRATE_LABEL2_POSITION_X = 133; +static constexpr uint16_t HEARTRATE_LABEL2_POSITION_Y = 200; +static constexpr uint16_t HEARTRATE_LABEL2_WIDTH = 180; +static constexpr uint16_t HEARTRATE_LABEL2_HEIGHT = 62; +static constexpr uint16_t HEARTRATE_LABLE_TITLE_POSITION_X = 195; +static constexpr uint16_t HEARTRATE_LABLE_TITLE_POSITION_Y = 40; +static constexpr uint16_t HEARTRATE_LABLE_TITLE_WIDTH = 260; +static constexpr uint16_t HEARTRATE_LABLE_TITLE_HEIGHT = 53; +static constexpr uint16_t HEARTRATE_LABLE_TITLE_FONT_SIZE = 38; +static constexpr uint16_t HEARTRATE_LABLEBACK_FONT_SIZE = 30; +static constexpr uint16_t VIDEO_WIDTH = 454; +static constexpr uint16_t VIDEO_HEIGHT = 454; +static constexpr uint16_t STRIDE_ALIGNMENT_VALUE = 128; +static constexpr uint16_t BUFFER_QUEUE_SIZE = 3; +static constexpr uint16_t JPEG_HEIGHT_DIVISOR = 2; +static constexpr uint16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128; +static constexpr uint16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; +static constexpr uint16_t HEART_TIME_NUM = 15; + +REGIST_SLICE_PAGE(VIEW_HEARTRATE, HeartRateAllView::HEARTRATE_MEASUREMENT_PAGE, HeartRateMeasurePage, false); + +HeartRateMeasurePage::HeartRateMeasurePage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateMeasurePage::HeartRateMeasurePage"); +} + +HeartRateMeasurePage::~HeartRateMeasurePage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelTimeOrResult_ != nullptr) { + delete labelTimeOrResult_; + labelTimeOrResult_ = nullptr; + } + + if (labelTips_ != nullptr) { + delete labelTips_; + labelTips_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (videoPlay_ != nullptr) { + videoPlay_->StopVideoPlay(); + delete videoPlay_; + videoPlay_ = nullptr; + } + + if (surfaceView_ != nullptr) { + delete surfaceView_; + surfaceView_ = nullptr; + } + + if (chartLineResultGroup_ != nullptr) { + delete chartLineResultGroup_; + chartLineResultGroup_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(HEART_RATE_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateMeasurePage::~HeartRateMeasurePage"); +} + +void HeartRateMeasurePage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + InitVideoView(); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(HEARTRATE_LABLE_TITLE_POSITION_X, HEARTRATE_LABLE_TITLE_POSITION_Y, + HEARTRATE_LABLE_TITLE_WIDTH, HEARTRATE_LABLE_TITLE_HEIGHT); + labelTitle_->SetText("心率"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, HEARTRATE_LABLE_TITLE_FONT_SIZE); + + labelTimeOrResult_ = new UILabel(); + if (labelTimeOrResult_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTimeOrResult_ fail"); + return; + } + labelTimeOrResult_->SetPosition(HEARTRATE_LABEL2_POSITION_X, + HEARTRATE_LABEL2_POSITION_Y); + labelTimeOrResult_->Resize(HEARTRATE_LABEL2_WIDTH, HEARTRATE_LABEL2_HEIGHT); + labelTimeOrResult_->SetStyle(STYLE_TEXT_FONT, HEARTRATE_LABEL_FRONT); + labelTimeOrResult_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelTimeOrResult_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTimeOrResult_->SetFont(BOLD_VECTOR_FONT_FILENAME, HEARTRATE_LABEL_FRONT); + + labelTips_ = new UILabel(); + if (labelTips_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTips_ fail"); + return; + } + labelTips_->SetPosition(HEARTRATE_BUTTON_TWO_POSITION_X, HEARTRATE_BUTTON_TWO_POSITION_Y); + labelTips_->Resize(HEARTRATE_LABEL2_WIDTH, HEARTRATE_LABEL2_HEIGHT); + labelTips_->SetStyle(STYLE_TEXT_FONT, HEARTRATE_LABEL_FRONT_BOTTOM); + labelTips_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelTips_->SetText("正在测量"); + labelTips_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTips_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEARTRATE_LABEL_FRONT_BOTTOM); + group_->Add(labelTimeOrResult_); + group_->Add(labelTips_); + + InitAnimator(); + gettimeofday(&startTime_, nullptr); + group_->Add(labelTitle_); + + AddViewToPageContainer(group_); + animator_->Start(); + + SetTestStatus(false); +} + +void HeartRateMeasurePage::OnResume() +{ + videoPlay_->StartVideoPlay(); + SettingDisplayModel::GetInstance().EnableSteadyOn(); +} + +void HeartRateMeasurePage::OnPause() +{ + videoPlay_->StopVideoPlay(); + SettingDisplayModel::GetInstance().DisableSteadyOn(); +} + +void HeartRateMeasurePage::InitAnimator() +{ + callBack_ = new HeartAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new callBack_ fail"); + return; + } + animator_ = new Animator(callBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ fail"); + return; + } +} + +void HeartRateMeasurePage::SetTimeAndResultText(std::string str) +{ + labelTimeOrResult_->SetText(str.c_str()); +} + +void HeartRateMeasurePage::SetTestStatus(bool value) +{ + measureStatus_ = value; +} + +void HeartRateMeasurePage::HeartAnimatorCallback::Callback(UIView *view) +{ + (void)view; + if (page_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "page_ is nullptr"); + return; + } + static int count = 0; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + int time = current_time.tv_sec - page_->startTime_.tv_sec; + std::string strTime; + // 测量结束,修改文本,显示当前心率 + if (time >= HEART_TIME_NUM) { + page_->StopAnimator(); + heartRateMeasurementInfo info; + info.heartRate = 80; // 80:心率打桩数据 + info.time = current_time; + strTime = std::to_string(info.heartRate) + "次/分"; + HeartRateModel::GetInstance().SetHeartRate(info); + page_->SetTestStatus(true); + page_->labelTips_->SetText("当前心率"); + std::string strHeartRate = std::to_string(info.heartRate); + if (page_->chartLineResultGroup_ == nullptr) { + page_->chartLineResultGroup_ = new HeartRateResultGroup(); + if (page_->chartLineResultGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chartLineResultGroup_ fail"); + return; + } + } + page_->chartLineResultGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + page_->chartLineResultGroup_->SetVisible(false); + page_->group_->Add(page_->chartLineResultGroup_); + page_->chartLineResultGroup_->labelHeartRateValue_->SetText(strHeartRate.c_str()); + page_->chartLineResultGroup_->SetVisible(true); + } else { + // 测量中,文本仅更新倒计时 + strTime = std::to_string(HEART_TIME_NUM - time) + "s"; + } + page_->SetTimeAndResultText(strTime); +} + +void HeartRateMeasurePage::StopAnimator() +{ + animator_->Stop(); +} + +bool HeartRateMeasurePage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + // 在测量完成后 才能拉起心率线状图 + if (measureStatus_) { + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + chartLineResultGroup_->SetVisible(false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + chartLineResultGroup_->SetVisible(true); + } + } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(HeartRateAllView::HEARTRATE_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void HeartRateMeasurePage::InitVideoView() +{ + surfaceView_ = new UILiteSurfaceView(); + if (surfaceView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new surfaceView_ fail"); + return; + } + colorKey_.full = 0xff202020; + surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT); + surfaceView_->SetPreview( + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_HEART_RATE_PREVIEW2, HEART_RATE_IMAGE)); + surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + surfaceView_->SetSurfaceColorkey(colorKey_); + group_->Add(surfaceView_); + + Surface *surface = surfaceView_->GetSurface(); + surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE); + surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT); + surface->SetQueueSize(BUFFER_QUEUE_SIZE); + surface->SetFormat(PIXEL_FMT_YCBCR_420_SP); + + int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT; + int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * + ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR; + int32_t bufferSize = ySize + uvSize; + surface->SetSize(bufferSize); + std::string uri("/user/res/video/heart.mp4"); + videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, false); + if (videoPlay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new videoPlay_ fail"); + return; + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateModel.cpp new file mode 100644 index 000000000..378a492bd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateModel.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateModel + * Create: 2025-06 + */ + +#include +#include "ohos_timer.h" +#include "wearable_log.h" +#include "heartrate/HeartRateView.h" +#include "heartrate/HeartRateModel.h" + +namespace OHOS { +HeartRateModel::HeartRateModel() {} + +HeartRateModel::~HeartRateModel() {} + +HeartRateModel &HeartRateModel::GetInstance() +{ + static HeartRateModel instance; + return instance; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRatePresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRatePresenter.cpp new file mode 100644 index 000000000..c5f52d6e3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRatePresenter.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRatePresenter + * Create: 2025-06 + */ + +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" +#include "wearable_log.h" +#include "heartrate/HeartRateView.h" +#include "heartrate/HeartRatePresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_HEARTRATE, HeartRateView, HeartRatePresenter, HEART_RATE_ICON, HEART_RATE_ICON, "心率"); +static HeartRatePresenter *g_pHeartRatePresenter = nullptr; +HeartRatePresenter *HeartRatePresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRatePresenter GetInstance"); + return g_pHeartRatePresenter; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateReadyPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateReadyPage.cpp new file mode 100644 index 000000000..0077c3fb7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateReadyPage.cpp @@ -0,0 +1,258 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateReadyPage + * Create: 2025-06 + */ + +#include +#include +#include "ui_test_group.h" +#include "main/LoadImg.h" +#include "ui_resource_heartRate.h" +#include "heartrate/HeartRatePresenter.h" +#include "heartrate/HeartRateReadyPage.h" + +namespace OHOS { +static constexpr uint16_t HEARTRATE_BUTTON_POSITION_X = 188; +static constexpr uint16_t HEARTRATE_BUTTON_WIDTH = 96; +static constexpr uint16_t HEARTRATE_BUTTON_HEIGHT = 96; +static constexpr uint16_t HEARTRATE_BUTTON_TWO_POSITION_Y = 288; +static constexpr uint16_t HEARTRATE_LABEL3_POSITION_X = 65; +static constexpr uint16_t HEARTRATE_LABEL3_POSITION_Y = 150; +static constexpr uint16_t HEARTRATE_LABLETIPSSATRT_POSITION_X = 110; +static constexpr uint16_t HEARTRATE_LABLETIPSSATRT_POSITION_Y = 200; +static constexpr uint16_t HEARTRATE_LABLETIPSSATRT_WIDTH = 424; +static constexpr uint16_t HEARTRATE_LABLETIPSSATRT_HEIGHT = 424; +static constexpr uint16_t HEARTRATE_LABLETIPSSATRT_FONT_SIZE = 36; +static constexpr uint16_t HEARTRATE_LABLEBACK_POSITION_X = 218; +static constexpr uint16_t HEARTRATE_LABLEBACK_POSITION_Y = 318; +static constexpr uint16_t HEARTRATE_LABLEBACK_WIDTH = 50; +static constexpr uint16_t HEARTRATE_LABLEBACK_HEIGHT = 50; +static constexpr uint16_t HEARTRATE_LABLEBACK_FONT_SIZE = 30; +static constexpr uint16_t HEARTRATE_PLAYBACK_POSITION_X = 140; +static constexpr uint16_t HEARTRATE_PLAYBACK_POSITION_Y = 250; +static constexpr uint16_t HEARTRATE_PLAYBACK_WIDTH = 172; +static constexpr uint16_t HEARTRATE_PLAYBACK_HEIGHT = 172; +static constexpr uint16_t HEARTRATE_PLAYBACK_VENTER_POSITION = 86; +static constexpr uint32_t HEARTRATE_PLAYBACK_RANGE = 100000; +static constexpr uint16_t HEARTRATE_PLAYBACK_RADIUS = 48; +static constexpr uint16_t HEARTRATE_PLAYBACK_START_ANGLE = 360; +static constexpr uint16_t HEARTRATE_PLAYBACK_STYLE_LINE_WIDTH = 12; +static constexpr uint16_t HEARTRATE_TIME_NUM = 3; +static constexpr uint16_t HEARTRATE_PROGRESS_TIME = 3; +static constexpr uint16_t HEARTRATE_TIME_USEC = 1000; +static constexpr char *HEART_START_BUTTON = "startButton"; + +REGIST_SLICE_PAGE(VIEW_HEARTRATE, HeartRateAllView::HEARTRATE_READY_PAGE, HeartRateReadyPage, false); + +HeartRateReadyPage::HeartRateReadyPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateReadyPage::HeartRateReadyPage"); +} + +HeartRateReadyPage::~HeartRateReadyPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (button_ != nullptr) { + delete button_; + button_ = nullptr; + } + + if (labelTips_ != nullptr) { + delete labelTips_; + labelTips_ = nullptr; + } + + if (timeProgress_ != nullptr) { + delete timeProgress_; + timeProgress_ = nullptr; + } + + if (labelProgressTime_ != nullptr) { + delete labelProgressTime_; + labelProgressTime_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(HEART_RATE_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateReadyPage::~HeartRateReadyPage"); +} + +void HeartRateReadyPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetOnDragListener(this); + + button_ = new UILabelButton(); + if (button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new button_ fail"); + return; + } + button_->SetPosition(HEARTRATE_BUTTON_POSITION_X, HEARTRATE_BUTTON_TWO_POSITION_Y); + button_->Resize(HEARTRATE_BUTTON_WIDTH, HEARTRATE_BUTTON_HEIGHT); + LOADIMG::LoadBtnImage(button_, HEART_RATE_IMAGE, IMAGE_HEART_RATE_RESET, IMAGE_HEART_RATE_RESET); + button_->SetViewId(HEART_START_BUTTON); + button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + button_->SetVisible(true); + button_->SetOnClickListener(this); + + labelTips_ = new UILabel(); + if (labelTips_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTips_ fail"); + return; + } + labelTips_->SetPosition(HEARTRATE_LABLETIPSSATRT_POSITION_X, HEARTRATE_LABLETIPSSATRT_POSITION_Y, + HEARTRATE_LABLETIPSSATRT_WIDTH, HEARTRATE_LABLETIPSSATRT_HEIGHT); + labelTips_->SetText("请佩戴手表测量"); + labelTips_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEARTRATE_LABLETIPSSATRT_FONT_SIZE); + labelTips_->SetVisible(true); + + InitCircleProgress(); + + InitAnimator(); + + group_->Add(button_); + group_->Add(labelTips_); + AddViewToPageContainer(group_); +} + +void HeartRateReadyPage::InitAnimator() +{ + callBack_ = new HeartAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new callBack_ fail"); + return; + } + animator_ = new Animator(callBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new animator_ fail"); + return; + } +} + +int HeartRateReadyPage::InitCircleProgress() +{ + labelProgressTime_ = new UILabel(); + if (labelProgressTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelProgressTime_ fail"); + return OHOS_FAILURE; + } + labelProgressTime_->SetPosition(HEARTRATE_LABLEBACK_POSITION_X, HEARTRATE_LABLEBACK_POSITION_Y, + HEARTRATE_LABLEBACK_WIDTH, HEARTRATE_LABLEBACK_HEIGHT); + labelProgressTime_->SetText("3"); + labelProgressTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEARTRATE_LABLEBACK_FONT_SIZE); + labelProgressTime_->SetVisible(false); + group_->Add(labelProgressTime_); + + timeProgress_ = new UICircleProgress(); + if (timeProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new timeProgress_ fail"); + return OHOS_FAILURE; + } + timeProgress_->SetPosition(HEARTRATE_PLAYBACK_POSITION_X, HEARTRATE_PLAYBACK_POSITION_Y, + HEARTRATE_PLAYBACK_WIDTH, HEARTRATE_PLAYBACK_HEIGHT); + timeProgress_->SetCenterPosition(HEARTRATE_PLAYBACK_VENTER_POSITION, HEARTRATE_PLAYBACK_VENTER_POSITION); + timeProgress_->SetRange(HEARTRATE_PLAYBACK_RANGE, 0); + timeProgress_->SetRadius(HEARTRATE_PLAYBACK_RADIUS); + timeProgress_->SetStartAngle(HEARTRATE_PLAYBACK_START_ANGLE); + timeProgress_->SetEndAngle(0); + timeProgress_->SetValue(0); + timeProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xFF491010); + timeProgress_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timeProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0xFFD72C2E); + timeProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, HEARTRATE_PLAYBACK_STYLE_LINE_WIDTH); + timeProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, HEARTRATE_PLAYBACK_STYLE_LINE_WIDTH); + timeProgress_->SetVisible(false); + group_->Add(timeProgress_); + return OHOS_SUCCESS; +} + +void HeartRateReadyPage::HeartAnimatorCallback::Callback(UIView *view) +{ + (void)view; + static int count = 0; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + long seconds = current_time.tv_sec - page_->startTime_.tv_sec; + long micros = current_time.tv_usec - page_->startTime_.tv_usec; + long time = (seconds * HEARTRATE_TIME_USEC) + (micros / HEARTRATE_TIME_USEC); + page_->SetLabelProgressTime(time); + if ((time / HEARTRATE_TIME_USEC) == HEARTRATE_TIME_NUM) { + page_->StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(HeartRateAllView::HEARTRATE_MEASUREMENT_PAGE, + TransitionType::TRANSITION_INVALID, false); + } +} + +void HeartRateReadyPage::StopAnimator() +{ + button_->SetVisible(false); + labelTips_->SetVisible(false); + timeProgress_->SetVisible(false); + labelProgressTime_->SetVisible(false); + animator_->Stop(); +} + +void HeartRateReadyPage::SetLabelProgressTime(int time) +{ + int progressTime = HEARTRATE_PROGRESS_TIME - (time / HEARTRATE_TIME_USEC); + std::string strTime = std::to_string(progressTime); + labelProgressTime_->SetText(strTime.c_str()); + double percentage = static_cast(time) / (HEARTRATE_TIME_NUM * HEARTRATE_TIME_USEC); + double value = round(percentage * 100000); + timeProgress_->SetValue(value); +} + +bool HeartRateReadyPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + StopAnimator(); + NativeAbility::GetInstance().SwitchPageInSlice(HeartRateAllView::HEARTRATE_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool HeartRateReadyPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), HEART_START_BUTTON) == 0) { + labelTips_->SetVisible(false); + labelTips_->SetPosition(HEARTRATE_LABEL3_POSITION_X, HEARTRATE_LABEL3_POSITION_Y); + labelTips_->SetText("请屏幕朝上偏紧佩戴, 保持静止"); + labelTips_->SetVisible(true); + button_->SetVisible(false); + animator_->Start(); + timeProgress_->SetVisible(true); + labelProgressTime_->SetVisible(true); + gettimeofday(&startTime_, nullptr); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateResultGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateResultGroup.cpp new file mode 100644 index 000000000..eb794032d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/heartrate/src/HeartRateResultGroup.cpp @@ -0,0 +1,440 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateResultGroup + * Create: 2025-06 + */ + +#include +#include "components/ui_list_nested.h" +#include "components/ui_chart.h" +#include "components/ui_scroll_view_nested.h" +#include "common/image_cache_manager.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "AppViewIDs.h" +#include "ui_resource_heartRate.h" +#include "heartrate/HeartRatePresenter.h" +#include "heartrate/HeartRateModel.h" +#include "heartrate/HeartRateResultGroup.h" + +static constexpr uint16_t PERSEC_HEART_RATE_FONT_SIZE = 38; +static constexpr uint16_t PERSEC_HEART_RATE_X = 195; +static constexpr uint16_t PERSEC_HEART_RATE_Y = 40; +static constexpr uint16_t PERSEC_HEART_RATE_WIDTH = 260; +static constexpr uint16_t PERSEC_HEART_RATE_HEIGHT = 53; +static constexpr uint16_t PERSEC_HEART_TEXT_FONT_SIZE = 56; +static constexpr uint16_t PERSEC_HEART_TEXT_X = 188; +static constexpr uint16_t PERSEC_HEART_TEXT_Y = 96; +static constexpr uint16_t PERSEC_HEART_TEXT_WIDTH = 80; +static constexpr uint16_t PERSEC_HEART_TEXT_HEIGHT = 64; +static constexpr uint16_t PERSEC_HEART_TEXT_FONT_SIZE_ONE = 21; +static constexpr uint16_t PERSEC_HEART_TEXT_ONE_X = 259; +static constexpr uint16_t PERSEC_HEART_TEXT_ONE_Y = 128; +static constexpr uint16_t PERSEC_HEART_TEXT_WIDTH_ONE = 55; +static constexpr uint16_t PERSEC_HEART_TEXT_HEIGHT_ONE = 24; +static constexpr uint16_t COORDINATE_POINT_X = 70; +static constexpr uint16_t COORDINATE_POINT_Y = 207; +static constexpr uint16_t COORDINATE_HEIGHT = 156; +static constexpr uint16_t COORDINATE_WIDTH = 330; +static constexpr uint16_t HEART_RATE_LIMIT_FONT_SIZE = 25; +static constexpr uint16_t HEART_RATE_X_FONT_SIZE = 16; +static constexpr uint16_t TOP_TEXT_WIDTH = 52; +static constexpr uint16_t TOP_TEXT_HEIGHT = 36; +static constexpr uint16_t TOP_TEXT_X = 177; +static constexpr uint16_t TOP_TEXT_Y = 392; +static constexpr uint16_t BOTTOM_TEXT_WIDTH = 35; +static constexpr uint16_t BOTTOM_TEXT_HEIGHT = 36; +static constexpr uint16_t BOTTOM_TEXT_X = 274; +static constexpr uint16_t BOTTOM_TEXT_Y = 392; +static constexpr uint16_t HEART_RATE_LIMIT_FONT_SIZE_ONE = 24; +static constexpr uint16_t BOTTOM_TEXT_WIDTH_ONE = 89; +static constexpr uint16_t BOTTOM_TEXT_HEIGHT_ONE = 29; +static constexpr uint16_t BOTTOM_TEXT_ONE_X = 188; +static constexpr uint16_t BOTTOM_TEXT_ONE_Y = 160; +static constexpr uint16_t ANIMATOR_IMAGE_X = 120; +static constexpr uint16_t ANIMATOR_IMAGE_Y = 98; +static constexpr uint16_t ANIMATOR_IMAGE_WIDTH = 60; +static constexpr uint16_t ANIMATOR_IMAGE_HEIGHT = 60; +static constexpr uint16_t HEART_LABLE_ONE_POSION_X = 63; +static constexpr uint16_t HEART_LABLE_THREE_POSION_X = 210; +static constexpr uint16_t HEART_LABLE_FIVE_POSION_X = 350; +static constexpr uint16_t HEART_LABLE_POSION_X = 10; +static constexpr uint16_t HEART_LABLE_POSION_Y = 369; +static constexpr uint16_t HEART_LABLE1_POSION_Y = 320; +static constexpr uint16_t HEART_LABLE2_POSION_Y = 290; +static constexpr uint16_t HEART_LABLE3_POSION_Y = 260; +static constexpr uint16_t HEART_LABLE4_POSION_Y = 230; +static constexpr uint16_t IMAGE_RED_TEXT_X = 157; +static constexpr uint16_t IMAGE_RED_TEXT_Y = 407; +static constexpr uint16_t IMAGE_BACK_TEXT_X = 254; +static constexpr uint16_t IMAGE_BACK_TEXT_Y = 407; +static constexpr uint16_t XAXIS_SETMARKNUM = 40; +static constexpr uint16_t XAXIS_LINENUM = 3; +static constexpr uint16_t YAXIS_SETMARKNUM = 5; +static constexpr uint16_t XAXIS_SETDATARANGE = 45; +static constexpr uint16_t YAXIS_SETDATARANGE = 200; +static constexpr uint16_t CHART_LINE_NUM_ONE = 10; +static constexpr uint16_t CHART_LINE_NUM_TWO = 60; + +namespace OHOS { +const int g_imageAnimatorInfo[HEARTRATE_ANIMATOR_IMAGE_NUM] = { + IMAGE_HEART_RATE_FRAME00, IMAGE_HEART_RATE_FRAME01, IMAGE_HEART_RATE_FRAME02, IMAGE_HEART_RATE_FRAME03, + IMAGE_HEART_RATE_FRAME04, IMAGE_HEART_RATE_FRAME05, IMAGE_HEART_RATE_FRAME06, IMAGE_HEART_RATE_FRAME07, + IMAGE_HEART_RATE_FRAME08, IMAGE_HEART_RATE_FRAME09, IMAGE_HEART_RATE_FRAME10, IMAGE_HEART_RATE_FRAME11, + IMAGE_HEART_RATE_FRAME12, IMAGE_HEART_RATE_FRAME13, IMAGE_HEART_RATE_FRAME14, IMAGE_HEART_RATE_FRAME15, + IMAGE_HEART_RATE_FRAME16, IMAGE_HEART_RATE_FRAME17, IMAGE_HEART_RATE_FRAME18, IMAGE_HEART_RATE_FRAME19, + IMAGE_HEART_RATE_FRAME20, IMAGE_HEART_RATE_FRAME21, IMAGE_HEART_RATE_FRAME22, IMAGE_HEART_RATE_FRAME23, + IMAGE_HEART_RATE_FRAME24, IMAGE_HEART_RATE_FRAME25, IMAGE_HEART_RATE_FRAME26, IMAGE_HEART_RATE_FRAME27, + IMAGE_HEART_RATE_FRAME28, IMAGE_HEART_RATE_FRAME29, +}; + +HeartRateResultGroup::HeartRateResultGroup() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateResultGroup::HeartRateResultGroup"); + InitPage(); +} + +void HeartRateResultGroup::InitPage() +{ + SetPosition(0, 0); + Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + mainImg_ = new UIImageView(); + if (mainImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new mainImg_ fail"); + return; + } + mainImg_->SetPosition(0, 0); + mainImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(mainImg_, HEART_RATE_IMAGE, IMAGE_HEART_RATE_BG2); + Add(mainImg_); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); + return; + } + labelTitle_->SetText("心率"); + labelTitle_->SetPosition(PERSEC_HEART_RATE_X, PERSEC_HEART_RATE_Y, PERSEC_HEART_RATE_WIDTH, + PERSEC_HEART_RATE_HEIGHT); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, PERSEC_HEART_RATE_FONT_SIZE); + Add(labelTitle_); + + labelHeartRateValue_ = new UILabel(); + if (labelHeartRateValue_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelHeartRateValue_ fail"); + return; + } + labelHeartRateValue_->SetPosition(PERSEC_HEART_TEXT_X, PERSEC_HEART_TEXT_Y, PERSEC_HEART_TEXT_WIDTH, + PERSEC_HEART_TEXT_HEIGHT); + labelHeartRateValue_->SetFont(BOLD_VECTOR_FONT_FILENAME, PERSEC_HEART_TEXT_FONT_SIZE); + heartRateMeasurementInfo info = HeartRateModel::GetInstance().GetHeartRate(); + std::string strHeartRate = std::to_string(info.heartRate); + labelHeartRateValue_->SetText(strHeartRate.c_str()); + Add(labelHeartRateValue_); + + labelUnitText_ = new UILabel(); + if (labelUnitText_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelUnitText_ fail"); + return; + } + labelUnitText_->SetText("次/分"); + labelUnitText_->SetPosition(PERSEC_HEART_TEXT_ONE_X, PERSEC_HEART_TEXT_ONE_Y, PERSEC_HEART_TEXT_WIDTH_ONE, + PERSEC_HEART_TEXT_HEIGHT_ONE); + labelUnitText_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, PERSEC_HEART_TEXT_FONT_SIZE_ONE); + Add(labelUnitText_); + + dataSerial_ = new UIChartDataSerial(); + if (dataSerial_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new dataSerial_ fail"); + return; + } + dataSerial_->SetMaxDataCount(XAXIS_SETDATARANGE); + // 打桩数据,真实测量数据的存储和更新需要客户自实现 + Point pointArray[XAXIS_SETDATARANGE] = { + {0, 100}, {1, 110}, {2, 112}, {3, 114}, {4, 116}, {5, 118}, {6, 120}, {7, 122}, {8, 124}, + {9, 126}, {10, 128}, {11, 140}, {12, 140}, {13, 160}, {14, 160}, {15, 160}, {16, 176}, {17, 180}, + {18, 192}, {19, 160}, {20, 176}, {21, 172}, {22, 172}, {23, 148}, {24, 146}, {25, 144}, {26, 120}, + {27, 110}, {28, 110}, {29, 108}, {30, 106}, {31, 104}, {32, 102}, {33, 88}, {34, 86}, {35, 78}, + {36, 78}, {37, 78}, {38, 80}, {39, 80}, {40, 82}, {41, 82}, {42, 88}, {43, 90}, {44, 96}}; + dataSerial_->AddPoints(pointArray, XAXIS_SETDATARANGE); + dataSerial_->SetLineColor(Color::Red()); + dataSerial_->SetFillColor(Color::Red()); + dataSerial_->EnableGradient(true); + + chartPolyline_ = new UIChartPolyline(); + if (chartPolyline_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new chartPolyline_ fail"); + return; + } + chartPolyline_->SetPosition(COORDINATE_POINT_X, COORDINATE_POINT_Y); + chartPolyline_->SetWidth(COORDINATE_WIDTH); + chartPolyline_->SetHeight(COORDINATE_HEIGHT); + chartPolyline_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + chartPolyline_->SetStyle(STYLE_BACKGROUND_OPA, 0); + chartPolyline_->SetStyle(STYLE_LINE_WIDTH, XAXIS_LINENUM); + + UIXAxis &xAxis = chartPolyline_->GetXAxis(); + UIYAxis &yAxis = chartPolyline_->GetYAxis(); + xAxis.SetDataRange(0, XAXIS_SETDATARANGE); + yAxis.SetDataRange(0, YAXIS_SETDATARANGE); + xAxis.SetMarkNum(XAXIS_SETMARKNUM); + yAxis.SetMarkNum(YAXIS_SETMARKNUM); + xAxis.SetStyle(STYLE_LINE_COLOR, 0x14FF5F5F5); + yAxis.SetStyle(STYLE_LINE_COLOR, 0x14FF5F5F5); + chartPolyline_->SetGradientOpacity(CHART_LINE_NUM_ONE, CHART_LINE_NUM_TWO); + chartPolyline_->AddDataSerial(dataSerial_); + Add(chartPolyline_); + + labelXAxisPointOne_ = new UILabel(); + if (labelXAxisPointOne_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointOne_ fail"); + return; + } + labelXAxisPointOne_->SetText("00:00"); + labelXAxisPointOne_->SetPosition(HEART_LABLE_ONE_POSION_X, HEART_LABLE_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelXAxisPointOne_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelXAxisPointOne_); + + labelXAxisPointTwo_ = new UILabel(); + if (labelXAxisPointTwo_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointTwo_ fail"); + return; + } + labelXAxisPointTwo_->SetText("12:00"); + labelXAxisPointTwo_->SetPosition(HEART_LABLE_THREE_POSION_X, HEART_LABLE_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelXAxisPointTwo_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelXAxisPointTwo_); + labelXAxisPointThree_ = new UILabel(); + if (labelXAxisPointThree_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelXAxisPointThree_ fail"); + return; + } + labelXAxisPointThree_->SetText("24:00"); + labelXAxisPointThree_->SetPosition(HEART_LABLE_FIVE_POSION_X, HEART_LABLE_POSION_Y, TOP_TEXT_WIDTH, + TOP_TEXT_HEIGHT); + labelXAxisPointThree_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelXAxisPointThree_); + + labelYAxisPointOne_ = new UILabel(); + if (labelYAxisPointOne_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelYAxisPointOne_ fail"); + return; + } + labelYAxisPointOne_->SetText("50"); + labelYAxisPointOne_->SetPosition(HEART_LABLE_POSION_X, HEART_LABLE1_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelYAxisPointOne_->SetAlign(TEXT_ALIGNMENT_RIGHT); + labelYAxisPointOne_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelYAxisPointOne_); + + labelYAxisPointTwo_ = new UILabel(); + if (labelYAxisPointTwo_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelYAxisPointTwo_ fail"); + return; + } + labelYAxisPointTwo_->SetText("100"); + labelYAxisPointTwo_->SetPosition(HEART_LABLE_POSION_X, HEART_LABLE2_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelYAxisPointTwo_->SetAlign(TEXT_ALIGNMENT_RIGHT); + labelYAxisPointTwo_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelYAxisPointTwo_); + + labelYAxisPointThree_ = new UILabel(); + if (labelYAxisPointThree_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelYAxisPointThree_ fail"); + return; + } + labelYAxisPointThree_->SetText("150"); + labelYAxisPointThree_->SetPosition(HEART_LABLE_POSION_X, HEART_LABLE3_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelYAxisPointThree_->SetAlign(TEXT_ALIGNMENT_RIGHT); + labelYAxisPointThree_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelYAxisPointThree_); + + labelYAxisPointFour_ = new UILabel(); + if (labelYAxisPointFour_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelYAxisPointFour_ fail"); + return; + } + labelYAxisPointFour_->SetText("200"); + labelYAxisPointFour_->SetPosition(HEART_LABLE_POSION_X, HEART_LABLE4_POSION_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelYAxisPointFour_->SetAlign(TEXT_ALIGNMENT_RIGHT); + labelYAxisPointFour_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_X_FONT_SIZE); + Add(labelYAxisPointFour_); + + labelMaxValue_ = new UILabel(); + if (labelMaxValue_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelMaxValue_ fail"); + return; + } + + // 打桩数据,后续需要根据测量结果修改最大值显示 + labelMaxValue_->SetText("148"); + labelMaxValue_->SetPosition(TOP_TEXT_X, TOP_TEXT_Y, TOP_TEXT_WIDTH, TOP_TEXT_HEIGHT); + labelMaxValue_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_LIMIT_FONT_SIZE); + Add(labelMaxValue_); + + imageRedArrow_ = new UIImageView(); + if (imageRedArrow_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imageRedArrow_ fail"); + return; + } + imageRedArrow_->SetPosition(IMAGE_RED_TEXT_X, IMAGE_RED_TEXT_Y); + imageRedArrow_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(imageRedArrow_, HEART_RATE_IMAGE, IMAGE_HEART_RATE_UP); + Add(imageRedArrow_); + labelMinValue_ = new UILabel(); + if (labelMinValue_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelMinValue_ fail"); + return; + } + + // 打桩数据,后续需要根据测量结果修改最小值显示 + labelMinValue_->SetText("59"); + labelMinValue_->SetPosition(BOTTOM_TEXT_X, BOTTOM_TEXT_Y, BOTTOM_TEXT_WIDTH, BOTTOM_TEXT_HEIGHT); + labelMinValue_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_LIMIT_FONT_SIZE); + Add(labelMinValue_); + + imageBlackArrow_ = new UIImageView(); + if (imageBlackArrow_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imageBlackArrow_ fail"); + return; + } + imageBlackArrow_->SetPosition(IMAGE_BACK_TEXT_X, IMAGE_BACK_TEXT_Y); + imageBlackArrow_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(imageBlackArrow_, HEART_RATE_IMAGE, IMAGE_HEART_RATE_DOWN); + Add(imageBlackArrow_); + + labelLastMeasureTime_ = new UILabel(); + if (labelLastMeasureTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelLastMeasureTime_ fail"); + return; + } + labelLastMeasureTime_->SetText("刚刚"); + labelLastMeasureTime_->SetPosition(BOTTOM_TEXT_ONE_X, BOTTOM_TEXT_ONE_Y, BOTTOM_TEXT_WIDTH_ONE, + BOTTOM_TEXT_HEIGHT_ONE); + labelLastMeasureTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEART_RATE_LIMIT_FONT_SIZE_ONE); + labelLastMeasureTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelLastMeasureTime_->SetStyle(STYLE_TEXT_COLOR, 0xFFCCCCCC); + labelLastMeasureTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + Add(labelLastMeasureTime_); + + SetDraggable(true); + SetTouchable(true); + InitImageAnimator(); +} + +HeartRateResultGroup::~HeartRateResultGroup() +{ + RemoveAll(); + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + if (labelHeartRateValue_ != nullptr) { + delete labelHeartRateValue_; + labelHeartRateValue_ = nullptr; + } + if (chartPolyline_ != nullptr) { + delete chartPolyline_; + chartPolyline_ = nullptr; + } + if (labelLastMeasureTime_ != nullptr) { + delete labelLastMeasureTime_; + labelLastMeasureTime_ = nullptr; + } + if (labelMaxValue_ != nullptr) { + delete labelMaxValue_; + labelMaxValue_ = nullptr; + } + if (labelMinValue_ != nullptr) { + delete labelMinValue_; + labelMinValue_ = nullptr; + } + if (labelUnitText_ != nullptr) { + delete labelUnitText_; + labelUnitText_ = nullptr; + } + if (imageAnimator_ != nullptr) { + delete imageAnimator_; + imageAnimator_ = nullptr; + } + if (dataSerial_ != nullptr) { + delete dataSerial_; + dataSerial_ = nullptr; + } + if (imageRedArrow_ != nullptr) { + delete imageRedArrow_; + imageRedArrow_ = nullptr; + } + if (imageBlackArrow_ != nullptr) { + delete imageBlackArrow_; + imageBlackArrow_ = nullptr; + } + if (labelXAxisPointOne_ != nullptr) { + delete labelXAxisPointOne_; + labelXAxisPointOne_ = nullptr; + } + if (labelXAxisPointTwo_ != nullptr) { + delete labelXAxisPointTwo_; + labelXAxisPointTwo_ = nullptr; + } + if (labelXAxisPointThree_ != nullptr) { + delete labelXAxisPointThree_; + labelXAxisPointThree_ = nullptr; + } + if (labelYAxisPointOne_ != nullptr) { + delete labelYAxisPointOne_; + labelYAxisPointOne_ = nullptr; + } + if (labelYAxisPointTwo_ != nullptr) { + delete labelYAxisPointTwo_; + labelYAxisPointTwo_ = nullptr; + } + if (labelYAxisPointThree_ != nullptr) { + delete labelYAxisPointThree_; + labelYAxisPointThree_ = nullptr; + } + if (labelYAxisPointFour_ != nullptr) { + delete labelYAxisPointFour_; + labelYAxisPointFour_ = nullptr; + } + if (mainImg_ != nullptr) { + delete mainImg_; + mainImg_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(HEART_RATE_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartRateResultGroup::~HeartRateResultGroup"); +} + +void HeartRateResultGroup::InitImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new imageAnimator_ fail"); + return; + } + for (uint8_t i = 0; i < HEARTRATE_ANIMATOR_IMAGE_NUM; i++) { + imageAnimatorImageInfo_[i].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[i], HEART_RATE_IMAGE); + imageAnimatorImageInfo_[i].imageType = IMG_SRC_IMAGE_INFO; + imageAnimatorImageInfo_[i].pos.x = ANIMATOR_IMAGE_X; + imageAnimatorImageInfo_[i].pos.y = ANIMATOR_IMAGE_Y; + imageAnimatorImageInfo_[i].width = ANIMATOR_IMAGE_WIDTH; + imageAnimatorImageInfo_[i].height = ANIMATOR_IMAGE_HEIGHT; + } + + imageAnimator_->SetPosition(PERSEC_HEART_TEXT_X, PERSEC_HEART_TEXT_Y); + imageAnimator_->SetImageAnimatorSrc(imageAnimatorImageInfo_, HEARTRATE_ANIMATOR_IMAGE_NUM, + HEARTRATE_ANIMATOR_IMAGE_UPDATE); + imageAnimator_->SetRepeat(true); + imageAnimator_->SetAutoEnable(false); + imageAnimator_->SetResizeMode(UIImageView::FILL); + imageAnimator_->Start(); + imageAnimator_->LayoutCenterOfParent(); + imageAnimator_->SetDraggable(true); + Add(imageAnimator_); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/activity/MainActivityView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/activity/MainActivityView.h index 2d0a6877d..b63973900 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/activity/MainActivityView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/activity/MainActivityView.h @@ -19,7 +19,6 @@ #include "font/ui_font_bitmap.h" #include "font/ui_font.h" #include "graphic_config.h" -#include "main/ModelListenerSample.h" #include "activity/ActivityModel.h" #include "activity/ActivityPresenter.h" #include "activity/ActivityWeekView.h" diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h index 073294924..11c5211ed 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h @@ -26,12 +26,12 @@ #include "components/ui_label_button.h" #include "components/ui_digital_clock.h" #include "gfx_utils/graphic_log.h" -#include "main/ModelListenerSample.h" #include "alarm/AlarmCloseRingView.h" #include "alarm/AlarmRingView.h" #include "alarm/AlarmPopUpView.h" #include "alarm/AlarmClockModel.h" #include "wearable_log.h" +#include "common/task.h" namespace OHOS { #define SET_TIME "settime" @@ -49,7 +49,7 @@ typedef enum { class AlarmPopUpView; class AlarmPopUpPresenter : public Presenter, public UIView::OnClickListener, - public UIView::OnDragListener, public ModelListenerSample { + public UIView::OnDragListener, public Task { public: AlarmPopUpPresenter(); ~AlarmPopUpPresenter() override; @@ -57,9 +57,11 @@ public: bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; bool OnDragEnd(UIView& view, const DragEvent& event) override; - void Notify() override; + void Callback() override; void CancelAlarmRing(void); void DelayAlarmRing(void); + void OnPause() override; + void OnResume() override; private: bool isStartCalcu{true}; uint16_t calcuNotifyNums{0}; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodPresenter.h index 0216f983f..d7f548924 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodPresenter.h @@ -11,18 +11,20 @@ #include "aod_view/AodView.h" #include "components/ui_view.h" #include "key/KeyInputListener.h" -#include "main/ModelListenerSample.h" +#include "common/task.h" namespace OHOS { class AodView; class AodModel; -class AodPresenter : public Presenter, public ModelListenerSample { +class AodPresenter : public Presenter, public Task { public: AodPresenter() {} ~AodPresenter() override {} AodPresenter(const AodPresenter &) = delete; AodPresenter &operator=(const AodPresenter &) = delete; - void Notify() override; + void OnResume() override; + void OnPause() override; + void Callback() override; }; // AodPresenter } // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodView.h index e012a460a..99f05876a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/aod_view/AodView.h @@ -9,10 +9,10 @@ #define AODVIEW_H #include "View.h" #include "main/MainModel.h" -#include "set_dial/SetDialInfo.h" #include "main/DialBinTypesV2.h" #include "components/ui_view.h" #include "components/ui_card_page.h" +#include "components/ui_fragment.h" namespace OHOS { class AodPresenter; @@ -25,7 +25,7 @@ public: void OnStart() override; void OnStop() override; - void PeriodicUpdate(); + void Update(); private: UIViewGroup *InitAodDial(DialSetting &setting); @@ -33,7 +33,8 @@ private: UIViewGroup *InitDefaultAod(); bool isLoaded_ = false; - UIViewGroup *clockDial_; + UIViewGroup *clockDial_{nullptr}; + UIFragment *clockDialFragment_{nullptr}; }; } // OHOS #endif // AODVIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/AppItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/AppItemView.h index 51eb58cfa..fa19b4914 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/AppItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/AppItemView.h @@ -33,46 +33,6 @@ private: UILabelExt label_; AppItem itemInfo_; }; - -class HexagonsItemView : public UIImageView { -public: - explicit HexagonsItemView(); - ~HexagonsItemView(); - void SetItemInfo(const AppItem &itemInfo); - AppViewId GetViewId(); - const char *GetAppUid(); -private: - HexagonsItemView(const HexagonsItemView &); - HexagonsItemView &operator = (const HexagonsItemView &); - AppItem itemInfo_; -}; - -class FootballItemView : public UIImageView { -public: - explicit FootballItemView() {} - ~FootballItemView(); - void SetItemInfo(const AppItem &itemInfo); - AppViewId GetViewId(); - const char *GetAppUid(); -private: - FootballItemView(const FootballItemView &); - FootballItemView &operator = (const FootballItemView &); - AppItem itemInfo_; -}; - - -class WaterfallItemView : public UIImageView { -public: - explicit WaterfallItemView() {} - ~WaterfallItemView(); - void SetItemInfo(const AppItem &itemInfo); - AppViewId GetViewId(); - const char *GetAppUid(); -private: - WaterfallItemView(const WaterfallItemView &); - WaterfallItemView &operator = (const WaterfallItemView &); - AppItem itemInfo_; -}; } #endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistModel.h index 1cd7bd0df..5371b1a67 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistModel.h @@ -57,13 +57,6 @@ struct AppItem { uid(uid) {} }; -enum AppListStyle { - APPLIST_STYLE, - HEXAGONS_STYLE, - FOOTBALL_STYLE, - WATERFALL_STYLE -}; - class ApplistPresenter; class ApplistModel { public: @@ -75,12 +68,14 @@ public: void ResolvingJSAppItems(void); void SetStartIndex(uint16_t index); uint16_t GetStartIndex(void); + void SetLastOffset(int16_t x, int16_t y); + void GetLastOffset(int16_t& x, int16_t& y); void SetHeadItemY(int index); int GetHeadItemY(void); void ApplistUpdate(void); void SetPresenter(ApplistPresenter *p); - AppListStyle GetCurrentStyle(void); void SetInitFlag(bool flag); + void CleanupApplistStrings(uint8_t nativeAppNumTotal); private: ApplistModel(); @@ -93,9 +88,11 @@ private: BundleInfo *bundleInfos = nullptr; int32 bundleLen = 0; uint8 appLen = 0; - + uint8 nativeAppNumTotal = 0; uint16_t startIndex = 0; int headItemY = 0; + int16_t lastOffsetX = 0; + int16_t lastOffsetY = 0; bool initFlag{false}; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistPresenter.h index 1275b0a5d..4e47b734f 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistPresenter.h @@ -9,37 +9,21 @@ #define APPLIST_PRESENTER_H #include "Presenter.h" -#include "ohos_types.h" -#include "applist/AppItemView.h" -#include "applist/ApplistView.h" -#include "applist/ApplistModel.h" -#include "components/root_view.h" +#include "ApplistView.h" +#include "ApplistModel.h" namespace OHOS { - class ApplistPresenter : public Presenter, public UIView::OnClickListener, - public ListScrollListener, public UIView::OnRotateListener { - public: - ApplistPresenter(); - ~ApplistPresenter() override; +class ApplistPresenter : public Presenter { +public: + ApplistPresenter(); + ~ApplistPresenter() override; + void OnStart() override; + void OnResume() override; + ApplistView* GetAppListView(); - void OnStart() override; - void OnResume() override; - bool OnRotate(UIView& view, const RotateEvent& event) override; - bool OnClick(UIView &view, const ClickEvent &event) override; - void OnItemSelected(int16 index, UIView *view) override; - void SetStartIndex(uint16_t index); - uint16_t GetStartIndex(void); - void SetHeadItemY(int y); - int GetHeadItemY(void); - uint8_t GetListItemNum(void); - ApplistView* GetAppListView(); - AppListStyle GetCurrentStyle(void); - - private: - AppItemView *itemViewSele{nullptr}; - AppItemView *preItemViewSele{nullptr}; - ApplistModel *model{nullptr}; - }; +private: + ApplistModel *model{nullptr}; +}; } #endif // APPLIST_PRESENTER_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistView.h index ab2ce4adb..7e502f0ab 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ApplistView.h @@ -9,147 +9,24 @@ #define APPLIST_VIEW_H #include "View.h" -#include "animator/animator_manager.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" -#include "components/ui_label.h" -#include "components/ui_list.h" -#include "components/ui_custom_hexagons_list.h" -#include "components/ui_waterfall_list.h" -#include "components/ui_icosahedron_view.h" -#include "gfx_utils/list.h" -#include "ohos_types.h" -#include "applist/ApplistAdapter.h" -#include "ChangeSliceListener.h" -#include "drag_event.h" -#include "UiConfig.h" +#include "UIDesktopFragment.h" namespace OHOS { -class AppListOnDragListener : public UIView::OnDragListener { -public: - AppListOnDragListener() - { - continueDrag = false; - } - ~AppListOnDragListener() override {} - bool OnDragStart(UIView& view, const DragEvent& event) override - { - UNUSED(view); - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondragstart!!"); - continueDrag = true; - return false; - } - - bool OnDrag(UIView& view, const DragEvent& event) override - { - UNUSED(view); - if (!continueDrag) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppList : Can not continue drag!!"); - return false; - } - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && - (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!"); - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TransitionType::TRANSITION_ZOOM); - } - - return false; - } - - bool OnDragEnd(UIView& view, const DragEvent& event) override - { - UNUSED(view); - UNUSED(event); - return false; - } -private: - bool continueDrag{false}; -}; - -class FootballAnimatorCallback : public AnimatorCallback { -public: - explicit FootballAnimatorCallback(UIView* view, int16_t startPos, int16_t endPos) - : startPos_(startPos), - endPos_(endPos), - startTime_(0), - animator_(new Animator(this, view, 1000, false)) {} // 1000:duration of animator_, in milliseconds. - - ~FootballAnimatorCallback() override - { - if (animator_ != nullptr) { - delete animator_; - animator_ = nullptr; - } - } - - void Callback(UIView* view) override; - - Animator* GetAnimator() const - { - return animator_; - } - - void SetStartTime(uint32_t time) - { - isStartAnim_ = false; - startTime_ = time; - } -protected: - int16_t startPos_; - int16_t endPos_; - uint32_t startTime_; - bool isStartAnim_ = false; - Animator* animator_; -}; - class ApplistPresenter; class ApplistView : public View { public: - ApplistView(); - ~ApplistView() override; + ApplistView() {}; + ~ApplistView() override {}; void OnStart() override; void OnStop() override; - - void LoadAppIconImage(UIImageView *view, const uint32_t id, const char *path); + void OnResume(); void AddAppItemToList(const AppItem &item); void ClearAppItemToList(); - void RefreshAppList(void); - void StartFootBallAnimator(); - void ResumeWaterFallDraggable(); + void RefreshAppList(); private: - /* for list style */ - void ListStyleOnStart(); - void ListStyleOnStop(); - ApplistAdapter *listAdapter_{nullptr}; - UIList *contentList_{nullptr}; - UIView::OnDragListener *dragListener_{nullptr}; - - /* for hexagons style */ - void HexagonsStyleOnStart(); - void HexagonsStyleOnStop(); - UICustomHexagonsList* hexagonsList_{nullptr}; - List listHexagonsView_; - uint16_t imgSize_ = 0; - uint16_t imgDistance_ = 0; - - /* for football style */ - void FootballStyleOnStart(); - void FootballStyleOnStop(); - UIIcosahedronView* footballList_ = nullptr; - List footballItemList_; - ImageInfo* footballDefaultImg_ = nullptr; - FootballAnimatorCallback* callback_ = nullptr; - Animator* enterAnimator_ = nullptr; - - /* for waterfall style */ - void WaterfallStyleOnStart(); - void WaterfallStyleOnStop(); - UIWaterfallList* waterfallList_{nullptr}; - List waterfallItemList_; + UIDesktopFragment *desktopFragment_ = nullptr; }; } -#endif // APPLIST_VIEW_H \ No newline at end of file +#endif // APPLIST_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/DesktopFactory.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/DesktopFactory.h new file mode 100644 index 000000000..f95f8af7f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/DesktopFactory.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: DesktopFactory + * Author: + * Create: 2025-07 + */ + +#ifndef DESKTOP_FACTORY_H +#define DESKTOP_FACTORY_H + +#include +#include "UIDesktopFragment.h" + +namespace OHOS { +class DesktopInterface; +class DesktopFactory { +public: + static DesktopFactory& GetInstance() + { + static DesktopFactory instance; + return instance; + } + void RegisterDesktopStyle(const uint16_t style, DesktopInterface* desktop); + UIDesktopFragment* CreateDesktopStyle(uint16_t style); + +private: + DesktopFactory() {}; + ~DesktopFactory() {}; + DesktopFactory(const DesktopFactory&) = delete; + DesktopFactory &operator=(const DesktopFactory&) = delete; + std::unordered_map desktops_; +}; + +class DesktopStyleRegister { +public: + DesktopStyleRegister(const uint16_t style, DesktopInterface* uiCardPage) + { + DesktopFactory::GetInstance().RegisterDesktopStyle(style, uiCardPage); + } +}; + +class DesktopInterface { +public: + virtual UIDesktopFragment* CreateDesktop() = 0; + DesktopInterface() = default; + virtual ~DesktopInterface() = default; + DesktopInterface(const DesktopInterface&) = delete; + DesktopInterface& operator=(const DesktopInterface&) = delete; + DesktopInterface(DesktopInterface&&) = delete; + DesktopInterface& operator=(DesktopInterface&&) = delete; +}; + +template +class DesktopProxy : public DesktopInterface { +public: + UIDesktopFragment* CreateDesktop() override + { + D* d = new D(); + UIDesktopFragment* fragment = dynamic_cast(d); + if (fragment == nullptr) { + delete d; + } + return fragment; + } +}; +} // namespace OHOS + +#define REGIST_DESKTOP_STYLE(style, D) \ + const static OHOS::DesktopStyleRegister (STATIC_VAR)(static_cast(style), new DesktopProxy()) + +#endif // DESKTOP_FACTORY_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/FootballDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/FootballDesktopFragment.h new file mode 100644 index 000000000..7c107603b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/FootballDesktopFragment.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: FootballDesktopFragment.h + * Author: + * Create: 2025-07-04 + */ + +#ifndef FOOTBALL_DESKTOP_FRAGMENT_H +#define FOOTBALL_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_icosahedron_view.h" + +namespace OHOS { +class FootballAnimatorCallback; +class FootballItemView; +class FootballDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + void OnResumeView() override; + +private: + UIIcosahedronView* footballList_ = nullptr; + List footballItemList_; + ImageInfo* footballDefaultImg_ = nullptr; + FootballAnimatorCallback* callback_ = nullptr; + Animator* enterAnimator_ = nullptr; +}; + +class FootballAnimatorCallback : public AnimatorCallback { +public: + explicit FootballAnimatorCallback(UIView* view, int16_t startPos, int16_t endPos) + : startPos_(startPos), + endPos_(endPos), + startTime_(0), + animator_(new Animator(this, view, 1000, false)) {} // 1000:duration of animator_, in milliseconds. + + ~FootballAnimatorCallback() override + { + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + } + + void Callback(UIView* view) override; + + Animator* GetAnimator() const + { + return animator_; + } + + void SetStartTime(uint32_t time) + { + isStartAnim_ = false; + startTime_ = time; + } +protected: + int16_t startPos_; + int16_t endPos_; + uint32_t startTime_; + bool isStartAnim_ = false; + Animator* animator_; +}; + +class FootballItemView : public UIImageView { +public: + explicit FootballItemView() {} + ~FootballItemView() override; + bool SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + FootballItemView(const FootballItemView &); + FootballItemView &operator = (const FootballItemView &); + AppItem itemInfo_; +}; +} + +#endif // FOOTBALL_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/HexagonsDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/HexagonsDesktopFragment.h new file mode 100644 index 000000000..fded07dcc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/HexagonsDesktopFragment.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: HexagonsDesktopFragment.h + * Author: + * Create: 2025-07-04 + */ + +#ifndef HEXAGONS_DESKTOP_FRAGMENT_H +#define HEXAGONS_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_custom_hexagons_list.h" + +namespace OHOS { +class HexagonsItemView; +class HexagonsDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnRotate(UIView& view, const RotateEvent& event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + UICustomHexagonsList* hexagonsList_{nullptr}; + List listHexagonsView_; +}; + +class HexagonsItemView : public UIImageView { +public: + explicit HexagonsItemView() {}; + ~HexagonsItemView(); + bool SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + HexagonsItemView(const HexagonsItemView &); + HexagonsItemView &operator = (const HexagonsItemView &); + AppItem itemInfo_; +}; +} + +#endif // HEXAGONS_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ListDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ListDesktopFragment.h new file mode 100644 index 000000000..6e8fbc773 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/ListDesktopFragment.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: ListDesktopFragment.h + * Author: + * Create: 2025-07-04 + */ + +#ifndef LIST_DESKTOP_FRAGMENT_H +#define LIST_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "ApplistAdapter.h" +#include "ChangeSliceListener.h" +#include "components/ui_list.h" +#include "drag_event.h" + +namespace OHOS { +class ListDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void OnItemSelected(int16 index, UIView *view) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + ApplistAdapter *listAdapter_{nullptr}; + UIList *contentList_{nullptr}; + UIView::OnDragListener *dragListener_{nullptr}; + AppItemView *itemViewSele{nullptr}; + AppItemView *preItemViewSele{nullptr}; +}; + +class AppListOnDragListener : public UIView::OnDragListener { +public: + AppListOnDragListener() + { + continueDrag_ = false; + } + ~AppListOnDragListener() override {} + bool OnDragStart(UIView& view, const DragEvent& event) override + { + UNUSED(view); + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondragstart!!"); + continueDrag_ = true; + return false; + } + + bool OnDrag(UIView& view, const DragEvent& event) override + { + UNUSED(view); + if (!continueDrag_) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppList : Can not continue drag!!"); + return false; + } + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!"); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TransitionType::TRANSITION_ZOOM); + } + + return false; + } + + bool OnDragEnd(UIView& view, const DragEvent& event) override + { + UNUSED(view); + UNUSED(event); + return false; + } +private: + bool continueDrag_{false}; +}; +} + +#endif // LIST_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/PlanetDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/PlanetDesktopFragment.h new file mode 100644 index 000000000..fa4982c11 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/PlanetDesktopFragment.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlanetDesktop + * Created: 2025-07-29 + */ + +#ifndef PLANET_DESKTOP_FRAGMENT_H +#define PLANET_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_custom_planet_list.h" + +namespace OHOS { +class PlanetItemView; +class PlanetDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + UICustomPlanetList* planetList_{nullptr}; + List pltItemList_; + List pltLabelList_; +}; + +class PlanetItemView : public UIImageView { +public: + explicit PlanetItemView() {} + ~PlanetItemView() {} + void SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); + const char *GetAppLabel(); + +private: + PlanetItemView(const PlanetItemView &) = delete; + PlanetItemView &operator = (const PlanetItemView &) = delete; + AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; +}; +} + +#endif // PLANET_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/SphereDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/SphereDesktopFragment.h new file mode 100644 index 000000000..28c34e977 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/SphereDesktopFragment.h @@ -0,0 +1,93 @@ + /* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: SphereDesktopFragment + * Author: Hisi Graphic Team + * Created: 2025-09 + */ + +#ifndef SPHERE_DESKTOP_FRAGMENT_H +#define SPHERE_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_sphere_view.h" +#include "components/ui_transform_group.h" + +namespace OHOS { +class SphereAnimatorCallback; +class SphereItemView; +class SphereDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnRotate(UIView& view, const RotateEvent& event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + void OnResumeView() override; + +private: + UISphereView* sphereView_{nullptr}; + List listSphereView_; + SphereAnimatorCallback* callback_ = nullptr; + Animator* enterAnimator_ = nullptr; +}; + +class SphereAnimatorCallback : public AnimatorCallback { +public: + explicit SphereAnimatorCallback(UIView* view, int16_t width, int16_t height) + : width_(width), + height_(height), + startTime_(0), + passTime_(0), + angle_(0), + animator_(new Animator(this, view, 600, false)) {} // 600 ms:duration of animator_ + + ~SphereAnimatorCallback() override + { + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + } + + void Callback(UIView* view) override; + + Animator* GetAnimator() const + { + return animator_; + } + + void SetStartTime(uint32_t time) + { + isStartAnim_ = false; + startTime_ = time; + } +protected: + int16_t width_; + int16_t height_; + uint32_t startTime_; + uint32_t passTime_; + bool isStartAnim_ = false; + int16_t angle_; + Animator* animator_; +}; + +class SphereItemView : public UITransformGroup { +public: + explicit SphereItemView() {}; + ~SphereItemView(); + bool SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + SphereItemView(const SphereItemView &); + SphereItemView &operator = (const SphereItemView &); + UIImageView* imageView_{nullptr}; + AppItem itemInfo_; +}; +} + +#endif // SPHERE_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/UIDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/UIDesktopFragment.h new file mode 100644 index 000000000..6bb8237d8 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/UIDesktopFragment.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: UIDesktopFragment.h + * Author: + * Create: 2025-07-07 + */ + +#ifndef UI_DESKTOP_FRAGMENT_H +#define UI_DESKTOP_FRAGMENT_H + +#include "applist/AppItemView.h" +#include "components/ui_fragment.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "settings/model/SettingDesktopModel.h" +#include "TransitionType.h" +#include "ohos_types.h" +#include "wearable_log.h" + +namespace OHOS { +class UIDesktopFragment : public UIFragment, public UIView::OnClickListener, + public ListScrollListener, public UIView::OnRotateListener { +public: + virtual void AddAppItemToList(const AppItem &item) = 0; + virtual void ClearAppItemToList() = 0; + virtual void RefreshAppList() = 0; + void SetPosition(int16_t x, int16_t y, int16_t width, int16_t height); + +protected: + uint16_t imgSize_ = 0; + uint16_t imgDistance_ = 0; + void OnCreateView(void* data) override {}; + void OnDestroyView() override {}; + bool SwitchView(AppViewId viewId, char *uid, TransitionType type, DesktopStyle style); +}; +} +#endif // UI_DESKTOP_FRAGMENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/WaterfallDesktopFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/WaterfallDesktopFragment.h new file mode 100644 index 000000000..4a2fa1833 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/applist/WaterfallDesktopFragment.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: WaterfallDesktopFragment.h + * Author: + * Create: 2025-07-04 + */ + +#ifndef WATERFALL_DESKTOP_FRAGMENT_H +#define WATERFALL_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_waterfall_list.h" + +namespace OHOS { +class WaterfallItemView; +class WaterfallDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + void OnResumeView() override; + +private: + UIWaterfallList* waterfallList_{nullptr}; + List waterfallItemList_; +}; + +class WaterfallItemView : public UIImageView { +public: + explicit WaterfallItemView() {} + ~WaterfallItemView(); + bool SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + WaterfallItemView(const WaterfallItemView &); + WaterfallItemView &operator = (const WaterfallItemView &); + AppItem itemInfo_; +}; +} + +#endif // WATERFALL_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodChartPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodChartPage.h new file mode 100644 index 000000000..f615267ce --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodChartPage.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodChartPage + * Create: 2025-06 + */ + +#ifndef BLOOD_CHART_PAGE_H +#define BLOOD_CHART_PAGE_H + +#include +#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" +#include "components/ui_swipe_view.h" +#include "components/ui_label.h" +#include "components/ui_chart.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "BloodView.h" +#include "BloodPresenter.h" + +namespace OHOS { +static constexpr uint8_t HEART_AVE_NUM = 360; +static constexpr uint8_t BLOOD_ANIMATOR_IMAGE_NUM = 30; +static constexpr uint8_t BLOOD_ANIMATOR_IMAGE_UPDATE = 40; +static constexpr uint8_t INDEX_1 = 1; +static constexpr uint8_t INDEX_2 = 2; +static constexpr uint8_t INDEX_3 = 3; +static constexpr uint8_t DATA_SERIAL_COUNT = 4; +class BloodPresenter; +class BloodChartPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodChartPage(); + ~BloodChartPage() override; + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitImageAnimator(); + +private: + UIViewGroup *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelTestTime_ = nullptr; + UILabel *labelXAxisPointOne_ = nullptr; + UILabel *labelXAxisPointTwo_ = nullptr; + UILabel *labelXAxisPointThree_ = nullptr; + UILabelButton *labelButtonRetest_ = nullptr; + UIChartDataSerial *dataSerial_{nullptr}; + UIChartPillar *chartPillar_ = nullptr; + UIImageView *mainImg_ = nullptr; + UIImageView *chartImg_ = nullptr; + UIImageAnimatorView *imageAnimator_ = nullptr; + ImageAnimatorInfo imageAnimatorImageInfo_[BLOOD_ANIMATOR_IMAGE_NUM]; +}; +} +#endif // BLOOD_CHART_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodExplainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodExplainPage.h new file mode 100644 index 000000000..7bc842158 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodExplainPage.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodExplainPage + * Create: 2025-06 + */ + +#ifndef BLOOD_EXPLAIN_PAGE_H +#define BLOOD_EXPLAIN_PAGE_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "BloodView.h" +#include "BloodModel.h" +#include "BloodPresenter.h" + +namespace OHOS { +static constexpr uint8_t LABEL_DES_COUNT = 4; +class BloodPresenter; +class BloodModel; +class BloodExplainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodExplainPage(); + ~BloodExplainPage() override; + static BloodExplainPage *GetInstance(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool InitSimilarLabel(int16 num, int16 labelX, int16 labelY, const char *labelText); +private: + UIScrollView *scrollGroup_ = nullptr; + UIImageView *imgNormal_ = nullptr; + UIImageView *imgGeneral_ = nullptr; + UIImageView *imgAbnormal_ = nullptr; + UILabel *labelNormal_ = nullptr; + UILabel *labelGeneral_ = nullptr; + UILabel *labelAbnormal_ = nullptr; + UILabel *labelDes_[LABEL_DES_COUNT]{nullptr}; +}; +} +#endif // BLOOD_EXPLAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMainPage.h new file mode 100644 index 000000000..12ec04ba0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMainPage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodMainPage + * Create: 2025-06 + */ + +#ifndef BLOOD_MAIN_PAGE_H +#define BLOOD_MAIN_PAGE_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_lite_surface_view.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "layout/grid_layout.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "video_play_wrapper.h" +#include "BloodModel.h" +#include "BloodPresenter.h" +#include "BloodView.h" + +namespace OHOS { +class BloodPresenter; +class BloodModel; +class BloodMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodMainPage(); + ~BloodMainPage() override; + static BloodMainPage *GetInstance(); + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnResume() override; + void OnPause() override; + void InitImageAnimator(); + bool IsToday(const struct timeval &tv); + void SetTestTime(); +private: + UIViewGroup *group_ = nullptr; + UILabelButton *buttonStart_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelPreTest_ = nullptr; + UILiteSurfaceView *surfaceView_ = nullptr; + MediaVideoPlay *videoPlay_ = nullptr; + ColorType colorKey_; +}; +} +#endif // BLOOD_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMeasurementPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMeasurementPage.h new file mode 100644 index 000000000..087e18f6f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodMeasurementPage.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodMeasurementPage + * Create: 2025-06 + */ + +#ifndef BLOOD_MEASUREMENT_PAGE_H +#define BLOOD_MEASUREMENT_PAGE_H + +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_lite_surface_view.h" +#include "layout/grid_layout.h" +#include "animator/animator.h" +#include "ChangeSliceListener.h" +#include "video_play_wrapper.h" +#include "View.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "BloodModel.h" +#include "BloodPresenter.h" +#include "BloodView.h" + + +namespace OHOS { +class BloodPresenter; +class BloodModel; +class BloodMeasurementPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodMeasurementPage(); + ~BloodMeasurementPage() override; + void OnStart(void *data) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnResume() override; + void OnPause() override; + void InitImageAnimator(); + void InitAnimator(); + void SetLabelTime(std::string str); + void StopAnimator(); + void ShowOnMeasurement(); + void StartAnimator(); +private: + UIViewGroup *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelTips_ = nullptr; + UILabel *labelTime_ = nullptr; + UILiteSurfaceView *surfaceView_ = nullptr; + MediaVideoPlay *videoPlay_ = nullptr; + ColorType colorKey_; + struct timeval startTime_; + class BloodAnimatorCallback : public AnimatorCallback { + public: + explicit BloodAnimatorCallback(BloodMeasurementPage *page) : page_(page) {} + ~BloodAnimatorCallback() override {} + void Callback(UIView *view) override; + private: + BloodMeasurementPage *page_{nullptr}; + }; + Animator *animator_ = nullptr; + BloodAnimatorCallback *callBack_ = nullptr; +}; +} +#endif // BLOOD_MEASUREMENT_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodModel.h index 47a2cae25..dd5e6f38a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodModel.h @@ -1,8 +1,7 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: SettingModel.h - * Author: - * Create: 2025-03-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodModel + * Create: 2025-06 */ #ifndef BLOOD_MODEL_H @@ -10,26 +9,32 @@ #include #include +#include #include "graphic_timer.h" namespace OHOS { - class BloodModel { - public: - static BloodModel &GetInstance(void); - bool GetbuttonStatus(); - void SetbuttonStatus(bool status); - std::string GetCurrentTimeString(); - void StartCurrentTimeTimer(); - void PauseCurrentTimeTimer(); - private: - virtual ~BloodModel(); - BloodModel(); - BloodModel(const BloodModel &); - void InitCurrentTimeTimer(); - void DisableCurrentTimeTimer(); - BloodModel &operator=(const BloodModel &); - bool buttonStatus = 0; - GraphicTimer *pCurrentTimeTimer_ = nullptr; +typedef struct { + uint16_t blood; + struct timeval time; +} bloodMeasurementInfo; +class BloodModel { +public: + static BloodModel &GetInstance(void); + void SetBlood(bloodMeasurementInfo value) + { + blood = value; }; + bloodMeasurementInfo GetBlood() + { + return blood; + }; + +private: + BloodModel(); + BloodModel(const BloodModel &); + BloodModel &operator=(const BloodModel &); + virtual ~BloodModel(); + bloodMeasurementInfo blood = {0, 0}; +}; } -#endif // BLOOD_MODEL_H \ No newline at end of file +#endif // BLOOD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodPresenter.h index 893d57789..ec00cf9fc 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodPresenter.h @@ -1,8 +1,7 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: SettingPresenter.h - * Author: - * Create: 2025-03-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodPresenter + * Create: 2025-06 */ #ifndef BLOOD_PRESENTER_H @@ -12,43 +11,7 @@ #include "components/ui_view.h" namespace OHOS { -typedef enum { - BLOOD_START, - BLOOD_TEST, - BLOOD_MORE, - MAX_BLOOD_PAGE, -} PageId; -constexpr short SET_ZERO = 0; -constexpr short SET_ONE = 1; -constexpr short SET_TWO = 2; -constexpr short SET_THREE = 3; -constexpr short SET_FOUR = 4; -constexpr short SET_FIVE = 5; -constexpr short TEMP_SET_SIX = 6; -constexpr short SET_SEVEN = 7; -constexpr short SET_EIGHT = 8; -constexpr short SET_NINE = 9; -constexpr short SET_HUNDRED = 100; -constexpr short SET_INT_MAX = 255; class BloodView; -class BloodModel; -class BloodPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener { -public: - BloodPresenter(); - ~BloodPresenter() override; - static BloodPresenter *GetInstance(); - - void OnResume() override; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; - void OnPause() override; - bool ClickFuncId(const char *buttonName); - -private: - BloodModel *findPhoneModel; -}; +class BloodPresenter : public Presenter {}; } - -#endif // BLOOD_PRESENTER_H \ No newline at end of file +#endif // BLOOD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodReadyPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodReadyPage.h new file mode 100644 index 000000000..f485a0ead --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodReadyPage.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodReadyPage + * Create: 2025-06 + */ + +#ifndef BLOOD_READY_PAGE_H +#define BLOOD_READY_PAGE_H + +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_lite_surface_view.h" +#include "layout/grid_layout.h" +#include "animator/animator.h" +#include "ChangeSliceListener.h" +#include "video_play_wrapper.h" +#include "View.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "BloodModel.h" +#include "BloodPresenter.h" +#include "BloodView.h" + + +namespace OHOS { +class BloodPresenter; +class BloodModel; +class BloodReadyPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodReadyPage(); + ~BloodReadyPage() override; + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitAnimator(); + void SetLabelProgressTime(int value); + void StopAnimator(); + void ShowOnMeasurement(); + int InitCircleProgress(); + +private: + UIViewGroup *group_ = nullptr; + UILabel *labelTips_ = nullptr; + UILabelButton *buttonStart_ = nullptr; + UICircleProgress *timeProgress_ = nullptr; + UILabel *labelProgressTime_ = nullptr; + class BloodAnimatorCallback : public AnimatorCallback { + public: + explicit BloodAnimatorCallback(BloodReadyPage *page) : page_(page) {} + ~BloodAnimatorCallback() override {} + void Callback(UIView *view) override; + + private: + BloodReadyPage *page_{nullptr}; + }; + struct timeval startTime_; + Animator *animator_ = nullptr; + BloodAnimatorCallback *callBack_ = nullptr; +}; +} +#endif // BLOOD_READY_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodResultPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodResultPage.h new file mode 100644 index 000000000..47d198623 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodResultPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodResultPage + * Create: 2025-06 + */ + +#ifndef BLOOD_RESULT_PAGE_H +#define BLOOD_RESULT_PAGE_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "BloodView.h" +#include "BloodModel.h" +#include "BloodPresenter.h" + +namespace OHOS { +class BloodPresenter; +class BloodModel; +class BloodResultPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodResultPage(); + ~BloodResultPage() override; + static BloodResultPage *GetInstance(); + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; +private: + UIViewGroup *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelData_ = nullptr; + UILabel *labelBloodOxygen_ = nullptr; + UILabelButton *buttonMore_ = nullptr; + UIImageView *mainImg_ = nullptr; + UIImageView *levelImg_ = nullptr; +}; +} +#endif // BLOOD_RESULT_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodView.h index f28958afa..ac4bb1313 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/blood/BloodView.h @@ -1,86 +1,23 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: SettingView.h - * Author: - * Create: 2025-03-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BloodView + * Create: 2025-06 */ #ifndef BLOOD_VIEW_H #define BLOOD_VIEW_H #include "View.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" -#include "components/ui_digital_clock.h" -#include "components/ui_label.h" -#include "components/ui_list.h" -#include "components/ui_image_animator.h" -#include "ChangeSliceListener.h" -#include "test_case_list_adapter.h" -#include "UiConfig.h" -#include "blood/BloodModel.h" -#include "blood/BloodPresenter.h" -#include "layout/grid_layout.h" -#include "ui_test.h" namespace OHOS { -class BloodPresenter; - -class BloodModel; -class BloodView : public View { -public: - BloodView(); - ~BloodView() override; - - static BloodView *GetInstance(); - - void OnStart() override; - void OnStop() override; - bool ClickButtonChange(bool status); - void SetupCurrentTime(); - void SetupImageAnimator(); - void UpdateCurrentTimeLabel(const char *currentTime); - bool IsCurrentTimeLabelValid(); - void SetUpImageAnimator(); - void SetupButton(); - void InitImageInfo(); - - void InitStart(); - void InitTest(); - void InitMore(); - bool TempInitLabel(void); - bool InitSimilarLabel(int16 num, int16 labelY, const char *labelText); - void ChangeView(int16 hideView, int16 showView); - - void DropView(UIView& view, int type); - bool ClickFunc(int16 interf); - bool ChangeBloodStart(int16_t thisView); - bool ChangeBloodTest(int16_t thisView); - bool ChangeBloodMore(int16_t thisView); -private: - UIView::OnDragListener *dragListener_ = nullptr; - TestCaseListAdapter* adapter_ = nullptr; - BloodModel *findPhoneModel; - UILabel *currentTime_{nullptr}; - GridLayout* layout_ = nullptr; - - UIViewGroup* container[MAX_BLOOD_PAGE] = {nullptr}; - UIViewGroup *group = nullptr; - UIViewGroup *groupTest = nullptr; - UIScrollView *scrollGroup = nullptr; - UILabelButton* button = nullptr; - UILabelButton* buttonMore = nullptr; - UILabel *label1_ = nullptr; - UILabel *label2_ = nullptr; - - ImageInfo* imageInfo1_ = nullptr; - ImageInfo* imageInfo2_ = nullptr; - ImageInfo* imageInfo3_ = nullptr; - ImageAnimatorInfo imageAnimatorImageInfo_[3] = { 0 }; - UIImageAnimatorView* imageAnimator_ = nullptr; - - UILabel *tempTitle{nullptr}; - UILabel *tempLabel[SET_THREE]{nullptr}; +enum BLOOD_PAGES { + BLOOD_MAIN_PAGE = 1, // 0 is invalid + BLOOD_READY_PAGE = 2, + BLOOD_MEASUREMENT_PAGE = 3, + BLOOD_RESULT_PAGE = 4, + BLOOD_CHART_PAGE = 5, + BLOOD_EXPLAIN_PAGE = 6, }; +class BloodPresenter; +class BloodView : public View {}; } -#endif // BLOOD_VIEW_H +#endif // BLOOD_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h index 3c645feb1..e777309ee 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h @@ -11,6 +11,7 @@ #include "bts_def.h" #include "bts_gatt_stru.h" #include "bts_gatt_server.h" +#include "bts_gatt_client.h" #include "bts_le_gap.h" #ifdef __cplusplus @@ -18,7 +19,9 @@ extern "C" { #endif errcode_t wrapper_gap_ble_register_callbacks(gap_ble_callbacks_t *func); +errcode_t wrapper_gattc_register_client(bt_uuid_t *uuid, uint8_t *clientId); errcode_t wrapper_gatts_register_callbacks(gatts_callbacks_t *func); +errcode_t wrapper_gattc_register_callbacks(gattc_callbacks_t *func); void wrapper_ble_register(void); errcode_t wrapper_gatts_register_server(bt_uuid_t *app_uuid, uint8_t *server_id); errcode_t wrapper_gatts_add_service(uint8_t server_id, bt_uuid_t *service_uuid, bool is_primary); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathExerPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathExerPage.h new file mode 100644 index 000000000..8f3c538f9 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathExerPage.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathExerPage + * Create: 2025-5-13 + */ +#ifndef BREATH_EXER_PAGE_H +#define BREATH_EXER_PAGE_H + +#include "layout/grid_layout.h" +#include "components/ui_label.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_animator.h" +#include "View.h" +#include "SlicePage.h" +#include "graphic_timer.h" +#include "SlicePageFactory.h" +#include "power_display_service.h" +#include "BreathModel.h" +#include "BreathPresenter.h" + +namespace OHOS { +int32_t g_StartTime; +class BreathExerPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathExerPage(); + ~BreathExerPage() override; + void OnStart(void* data) override; + void OnPause() override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void SetUpImageAnimator(); + void UpdateTextOpa(); + void UpdateImageRotate(); + class BreathExerPageCallback : public AnimatorCallback { + public: + BreathExerPageCallback(BreathExerPage* page) : BreathExerPage(page) {} + virtual ~BreathExerPageCallback() override {} + void Callback(UIView* view) override; + private: + BreathExerPage* BreathExerPage{nullptr}; + }; + BreathExerPageCallback* animatorCallBack_{nullptr}; + Animator *animator_ = nullptr; +private: + UIViewGroup *group_ = nullptr; + UIImageView* mainImg_ = nullptr; + UIImageView* romataImg_ = nullptr; + UIImageView* romataImgVirtual_ = nullptr; + UILabel *breathInhale_ = nullptr; + UILabel *breathExhale_ = nullptr; + float scale_ = 0; + float angle_ = 0; + bool flag_ = true; + float rotateStep_ = 0.0f; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathMainPage.h new file mode 100644 index 000000000..1b5c16b09 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathMainPage.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathMainPage + * Create: 2025-5-13 + */ +#ifndef BREATH_MAIN_PAGE_H +#define BREATH_MAIN_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_animator.h" +#include "View.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "BreathView.h" +#include "BreathModel.h" +#include "BreathPresenter.h" +#ifndef _WIN32 +#include "time64.h" +#endif + +namespace OHOS { + +class BreathMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathMainPage(); + ~BreathMainPage() override; + void OnStart(void* data) override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + +private: + UIViewGroup *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UIButton *buttonTime_ = nullptr; + UIButton *buttonSetting_ = nullptr; + UIButton *buttonStart_ = nullptr; + UILabel *lableSetting_ = nullptr; + UILabel *lableTime_ = nullptr; + UIImageView *bgImg_ = nullptr; + UIImageView *center_ = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathModel.h new file mode 100644 index 000000000..ebc5bfd0a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathModel.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathModel + * Create: 2025-5-13 + */ +#ifndef BREATH_MODEL_H +#define BREATH_MODEL_H + +#include +#include "gfx_utils/graphic_math.h" +namespace OHOS { +class BreathModel { +public: + static BreathModel &GetInstance(); + virtual ~BreathModel(); + + uint8_t GetTrainTime(); + void SetTrainTime(uint16_t value); // 设置呼吸训练时间 + uint8_t GetRhythm(); + void SetRhythm(uint16_t value); // 设置呼吸节奏 + int32_t GetStartTime(); + void SetStartTime(int32_t value); // 设置呼吸准备页面开始时间 + int32_t GetBeginTime(); + void SetBeginTime(int32_t value); // 设置呼吸训练开始时间 + uint8_t GetFrequencyScore(); + void SetFrequencyScore(); // 调用传感器接口实现呼吸数据,客户自实现 + uint8_t GetHeartRate(); + void SetHeartRate(); // 调用传感器接口实现心率数据,客户自实现 + std::string GetTrainingDurationTime(); + void SetTrainingDurationTime(uint16_t data); // 增加训练总时长 + std::string GetTrainingCount(); + void SetTrainingCount(); // 增加训练总次数 + float GetRotateStep(); // 获取图片旋转步频 + char *GetRhythmText(); // 获取呼吸频率节奏文本 + +private: + BreathModel(); + BreathModel(const BreathModel &); + BreathModel &operator=(const BreathModel &); + uint8_t selectTrainTime_ = 0; + uint8_t selectRhythm_ = 0; + uint8_t trainingDurationTime_ = 0; + uint8_t trainingCount_ = 0; + int32_t startTime_ = 0; // 用于记录五秒倒计时开始时间 + int32_t beginTime_ = 0; // 用于记录训练倒计时开始时间 + uint8_t frequencyScore_ = 0; + uint8_t heartRate_ = 0; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathPresenter.h new file mode 100644 index 000000000..74147f6cb --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathPresenter.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathPresenter + * Create: 2025-5-23 + */ + +#ifndef Breath_PRESENTER_H +#define Breath_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class BreathView; +class BreathPresenter : public Presenter {}; +} + +#endif // Breath_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathResultPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathResultPage.h new file mode 100644 index 000000000..b80729dd1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathResultPage.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathResult + * Create: 2025-5-13 + */ +#ifndef BREATH_RESULT_PAGE_H +#define BREATH_RESULT_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button.h" +#include "components/ui_toggle_button.h" +#include "View.h" +#include "power_display_service.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "BreathModel.h" +#include "BreathPresenter.h" +#ifndef _WIN32 +#include "time64.h" +#endif + +namespace OHOS { +static constexpr uint16_t LABEL_COUNT = 5; + +class BreathResultPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathResultPage(); + ~BreathResultPage() override; + void OnStart(void* data) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + void InitBtn(); + void InitBtnBg(); + void InitLabelDes(); + void InitLabelCount(); + void InitLabelUnit(); + uint8_t GetTimeScour(); +private: + UIScrollView *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelTimeAndRhythmTitle_ = nullptr; + UIButton *buttonBg_[LABEL_COUNT]{nullptr}; + UILabel *labelDes_[LABEL_COUNT]{nullptr}; + UILabel *labelValue_[LABEL_COUNT]{nullptr}; + UILabel *labelUnit_[LABEL_COUNT]{nullptr}; + UIImageView *scores_ = nullptr; + UIImageView *pageBgImg_ = nullptr; + UIButton *buttonComplete_ = nullptr; + UIButton *buttonRestart_ = nullptr; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathRhythmSetPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathRhythmSetPage.h new file mode 100644 index 000000000..1bfcbf323 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathRhythmSetPage.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathRhythmSetPage + * Create: 2025-5-13 + */ +#ifndef BREATH_RHYTHM_SET_PAGE_H +#define BREATH_RHYTHM_SET_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "View.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "BreathModel.h" +#include "BreathPresenter.h" + +namespace OHOS { +class BreathRhythmSetPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIPicker::SelectedListener { +public: + BreathRhythmSetPage(); + ~BreathRhythmSetPage() override; + void OnStart(void* data) override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + +private: + UILabel *lableRhythm_ = nullptr; + UIPicker *pickerRhythm_ = nullptr; + UIButton *buttonOk_ = nullptr; + UIViewGroup *group_ = nullptr; + UIImageView *pickerImg_ = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathStartPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathStartPage.h new file mode 100644 index 000000000..5ffb85679 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathStartPage.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathStartPage + * Create: 2025-5-13 + */ +#ifndef BREATH_START_PAGE_H +#define BREATH_START_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "View.h" +#include "power_display_service.h" +#include "SlicePage.h" +#include "graphic_timer.h" +#include "SlicePageFactory.h" +#include "BreathModel.h" +#include "BreathPresenter.h" +#ifndef _WIN32 +#include "time64.h" +#endif + +namespace OHOS { +class BreathStartPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathStartPage(); + ~BreathStartPage() override; + void OnStart(void* data) override; + void OnTimer(); + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnPause() override; +private: + UILabel *titleLable_ = nullptr; + UILabel *guideLable_ = nullptr; + UIImageView *centerImg_ = nullptr; + UIViewGroup *group_ = nullptr; + UIImageView *bgImg_ = nullptr; + + class BreathStartCallback : public AnimatorCallback { + public: + BreathStartCallback(BreathStartPage* page) : BreathStartPage(page) {} + virtual ~BreathStartCallback() override {} + void Callback(UIView* view) override; + private: + BreathStartPage* BreathStartPage{nullptr}; + }; + BreathStartCallback* animatorCallBack_{nullptr}; + Animator *animator_ = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTimeSetPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTimeSetPage.h new file mode 100644 index 000000000..93f9d95f2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTimeSetPage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathTimeSetPage + * Create: 2025-5-13 + */ +#ifndef BREATH_TIME_SET_PAGE_H +#define BREATH_TIME_SET_PAGE_H + +#include +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button.h" +#include "components/ui_toggle_button.h" +#include "View.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "BreathModel.h" +#include "BreathPresenter.h" + +namespace OHOS { +class BreathTimeSetPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathTimeSetPage(); + ~BreathTimeSetPage() override; + void OnStart(void* data) override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; +private: + UILabel *labelTitle_ = nullptr; + UIPicker *pickerTime_ = nullptr; + UIButton *buttonOk_ = nullptr; + UIViewGroup *group_ = nullptr; + UIImageView *pickerImg_ = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTrainingRecordsPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTrainingRecordsPage.h new file mode 100644 index 000000000..593e17bd3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathTrainingRecordsPage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathTrainingRecordsPage + * Create: 2025-5-13 + */ +#ifndef BREATH_TRAINING_PAGE_H +#define BREATH_TRAINING_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "View.h" +#include "SlicePage.h" +#include "graphic_timer.h" +#include "SlicePageFactory.h" +#include "BreathModel.h" +#include "BreathPresenter.h" + +namespace OHOS { +class BreathTrainingRecordsPage : public SlicePage, + public UIView::OnDragListener { +public: + BreathTrainingRecordsPage(); + ~BreathTrainingRecordsPage() override; + void OnStart(void* data) override; + void OnResume() override; + bool OnDrag(UIView &view, const DragEvent &event) override; + +private: + UILabel *labelTitle_ = nullptr; + UILabel *labelTimeDes_ = nullptr; + UILabel *labelTimeUnit_ = nullptr; + UILabel *labelTimeValue_ = nullptr; + UILabel *labelCountDes_ = nullptr; + UILabel *labelCountUnit_ = nullptr; + UILabel *labelCountValue_ = nullptr; + UIViewGroup *group_ = nullptr; + UIImageView *bgImg1_ = nullptr; + UIImageView *bgImg2_ = nullptr; + UIImageView *bgImg3_ = nullptr; + UIImageView *bgImg4_ = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathView.h new file mode 100644 index 000000000..c7a8a5f50 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/breathexercise/BreathView.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathView + * Create: 2025-5-14 + */ + +#ifndef BREATH_VIEW_H +#define BREATH_VIEW_H + +#include "View.h" +namespace OHOS { +enum BREATH_PAGE { + BREATH_MAIN_VIEW = 1, + BREATH_DUR_VIEW = 2, + BREATH_EXER_VIEW = 3, + BREATH_RHY_VIEW = 4, + BREATH_START_VIEW = 5, + BREATH_RESULT_VIEW = 6, + BREATH_TRAINING_VIEW = 7, +}; + +class BreathPresenter; +class BreathView : public View {}; +} +#endif // BREATH_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraMainPage.h index 01aa7b8de..558c2dfa6 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraMainPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraMainPage.h @@ -29,9 +29,7 @@ #include "camera/CameraPresenter.h" namespace OHOS { - class CameraPresenter; - class CameraModel; class CameraMainPage : public SlicePage, public UIView::OnClickListener, @@ -39,17 +37,14 @@ class CameraMainPage : public SlicePage, public: CameraMainPage(); ~CameraMainPage() override; - static CameraMainPage *GetInstance(); - void OnStart(void* data) override; uint8_t GetConnectStatus(); bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; void OnPause() override; - - bool GetFirstFlag(); - void SetFirstFlag(bool value); + bool GetFirstClickFlag(); + void SetFirstClickFlag(bool value); void SetUpButton(); void InitCameraTimer(); void InitCameraView(); @@ -58,15 +53,16 @@ public: void StopAnimator(); void PhotoTaken(); void Refresh_page(); + private: - UILabel *title = nullptr; - UILabel *cameraFind = nullptr; - UILabel *cameraTitle = nullptr; - UILabel *cameraTime = nullptr; - UIButton *button = nullptr; - bool isFirst; + UILabel *disconnectTitle_ = nullptr; + UILabel *cameraFind_ = nullptr; + UILabel *cameraTitle_ = nullptr; + UILabel *cameraTime_ = nullptr; + UIButton *takePhotoButton_ = nullptr; UIScrollView* container_ = nullptr; - UIImageView *bluetoothDisconnected = nullptr; + UIImageView *btDisconnected_ = nullptr; + bool isFirstClick_; class CameraAnimatorCallback : public AnimatorCallback { public: @@ -81,4 +77,4 @@ private: CameraAnimatorCallback *callBack_ = nullptr; }; } -#endif // CAMERA_VIEW_H +#endif // CAMERA_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraModel.h index 61a9c5ed5..70adcb318 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraModel.h @@ -20,7 +20,6 @@ private: CameraModel(const CameraModel &); CameraModel &operator=(const CameraModel &); virtual ~CameraModel(); - bool buttonStatus = 0; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraPresenter.h index dced5767c..a67e1788c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/camera/CameraPresenter.h @@ -11,7 +11,6 @@ #include "components/ui_view.h" namespace OHOS { - class CameraView; class CameraPresenter : public Presenter { }; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/AmbientClockView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/AmbientClockView.h index bb20b9c1c..1f52f763c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/AmbientClockView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/AmbientClockView.h @@ -24,27 +24,27 @@ #include "main/HealthModel.h" #include "activity/ActivityModel.h" #include "UiConfig.h" -#include "components/ui_card_page.h" +#include "components/ui_fragment.h" #include "animator/animator_manager.h" #include "sys/time.h" +#include "common/periodicupdate_interface.h" namespace OHOS { -class AmbientClockView : public UICardPage { +class AmbientClockView : public UIFragment, public PeriodicUpdateInterface { public: AmbientClockView(); ~AmbientClockView() override; AmbientClockView(const AmbientClockView &) = delete; AmbientClockView &operator=(const AmbientClockView &) = delete; - - bool InitView(void); - void PreLoad(void) override; - void UpdateTime(void); - uint32_t GetPeriod(void) const + void Update(void) override; + uint32_t GetPeriod(void) override { return 1000; // 1000: ms } private: + void OnCreateView(void* data) override; + void OnDestroyView() override; bool InitCenterCircleView(void); bool InitHandView(void); void InitDateTime(void); @@ -58,7 +58,6 @@ private: Image *bigCircle_{nullptr}; Image *medCircle_{nullptr}; Image *smallCircle_{nullptr}; - bool viewiInitStatus_{false}; }; // class AmbientClockView } // namespace OHOS #endif // AMBIENT_VIEW_GROUP_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/ClockResourceImage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/ClockResourceImage.h new file mode 100644 index 000000000..29838a2c5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/ClockResourceImage.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: ClockResourceImage + * Author: + * Create: 2025-05-06 + */ + +#ifndef CLOCK_RESOURCE_IMAGE_H +#define CLOCK_RESOURCE_IMAGE_H +#include "UiConfig.h" + +namespace OHOS { + static constexpr const char *PNG_GRADIENT_CLOCK_RESOURCE = APP_RES_PATH"/GRADIENT_CLOCK_IMAGES.bin"; + + static const int PNG_DATA_0 = 0x100001; + static const int PNG_DATA_1 = 0x100002; + static const int PNG_DATA_2 = 0x100003; + static const int PNG_DATA_3 = 0x100004; + static const int PNG_DATA_4 = 0x100005; + static const int PNG_DATA_5 = 0x100006; + static const int PNG_DATA_6 = 0x100007; + static const int PNG_DATA_7 = 0x100008; + static const int PNG_DATA_8 = 0x100009; + static const int PNG_DATA_9 = 0x10000a; + static const int PNG_DATA_SPLIT = 0x10000b; + static const int PNG_TIME_0 = 0x10000c; + static const int PNG_TIME_1 = 0x10000d; + static const int PNG_TIME_2 = 0x10000e; + static const int PNG_TIME_3 = 0x10000f; + static const int PNG_TIME_4 = 0x100010; + static const int PNG_TIME_5 = 0x100011; + static const int PNG_TIME_6 = 0x100012; + static const int PNG_TIME_7 = 0x100013; + static const int PNG_TIME_8 = 0x100014; + static const int PNG_TIME_9 = 0x100015; + static const int PNG_TIME_SCALE = 0x100016; + static const int PNG_TIME_SPLIT = 0x100017; + static const int PNG_WEEK_FRI = 0x100018; + static const int PNG_WEEK_MON = 0x100019; + static const int PNG_WEEK_SAT = 0x10001a; + static const int PNG_WEEK_SUN = 0x10001b; + static const int PNG_WEEK_THU = 0x10001c; + static const int PNG_WEEK_TUE = 0x10001d; + static const int PNG_WEEK_WED = 0x10001e; +} // OHOS + +#endif // CLOCK_RESOURCE_IMAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientAodView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientAodView.h new file mode 100644 index 000000000..28e3d8d96 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientAodView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientAodView + * Create: 2025-04 + */ + +#ifndef GRADIENT_AOD_VIEW_H +#define GRADIENT_AOD_VIEW_H + +#include "components/ui_card_page.h" +#include "GradientDateView.h" +#include "components/ui_fragment.h" +#include "common/periodicupdate_interface.h" + +namespace OHOS { + +class GradientAodView : public UIFragment, public PeriodicUpdateInterface { +public: + GradientAodView(); + ~GradientAodView() override; + GradientAodView(const GradientAodView &) = delete; + static GradientAodView* GetInstance(void); + GradientAodView &operator=(const GradientAodView &) = delete; + void Update(void) override; + uint32_t GetPeriod(void) override + { + return 1000; // 1000: ms + } + +private: + void OnCreateView(void* data) override; + void OnDestroyView() override; + GradientDateView* gradientDateView_{nullptr}; +}; // class GradientAodView + +} // namespace OHOS + +#endif // GRADIENT_AOD_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientClockView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientClockView.h new file mode 100644 index 000000000..1f86e28dd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientClockView.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientClockView + * Create: 2025-04 + */ + +#ifndef GRADIENT_CLOCK_VIEW_H +#define GRADIENT_CLOCK_VIEW_H + +#include +#include "View.h" +#include "components/ui_canvas_ext.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "components/ui_card_page.h" +#include "GradientDateView.h" +#include "common/periodicupdate_interface.h" + +namespace OHOS { + +struct sectorInfo { + float startAngle; + float angleRange; + uint16_t sectorRadius; + uint16_t stopCount; + ColorStop* colorStop; + + sectorInfo(float start, float angle, uint16_t radius, uint16_t count, ColorStop* color = nullptr): + startAngle(start), angleRange(angle), sectorRadius(radius), stopCount(count), colorStop(color) + {} +}; + +class GradientClockView : public UICardPage, public PeriodicUpdateInterface { +public: + GradientClockView(); + static GradientClockView *GetInstance(void); + ~GradientClockView() override; + GradientClockView(const GradientClockView &) = delete; + GradientClockView &operator=(const GradientClockView &) = delete; + bool InitView(void); + void PreLoad(void) override; + void Update(void) override; + uint32_t GetPeriod(void) override + { + return DEFAULT_TASK_PERIOD; + } + +private: + void UpdateHands(uint8_t minute, uint8_t second, uint64_t milliSecond); + void UpdateCanvas(UICanvasExt* canvas, const sectorInfo& sectorInfo); + void SafeDelete(UIView* ptr); + UICanvasExt* backgroudCanvas_; + UICanvasExt* secondHandCanvas_; + UICanvasExt* minuteHandCanvas_; + bool viewiInitStatus_{false}; + uint8_t second_ = 0xFF; + float secondAngle_; + GradientDateView* gradientDateView_{nullptr}; +}; // class GradientClockView +} // namespace OHOS + +#endif // GRADIENT_CLOCK_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientDateView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientDateView.h new file mode 100644 index 000000000..5b1410a05 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/GradientDateView.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: GradientDateView + * Create: 2025-04 + */ + +#ifndef GRADIENT_DATE_VIEW_H +#define GRADIENT_DATE_VIEW_H + +#include +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "main/dial/DialDigitalImgView.h" + +namespace OHOS { + +class GradientDateView : public UIViewGroup { +public: + GradientDateView(); + ~GradientDateView(); + GradientDateView(const GradientDateView &) = delete; + GradientDateView &operator=(const GradientDateView &) = delete; + bool InitView(void); + void UpdateTime(void); + +private: + bool LoadClockImageById(UIImageView* view, uint32_t resId); + bool LoadGradientDateImages(std::vector &imgInfos, std::vector resIds, uint16_t length); + void InitDigitalImgView(DialDigitalImgView* &dialView, Point pos, uint16_t integerLength, + std::vector &numImgInfo); + void HandleDigitalData(DialDigitalImgView* digitalView, float data); + void InitWeekImgView(void); + void InitDateImgViews(void); + void InitTimeImgViews(void); + UIImageView weekImgView_; + std::vector weekInfo_; + DialDigitalImgView* yearImgView_{nullptr}; + DialDigitalImgView* monthImgView_{nullptr}; + DialDigitalImgView* dayImgView_{nullptr}; + UIImageView dateSplitLeft_; + UIImageView dateSplitRight_; + std::vector dateNumImgInfo_; + DialDigitalImgView* hourImgView_{nullptr}; + DialDigitalImgView* minuteImgView_{nullptr}; + std::vector timeNumImgInfo_; + UIImageView timeSplit_; + UIImageView* backgroudImage_; + bool viewiInitStatus_{false}; +}; // class GradientDateView + +} // namespace OHOS + +#endif // GRADIENT_DATE_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/MainClockView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/MainClockView.h index c643693d5..75e224986 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/MainClockView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/clock/MainClockView.h @@ -28,9 +28,10 @@ #include "animator/animator_manager.h" #include #include "sys/time.h" +#include "common/periodicupdate_interface.h" namespace OHOS { -class MainClockView : public UICardPage { +class MainClockView : public UICardPage, public PeriodicUpdateInterface { public: MainClockView(); ~MainClockView() override; @@ -42,7 +43,11 @@ public: void RefreshHeartRate(int value); void ClockAnimatorStart(void); void ClockAnimatorStop(void); - void UpdateTime(void); + void Update(void) override; + uint32_t GetPeriod(void) override + { + return DEFAULT_TASK_PERIOD; + } private: void InitStepValue(); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassCalibrationView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassCalibrationView.h new file mode 100644 index 000000000..704e60d96 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassCalibrationView.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassCalibrationView.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_CALIBRATION_VIEW_H +#define COMPASS_CALIBRATION_VIEW_H + +#include "components/ui_label.h" +#include "View.h" +#include "ohos_types.h" +#include "AppGroupView.h" +#include "components/ui_image_view.h" + +namespace OHOS { +class CompassCalibrationView : public AppGroupView { +public: + CompassCalibrationView(); + ~CompassCalibrationView() override; + + bool CreateUIViewGroup(void); + static CompassCalibrationView *GetInstance(void); + bool InitView(void *caller) override; +private: + UILabel *labelOne{nullptr}; + UILabel *labelTwo{nullptr}; + UIImageView *imageView{nullptr}; + + void ClearAll(void); +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassControlView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassControlView.h index e2242e1c8..4f52df81f 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassControlView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassControlView.h @@ -10,18 +10,26 @@ #include "components/ui_card_page.h" #include "compass/CompassFragment.h" +#include "common/periodicupdate_interface.h" namespace OHOS { -class CompassControlView : public UICardPage { +class CompassControlView : public UICardPage, public PeriodicUpdateInterface { public: CompassControlView(); + ~CompassControlView() override; void PreLoad(void) override; void UnLoad(void) override; void OnPause(void) override; void OnActive(void) override; void ScrollBegin(bool isActive) override; void ScrollEnd(bool isActive) override; + void Update(void) override; + uint32_t GetPeriod(void) override + { + return DEFAULT_TASK_PERIOD; // DEFAULT_TASK_PERIOD: ms + } + private: CompassFragment *compassFragment_{nullptr}; }; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassFragment.h index 64c6ee054..b4e6fba5c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassFragment.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassFragment.h @@ -11,16 +11,15 @@ #include "components/ui_label.h" #include "components/ui_image_view.h" #include "components/ui_fragment.h" -#include "common/task.h" namespace OHOS { -class CompassFragment : public UIFragment, public Task { +class CompassFragment : public UIFragment { public: void OnCreateView(void* data) override; void OnResumeView() override; void OnPauseView() override; void OnDestroyView() override; - void Callback() override; + void Update(void); private: bool InitCompassImage(void); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassPresenter.h new file mode 100644 index 000000000..68d6877d8 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassPresenter.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassPresenter.h + * Author: + * Create: 2021-12-21 + */ +#ifndef COMPASS_PRESENTER_H +#define COMPASS_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" +#include "components/ui_image_view.h" +#include "ohos_types.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "CompassView.h" + +namespace OHOS { +typedef struct { + uint16_t beginAngle; + uint16_t endAngle; + const char *dir; +} CompassItem; + +class CompassView; +class CompassPresenter { +public: + CompassPresenter(); + virtual ~CompassPresenter(); + + static CompassPresenter *GetInstance(void); + void DisplayAngleDir(uint16_t angle); + void DetermineToRotate(void); + void InScopeRotate(void); + void TimeCreateRandomNum(void); + void DisplayAngleRight(uint16_t angle); + +private: + int16_t lastRotateAngle{0}; + int16_t currentRotateAngle{0}; + int16_t angleDiff{0}; + bool getAngleStatus{false}; + bool initDisplayStatus{true}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassView.h new file mode 100644 index 000000000..97cd957d1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/CompassView.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassView.h + * Author: + * Create: 2021-12-21 + */ + +#ifndef COMPASS_VIEW_H +#define COMPASS_VIEW_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "AppGroupView.h" +#include "CompassCalibrationView.h" + +namespace OHOS { +static constexpr float VIEW_CENTERS = 227; + +class CompassView : public AppGroupView { +public: + CompassView(); + ~CompassView() override; + + void DirectionSetText(const char *text, const char *angle); + static CompassView *GetInstance(void); + void CompassStartRotate(int16_t numb); + bool InitPage(void); + bool InitView(void *caller) override; + bool GetInitViewState(void); + bool InitCompassImage(void); + +private: + bool LoadCompassImage(UIImageView *view, uint32_t resId); + void ClearAll(void); + UILabel *directionLabel{nullptr}; + UILabel *angledLabel{nullptr}; + UIImageView *backGround{nullptr}; + UIImageView *rotateShaft{nullptr}; + UIImageView *triangulation{nullptr}; + const Vector2 VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/MainCompassPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/MainCompassPresenter.h index 2588f0a43..ef4bc0b2a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/MainCompassPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/compass/MainCompassPresenter.h @@ -10,16 +10,19 @@ #include "Presenter.h" #include "compass/MainCompassView.h" #include "compass/CompassModel.h" +#include "common/task.h" namespace OHOS { class MainCompassView; -class MainCompassPresenter : public Presenter, public UIView::OnDragListener { +class MainCompassPresenter : public Presenter, public UIView::OnDragListener, public Task { public: bool OnDrag(UIView& view, const DragEvent& event) override; void OnResume() override; void OnPause() override; + + void Callback() override; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateButtonItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateButtonItemView.h index c03c4b284..0b38897a4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateButtonItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateButtonItemView.h @@ -7,7 +7,7 @@ #ifndef DATE_BUTTON_ITEM_VIEW_H #define DATE_BUTTON_ITEM_VIEW_H -#include "date/DateModel.h" +#include "DateModel.h" #include "UiConfig.h" #include "components/ui_canvas.h" #include "components/ui_image_view.h" @@ -22,13 +22,11 @@ public: explicit DateButtonItemView(); ~DateButtonItemView() override; virtual void SetItemInfo(const DateButtonItem itemInfo); - virtual void SetUpChild(); DateButtonItem GetItem(); private: - static bool flag; - UILabelButton sLabelButton; - DateButtonItem sItemInfo = {nullptr, 0, false, false}; + UILabelButton labelButton_; + DateButtonItem itemInfo_ = {"", nullptr, false, false}; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateContentItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateContentItemView.h new file mode 100644 index 000000000..befc60a83 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateContentItemView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateContentItemView + * Create: 2025-03-23 + */ + +#ifndef DATE_CONTENT_ITEM_VIEW_H +#define DATE_CONTENT_ITEM_VIEW_H + +#include "DateModel.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class DateContentItemView : public UIViewGroup { +public: + explicit DateContentItemView(); + ~DateContentItemView() override; + virtual void SetItemInfo(const DateItem itemInfo); + const char *GetViewId(); + bool GetVisiable(); + +private: + UILabel labelTitle_; + UILabel labelDes_; + UILabel labelAddress_; + UIImageView signs_; + UIButton backGround_; + DateItem itemInfo_ = {nullptr, nullptr, nullptr, nullptr, false}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMainPage.h index 9bb45843e..f365ca976 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMainPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMainPage.h @@ -11,20 +11,20 @@ #include #include #include +#include "gfx_utils/vector.h" #include "components/ui_scroll_view.h" #include "components/ui_label.h" -#include "components/ui_list.h" -#include "date/DateAdapter.h" -#include "date/DateButtonAdapter.h" -#include "date/DatePresenter.h" +#include "components/ui_button.h" +#include "components/ui_simple_list.h" +#include "DateButtonItemView.h" +#include "DateContentItemView.h" +#include "DatePresenter.h" #include "SlicePage.h" #include "UiConfig.h" -#include "date/DateView.h" -#include "components/ui_button.h" +#include "DateView.h" namespace OHOS { -#define LABEL_COUNT 4 -static constexpr int16_t START_YEAR = 1900; +static constexpr int16_t WEEK_DYAS = 7; class DatePresenter; class DateMainPage : public SlicePage, @@ -33,26 +33,30 @@ class DateMainPage : public SlicePage, public: DateMainPage(); ~DateMainPage() override; + static DateMainPage *GetInstance(); void OnStart(void* data) override; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; - void InitDownList(); - void UpdateMsg(std::string dateMsg); - void SetDownListAdapter(); - bool InitDateTop(); + void InitList(); + bool InitListTopDate(); + void SetContentListDate(); + void SetDateButtonList(std::string viewId); + void RefreshDateMsg(std::string dateMsg); std::string GetFutureDate(int days_ahead); - void RefreshButtonListDate(int value); + void ReloadPage(); + void ClearButtonList(); + void ClearContentList(); + void RefreshListData(); + private: - UIScrollView *uiScrollView = nullptr; - DateAdapter *listAdapter{nullptr}; - UIList *downContentList{nullptr}; - UIImageView *image1{nullptr}; - DateButtonAdapter *buttonAdapter{nullptr}; - UIList *buttonContentList{nullptr}; - UILabel *title{nullptr}; - std::list listTop; - std::string strDate[SET_SEVEN]; - std::string strDay[SET_SEVEN]; + UIScrollView *uiScrollView_{nullptr}; + UISimpleList *detailList_{nullptr}; + UISimpleList *dateList_{nullptr}; + UIImageView *bgImage_{nullptr}; + UILabel *titlLabel_{nullptr}; + Graphic::Vector listTop_; + std::string strDate_[WEEK_DYAS]; + std::string strDay_[WEEK_DYAS]; }; } #endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMessagePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMessagePage.h index 8a5e59ca6..01022b01b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMessagePage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateMessagePage.h @@ -12,14 +12,13 @@ #include "components/ui_label_button.h" #include "components/ui_swipe_view.h" #include "ui_swipe_view.h" -#include "date/DatePresenter.h" -#include "date/DateModel.h" -#include "date/DateView.h" +#include "DatePresenter.h" +#include "DateModel.h" +#include "DateView.h" #include "SlicePage.h" #include "UiConfig.h" namespace OHOS { -#define LABEL_COUNT 8 class DatePresenter; class DateMessagePage : public SlicePage, public UIView::OnDragListener { @@ -28,13 +27,15 @@ public: ~DateMessagePage() override; void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; + void InitLabel(); private: - UIViewGroup *group; - UIImageView *image1; - UILabel *labelTitle{nullptr}; - UILabel *labelMessage{nullptr}; - UILabel *labelTime{nullptr}; + UIScrollView *group_{nullptr}; + UIImageView *bgImage_{nullptr}; + UILabel *labelTitle_{nullptr}; + UILabel *labelMessage_{nullptr}; + UILabel *labelAddress_{nullptr}; + UILabel *labelTime_{nullptr}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateModel.h index b86e3e2e6..2faac991b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateModel.h @@ -19,64 +19,94 @@ #include #include #include +#include +#include "graphic_timer.h" +#include "ohos_timer.h" #include "hal_tick.h" #include "AppViewIDs.h" #include "UiConfig.h" #include "cJSON.h" - +#include "diag_service.h" +#include "gfx_utils/vector.h" +#ifndef _WIN32 +#include "time64.h" +#define DATE_PATH "/user/app/user/ace/data/com.vendor.Weather" +#else +#define DATE_PATH APP_RES_PATH +#endif namespace OHOS { +static constexpr int16 DATE_COUNT = 24; +static constexpr int16 DATE_HOUR = 12; static constexpr int16 HOUR_COUNT = 24; static constexpr uint64_t CENTI_SECOND_UNIT = 100; static constexpr uint64_t MS_ONE_SECONDS = 1000; -static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_THIRTY = 30; static constexpr uint16_t NUM_TIME_MIN = 60; static constexpr uint16_t NUM_TIME_HOUR = 3600; -static constexpr int32_t NUM_TIME_DAY = 86400; -static constexpr int16_t MIN_TO_HOUR = 60; -static constexpr int16_t HOURLY_SYSTEM = 24; +static constexpr uint32_t NUM_TIME_DAY = 86400; +static constexpr uint16_t TIME_END = 16; +static constexpr uint8_t DATE_UNIT_COUNT = 3; +static constexpr uint8_t PAGE_STATUS_0 = 0; // 主页面滑动/按钮退出或在子页面通过按钮退出应用,清除selectButton_记录 +static constexpr uint8_t PAGE_STATUS_1 = 1; // 从主页面进入子页面,设置resetPage,用于主页面恢复选择记录 +static constexpr uint8_t PAGE_STATUS_2 = 2; // 从子页面回退到主页面,当在主页面未点击任何按钮,不修改selectButton_记录,退出到主页面时清除记录 + typedef struct { std::string hour; std::string eventTitle; - std::string startTime; - std::string week; + std::string address; + std::string index; } DateMsg; typedef struct { - const char *label_1; - const char *label_2; + const char *title; + const char *describetion; + const char *address; const char *index; bool visiable; } DateItem; typedef struct { - const char *button_viewId; - const char *button_day; - int index; + std::string buttonViewId; + const char *buttonDay; bool isFirst; bool isSelect; } DateButtonItem; +typedef struct { + std::string eventTitle; + std::string time; +} DateToMessage; + static const uint16_t DATE_ITEM_COUNT = 10; + class DateModel { public: static DateModel &GetInstance(void); virtual ~DateModel(); - bool InitDateVec(std::string dateStr); + void Init(); bool InitDate(); - + bool InitDateVec(std::string dateStr); const char *GetViewId(); - std::unordered_map> keyValues; - std::list listDate; - std::string now; - std::string titleName; - std::string messageIndex; - std::string strIndex; + void InitDateTimer(); + void DisableDatePhoneTimer(); + void PollFileUntilChange(const std::string& filePath); + void CalcClockTime(std::string hour, std::string eventTitle); + void ClearData(); + uint8_t GetConnectStatus(); + std::vector dateClockVec_; + std::vector listDate_; + std::string titleName_ = ""; + std::string selectButton_ = ""; + int resetPage_ = 0; + std::string messageIndex_; private: DateModel(); DateModel(const DateModel &); DateModel &operator=(const DateModel &); + GraphicTimer *startCount_ = nullptr; + std::unordered_map> keyValues_; }; } -#endif // DATE_MODEL_H \ No newline at end of file +#endif // Date_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DatePresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DatePresenter.h index 813c5ba44..f0ae9c2e1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DatePresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DatePresenter.h @@ -7,30 +7,13 @@ #ifndef DATE_PRESENTER_H #define DATE_PRESENTER_H -#include "date/DateModel.h" +#include "DateModel.h" #include "Presenter.h" #include "components/ui_view.h" namespace OHOS { -constexpr int16 BACKGROUND_IMAGE_WIDTH = 190; -constexpr int16 SET_ZERO = 0; -constexpr int16 SET_ONE = 1; -constexpr int16 SET_TWO = 2; -constexpr int16 SET_THREE = 3; -constexpr int16 SET_FOUR = 4; -constexpr int16 SET_FIVE = 5; -constexpr int16 SET_SIX = 6; -constexpr int16 SET_SEVEN = 7; -constexpr int16 SET_EIGHT = 8; -constexpr int16 SET_NINE = 9; -constexpr int16 SET_TEN = 10; -constexpr int16 SET_TWELVE = 12; -constexpr int16 SET_THIRTEEN = 13; -constexpr int16 SET_FOURTEEN = 14; -constexpr int16 SET_HUNDRED = 100; -constexpr int16 SET_TWO_HUNDRED = 200; class DateView; class DatePresenter : public Presenter {}; } -#endif // DATE_PRESENTER_H \ No newline at end of file +#endif // DATE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateView.h index 8271b29e0..93a6e52f8 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/date/DateView.h @@ -17,4 +17,4 @@ enum DATE_PAGES { class DatePresenter; class DateView : public View {}; } -#endif // Date_VIEW_H +#endif // Date_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPage.h index 0b497c751..889b4d6d3 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPage.h @@ -1,15 +1,15 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: EmptyPage * Create: 2025-04-24 */ #ifndef EMPTY_PAGE_H #define EMPTY_PAGE_H #include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" #include "components/ui_label.h" #include "SlicePage.h" -#include "emptypage/EmptyPresenter.h" +#include "EmptyPresenter.h" namespace OHOS { @@ -17,11 +17,10 @@ class EmptyPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - EmptyPage(){}; + EmptyPage(); ~EmptyPage(); void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; - bool OnClick(UIView& view, const ClickEvent& event) override; private: EmptyPage(const EmptyPage &) = delete; @@ -29,17 +28,17 @@ private: EmptyPage(EmptyPage &&) = delete; EmptyPage &operator=(EmptyPage &&) = delete; - UIScrollView *container_ = nullptr; - UILabel *memLabel_ = nullptr; - uint32_t used_ = 0; - uint32_t free_ = 0; + UIViewGroup *container_ = nullptr; + UIImageView *bgImg_{nullptr}; + UILabel *memUsedLabel_ = nullptr; + UILabel *memFreeLabel_ = nullptr; }; #ifdef __cplusplus extern "C" { #endif #if !defined(_WIN32) -uint32_t test_get_mem_info(uint8_t memType, uint32_t *used, uint32_t *free); +uint32_t test_get_mem_info(uint32_t *used, uint32_t *free); #endif #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPresenter.h index ca245c8d2..35e9ad6ee 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyPresenter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: EmptyPresenter * Create: 2025-04-24 */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyView.h index b17ea9e70..fdcce2536 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/emptypage/EmptyView.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: EmptyView * Create: 2025-04-24 */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h index 39e3b9222..5f1224d96 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h @@ -24,13 +24,12 @@ #include "SlicePage.h" #include "diag_service.h" #include "ohos_timer.h" -#include "findphone/FindPhoneModel.h" -#include "findphone/FindPhonePresenter.h" +#include "FindPhoneModel.h" +#include "FindPhonePresenter.h" -#define ALIPAY_BIND_SEARCH_IMAGE_NUM 28 namespace OHOS { -static int timeCount = 0; -static constexpr uint64_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t FINDPHONE_IMAGE_COUNT = 28; + class FindPhonePresenter; class FindPhoneModel; class FindPhoneMainPage : public SlicePage, @@ -45,8 +44,8 @@ public: bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; bool ClickButtonChange(); - void SetUpImageAnimator(); - void SetupButton(); + void InitImageAnimator(); + void InitButton(); void InitImageInfo(); void ShowReset(); void DisableFindPhoneTimer(); @@ -54,21 +53,17 @@ public: bool StopFindPhone(); uint8_t GetConnectStatus(); void ChangeToDisConnect(); + private: UIViewGroup* container_ = nullptr; - UILabel* labelUnder = nullptr; - UILabel* labelFindTitle = nullptr; - UIButton* buttonFind = nullptr; - UIButton* buttonRty = nullptr; - UILabel *labelRing = nullptr; - UIImageView *mainImage = nullptr; - ImageInfo* imageInfo1_ = nullptr; - ImageInfo* imageInfo2_ = nullptr; - ImageInfo* imageInfo3_ = nullptr; - ImageAnimatorInfo imageAnimatorImageInfo_[SET_THREE] = { 0 }; + UILabel* labelDisconnect_ = nullptr; + UILabel* labelTitle_ = nullptr; + UIButton* buttonFind_ = nullptr; + UIButton* buttonRetry_ = nullptr; + UILabel *labelRing_ = nullptr; UIImageAnimatorView* imageAnimator_ = nullptr; - GraphicTimer *g_startCount = nullptr; - ImageAnimatorInfo searchImageInfo[ALIPAY_BIND_SEARCH_IMAGE_NUM]; + GraphicTimer *startCount_ = nullptr; + ImageAnimatorInfo searchImageInfo_[FINDPHONE_IMAGE_COUNT]; }; } -#endif // FINDPHONE_VIEW_H +#endif // FINDPHONE_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneModel.h index 494c171be..f093182d2 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneModel.h @@ -13,19 +13,6 @@ #include "graphic_timer.h" namespace OHOS { -constexpr int16_t SET_ZERO = 0; -constexpr int16_t SET_ONE = 1; -constexpr int16_t SET_TWO = 2; -constexpr int16_t SET_THREE = 3; -constexpr int16_t SET_FOUR = 4; -constexpr int16_t SET_FIVE = 5; -constexpr int16_t SET_SIX = 6; -constexpr int16_t SET_SEVEN = 7; -constexpr int16_t SET_EIGHT = 8; -constexpr int16_t SET_NINE = 9; -constexpr int16_t SET_TEN = 10; -constexpr int16_t SET_INT_MAX = 255; - class FindPhoneModel { public: static FindPhoneModel &GetInstance(void); @@ -35,7 +22,6 @@ private: FindPhoneModel(const FindPhoneModel &); FindPhoneModel &operator=(const FindPhoneModel &); virtual ~FindPhoneModel(); - bool buttonStatus = 0; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhonePresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhonePresenter.h index 6c74c4669..5515e75c4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhonePresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhonePresenter.h @@ -14,5 +14,4 @@ namespace OHOS { class FindPhoneView; class FindPhonePresenter : public Presenter {}; } - #endif // FINDPHONE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneView.h index 6cb7de185..547b617c7 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/findphone/FindPhoneView.h @@ -11,7 +11,6 @@ namespace OHOS { enum FIND_PHONE_PAGES { FIND_PHONE_MAIN_PAGE = 1, // 0 is invalid - FIND_PHONE_MESSAGE_PAGE = 2, }; class FindPhonePresenter; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h index 46f4ef937..2dddf14a8 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h @@ -11,7 +11,7 @@ #include "components/ui_label_button_ext.h" #include "components/ui_scroll_view.h" #include "SlicePage.h" -#include "flashlight/FlashLightPresenter.h" +#include "FlashLightPresenter.h" #include "components/ui_picker.h" namespace OHOS { @@ -19,7 +19,7 @@ class FlashLightBlinkPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - FlashLightBlinkPage(){}; + FlashLightBlinkPage(); ~FlashLightBlinkPage(); void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h index acbe25c21..33851596a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h @@ -11,14 +11,14 @@ #include "components/ui_label_button_ext.h" #include "components/ui_scroll_view.h" #include "SlicePage.h" -#include "flashlight/FlashLightPresenter.h" +#include "FlashLightPresenter.h" namespace OHOS { class FlashLightColorPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - FlashLightColorPage(){}; + FlashLightColorPage(); ~FlashLightColorPage(); void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; @@ -32,15 +32,15 @@ private: UIScrollView *container_ = nullptr; UILabel *colorLabel_ = nullptr; - UILabelButtonExt *color1Button_ = nullptr; - UILabelButtonExt *color2Button_ = nullptr; - UILabelButtonExt *color3Button_ = nullptr; - UILabelButtonExt *color4Button_ = nullptr; - UILabelButtonExt *color5Button_ = nullptr; - UILabelButtonExt *color6Button_ = nullptr; - UILabelButtonExt *color7Button_ = nullptr; - UILabelButtonExt *color8Button_ = nullptr; - UILabelButtonExt *color9Button_ = nullptr; + UILabelButtonExt *colorWhiteButton_ = nullptr; + UILabelButtonExt *colorRedButton_ = nullptr; + UILabelButtonExt *colorOrangeButton_ = nullptr; + UILabelButtonExt *colorYellowButton_ = nullptr; + UILabelButtonExt *colorGreenButton_ = nullptr; + UILabelButtonExt *colorLightBlueButton_ = nullptr; + UILabelButtonExt *colorDarkBlueButton_ = nullptr; + UILabelButtonExt *colorPurpleButton_ = nullptr; + UILabelButtonExt *colorMultiButton_ = nullptr; }; } // namespace OHOS #endif /* FLASHLIGHT_COLOR_PAGE_H */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightModel.h index adf42ce13..a19e656ab 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightModel.h @@ -13,8 +13,8 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "flashlight/FlashLightPresenter.h" -#include "flashlight/FlashlightUiResourceImage.h" +#include "FlashLightPresenter.h" +#include "ui_resource_flashlight.h" #ifndef _WIN32 #include "time64.h" #endif @@ -38,8 +38,8 @@ class FlashLightModel { public: static FlashLightModel &GetInstance(void); // 设置手电筒颜色; - FlashLightColorAttribute GetViewColor(); - void SetViewColor(FlashLightColorAttribute color); + FlashLightColorAttribute GetViewColorId(); + void SetViewColorId(FlashLightColorAttribute color); // 设置手电筒闪烁频率; FlashLightBlinkFrequency GetBlinkFrequency(); void SetBlinkFrequency(FlashLightBlinkFrequency blinkFrequency); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPage.h index 629a2e871..035013677 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPage.h @@ -21,7 +21,7 @@ #include "ChangeSliceListener.h" #include "UiConfig.h" #include "SlicePage.h" -#include "flashlight/FlashLightPresenter.h" +#include "FlashLightPresenter.h" #include "animator.h" namespace OHOS { @@ -29,7 +29,7 @@ class FlashLightPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - FlashLightPage(){}; + FlashLightPage(); ~FlashLightPage(); void OnStart(void* data) override; @@ -45,9 +45,9 @@ private: }; TimeAnimatorCallback* timeCallback_ = nullptr; Animator* timeAnimator_ = nullptr; - UILabelButton* flashLightOn_ = nullptr; + UILabelButton* flashLightButtonOn_ = nullptr; UILabel* systemTime_ = nullptr; - UILabel* OnLabel_ = nullptr; + UILabel* tipsLabel_ = nullptr; UIImageView* imageArrow_ = nullptr; UIScrollView *container_ = nullptr; }; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h index b7fc36541..b0bce0c83 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h @@ -10,15 +10,17 @@ #include "components/ui_image_view.h" #include "components/ui_image_animator.h" #include "SlicePage.h" -#include "flashlight/FlashLightPresenter.h" -#include "flashlight/FlashLightModel.h" +#include "FlashLightPresenter.h" +#include "FlashLightModel.h" namespace OHOS { +static constexpr uint8_t IMAGE_NUM = 2; + class FlashLightPlayPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - FlashLightPlayPage(){}; + FlashLightPlayPage(); ~FlashLightPlayPage(); void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; @@ -31,8 +33,8 @@ private: FlashLightPlayPage &operator=(FlashLightPlayPage &&) = delete; UIScrollView *container_ = nullptr; - UIImageAnimatorView *playImageAnimal = nullptr; - ImageAnimatorInfo playImageInfo[2]; + UIImageAnimatorView *playImageAnimal_ = nullptr; + ImageAnimatorInfo playImageInfo_[IMAGE_NUM]; }; } // namespace OHOS #endif /* FLASHLIGHT_PLAY_PAGE_H */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightRecoverPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightRecoverPage.h new file mode 100644 index 000000000..62d67461e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightRecoverPage.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightRecoverPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_RECOVER_PAGE_H +#define FLASHLIGHT_RECOVER_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "FlashLightPresenter.h" + +namespace OHOS { +class FlashLightRecoverPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightRecoverPage(); + ~FlashLightRecoverPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightRecoverPage(const FlashLightRecoverPage &) = delete; + FlashLightRecoverPage &operator=(const FlashLightRecoverPage &) = delete; + FlashLightRecoverPage(FlashLightRecoverPage &&) = delete; + FlashLightRecoverPage &operator=(FlashLightRecoverPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *recoverLabel_ = nullptr; + UILabelButtonExt *cancelButton_ = nullptr; + UILabelButtonExt *confirmButton_ = nullptr; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_RECOVER_PAGE_H */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h index 1704f88ab..baf74a6a0 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h @@ -13,7 +13,6 @@ namespace OHOS { typedef struct { - uint8_t item; uint32_t resId; std::string label; std::string itemLabel; @@ -25,14 +24,13 @@ public: FlashLightSetItemView(); ~FlashLightSetItemView() override; virtual void SetItemInfo(const FlashLightSetItem itemInfo); - const char *GetViewId() const; private: - UIImageView sIcon; - UILabel sLabel; - UILabel itemLabel; - UIImageView sNextImage; - FlashLightSetItem sItemInfo = {0, 0, "", "", ""}; + UIImageView sIcon_; + UILabel sLabel_; + UILabel itemLabel_; + UIImageView sNextImage_; + FlashLightSetItem itemInfo_ = {0, "", "", ""}; }; } #endif // FLASHLIGHTSET_ITEM_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h index d1f1b068b..8c48bcd1d 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h @@ -10,21 +10,20 @@ #include "components/ui_label.h" #include "components/ui_label_button_ext.h" #include "components/ui_scroll_view.h" -#include "components/ui_list.h" +#include "components/ui_simple_list.h" #include "SlicePage.h" -#include "flashlight/FlashLightPresenter.h" -#include "flashlight/FlashLightSetItemAdapter.h" -#include "flashlight/FlashLightSetItemView.h" +#include "FlashLightPresenter.h" +#include "FlashLightSetItemView.h" #include "UiConfig.h" #include "main/LoadImg.h" -#include "flashlight/FlashlightUiResourceImage.h" +#include "ui_resource_flashlight.h" namespace OHOS { class FlashLightSetPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - FlashLightSetPage(){}; + FlashLightSetPage(); ~FlashLightSetPage(); void OnStart(void* data) override; bool OnDrag(UIView& view, const DragEvent& event) override; @@ -37,13 +36,9 @@ private: FlashLightSetPage &operator=(FlashLightSetPage &&) = delete; UIScrollView *container_ = nullptr; - UILabel *setLabel_ = nullptr; + UILabel *titleLabel_ = nullptr; UILabelButtonExt *recoverButton_ = nullptr; - - UIList* setItemList_ = nullptr; - FlashLightSetItemAdapter *setItemAdapter_ = nullptr; - FlashLightSetItem colorItem_ = {1, IMAGE_CONVERTER_TOOL_COLORITEM, "灯光颜色"}; - FlashLightSetItem blinkItem_ = {2, IMAGE_CONVERTER_TOOL_BLINKITEM, "闪烁频率"}; + UISimpleList* setItemList_ = nullptr; }; } // namespace OHOS #endif /* FLASHLIGHT_SET_PAGE_H */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightView.h index 463a94e1c..c3e1783cb 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/flashlight/FlashLightView.h @@ -10,12 +10,12 @@ namespace OHOS { enum FlashLightAllView { - FLASH_LIGTH_VIEW = 1, // 手电筒主界面 + FLASH_LIGHT_VIEW = 1, // 手电筒主界面 FLASH_LIGHT_PLAY_VIEW, // 手电筒显示播放 FLASH_LIGHT_SET_VIEW, // 手电筒设置 FLASH_LIGHT_COLOR_VIEW, // 手电筒颜色 FLASH_LIGHT_BLINK_VIEW, // 手电筒闪烁 - FLASH_LIGHT_DEFAULT_VIEW, // 手电筒默认 + FLASH_LIGHT_RECOVER_VIEW, // 手电筒默认 FLASH_LIGHT_ALL_VIEW, }; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMainPage.h new file mode 100644 index 000000000..08e23ab58 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMainPage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateMainPage + * Create: 2025-06 + */ + +#ifndef HEART_RATE_MAIN_PAGE_H +#define HEART_RATE_MAIN_PAGE_H + +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_image_animator.h" +#include "components/ui_lite_surface_view.h" +#include "layout/grid_layout.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "ui_test.h" +#include "View.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "video_play_wrapper.h" + +namespace OHOS { +class HeartRatePresenter; +class HeartRateMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + HeartRateMainPage(); + ~HeartRateMainPage() override; + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnResume() override; + void OnPause() override; + bool IsToday(const struct timeval &tv); + void SetTestTime(); + void InitImageAnimator(); + +private: + UIViewGroup *group_ = nullptr; + UILabelButton *button_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelPreTest_ = nullptr; + UILiteSurfaceView *surfaceView_ = nullptr; + MediaVideoPlay *videoPlay_ = nullptr; + ColorType colorKey_; +}; +} +#endif // HEART_RATE_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMeasurePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMeasurePage.h new file mode 100644 index 000000000..a97835ba2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateMeasurePage.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateMeasurePage + * Create: 2025-06 + */ + +#ifndef HEART_RATE_MEASURE_PAGE_H +#define HEART_RATE_MEASURE_PAGE_H + +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_lite_surface_view.h" +#include "layout/grid_layout.h" +#include "animator/animator.h" +#include "ChangeSliceListener.h" +#include "View.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "video_play_wrapper.h" +#include "HeartRateModel.h" +#include "HeartRatePresenter.h" +#include "HeartRateView.h" +#include "HeartRateResultGroup.h" + +namespace OHOS { +class HeartRatePresenter; +class HeartRateMeasurePage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + HeartRateMeasurePage(); + ~HeartRateMeasurePage() override; + void OnStart(void *data) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitAnimator(); + void StopAnimator(); + void InitVideoView(); + void SetTimeAndResultText(std::string str); + void SetTestStatus(bool value); + void OnResume() override; + void OnPause() override; +private: + + // 心率线型图结果展示页面,通过setvisible进行显示隐藏操作 + // 作用:线型图退出之后不会重新进入心率测量状态 + HeartRateResultGroup *chartLineResultGroup_ = nullptr; + UIViewGroup *group_ = nullptr; + UILabel *labelTitle_ = nullptr; + UILabel *labelTimeOrResult_ = nullptr; + UILabel *labelTips_ = nullptr; + UILiteSurfaceView *surfaceView_ = nullptr; + MediaVideoPlay *videoPlay_ = nullptr; + ColorType colorKey_; + struct timeval startTime_; + bool measureStatus_; + class HeartAnimatorCallback : public AnimatorCallback { + public: + explicit HeartAnimatorCallback(HeartRateMeasurePage *page) : page_(page) {} + ~HeartAnimatorCallback() override {} + void Callback(UIView *view) override; + private: + HeartRateMeasurePage *page_{nullptr}; + }; + Animator *animator_ = nullptr; + HeartAnimatorCallback *callBack_ = nullptr; +}; +} +#endif // HEART_RATE_MEASURE_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateModel.h new file mode 100644 index 000000000..6d8f6e5f1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateModel.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateModel + * Create: 2025-06 + */ + +#ifndef HREATE_RATE_ITEM_MODEL_H +#define HREATE_RATE_ITEM_MODEL_H + +#include +#include +#include +#include "graphic_timer.h" + +namespace OHOS { +static constexpr uint16_t HEART_ALL_POINTS = 360; + +typedef struct { + uint16_t heartRate; + struct timeval time; +} heartRateMeasurementInfo; + +typedef struct { + /** X coordinate */ + uint16_t x; + /** Y coordinate */ + uint16_t y; +} HeartPoint; + +typedef struct { + uint16_t perSec; + uint16_t rest; + uint16_t minX; + uint16_t minValue; + uint16_t maxX; + uint16_t maxValue; + uint16_t index; + HeartPoint value[HEART_ALL_POINTS]; +} HeartDatas; + +class HeartRateModel { +public: + static HeartRateModel &GetInstance(void); + void SetHeartRate(heartRateMeasurementInfo value) + { + heartRate = value; + }; + heartRateMeasurementInfo GetHeartRate() + { + return heartRate; + }; + +private: + HeartRateModel(); + HeartRateModel(const HeartRateModel &); + HeartRateModel &operator=(const HeartRateModel &); + virtual ~HeartRateModel(); + heartRateMeasurementInfo heartRate = {0, 0}; +}; +} +#endif // HREATE_RATE_ITEM_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRatePresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRatePresenter.h new file mode 100644 index 000000000..b989229cd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRatePresenter.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRatePresenter + * Create: 2025-06 + */ + +#ifndef HEART_RATE_PRESENTER_H +#define HEART_RATE_PRESENTER_H + +#include "components/ui_view.h" +#include "Presenter.h" + +namespace OHOS { +class HeartRateView; +class HeartRatePresenter : public Presenter { + HeartRatePresenter *GetInstance(); +}; +} + +#endif // HEART_RATE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateReadyPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateReadyPage.h new file mode 100644 index 000000000..d6130573d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateReadyPage.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateReadyPage + * Create: 2025-06 + */ + +#ifndef HEART_RATE_READY_PAGE_H +#define HEART_RATE_READY_PAGE_H + +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_label_button.h" +#include "layout/grid_layout.h" +#include "animator/animator.h" +#include "ChangeSliceListener.h" +#include "View.h" +#include "ui_test.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "HeartRateModel.h" +#include "HeartRatePresenter.h" +#include "HeartRateView.h" + +namespace OHOS { +class HeartRatePresenter; +class HeartRateReadyPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + HeartRateReadyPage(); + ~HeartRateReadyPage() override; + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitAnimator(); + void SetLabelProgressTime(int value); + void StopAnimator(); + int InitCircleProgress(); + void InitImageAnimator(); + +private: + UILabel *labelTips_ = nullptr; + UIViewGroup *group_ = nullptr; + UILabelButton *button_ = nullptr; + UICircleProgress *timeProgress_ = nullptr; + UILabel *labelProgressTime_ = nullptr; + struct timeval startTime_; + class HeartAnimatorCallback : public AnimatorCallback { + public: + explicit HeartAnimatorCallback(HeartRateReadyPage *page) : page_(page) {} + ~HeartAnimatorCallback() override {} + void Callback(UIView *view) override; + + private: + HeartRateReadyPage *page_{nullptr}; + }; + Animator *animator_ = nullptr; + HeartAnimatorCallback *callBack_ = nullptr; +}; +} +#endif // HEART_RATE_READY_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateResultGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateResultGroup.h new file mode 100644 index 000000000..8ef909677 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateResultGroup.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateResultGroup + * Create: 2025-06 + */ + +#ifndef HEARTRATE_RESULT_GROUP_H +#define HEARTRATE_RESULT_GROUP_H + +#include +#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" +#include "components/ui_swipe_view.h" +#include "components/ui_label.h" +#include "components/ui_chart.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "HeartRatePresenter.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "HeartRateView.h" + +namespace OHOS { +static constexpr uint16_t HEARTRATE_ANIMATOR_IMAGE_NUM = 30; +static constexpr uint16_t HEARTRATE_ANIMATOR_IMAGE_UPDATE = 70; +class HeartRatePresenter; +class HeartRateResultGroup : public UIViewGroup { +public: + HeartRateResultGroup(); + ~HeartRateResultGroup() override; + void InitPage(); + void InitImageAnimator(); + UILabel *labelHeartRateValue_ = nullptr; +private: + UIImageAnimatorView *imageAnimator_ = nullptr; + UILabel *labelTitle_ = nullptr; + UIChartPolyline *chartPolyline_ = nullptr; + UILabel *labelLastMeasureTime_ = nullptr; + UILabel *labelUnitText_ = nullptr; + UIChartDataSerial *dataSerial_{nullptr}; + UIImageView *imageRedArrow_ = nullptr; + UILabel *labelMaxValue_ = nullptr; + UIImageView *imageBlackArrow_ = nullptr; + UILabel *labelMinValue_ = nullptr; + // X轴坐标三个点位 + UILabel *labelXAxisPointOne_ = nullptr; + UILabel *labelXAxisPointTwo_ = nullptr; + UILabel *labelXAxisPointThree_ = nullptr; + // Y轴坐标四个点位 + UILabel *labelYAxisPointOne_ = nullptr; + UILabel *labelYAxisPointTwo_ = nullptr; + UILabel *labelYAxisPointThree_ = nullptr; + UILabel *labelYAxisPointFour_ = nullptr; + UIImageView *mainImg_ = nullptr; + ImageAnimatorInfo imageAnimatorImageInfo_[HEARTRATE_ANIMATOR_IMAGE_NUM]; +}; +} +#endif // HEARTRATE_RESULT_GROUP_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateView.h index 152b81259..3a125f8a2 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/heartrate/HeartRateView.h @@ -1,104 +1,22 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: heartRate view - * Author: - * Create: 2021-07-26 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: HeartRateView + * Create: 2025-06 */ -#ifndef HEART_RATE_VIEW_H -#define HEART_RATE_VIEW_H +#ifndef HEART_RATE_ITEM_VIEW_H +#define HEART_RATE_ITEM_VIEW_H #include "View.h" -#include "components/ui_image_animator.h" -#include "components/ui_chart.h" -#include "wearable_log.h" -#include "ohos_types.h" -#include "components/ui_card_page.h" -#include "heartrate/HeartModel.h" namespace OHOS { -#define HEART_AVE_NUM 360 -#define HEART_RATE_LIMIT_UPPER 200 -#define HEART_RATE_LIMIT_LOWER 0 -#define INVALID_HEART_VALUE ((int16)0xFFFF) - -#define NUM_1 1 -#define NUM_2 2 -#define NUM_3 3 -#define NUM_4 4 -#define NUM_5 5 -#define NUM_7 7 -#define NUM_16 16 -#define NUM_99 99 - -class HeartRateView : public UICardPage { -public: - HeartRateView(); - ~HeartRateView() override; - static HeartRateView *GetInstance(void); - - bool InitView(void); - void PreLoad(void) override; - void UnLoad(void) override; - int32_t SetHeartRateData(Point *rateData, uint32 rateDataSize); // 设置心率数据,用于画心率曲线 - void RefreshElectrocardiogram(void); // 刷新心率曲线 - void ClearElectrocardiogram(void); // 清空心率曲线 - void RefreshHeartRatePerSec(uint16_t value); // 刷新每秒心率 - void RefreshHeartRateMax(uint16_t max); // 刷新心率最大值 - void RefreshHeartRateMin(uint16_t min); // 刷新心率最小值 - void RefreshRestHeartRate(uint16_t value); // 刷新静息心率 - void HeartbeatImageAnimatorStart(void); // 心形动画启动 - void HeartbeatImageAnimatorStop(void); // 心形动画停止 - void InitRefreshInterface(void); - -private: - typedef struct { - uint8_t fontSize; - int16 x; - int16 y; - int16 width; - int16 height; - } LabelInfo; - - int32_t InitHeartRateData(void); - void SetLabel(UILabel *label, LabelInfo labelInfo); - void HeartRateLabelDisplay(void); - void HeartRateCoordinate(void); - void HeartRateElectrocardiogram(void); - void InsertTopAndBottomRateImage(void); - void UpdataTopAndBottomRate(void); - void ElectrocardiogramOnePoint(Point *rateData, uint16_t index); - void ElectrocardiogramMultiPoint(Point *rateData, uint16_t rateDataNume); - int32_t HeartRateDataProc(void); - void HeartbeatImageAnimator(void); - -private: - Point heartRateData[HEART_AVE_NUM]; - Point rateDataTmp[HEART_AVE_NUM]; - - bool viewiInitStatus{false}; - bool resLoadStatus{false}; - UIChartPolyline *chart{nullptr}; - uint16_t dataNume; // 心率曲线记录数据总个数 - uint16_t currIndex; // 当前已显示心率曲线心率个数 - UIChartDataSerial *dataSerial[HEART_AVE_NUM]{nullptr}; - UIChartDataSerial *dataTopAndbottom{nullptr}; - UIImageView *imageViewTop{nullptr}; - UIImageView *imageViewBottom{nullptr}; - uint16_t serialIndex; - UIImageAnimatorView *imageAnimator{nullptr}; - UIImageView *imageViewCoordinate{nullptr}; - - UILabel *topRate{nullptr}; - UILabel *bottomRate{nullptr}; - UILabel *ratePerSec{nullptr}; - UILabel *ratePerSecText{nullptr}; - UILabel *restRate{nullptr}; - UILabel *restRateText1{nullptr}; - UILabel *restRateText2{nullptr}; - - uint16_t maxRate; - uint16_t minRate; +enum HeartRateAllView { + HEARTRATE_MAIN_PAGE = 1, // 0 is invalid + HEARTRATE_READY_PAGE = 2, + HEARTRATE_MEASUREMENT_PAGE = 3, }; -} // namespace OHOS -#endif // HEART_RATE_VIEW_H + +class HeartRatePresenter; +class HeartRateView : public View {}; +} +#endif // HEART_RATE_ITEM_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/AppGroupView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/AppGroupView.h index 08529bdb5..2f9be05c5 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/AppGroupView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/AppGroupView.h @@ -1,28 +1,28 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: APPVEIW - * Author: - * Create: 2021-10-15 - */ - -#ifndef APP_GROUP_VIEW_H -#define APP_GROUP_VIEW_H - -#include -#include "View.h" -#include "components/ui_card_page.h" -#include "common/screen.h" - -namespace OHOS { -class AppGroupView : public UICardPage { -public: - AppGroupView() - { - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - } - ~AppGroupView() override {} - virtual bool InitView(void *caller)=0; - bool initViewStatus{false}; -}; -} // namespace OHOS -#endif // APP_GROUP_VIEW_H +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: APPVEIW + * Author: + * Create: 2021-10-15 + */ + +#ifndef APP_GROUP_VIEW_H +#define APP_GROUP_VIEW_H + +#include +#include "View.h" +#include "components/ui_card_page.h" +#include "common/screen.h" + +namespace OHOS { +class AppGroupView : public UICardPage { +public: + AppGroupView() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + } + ~AppGroupView() override {} + virtual bool InitView(void *caller)=0; + bool initViewStatus{false}; +}; +} // namespace OHOS +#endif // APP_GROUP_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/DialBinTypesV2.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/DialBinTypesV2.h index d49b354c7..07e92baff 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/DialBinTypesV2.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/DialBinTypesV2.h @@ -1,167 +1,167 @@ -/* - * Copyright (c) CompanyNameMagicTag 2024-2024. All rights reserved. - * Description: DialBinTypesV2 - * Author: - * Create: 2024-10-30 - */ - -#ifndef GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H -#define GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H -#include "main/DialBinTypes.h" - -namespace OHOS { -enum class DisplayState { - NORMAL, - AOD, -}; -static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY = 0; -static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY = 1; -static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_AMBITIENT_NORMAL = 2; - -struct DialHeader_V2 { - char dialName[DIAL_NAME_MAX_LEN]; - int16_t width; - int16_t height; - char version[DIAL_VERSION_MAX_LEN]; - uint16_t previewImgId; - char description[DIAL_DESCRIPTION_MAX_LEN]; - uint32_t imageOffset; - uint8_t freq; - uint8_t dialViewCount; - uint8_t displayCapabiliy; - uint8_t ambientFreq; -}; - -struct DialStaticImg_V2 { - Point pos; - Point center; - float rotate; - uint16_t imgId; - uint8_t displayMode; -}; - -struct DialSequenceImg_V2 { - Point pos; - uint16_t interval; - bool repeat; - uint8_t imgNum; - uint8_t displayMode; -}; - -struct DialRotateImg_V2 { - Point pos; - Point center; - int16_t rotateStart; - int16_t rotateEnd; - uint16_t imgId; - int16_t bindData; - bool isPeriod; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialOptionImg_V2 { - Point pos; - int16_t bindData; - bool isPeriod; - uint8_t count; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialDigitalImg_V2 { - uint8_t alignType : 4; - uint8_t integerLength : 4; - uint8_t decimalPrecision; - uint16_t imgIds[DIAL_DIGITALIMG_IMG_MAX_NUM]; - int16_t signImgId; - int16_t decimalPointImgId; - uint16_t space; - Point alignPosition; - int16_t bindData; - bool isPeriod; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialLabel_V2 { - uint8_t breakMode; - uint8_t align; - uint8_t fontSize; - bool isPeriod; - DialRect rect; - uint32_t color; - char fontName[64]; - char text[64]; - int16_t bindData; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialArcLabel_V2 { - uint8_t align; - uint8_t fontSize; - Point center; - int16_t radius; - int16_t rotateStart; - int16_t rotateEnd; - uint32_t color; - char fontName[64]; - char text[64]; - int16_t bindData; - bool isPeriod; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialBoxProgress_V2 { - uint8_t cap; - uint8_t direction; - bool isPeriod; - int16_t bindData; - uint32_t bgColor; - DialProgressType typeData; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialArcProgress_V2 { - uint8_t cap; - bool isPeriod; - uint16_t radius; - uint16_t startAngle; - uint16_t endAngle; - uint16_t lineWidth; - int16_t bindData; - uint32_t bgColor; - DialProgressType typeData; - uint8_t displayMode; - bool isAmbientPeriodic; -}; - -struct DialVideo_V2 { - DialRect rect; - uint32_t offset; - Color32 colorKey; - uint32_t imgId; - uint8_t displayMode; -}; - -struct DialClick_V2 { - uint8_t type; - DialRect rect; - union { - uint32_t sliceId; - char bundleName[64]; - }; - uint8_t displayMode; -}; - -struct DialKaleidoscope_V2 { - uint16_t imgId; - float crownRotateStep; - float animatorRotateStep; - uint8_t displayMode; -}; -} // namespace OHOS -#endif // GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H +/* + * Copyright (c) CompanyNameMagicTag 2024-2024. All rights reserved. + * Description: DialBinTypesV2 + * Author: + * Create: 2024-10-30 + */ + +#ifndef GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H +#define GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H +#include "main/DialBinTypes.h" + +namespace OHOS { +enum class DisplayState { + NORMAL, + AOD, +}; +static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY = 0; +static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY = 1; +static constexpr uint8_t DIAL_DISPLAY_CAPABILITY_AMBITIENT_NORMAL = 2; + +struct DialHeader_V2 { + char dialName[DIAL_NAME_MAX_LEN]; + int16_t width; + int16_t height; + char version[DIAL_VERSION_MAX_LEN]; + uint16_t previewImgId; + char description[DIAL_DESCRIPTION_MAX_LEN]; + uint32_t imageOffset; + uint8_t freq; + uint8_t dialViewCount; + uint8_t displayCapabiliy; + uint8_t ambientFreq; +}; + +struct DialStaticImg_V2 { + Point pos; + Point center; + float rotate; + uint16_t imgId; + uint8_t displayMode; +}; + +struct DialSequenceImg_V2 { + Point pos; + uint16_t interval; + bool repeat; + uint8_t imgNum; + uint8_t displayMode; +}; + +struct DialRotateImg_V2 { + Point pos; + Point center; + int16_t rotateStart; + int16_t rotateEnd; + uint16_t imgId; + int16_t bindData; + bool isPeriod; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialOptionImg_V2 { + Point pos; + int16_t bindData; + bool isPeriod; + uint8_t count; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialDigitalImg_V2 { + uint8_t alignType : 4; + uint8_t integerLength : 4; + uint8_t decimalPrecision; + uint16_t imgIds[DIAL_DIGITALIMG_IMG_MAX_NUM]; + int16_t signImgId; + int16_t decimalPointImgId; + uint16_t space; + Point alignPosition; + int16_t bindData; + bool isPeriod; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialLabel_V2 { + uint8_t breakMode; + uint8_t align; + uint8_t fontSize; + bool isPeriod; + DialRect rect; + uint32_t color; + char fontName[64]; + char text[64]; + int16_t bindData; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialArcLabel_V2 { + uint8_t align; + uint8_t fontSize; + Point center; + int16_t radius; + int16_t rotateStart; + int16_t rotateEnd; + uint32_t color; + char fontName[64]; + char text[64]; + int16_t bindData; + bool isPeriod; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialBoxProgress_V2 { + uint8_t cap; + uint8_t direction; + bool isPeriod; + int16_t bindData; + uint32_t bgColor; + DialProgressType typeData; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialArcProgress_V2 { + uint8_t cap; + bool isPeriod; + uint16_t radius; + uint16_t startAngle; + uint16_t endAngle; + uint16_t lineWidth; + int16_t bindData; + uint32_t bgColor; + DialProgressType typeData; + uint8_t displayMode; + bool isAmbientPeriodic; +}; + +struct DialVideo_V2 { + DialRect rect; + uint32_t offset; + Color32 colorKey; + uint32_t imgId; + uint8_t displayMode; +}; + +struct DialClick_V2 { + uint8_t type; + DialRect rect; + union { + uint32_t sliceId; + char bundleName[64]; + }; + uint8_t displayMode; +}; + +struct DialKaleidoscope_V2 { + uint16_t imgId; + float crownRotateStep; + float animatorRotateStep; + uint8_t displayMode; +}; +} // namespace OHOS +#endif // GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/HealthModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/HealthModel.h index 9b6015779..9b087ae7e 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/HealthModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/HealthModel.h @@ -18,7 +18,7 @@ #include #include "gfx_utils/list.h" -#include "main/UiServersMsg.h" +#include "UiServersMsg.h" namespace OHOS { #define NUM_1 1 diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/LoadImg.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/LoadImg.h index b92e242a7..0804abc01 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/LoadImg.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/LoadImg.h @@ -1,8 +1,9 @@ /* - * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: LoadImg * Create: 2025-06-05 */ + #ifndef LOAD_IMG_H #define LOAD_IMG_H @@ -18,6 +19,8 @@ namespace LOADIMG { void LoadBtnImage(UIButton *btn, std::string file, uint32_t resId1, uint32_t resId2); void LoadImageViewImg(UIImageView *view, std::string file, uint32_t resId); + +void LoadImageImg(Image *view, std::string file, uint32_t resId); } } #endif // LOAD_IMG_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainPresenterSample.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainPresenterSample.h index 444436189..6a1dd40a0 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainPresenterSample.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainPresenterSample.h @@ -1,87 +1,78 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainPresenterSample - * Author: - * Create: - */ - -#ifndef MAIN_PRESENTER_SAMPLE_H -#define MAIN_PRESENTER_SAMPLE_H - -#include "Presenter.h" -#include "main/ModelListenerSample.h" -#include "components/root_view.h" -#include "drag_event.h" -#include "main/MainViewSample.h" -#include "main/MainModel.h" -#include "components/ui_swipe_view.h" -#include "components/ui_view.h" -#include "compass/MainCompassView.h" -#include "compass/MainCompassPresenter.h" -#include "player/PlayersView.h" -#include "heartrate/HeartRateView.h" -#include "swipe_effect/zoom_effect.h" - -namespace OHOS { -static constexpr const char *MAIN_CLICK_WEATHER = "mainclickweather"; -static constexpr const char *MAIN_CLICK_ACTIVITY = "mainclickactivity"; -static constexpr const char *MAIN_CLICK_MESSAGE = "mainclickmessage"; -static constexpr const char *MAIN_CLICK_HEARTRATE = "mainclickheartrate"; - -static constexpr const char *DROPDOWN_CLICK_DONOTDISTURB = "dropdownclickdonotdisturb"; -static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = "dropdownclickbrightscreen"; -static constexpr const char *DROPDOWN_CLICK_FINDMYPHONE = "dropdownclickfindmyphone"; -static constexpr const char *DROPDOWN_CLICK_ALARM = "dropdownclickalarm"; -static constexpr const char *DROPDOWN_CLICK_SETTING = "dropdownclicksetting"; -constexpr uint16_t VERTICAL_STATUS = 1; -constexpr uint16_t HORIZONTAL_STATUS = 0; -enum class MainPresenterState { - START, - RESUME, - PAUSE, - STOP, -}; - -class MainViewSample; -class MainPresenterSample : public Presenter, public ModelListenerSample, - public UIView::OnClickListener, public UISwipeView::OnSwipeListener, - public UIView::OnLongPressListener, public UISwipeView { -public: - MainPresenterSample(); - ~MainPresenterSample() override; - static MainPresenterSample *GetInstance(void); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - void Notify() override; - bool OnClick(UIView& view, const ClickEvent& event) override; - bool OnLongPress(UIView& view, const LongPressEvent& event) override; - void OnSwipe(UISwipeView& view) override; - void SetPage(int8_t id, bool loadAdjacent = true); - void SetTaskPeroid(CardId cardId); - - void InitCardSettings(void); - uint8_t GetCardSettingCount(void); - CardId *GetCardSettings(void); - void InitDialSettings(void); - DialSetting& GetDialSetting(); - bool IsFromSetCardView(void) const; - void SetFromSetCardView(bool isFrom); - uint8_t GetFromCardId(void); - MainPresenterState GetMainPresenterState(); - -private: - void ProcessDataNotify(void); - void SetCircleProgress(void); - uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - int64_t playerCurrentTime_{0}; - int64_t playerMusicDuration_{0}; - int64_t playerProgressValue_{0}; - bool isCompassSensorOpened_{false}; - MainPresenterState mainPresenterState_ = MainPresenterState::STOP; -}; -} - -#endif // MAIN_PRESENTER_H +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainPresenterSample + * Author: + * Create: + */ + +#ifndef MAIN_PRESENTER_SAMPLE_H +#define MAIN_PRESENTER_SAMPLE_H + +#include "Presenter.h" +#include "components/root_view.h" +#include "drag_event.h" +#include "main/MainViewSample.h" +#include "main/MainModel.h" +#include "components/ui_swipe_view.h" +#include "components/ui_view.h" +#include "compass/MainCompassView.h" +#include "compass/MainCompassPresenter.h" +#include "player/PlayersView.h" +#include "common/task.h" + +namespace OHOS { +static constexpr const char *MAIN_CLICK_WEATHER = "mainclickweather"; +static constexpr const char *MAIN_CLICK_ACTIVITY = "mainclickactivity"; +static constexpr const char *MAIN_CLICK_MESSAGE = "mainclickmessage"; + +static constexpr const char *DROPDOWN_CLICK_DONOTDISTURB = "dropdownclickdonotdisturb"; +static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = "dropdownclickbrightscreen"; +static constexpr const char *DROPDOWN_CLICK_FINDMYPHONE = "dropdownclickfindmyphone"; +static constexpr const char *DROPDOWN_CLICK_ALARM = "dropdownclickalarm"; +static constexpr const char *DROPDOWN_CLICK_SETTING = "dropdownclicksetting"; +constexpr uint16_t VERTICAL_STATUS = 1; +constexpr uint16_t HORIZONTAL_STATUS = 0; +enum class MainPresenterState { + START, + RESUME, + PAUSE, + STOP, +}; + +class MainViewSample; +class MainPresenterSample : public Presenter, public UIView::OnClickListener, public Task, + public UISwipeView::OnSwipeListener, public UIView::OnLongPressListener, public UISwipeView { +public: + MainPresenterSample(); + ~MainPresenterSample() override; + static MainPresenterSample *GetInstance(void); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnLongPress(UIView& view, const LongPressEvent& event) override; + void OnSwipe(UISwipeView& view) override; + void SetPage(int8_t id, bool loadAdjacent = true); + void SetTaskPeroid(CardId cardId); + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void InitDialSettings(void); + DialSetting& GetDialSetting(); + bool IsFromSetCardView(void) const; + void SetFromSetCardView(bool isFrom); + uint8_t GetFromCardId(void); + MainPresenterState GetMainPresenterState(); + +private: + void ProcessDataNotify(void); + void Callback() override; + uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + bool isCompassSensorOpened_{false}; + MainPresenterState mainPresenterState_ = MainPresenterState::STOP; +}; +} + +#endif // MAIN_PRESENTER_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainViewSample.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainViewSample.h index b1be728de..eb0ae73d6 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainViewSample.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MainViewSample.h @@ -1,103 +1,102 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainViewSample - * Author: - * Create: - */ - -#ifndef MAIN_VIEW_SAMPLE_H -#define MAIN_VIEW_SAMPLE_H - -#include -#include "View.h" -#include "components/root_view.h" -#include "swipe_effect/zoom_effect.h" -#include "ChangeSliceListener.h" -#include "font/ui_font.h" -#include "graphic_config.h" -#include "main/ModelListenerSample.h" -#include "screensetting/ScreenModels.h" -#include "activity/ActivityWeekView.h" -#include "compass/CompassControlView.h" -#include "main/dial/DialViewGroup.h" -#include "clock/MainClockView.h" -#include "player/PlayersView.h" -#include "main/MainPresenterSample.h" -#include "heartrate/HeartRateView.h" -#include "components/ui_card_page.h" -#include "main/PullUpDownView.h" -#include "components/ui_cross_view.h" -#include "set_card/SetCardModel.h" -#include "videocard/VideoCard.h" - -namespace OHOS { -class MainPresenterSample; -class MainViewSample : public View { -public: - MainViewSample(); - ~MainViewSample() override; - static MainViewSample *GetInstance(void); - void OnStart() override; - void OnStop() override; - UICardPage *InitWatchFacePage(void); - UICardPage *InitHeartRatePage(void); - UICardPage *InitActivityPage(void); - UICardPage *InitCompassPage(void); - UICardPage *InitMusicPlayerPage(void); - UICardPage *InitVideoCardPage1(void); - UICardPage *InitVideoCardPage2(void); - UICardPage *InitVideoCardPage3(void); - void AnimatorStart(int pageIndex); - void AnimatorStop(void); - CardId GetHorCurrentCard() const; - UIView* GetMainViewGroup(void) const - { - return mainSwipeGroup; - } - - UICardPage* GetViewById(int16_t id) const - { - if (id >= MAX_CARD) { - return nullptr; - } - return recordCard[id]; - } - - void SwitchToClockPage(bool loadAdjacent = true) - { - if (mainClockView != nullptr) { - SetPage(mainClockView->GetViewIndex(), loadAdjacent); - } - } - void SwitchToCard(uint8_t cardId, bool loadAdjacent = true); - bool IsMainClockPage(void); - void SetPage(int16_t page, bool loadAdjacent = true); - void ReloadWatchFace(); - -private: - PullUpDownView *dropDownView{nullptr}; - UICardPage *messageView{nullptr}; - UILabel *messageLable{nullptr}; - UICardPage *mainClockView{nullptr}; - ActivityWeekView *activityWeekView{nullptr}; - PlayersView *playersView{nullptr}; - CompassControlView *compassControlView{nullptr}; - HeartRateView *heartRateView{nullptr}; - UICardPage *recordCard[MAX_CARD]{nullptr}; - bool pageStatus[MAX_CARD]{false}; - UICrossView *mainSwipeGroup{nullptr}; - ZoomEffect* callback{nullptr}; - VideoCard *videoCard1{nullptr}; - VideoCard *videoCard2{nullptr}; - VideoCard *videoCard3{nullptr}; - - bool HorizontalViewInit(void); - void VerticalViewInit(void); - void VertViewLoad(void); - void HorViewLoad(void); - UICardPage *InitWatchOffDial(DialSetting &setting); - UICardPage *InitWatchDial(DialSetting &setting); - UICardPage *InitVideoCardPage(const std::string &video, const std::string &preview); -}; -} // namespace OHOS -#endif // MAIN_VIEW_SAMPLE_H +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainViewSample + * Author: + * Create: + */ + +#ifndef MAIN_VIEW_SAMPLE_H +#define MAIN_VIEW_SAMPLE_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "swipe_effect/zoom_effect.h" +#include "ChangeSliceListener.h" +#include "font/ui_font.h" +#include "graphic_config.h" +#include "screensetting/ScreenModels.h" +#include "activity/ActivityWeekView.h" +#include "compass/CompassControlView.h" +#include "main/dial/DialViewGroup.h" +#include "clock/MainClockView.h" +#include "player/PlayersView.h" +#include "main/MainPresenterSample.h" +#include "components/ui_card_page.h" +#include "main/PullUpDownView.h" +#include "components/ui_cross_view.h" +#include "settings/model/SettingCardModel.h" +#include "settings/common/SettingCardEffectSample.h" +#include "videocard/VideoCard.h" +#include "main/MessageMainPage.h" + +namespace OHOS { +class MainPresenterSample; +class MainViewSample : public View { +public: + MainViewSample(); + ~MainViewSample() override; + static MainViewSample *GetInstance(void); + void OnStart() override; + void OnStop() override; + UICardPage *InitWatchFacePage(void); + UICardPage *InitActivityPage(void); + UICardPage *InitCompassPage(void); + UICardPage *InitMusicPlayerPage(void); + UICardPage *InitVideoCardPage1(void); + UICardPage *InitVideoCardPage2(void); + UICardPage *InitVideoCardPage3(void); + void AnimatorStart(int pageIndex); + void AnimatorStop(void); + CardId GetHorCurrentCard() const; + void GetVerCurrentCard() const; + UIView* GetMainViewGroup(void) const + { + return mainSwipeGroup; + } + + UICardPage* GetViewById(int16_t id) const + { + if (id >= MAX_CARD) { + return nullptr; + } + return recordCard[id]; + } + + void SwitchToClockPage(bool loadAdjacent = true) + { + if (mainClockView != nullptr) { + SetPage(mainClockView->GetViewIndex(), loadAdjacent); + } + } + void SwitchToCard(uint8_t cardId, bool loadAdjacent = true); + bool IsMainClockPage(void); + void SetPage(int16_t page, bool loadAdjacent = true); + void ReloadWatchFace(); + +private: + PullUpDownView *dropDownView{nullptr}; + MessageMainPage *messageView{nullptr}; + UICardPage *mainClockView{nullptr}; + ActivityWeekView *activityWeekView{nullptr}; + PlayersView *playersView{nullptr}; + CompassControlView *compassControlView{nullptr}; + UICardPage *recordCard[MAX_CARD]{nullptr}; + bool pageStatus[MAX_CARD]{false}; + UICrossView *mainSwipeGroup{nullptr}; + CardSwipe* callback{nullptr}; + VideoCard *videoCard1{nullptr}; + VideoCard *videoCard2{nullptr}; + VideoCard *videoCard3{nullptr}; + + bool HorizontalViewInit(void); + void VerticalViewInit(void); + void VertViewLoad(void); + void HorViewLoad(void); + UICardPage *InitWatchOffDial(DialSetting &setting); + UICardPage *InitWatchDial(DialSetting &setting); + UICardPage *InitVideoCardPage(const std::string &video, const std::string &preview); + bool SetCardEffect(CardEffectID style); +}; +} // namespace OHOS +#endif // MAIN_VIEW_SAMPLE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageDetailsGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageDetailsGroup.h new file mode 100644 index 000000000..006eda0a2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageDetailsGroup.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageDetailsGroup + * Create: 2025-06-29 + */ + +#ifndef MESSAGE_DETAILS_GROUP_H +#define MESSAGE_DETAILS_GROUP_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_message.h" +#include "MessageModel.h" + +namespace OHOS { +class DetailsGroup : public UIScrollView { +public: + DetailsGroup(); + ~DetailsGroup() override; + void InitDetailsPage(); + void RefreshNotify(); + MessageItem detailsMsg_; + +private: + UIImageView *detailsMsgIcon_{nullptr}; + UILabel *detailsMsgTitle_{nullptr}; + UILabel *detailsMsgContacts_{nullptr}; + UILabel *detailsMsgContents_{nullptr}; + UILabel *detailsMsgTime_{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageItemView.h index 73ec20a55..743fc36a5 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageItemView.h @@ -1,11 +1,7 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: weather/WeatherItemView.h - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageItemView + * Create: 2025-06-29 */ #ifndef MESSAGE_ITEM_VIEW_H @@ -15,25 +11,39 @@ #include "components/ui_view_group.h" #include "components/ui_image_view.h" #include "components/ui_canvas.h" - #include "UiConfig.h" #include "main/MessageModel.h" namespace OHOS { -class MessageItemView : public UIViewGroup { +class MessageItemView : public UIViewGroup, + public UIView::OnClickListener, + public UIView::OnDragListener { public: explicit MessageItemView(); ~MessageItemView() override; virtual void SetItemInfo(const MessageItem itemInfo); - virtual void SetUpChild(); + bool OnDragStartEvent(const DragEvent& event) override; + bool OnDragEvent(const DragEvent& event) override; + bool OnDragEndEvent(const DragEvent& event) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + void SetIndex(uint16_t index); + uint16_t GetIndex(); + MessageItem GetItem(); + void UpdateItemStatus(); + + int posX; + int x = 0; private: - UILabel sLabel_1; - UIImageView sIcon; - UILabel sLabel_2; - UILabel sLabel_3; - UIImageView sNextImage; - UILabel sback; - MessageItem sItemInfo = { nullptr, nullptr, nullptr, nullptr}; + uint16_t itemIndex_; + UIViewGroup group_; + UILabel appName_; + UIImageView appIcon_; + UILabel appContact_; + UILabel appContents_; + UILabel msgTime_; + UIImageView bgImg_; + UIImageView deleteImg_; + MessageItem msgItemInfo_ = {"", "", "", "", 0, 0, false}; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageMainPage.h new file mode 100644 index 000000000..7d0820d64 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageMainPage.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageMainPage + * Create: 2025-06-29 + */ + +#ifndef MESSAGE_MAIN_VIEW_H +#define MESSAGE_MAIN_VIEW_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_card_page.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" +#include "components/ui_simple_list.h" +#include "components/ui_list.h" +#include "main/MessageDetailsGroup.h" +#include "main/MessageModel.h" +#include "MainModel.h" +#include "main/MessageItemView.h" +namespace OHOS { +class MessageMainPage : public UICardPage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + MessageMainPage(); + ~MessageMainPage() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStartEvent(const DragEvent& event) override; + bool OnDragEvent(const DragEvent& event) override; + bool OnDragEndEvent(const DragEvent& event) override; + static MessageMainPage *GetInstance(void); + bool InitView(); + void PreLoad(void) override; + void VerticalViewInits(void); + void ConfirmDelete(void); + void CancelDelete(void); + void InitMsgList(void); + void DeleteView(void); + void NoNotify(void); + void NewNotify(void); + void RefreshMsgList(std::vector &item); + bool InitScrollData(); + void LoadDetailsView(void); + void DeleteDetailsView(void); + UISimpleList *msgList_{nullptr}; +private: + UILabel *noMsgLable_{nullptr}; + UILabel *msgLable_{nullptr}; + UIImageView *noMsgImage_{nullptr}; + UIImageView *deleteImage_{nullptr}; + UIScrollView *deleteGroup_{nullptr}; + UILabel *deleteTips_{nullptr}; + UIImageView *confirm_{nullptr}; + UIImageView *cancel_{nullptr}; + DetailsGroup *detailsGroup_{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageModel.h index fd24ca33d..2b135190a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/MessageModel.h @@ -1,8 +1,7 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainModel.h - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageModel + * Create: 2025-06-29 */ #ifndef MESSAGE_MODEL_H @@ -10,34 +9,45 @@ #include #include +#include #include "UiConfig.h" namespace OHOS { typedef struct { - std::string label_1; - std::string icon; - std::string label_2; - std::string label_3; + std::string appName; + std::string appContact; + std::string appContents; + std::string time; + uint16_t index; + long initialTime; + bool status; } MessageItem; - // static const uint16_t WEATHER_ITEM_COUNT = 10; class MessageModel { public: static MessageModel &GetInstance(void); - void InitMessageItem(); - const std::vector GetMessagelistItems() const; + void SaveMsgToModel(std::string app, std::string contact, std::string information); + void SetMsgListItems(); + std::vector &GetMsgListItems(); void ClearListItem(); - void GetMessageInfo(std::string app, std::string contact, std::string information); void SetViewStatus(bool viewStatus); bool GetViewStatus(void); + std::string UpdateTime(long time); + void SetTime(void); + void DeleteItem(MessageItem itemInfo); + void SetIndex(uint16_t itemIndex); private: MessageModel(); MessageModel(const MessageModel &); MessageModel &operator=(const MessageModel &); virtual ~MessageModel(); - std::vector vecMsg; - MessageItem mes; - bool viewInitStatus{false}; + std::vector vecMsg_; + MessageItem mes_; + struct timeval currentTime_; + bool viewInitStatus_ = false; + bool indexAdd_ = true; + std::string durTime_; + uint16_t index_ = 0; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/ModelListenerSample.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/ModelListenerSample.h index 3484cb6e8..7fef86b47 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/ModelListenerSample.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/ModelListenerSample.h @@ -28,4 +28,4 @@ public: void Callback() override; }; } -#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/VolumeSettingPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/VolumeSettingPresenter.h index 2e0017072..695db8dd1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/VolumeSettingPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/VolumeSettingPresenter.h @@ -1,56 +1,56 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: VolumeSettingView view - * Create: 2021-09-5 - */ - -#ifndef VOLUME_SETTING_PRESENTER_H -#define VOLUME_SETTING_PRESENTER_H - -#include "components/ui_image_view.h" -#include "components/ui_label_button.h" -#include "components/ui_view_group.h" -#include "components/ui_slider.h" -#include "main/VolumeSettingView.h" -#include "player/PlayersView.h" - -namespace OHOS { -#define INCREASE_BUTTON "increaseButton" -#define DECREASE_BUTTON "decreaseButton" -#define VOLUME_PROGRESS "progress" -#define VOLUME_VIEW "volumeview" - -typedef enum : uint16_t { - VOLUMEPHONE = 1, - VOLUMEPLAYERS = 3, - VOLUMEPHONENOTIFY = 4, -} VolumeFactor; - -typedef enum : uint8_t { - VOLUMEDOWN = 0, - VOLUMEUP = 1, - VOLUMEDRAG = 2, -} VolumeChangeStatus; - -class VolumeSettingView; -class VolumeSliderEventListener : public UISlider::UISliderEventListener, - public UIView::OnClickListener, - public UIView::OnDragListener { -public: - VolumeSliderEventListener(VolumeSettingView *volumeSetting); - ~VolumeSliderEventListener(); - static VolumeSliderEventListener *GetInstance(); - void OnChange(int32_t progress) override; - void OnRelease(int32_t progress) override; - void ChangeVolume(VolumeChangeStatus status); - bool OnClick(UIView& view, const ClickEvent& event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; - void SetPlayerCoefficients(int16_t value); - void BtAndLocalVolumeSet(int16_t sounding); -private: - int16_t preSound{0}; - int16_t playerCoefficients{0}; - VolumeSettingView *volumeSettingView{nullptr}; -}; -} // namespace OHOS -#endif +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: VolumeSettingView view + * Create: 2021-09-5 + */ + +#ifndef VOLUME_SETTING_PRESENTER_H +#define VOLUME_SETTING_PRESENTER_H + +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "components/ui_slider.h" +#include "main/VolumeSettingView.h" +#include "player/PlayersView.h" + +namespace OHOS { +#define INCREASE_BUTTON "increaseButton" +#define DECREASE_BUTTON "decreaseButton" +#define VOLUME_PROGRESS "progress" +#define VOLUME_VIEW "volumeview" + +typedef enum : uint16_t { + VOLUMEPHONE = 1, + VOLUMEPLAYERS = 3, + VOLUMEPHONENOTIFY = 4, +} VolumeFactor; + +typedef enum : uint8_t { + VOLUMEDOWN = 0, + VOLUMEUP = 1, + VOLUMEDRAG = 2, +} VolumeChangeStatus; + +class VolumeSettingView; +class VolumeSliderEventListener : public UISlider::UISliderEventListener, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + VolumeSliderEventListener(VolumeSettingView *volumeSetting); + ~VolumeSliderEventListener(); + static VolumeSliderEventListener *GetInstance(); + void OnChange(int32_t progress) override; + void OnRelease(int32_t progress) override; + void ChangeVolume(VolumeChangeStatus status); + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void SetPlayerCoefficients(int16_t value); + void BtAndLocalVolumeSet(int16_t sounding); +private: + int16_t preSound{0}; + int16_t playerCoefficients{0}; + VolumeSettingView *volumeSettingView{nullptr}; +}; +} // namespace OHOS +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialDataType.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialDataType.h index 8f1632072..4bc17da58 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialDataType.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialDataType.h @@ -143,6 +143,7 @@ enum class DialDataType : int16_t { // 结束:单个浮点数据,OH标准协议部分,禁止改动,到4095结束(包括4095) // 起始:单个浮点数据,私有可定制部分,从4096开始(包括4096,二进制格式为:0001,xxxx,xxxx,xxxx) + ARC_PROGRESS_TEST = 8189, // arc progree test SWIVEL_GEAR_POSITIVE = 8190, // private data, clockwise SWIVEL_GEAR_NEGATIVE = 8191, // counterclockwise // 结束:单个浮点数据,私有可定制部分,到8191结束(包括8191) diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialModelArcProgress.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialModelArcProgress.h new file mode 100644 index 000000000..a1cb6af6d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/main/dial/DialModelArcProgress.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: DialModelArcProgress + * Author: Hisi Graphic + * Create: 2025-08 + */ + +#ifndef DIAL_MODEL_ARC_PROGRESS_H +#define DIAL_MODEL_ARC_PROGRESS_H + +#include "main/dial/DialBaseModel.h" + +namespace OHOS { +class DialModelArcProgress : public DialBaseModel { +public: + static DialModelArcProgress* GetInstance(); + bool GetDialFloatData(DialDataType& type, float& out) override; +private: + DialModelArcProgress() {} + ~DialModelArcProgress() override {} + + DialModelArcProgress(const DialModelArcProgress &) = delete; + const DialModelArcProgress &operator=(const DialModelArcProgress &) = delete; + float data_ = 0.1; // 0.1: default heart value as reference +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyModel.h new file mode 100644 index 000000000..73e3d1c26 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyModel.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyModel + * Create: 2025-04-24 + */ +#ifndef MONKEY_MODEL_H +#define MONKEY_MODEL_H + +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "animator.h" + +namespace OHOS { +typedef struct { + uint32_t sliceId; + uint32_t pageId; +} SlicePageId; + +class MonkeyModel { +public: + static MonkeyModel &GetInstance(void); + void SetStart(bool start); + +private: + MonkeyModel(); + MonkeyModel(const MonkeyModel &); + MonkeyModel &operator=(const MonkeyModel &); + virtual ~MonkeyModel(); + class TimeAnimatorCallback : public AnimatorCallback { + public: + TimeAnimatorCallback(uint32_t periol) : periol_(periol) {} + virtual ~TimeAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + uint32_t periol_; + }; + TimeAnimatorCallback* timeCallback_ = nullptr; + Animator* timeAnimator_ = nullptr; +}; +} + +#endif // MONKEY_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPage.h new file mode 100644 index 000000000..65e97ec01 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPage.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyPage + * Create: 2025-04-24 + */ +#ifndef MONKEY_PAGE_H +#define MONKEY_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "SlicePage.h" +#include "MonkeyPresenter.h" + +namespace OHOS { +enum MONKEY_PAGES { + MONKEY_MAIN_PAGE = 1, // 0 is invalid +}; + +class MonkeyPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + MonkeyPage(); + ~MonkeyPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + MonkeyPage(const MonkeyPage &) = delete; + MonkeyPage &operator=(const MonkeyPage &) = delete; + MonkeyPage(MonkeyPage &&) = delete; + MonkeyPage &operator=(MonkeyPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel* monkeyLabel_ = nullptr; + UILabelButtonExt* startMonkeyButton_ = nullptr; + UILabelButtonExt* endMonkeyButton_ = nullptr; +}; +} // namespace OHOS +#endif /* MONKEY_PAGE_H */ diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPresenter.h new file mode 100644 index 000000000..a49fe47b8 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyPresenter.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyPresenter + * Create: 2025-04-24 + */ +#ifndef MONKEY_PRESENTER_H +#define MONKEY_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class MonkeyView; +class MonkeyPresenter : public Presenter {}; +} + +#endif // MONKEY_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyView.h new file mode 100644 index 000000000..995324398 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/monkey/MonkeyView.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyView + * Create: 2025-04-24 + */ +#ifndef MONKEY_VIEW_H +#define MONKEY_VIEW_H + +#include "View.h" + +namespace OHOS { +class MonkeyPresenter; +class MonkeyView : public View {}; +} +#endif // MONKEY_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogItemView.h new file mode 100644 index 000000000..be0d54bf6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogItemView.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogItemView + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_CALLER_LOG_ITEM_VIEW_H +#define PHONE_MENU_CALLER_LOG_ITEM_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "phoneservice/PhoneService.h" + +namespace OHOS { +class PhoneMenuCallerLogItemView : public UIViewGroup { +public: + PhoneMenuCallerLogItemView(); + ~PhoneMenuCallerLogItemView() override; + void SetItemInfo(const CallLogInfo &itemInfo); + unsigned char *GetItemPhoneNumber(); + +private: + UIViewGroup bg_; + UIImageView icon_; + UILabel phoneLabel_; + UILabel stutasLabel_; + unsigned char tel_[MAX_PHONE_NUM]; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogModel.h new file mode 100644 index 000000000..25efe032e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogModel.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogModel + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_CALLER_LOG_MODEL_H +#define PHONE_MENU_CALLER_LOG_MODEL_H + +#include "string" +#include "AppViewIDs.h" +#include "message.h" +#include "msg_center.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuSync.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { CHANGE_STATUS = 0, SCO_STATUS, ERROR_MESSAGE } MessageType; + +enum PhoneStatus { PHONE_MULTI_STATUS = 0, PHONE_SINGLE_STATUS }; + +bool MulitplePhoneTextReplaces(); +bool FindCallListInfoAndSetPriorityNumber(); +void PhoneScoStatausCallback(hfp_sco_connect_state_t state); +void PhoneChangeStatusCallback(const PhoneCallInfo *phoneCall); +void PhoneErrorCallback(PhoneServiceErrorType type, int volume); +void UsingPhoneScoStatausCallback(hfp_sco_connect_state_t state); +void UsingPhoneChangeStatusCallback(const PhoneCallInfo *phoneCall); +void UsingPhoneErrorCallback(PhoneServiceErrorType type); + +namespace OHOS { +class VolumeSettingView; +void HonrsViewChange(void); +VolumeSettingView *GetvolumeSetting(void); +class PhoneMenuCallerLogModel { +public: + void InitPhoneService(); + static PhoneMenuCallerLogModel *GetInstance(void); + std::string GetPhoneNumber(void); + void SetoperateNumber(const char *number, char number_len); + bool GetPhoneStatus(); + void SetMakePhoneStatus(bool status); + bool GetVolumeScreenStatus(); + void SetVolumeScreenStatus(bool status); + bool GetCallStatus(); + void SetCallStatus(bool status); + bool GetWaitingStatus(); + void SetWaitingStatus(bool status); + bool GetMulitplePhoneStatus(); + void SetMulitplePhoneStatus(bool status); + std::string GetDialingStatus(void); + void SetDialingStatus(const char *text); + std::string InitDateHourTime(); + std::string &DisplayCallDuration(); + int CurrCallNum(); + bool GetNotifyFlag(void); + void SetNotifyFlag(bool flag); + bool IsMulitplePhoneStatus(void); + std::list &GetContacts(); + bool GetMicMute() + { + return isMicMute_; + } + void SetMicMute(bool isMicMute) + { + isMicMute_ = isMicMute; + } + void SaveCurPage(); + void BackToPrePage(); + +private: + PhoneMenuCallerLogModel(); + PhoneMenuCallerLogModel(const PhoneMenuCallerLogModel &); + PhoneMenuCallerLogModel &operator=(const PhoneMenuCallerLogModel &); + virtual ~PhoneMenuCallerLogModel(); + + std::string dialingStatus_; + std::string timers_; + std::string callDuration_; + std::string phoneNumber_; + bool mulitplePhoneStatus_{false}; + bool waitingStatus_{false}; + bool volumeStatus_{false}; + bool phoneStatus_{false}; + bool callStatus_{false}; + bool notifyFlag_{false}; + bool isMicMute_{false}; + uint16_t preSliceId_{VIEW_MAIN_SAMPLE}; + uint16_t prePageId_{0}; +}; +} +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogPage.h new file mode 100644 index 000000000..25b3a7869 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallerLogPage.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogPage + * Create: 2025-06-06 + */ + +#ifndef PHONE_MENU_CALLER_LOG_PAGE_H +#define PHONE_MENU_CALLER_LOG_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_simple_list.h" +#include "phoneservice/PhoneService.h" +#include "SlicePage.h" +#include "PhoneMenuPresenter.h" + +namespace OHOS { +class PhoneMenuCallerLogPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuCallerLogPage(); + ~PhoneMenuCallerLogPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + UIScrollView *group_{nullptr}; + UILabel *titleLabel_{nullptr}; + UILabel *noCallLabel_{nullptr}; + UILabelButton *clearButton_{nullptr}; + UISimpleList *callerLogList_{nullptr}; + CallLogInfo *info_{nullptr}; +}; +} // namespace OHOS +#endif // PHONE_MENU_CALLER_LOG_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallingPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallingPage.h new file mode 100644 index 000000000..31f881e1d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuCallingPage.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallingPage + * Create: 2025-06-06 + */ + +#ifndef PHONE_MENU_CALLING_PAGE_H +#define PHONE_MENU_CALLING_PAGE_H + +#include "SlicePage.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "PhoneMenuPresenter.h" + +namespace OHOS { +class PhoneMenuCallingPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuCallingPage(); + ~PhoneMenuCallingPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + static PhoneMenuCallingPage *GetInstance(); + UILabel *GetCallingPhoneNumberLabel(); + UILabel *GetCallingStateLabel(); + enum class CallingState : uint8_t {SESSION, INCOMING, OUTGOING, WAITING}; + CallingState GetCallingState(); +private: + CallingState state_; + void CreateUILabel(void); + void CreateUIButton(void); + UIViewGroup *group_{nullptr}; + UIImageView *icon_{nullptr}; + UILabel *phoneNumber_{nullptr}; + UILabel *stateLabel_{nullptr}; + UIButton *answerButton_{nullptr}; + UIButton *hangUpButton_{nullptr}; + UIButton *volumeButton_{nullptr}; +}; +} // namespace OHOS +#endif // PHONE_MENU_CALLING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsItemView.h new file mode 100644 index 000000000..a9777854f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsItemView.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuContactsItemView + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_CONTACTS_ITEM_VIEW_H +#define PHONE_MENU_CONTACTS_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + std::string cid; + std::string name; + std::string phoneNumber; +} PhoneMenuContactsItem; + +class PhoneMenuContactsItemView : public UIViewGroup { +public: + PhoneMenuContactsItemView(); + ~PhoneMenuContactsItemView() override; + virtual void SetItemInfo(const PhoneMenuContactsItem &itemInfo); + const char *GetContactsName() const; + const char *GetContactsCid() const; + const char *GetContactsPhoneNumber() const; + +private: + UIViewGroup bg_; + UIImageView icon_; + UILabel label_; + PhoneMenuContactsItem itemInfo_; +}; +} +#endif // PHONE_MENU_CONTACTS_ITEM_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsPage.h new file mode 100644 index 000000000..8a345ff7d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuContactsPage.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuContactsPage + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_CONTACTS_PAGE_H +#define PHONE_MENU_CONTACTS_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "View.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "PhoneMenuPresenter.h" +#include "PhoneMenuContactsItemView.h" + +namespace OHOS { +class PhoneMenuContactsPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuContactsPage(); + ~PhoneMenuContactsPage() override; + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + UIScrollView* container_ = nullptr; + UISimpleList* contactsList_ = nullptr; + UIImageView* image_ = nullptr; + UILabel* contactsLabel_ = nullptr; +}; +} +#endif // PHONE_MENU_CONTACTS_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDialPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDialPage.h new file mode 100644 index 000000000..de24c8cd0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDialPage.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuDialPage + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_DIAL_PAGE_H +#define PHONE_MENU_DIAL_PAGE_H + +#include +#include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "View.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "PhoneMenuPresenter.h" + +namespace OHOS { +class PhoneMenuDialPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuDialPage(); + ~PhoneMenuDialPage() override; + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + UIScrollView* container_ = nullptr; + UILabel* dialNumberLabel_ = nullptr; + UILabelButton* key0Button_ = nullptr; + UILabelButton* key1Button_ = nullptr; + UILabelButton* key2Button_ = nullptr; + UILabelButton* key3Button_ = nullptr; + UILabelButton* key4Button_ = nullptr; + UILabelButton* key5Button_ = nullptr; + UILabelButton* key6Button_ = nullptr; + UILabelButton* key7Button_ = nullptr; + UILabelButton* key8Button_ = nullptr; + UILabelButton* key9Button_ = nullptr; + UILabelButton* deleteButton_ = nullptr; + UILabelButton* keyStarButton_ = nullptr; + UILabelButton* keyPoundButton_ = nullptr; + UILabelButton* diagButton_ = nullptr; + std::string dialNumber_; +}; +} +#endif // PHONE_MENU_DIAL_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDisconnectPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDisconnectPage.h new file mode 100644 index 000000000..4bb124f48 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuDisconnectPage.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuDisconnectPage + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_DISCONNECT_PAGE_H +#define PHONE_MENU_DISCONNECT_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "View.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "PhoneMenuPresenter.h" + +namespace OHOS { +class PhoneMenuDisconnectPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuDisconnectPage(); + ~PhoneMenuDisconnectPage() override; + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + UIScrollView *container_{nullptr}; + UIImageView *image_{nullptr}; + UILabel *text_{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainItemView.h new file mode 100644 index 000000000..6cc287e6e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainItemView.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuMainItemView + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_MAIN_ITEM_VIEW_H +#define PHONE_MENU_MAIN_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + int iconResId; + const char *label; + const char *viewId; +} PhoneMenuItem; + +class PhoneMenuMainItemView : public UIViewGroup { +public: + PhoneMenuMainItemView(); + ~PhoneMenuMainItemView() override; + virtual void SetItemInfo(const PhoneMenuItem &itemInfo); + +private: + UIImageView icon_; + UILabel label_; + UIViewGroup bg_; +}; +} +#endif // PHONE_MENU_MAIN_ITEM_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainPage.h new file mode 100644 index 000000000..167a0eccf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuMainPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuMainPage + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_MAIN_PAGE_H +#define PHONE_MENU_MAIN_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "View.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "SlicePage.h" +#include "ui_resource_phonemenu.h" +#include "PhoneMenuPresenter.h" +#include "PhoneMenuMainItemView.h" + +namespace OHOS { +constexpr uint8_t PHOEN_MENU_ITEM_NUM = 3; +const char *PHONE_MENU_ITEM_CONTACTS_BOOKS = "phoneMenuItemContactsBooks"; +const char *PHONE_MENU_ITEM_RECENT_CALL = "phoneMenuItemRecentCall"; +const char *PHONE_MENU_ITEM_DIAL = "phoneMenuItemDial"; + +class PhoneMenuMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PhoneMenuMainPage(); + ~PhoneMenuMainPage() override; + void OnStart(void *data) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + +private: + UIScrollView *container_ = nullptr; + UILabel *titleLabel_ = nullptr; + UISimpleList *phoneMenuList_ = nullptr; + PhoneMenuItem phoneMenu_[PHOEN_MENU_ITEM_NUM] = { + {IMAGE_PHONEMENU_CONTACTS_BOOKS, "通讯录", PHONE_MENU_ITEM_CONTACTS_BOOKS}, + {IMAGE_PHONEMENU_RECENT_CALL, "最近通话", PHONE_MENU_ITEM_RECENT_CALL}, + {IMAGE_PHONEMENU_DIAL, "拨号", PHONE_MENU_ITEM_DIAL}, + }; +}; +} // namespace OHOS +#endif // PHONE_MENU_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuPresenter.h new file mode 100644 index 000000000..3a3c9bd26 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuPresenter.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuPresenter + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_PRESENTER_H +#define PHONE_MENU_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class PhoneMenuView; +class PhoneMenuPresenter : public Presenter {}; +} + +#endif // PHONE_MENU_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuSync.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuSync.h new file mode 100644 index 000000000..518404e66 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuSync.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuSync + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_SYNC_H +#define PHONE_MENU_SYNC_H +#include +#include +#include +#include +#include +#include "UiConfig.h" + +namespace OHOS { + +enum CONTACT_DATA_ERROE { + OK = 0, + JSON_CREATE_FAIL = 1, + JSON_PARSE_FAIL = 2, + JSON_TYPE_FAIL = 3, + JSON_KEY_FAIL = 4, + JSON_TO_STRING_FAIL = 5, + JSON_FILE_OPEN_FAIL = 6, +}; + +typedef struct { + std::string cid_; + std::string name_; + std::string phone_; +} Contacts; + +const std::string CONTACTS_FILE_PATH = APP_RES_PATH "/contactsInfo.json"; +class PhoneMenuSync { +public: + static uint32_t WriteFileContact(const std::string &filePath, std::string &content); + static uint32_t ReadFileContact(const std::string &filePath); + static uint32_t ParseContactsMsg(std::string &msgContent); + static std::list &GetContacts(); + static uint32_t PrintContacts(); + static uint32_t LookContacts(std::string &contacts); + static uint32_t CleanFileContacts(const std::string &filePath); + +private: + static std::list list_; +}; +} +#endif // PHONE_MENU_SYNC_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuView.h new file mode 100644 index 000000000..a907d98c4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/phonemenu/PhoneMenuView.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuView + * Create: 2025-07-12 + */ + +#ifndef PHONE_MENU_VIEW_H +#define PHONE_MENU_VIEW_H +#include "View.h" +#include "PhoneMenuPresenter.h" + +namespace OHOS { +enum PhoneMenuPages : uint8_t { + PHONE_MENU_MAIN_PAGE = 1, + PHONE_MENU_CONTACTS_PAGE, + PHONE_MENU_DIAL_PAGE, + PHONE_MENU_DISCONNECT_PAGE, + PHONE_MENU_CALLER_LOG_PAGE, + PHONE_MENU_CALLING_PAGE, +}; + +class PhoneMenuView : public View {}; +} +#endif // PHONE_MENU_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersModel.h index f24dfceb7..131ed8d2c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersModel.h @@ -1,8 +1,7 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Player view - * Author: - * Create: 2021-07-26 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersModel + * Create: 2025-03-23 */ #ifndef PLAYERS_MODEL_H @@ -13,10 +12,14 @@ #include "main/UiServersMsg.h" #include "player.h" #include "source.h" +#include "bts_br_gap.h" +#include "bts_avrcp_controller.h" +#include "bts_avrcp_target.h" +#include "bts_a2dp_source.h" #include "audio_manager.h" #include "audio_base_type.h" +#include "settings/model/SettingBluetoothModel.h" #include "player/PlayersPresenter.h" -#include "bts_avrcp_controller.h" namespace OHOS { using OHOS::Media::Player; @@ -93,6 +96,9 @@ public: void ConncetBtResetButton(); void ClearActivateAudioInterrupt(void); void GetDuration(int64_t &duration); + + void SetViewStatus(bool viewStatus) { viewInitStatus_ = viewStatus; }; + bool GetViewStatus(void) { return viewInitStatus_;}; private: int64_t duration_{0}; bool isInterruptedPause_{false}; @@ -117,6 +123,7 @@ private: char *currentSongName{nullptr}; bool isStopAndReset{false}; bool isActivateAudioInterrupt{false}; + bool viewInitStatus_; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicItemView.h new file mode 100644 index 000000000..4b4365a29 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicItemView.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersMusicItemView + * Create: 2025-03-23 + */ + +#ifndef DATE_BUTTON_ITEM_VIEW_H +#define DATE_BUTTON_ITEM_VIEW_H + +#include "UiConfig.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "player/PlayersPresenter.h" +#include "main/LoadImg.h" + +namespace OHOS { +class PlayersMusicItemView : public UIViewGroup { +public: + explicit PlayersMusicItemView(); + ~PlayersMusicItemView() override; + virtual void SetItemInfo(const PlayerCaseInfo itemInfo); + PlayerCaseInfo GetItem(); + +private: + UILabelButton labelButton_; + PlayerCaseInfo itemInfo_ = {"", 0}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicListGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicListGroup.h new file mode 100644 index 000000000..a556afecf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersMusicListGroup.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersMusicListGroup + * Create: 2025-06-29 + */ + +#ifndef PLAYER_MUSIC_LIST_GROUP_H +#define PLAYER_MUSIC_LIST_GROUP_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_card_page.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_scroll_view.h" +#include "components/ui_radio_button.h" +#include "components/ui_card_page.h" +#include "components/ui_circle_progress.h" +#include "components/ui_checkbox.h" + +namespace OHOS { +class PlayersMusicListGroup : public UIViewGroup, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PlayersMusicListGroup(); + ~PlayersMusicListGroup() override; + static PlayersMusicListGroup *GetInstance(void); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void RefreshMusicList(); + void BtnOnListData(UIView& view); + +private: + UISimpleList *musicList_{nullptr}; + char *sliceId_{nullptr}; + int16_t index_{0}; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersOptionGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersOptionGroup.h new file mode 100644 index 000000000..bc05f4ab2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersOptionGroup.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersOptionGroup + * Create: 2025-06-29 + */ + +#ifndef PLAYER_OPTION_GROUP_H +#define PLAYER_OPTION_GROUP_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_card_page.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_scroll_view.h" +#include "components/ui_radio_button.h" +#include "components/ui_card_page.h" +#include "components/ui_circle_progress.h" +#include "components/ui_checkbox.h" + +namespace OHOS { +class PlayersOptionGroup : public UIViewGroup, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + PlayersOptionGroup(); + ~PlayersOptionGroup() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitButton(); + void InitLabel(); + void InitImage(); + +private: + UILabel *watchLabel_{nullptr}; + UILabel *phoneLabel_{nullptr}; + UILabel *bluetoothLabel_{nullptr}; + UIImageView *watchImage_{nullptr}; + UIImageView *phoneImage_{nullptr}; + UIImageView *bluetoothImage_{nullptr}; + UIRadioButton *watchButton_{nullptr}; + UIRadioButton *phoneButton_{nullptr}; + UIButton *bluetoothButton_{nullptr}; + UILabelButton *deleteButton{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersPresenter.h index 07d019467..ca178339c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersPresenter.h @@ -1,8 +1,7 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Player view - * Author: - * Create: 2021-07-26 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersPresenter + * Create: 2025-06-29 */ #ifndef PLAYERS_PRESENTER_H @@ -13,19 +12,11 @@ #include "player.h" #include "audio_manager.h" #include "audio_base_type.h" -#include "player/BluetoothView.h" #include "main/VolumeSettingView.h" #include "main/VolumeSettingPresenter.h" -#include "bluetooth/BluetoothModel.h" -#include "bluetooth/BluetoothEarPhoneView.h" -#include "bluetooth/BluetoothEarListView.h" -#include "bluetooth/BluetoothOptionsView.h" -#include "bluetooth/BluetoothReconnectView.h" -#include "bluetooth/TipsSuccMessageView.h" -#include "bluetooth/TipsConnFailMessageView.h" -#include "bluetooth/TipsFailMessageView.h" -#include "bluetooth/BluetoothDeviceListView.h" -#include "bluetooth/BluetoothItemView.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "settings/model/SettingBluetoothModel.h" namespace OHOS { using OHOS::Media::Player; @@ -34,37 +25,14 @@ using namespace::Audio; using Audio::AudioManager; class VolumeSettingView; #define DEC_NUM_256 256 -// 点击按钮视图ID -#define BLUETOOTH_RESCAN_BUTTON "rescanButton" -#define BLUETOOTH_NEWEQUIPMENT_BUTTON "newEquipmentButton" -#define BLUETOOTH_CANCELCONNEDREQUEST_BUTTON "cancelConnedRequestButton" -#define BLUETOOTH_UNPAIR_BUTTON "unpairButton" -#define BLUETOOTH_OPTIONONE_BUTTON "optionsOneButton" -#define BLUETOOTH_SETTING_BUTTON "settingButton" -#define BLUETOOTH_DELETE_BUTTON "deleteButton" -#define BLUETOOTH_SUCC_BACK_BUTTON "succBackButton" -#define BLUETOOTH_FAIL_BACK_BUTTON "failBackButton" // 重试按钮 -#define BLUETOOTH_CONN_FAIL_BACK_BUTTON "connfailBackButton" -// 视图滑动事件ID -#define BLUETOOTH_EARLIST_VIEW "BluetoothEarListView" -#define BLUETOOTH_DEVICE_LIST_VIEW "BluetoothDeviceListView" -#define BLUETOOTH_EAR_PHONE_VIEW "BluetoothEarPhoneView" -#define BLUETOOTH_OPTIONS_VIEW "BluetoothOptionsView" -#define BLUETOOTH_RECONNECT_VIEW "BluetoothReconnectView" -#define BLUETOOTH_VIEW "BluetoothView" -#define TIPS_SUCC_MESSAGE_VIEW "TipsSuccMessageView" -#define TIPS_FAIL_MESSAGE_VIEW "TipsFailMessageView" -#define TIPS_CONN_FAIL_MESSAGE_VIEW "TipsConnFailMessageView" - -static constexpr uint8_t FONT_THIRTY_SIZE = 30; // 30:字体大小 -static constexpr uint8_t FONT_FORTY_SIZE = 40; // 40:字体大小 +static constexpr uint8_t FONT_THIRTY_SIZE = 30; +static constexpr uint8_t FONT_FORTY_SIZE = 40; struct PlayerCaseInfo { char sliceId[DEC_NUM_256]; int16_t index; }; - class PlayersListGroup { public: PlayersListGroup() {} @@ -84,33 +52,6 @@ private: int GetAllFiles(List *playersCaseList); }; -// Button OnClick -class ButtonOnClickListener : public UIView::OnClickListener { -public: - enum VolumeSetState : uint8_t { - MUTE, - LOW, - MEDIUM, - LOUD, - }; - ButtonOnClickListener() {} - ButtonOnClickListener(UIView *view) : view_(view) {} - ~ButtonOnClickListener(); - static ButtonOnClickListener *GetInstance() - { - static ButtonOnClickListener instance; - return &instance; - } - bool OnClick(UIView& view, const ClickEvent& event) override; -private: - UIView *view_{nullptr}; - void PlayerButtonOnClick(); - void SoundButtonOnClick(); - void PlayerModelButtonOnClick(); - void OptionsButtonOnClick(); - VolumeSettingView *volumeSettingView{nullptr}; -}; - // 播放器回调 class PlayerCallbackImpl : public OHOS::Media::PlayerCallback { public: @@ -155,93 +96,12 @@ private: bool isInterruptedPause_{false}; }; -// 滑动手势 -class PlayerOnDragListener : public UIView::OnDragListener { -public: - PlayerOnDragListener(); - ~PlayerOnDragListener(); - bool OnDragEnd(UIView& view, const DragEvent& event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; - static PlayerOnDragListener *GetInstance(); -private: - void OnDragChangView(const DragEvent& event, int16_t hideView, int16_t showView, bool isStopScan); - void OnDragChangBluetoothView(const DragEvent& event); - void DropEarPhoneView(const DragEvent& event); - void DropEarListView(const DragEvent& event); - void CorrespondingJump(const DragEvent& event, int16_t hideView); -}; - -// Bluetooth View redirection -class BluetoothEarListView; -class BluetoothOptionsView; -class BluetoothDeviceListView; -class JumpView { -public: - enum BluetoothJumpViewNum : uint8_t { - BLUETOOTHEARPHONEVIEW = 0, // 扫描 - BLUETOOTHEARLISTVIEW, // 扫描列表 - BLUETOOTHDEVICELISTVIEW, // 已配对设备列表 - BLUETOOTHEOPTIONSVIEW, // 选择界面 - BLUETOOTHRECONNECTVIEW, - TIPSSUCCMESSAGEVIEW, // 连接成功 - TIPSCONNFAILMESSAGEVIEW, // 连接失败 - TIPSFAILMESSAGEVIEW, - BLUETOOTHEVIEW, // 设置界面 - BLUETOOTHEJUMP_MAX, - }; - JumpView(); - ~JumpView(); - static JumpView *GetInstance(); - void ChangeView(int16_t hideView, int16_t showView); -private: - bool ChangeTipsFailMessageView(int16_t hideView, int16_t thisView); - bool ChangeTipsConnFailMessageView(int16_t hideView, int16_t thisView); - bool ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothEarListView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView); - bool ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView); - bool CheckViewParam(int16_t hideView, int16_t showView); - void ResetEarListView(int16_t hideView); - UIViewGroup *container[BLUETOOTHEJUMP_MAX]{nullptr}; // CONTAINER_NUM :蓝牙耳机连接的9个界面容器 - BluetoothEarPhoneView *bluetoothEarPhoneView{nullptr}; - BluetoothEarListView *bluetoothEarListView{nullptr}; - BluetoothView *bluetoothView{nullptr}; - BluetoothOptionsView *bluetoothOptionsView{nullptr}; - BluetoothDeviceListView *bluetoothDeviceListView{nullptr}; - BluetoothReconnectView *bluetoothReconnectView{nullptr}; - TipsSuccMessageView *tipsSuccMessageView{nullptr}; - TipsConnFailMessageView *tipsConnFailMessageView{nullptr}; - TipsFailMessageView *tipsFailMessageView{nullptr}; - typedef bool (JumpView::*PreprosssChangeView)(int16_t hideView, int16_t thisView); - PreprosssChangeView preProcessView[BLUETOOTHEJUMP_MAX]; -}; - class PlayersPresenter : public UIView::OnClickListener { public: PlayersPresenter(); ~PlayersPresenter(); static PlayersPresenter *GetInstance(); - void OnClickRescanButton(void); - void OnClickNewEquipmentButton(void); - void OnClickCancelConnedRequestButton(void); - void OnClickButtonUnpair(void); - void OnClickButtonOptionOne(void); - void OnClickSetting(void); - void OnClickDelete(void); - void OnClickSuccBack(void); - void OnClickConnFailBack(void); - void OnClickFailBack(void); - void SetTitleSetText(const char *text); - void SetPlaybackProgress(int64_t value); - void SetPlayerState(bool value); - void PlayerbackReset(void); - void PlayerHeadsetReset(void); - void ShowPlayerListGroup(void); private: - bool OnClick(UIView& view, const ClickEvent& event) override; }; } // namespace OHOS #endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersView.h index 757fff50f..cb0916fb8 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/player/PlayersView.h @@ -1,8 +1,7 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Player view - * Author: - * Create: 2021-07-26 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersView + * Create: 2025-03-23 */ #ifndef PLAYERS_VIEW_H @@ -18,96 +17,81 @@ #include "components/ui_abstract_scroll.h" #include "components/ui_circle_progress.h" #include "components/ui_checkbox.h" -#include "components/ui_list.h" +#include "components/ui_simple_list.h" #include "font/ui_font_bitmap.h" #include "font/ui_font.h" #include "graphic_config.h" #include "components/ui_card_page.h" +#include "main/VolumeSettingView.h" #include "player/PlayersPresenter.h" +#include "player/PlayersOptionGroup.h" +#include "player/PlayersMusicListGroup.h" +#include "common/periodicupdate_interface.h" namespace OHOS { #define PLAY_PROGRESS_MIN 0 #define PLAY_PROGRESS_MAX 100 -class JumpView; class PlayersPresenter; -class PlayersCaseListAdapter; -class PlayersView : public UICardPage { +class VolumeSettingView; +class VolumeSliderEventListener; +class PlayersView : public UICardPage, public PeriodicUpdateInterface, + public UIView::OnClickListener, + public UIView::OnDragListener { public: PlayersView(); ~PlayersView() override; static PlayersView *GetInstance(void); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragEvent(const DragEvent& event) override; bool InitView(void); void PreLoad(void) override; void UnLoad(void) override; - bool OnDragEvent(const DragEvent& event) override; - - void SetUpLabel(const char *title, int16_t x, int16_t y); - void ShowUpListView(void); + void OnInactive(void) override; + void InitButton(); + void InitLabel(); + void InitImage(); + void InitCircleProgress(); + void InitSoundAdjust(); + void InitOption(); + void InitListView(void); + void SetUpPlayerMode(); + void PlayOrPauseButtonOnClick(); void TitleSetText(const char *text); void PlayerModelButtonSetSrc(uint32_t playMode); - int16_t GetVolumeRank(void); - void SetVolumeRank(int16_t value); - void SetVolumeAddOne(void); - UILabelButton *GetBackButton(void); - UIButton *GetPullButton(void); - UIButton *GetOptionsButton(void); - UIButton *GetPreButton(void); - UIButton *GetNextButton(void); - UILabel *GetTitleLabel(void); - UICheckBox *GetPlayerButton(void); - UIImageView *GetSoundButton(void); - UIImageView *GetPlayerModelButton(void); - UICircleProgress *GetPlaybackProgress(void); + void SetPlaybackProgress(int8_t value); UICheckBox::UICheckBoxState GetPlayerButtonState(void); + void SetPlayerState(bool value); void SetPlayerButtonState(UICheckBox::UICheckBoxState state); - UIList *GetPlayerList(void); - void SetPlayerListGroupStatus(bool status); + void PlayerHeadsetReset(); + void SetPlayerCtrVolume(float leftVolume, float rightVolume); - void CreateJumpView(void); - void CreatePlayersPresenter(void); - void CreatePlayerOnDragListener(void); + int16_t GetVolumeRank(void); + void SetVolumeRank(int16_t value); + void SetVolumeAddOne(void); + void Update(void) override; + uint32_t GetPeriod(void) override; private: - bool InitBackGround(void); - void TearDownView(); - void CreatePlayerMusicName(); - int ShowUpCheckBoxButton(); - int ShowUpButton(); - int ShowUpButtonOptions(); - int ShowUpButtonView(); - int ShowUpCircleProgress(); - bool ShowUpPlayerMode(); - void SetUpButton(UIButton *btn, const Point& point, int16_t width, int16_t height, - UIView::OnClickListener *listener); - bool LoadPlayerImage(UIImageView *View, uint32_t resId); - bool LoadPlayerImage(UIButton *button, uint32_t resId, uint32_t hlResId); - - UIImageView *backGround{nullptr}; - UILabel *subTitleLabel{nullptr}; - PlayersCaseListAdapter *adapterText{nullptr}; - UILabel *titleLabel{nullptr}; - UILabelButton *backButton{nullptr}; - UIButton *pullButton{nullptr}; - UIButton *optionsButton{nullptr}; - UIButton *preButton{nullptr}; - UIButton *nextButton{nullptr}; - UIViewGroup *listGroup{nullptr}; - UIImageView *soundButton{nullptr}; - UIImageView *playerModelButton{nullptr}; - UICheckBox *playerButton{nullptr}; - UICircleProgress *playbackProgress{nullptr}; + UIImageView *bgImg_{nullptr}; + UILabel *musicNameLabel_{nullptr}; + UILabel *musicAuthorLabel_{nullptr}; + UIImageView *optionsButton_{nullptr}; + UIImageView *preButton_{nullptr}; + UIImageView *nextButton_{nullptr}; + UIImageView *soundButton_{nullptr}; + UIImageView *playModelChangeButton_{nullptr}; + UIImageView *pullButton_{nullptr}; + UICheckBox *playerOrPauseButton_{nullptr}; + UICircleProgress *playbackProgress_{nullptr}; + VolumeSettingView *volumeSettingView_{nullptr}; + VolumeSliderEventListener *volumeSliderEventListener_{nullptr}; + PlayersMusicListGroup *playersMusicListGroup{nullptr}; + PlayersOptionGroup *playerOptionGroup_{nullptr}; int16_t volumeSet{0}; - UIList *list{nullptr}; - JumpView *jumpView{nullptr}; - PlayersPresenter *playersPresenter{nullptr}; - PlayerOnDragListener *playerOnDragListener{nullptr}; uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - UIView::OnClickListener *playerlistener{nullptr}; - UIView::OnClickListener *soundlistener{nullptr}; - UIView::OnClickListener *nextlistener{nullptr}; - UIView::OnClickListener *prelistener{nullptr}; - UIView::OnClickListener *modellistener{nullptr}; - UIView::OnClickListener *optionslistener{nullptr}; bool viewiInitStatus{false}; + int64_t playerCurrentTime_{0}; + int64_t playerMusicDuration_{0}; + int64_t playerProgressValue_{0}; }; } // namespace OHOS #endif // MAIN_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/quickaccess/FloatAccessView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/quickaccess/FloatAccessView.h new file mode 100644 index 000000000..fceeffd0d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/quickaccess/FloatAccessView.h @@ -0,0 +1,86 @@ + /* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: FloatAccessView + * Author: Hisi Graphic Team + * Created: 2025-09 + */ + +#ifndef FLOAT_ACCESS_VIEW_H +#define FLOAT_ACCESS_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_float_box_view.h" +#include "applist/AppItemView.h" + +namespace OHOS { +namespace { + constexpr uint16_t MAX_ITEM_SIZE = 3; +} +class FloatAnimatorCallback; +class FloatAccessView : public UIViewGroup, + public UIFloatBoxView::OnItemClickListener, + public UIView::OnClickListener { +public: + static FloatAccessView *GetInstance(void); + FloatAccessView(const FloatAccessView &) = delete; + FloatAccessView &operator=(const FloatAccessView &) = delete; + void AddItem(AppItem item, uint8_t index); + void DeleteItem(const char* label); + AppItem GetItem(uint8_t index); + + void OnItemClick(const std::string& name) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + + void ShowView(); + void ExitView(); + void CleanView(); + bool IsShowView(); + void LoadAppItemsData(); +private: + FloatAccessView() {} + ~FloatAccessView() {} + uint8_t GetItemSize(); + void SaveAppItemsData(); + void AddAppItemsData(); + void InitView(); + void EnterApp(); + bool isInitView_{false}; + bool isShowView_{false}; + bool isLoadData_{false}; + bool isClickItem_{false}; // 标记点击了快捷应用 + UIFloatBoxView* floatBoxView_ = nullptr; + AppItem items_[MAX_ITEM_SIZE] = {}; + FloatAnimatorCallback* enterCallback_ = nullptr; +}; + +class FloatAnimatorCallback : public AnimatorCallback { +public: + explicit FloatAnimatorCallback(UIView* view) + : startPos_(0), endPos_(0), startTime_(0), passTime_(0), isExit_(false), + animator_(new Animator(this, view, 300, false)) {} // 300 ms: 动画持续时间 + + ~FloatAnimatorCallback() override + { + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + } + void Callback(UIView* view) override; + void OnStop(UIView& view) override; + void DoEnter(); + void DoExit(); + uint8_t GetState() + { + return animator_->GetState(); + } +protected: + int16_t startPos_; + int16_t endPos_; + uint32_t startTime_; + uint32_t passTime_; + bool isExit_; + Animator* animator_; +}; +} // namespace OHOS +#endif // LOADING_FRAGMENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/LoadingFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/LoadingFragment.h new file mode 100644 index 000000000..5e5abd757 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/LoadingFragment.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: LoadingFragment.h + * Author: + * Create: 2025-07-17 + */ + +#ifndef LOADING_FRAGMENT_H +#define LOADING_FRAGMENT_H + +#include "components/ui_fragment.h" +#include "components/ui_label.h" + +namespace OHOS { + +class LoadingFragment : public UIFragment { +public: + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + UILabel* loadingLabel_ = nullptr; +}; +} // namespace OHOS +#endif // LOADING_FRAGMENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h index ccc47e1be..3f6bc5c57 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h @@ -21,12 +21,11 @@ namespace OHOS { class RecentAppView; -class RecentAppPresenter : public Presenter, public UIView::OnClickListener { +class RecentAppPresenter : public Presenter { public: - RecentAppPresenter(); - ~RecentAppPresenter() override; + RecentAppPresenter() {} + ~RecentAppPresenter() override {} void OnResume() override; - bool OnClick(UIView &view, const ClickEvent &event) override; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppView.h index 02dc69422..1a82d6819 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RecentAppView.h @@ -16,29 +16,20 @@ #ifndef RECENT_APP_VIEW_H #define RECENT_APP_VIEW_H -#include -#include "recent_app/RecentAppPresenter.h" #include "View.h" +#include "RecentAppPresenter.h" +#include "LoadingFragment.h" #include "animator/animator.h" -#include "components/ui_label.h" -#include "components/ui_label_button.h" -#include "components/ui_roller_view.h" namespace OHOS { -static constexpr const char* RECENT_APP_DELETE_BTN_ID = "RecentAppDeleteBtn"; -static std::string RECENT_ITEM_NATIVE_PREFIX = "NA_"; -static std::string RECENT_ITEM_JS_PREFIX = "JS_"; -static constexpr const uint8_t RECENT_ITEM_PREFIX_LEN = 3; class RecentAppView : public View { public: - RecentAppView(); + RecentAppView() {} ~RecentAppView() override; + void OnStart() override; - void LoadContent(); - UIRollerView* GetRollerView() - { - return roller_; - } + void OnResume(); + private: class LoadingAnimCb : public AnimatorCallback { public: @@ -53,16 +44,12 @@ private: RecentAppView* recentAppView_; }; - void AddRecentAppToRoller(); - void LoadRecentAppContent(); - void InitRecentApps(); - UIRollerView* roller_ = nullptr; - Animator* loadingAnim_ = nullptr; - UILabel* loadingLabel_ = nullptr; - UILabel* noRecentAppLabel_ = nullptr; - UILabelButton* delBtn_ = nullptr; - LoadingAnimCb loadingAnimCb_; + void LoadContent(); bool viewiInitStatus_ = false; + LoadingAnimCb loadingAnimCb_; + Animator* loadingAnim_ = nullptr; + LoadingFragment *loadingFragment_ = nullptr; + UIFragment *rencentAppFragment_ = nullptr; }; } // namespace OHOS #endif // RECENT_APP_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RollerRecentAppFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RollerRecentAppFragment.h new file mode 100644 index 000000000..2d2fc15cd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/RollerRecentAppFragment.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: RollerRecentAppFragment.h + * Author: + * Create: 2025-07-17 + */ + +#ifndef ROLLER_RECENT_APP_FRAGMENT_H +#define ROLLER_RECENT_APP_FRAGMENT_H + +#include +#include "animator/animator.h" +#include "components/ui_fragment.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_roller_view.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +static constexpr const char* RECENT_APP_DELETE_BTN_ID = "RecentAppDeleteBtn"; +static std::string RECENT_ITEM_NATIVE_PREFIX = "NA_"; +static std::string RECENT_ITEM_JS_PREFIX = "JS_"; +static constexpr const uint8_t RECENT_ITEM_PREFIX_LEN = 3; + +class RollerRecentAppFragment : public UIFragment, public UIView::OnClickListener { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void LoadRecentAppContent(); + void InitRecentApps(); + void AddRecentAppToRoller(); + + UILabel* noRecentAppLabel_ = nullptr; + UIRollerView* rollerContainer_ = nullptr; + UILabelButton* delBtn_ = nullptr; +}; +} // namespace OHOS +#endif // ROLLER_RECENT_APP_FRAGMENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/SlipFlowRecentAppFragment.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/SlipFlowRecentAppFragment.h new file mode 100644 index 000000000..9fdfec73e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/recent_app/SlipFlowRecentAppFragment.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: SlipFlowRecentAppFragment.h + * Author: + * Create: 2025-07-17 + */ + +#ifndef SLIPFLOW_RECENT_APP_FRAGMENT_H +#define SLIPFLOW_RECENT_APP_FRAGMENT_H + +#include +#include "animator/animator.h" +#include "components/ui_fragment.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_slipflow_view.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +static std::string RECENT_ITEM_NATIVE_PREFIX = "NA_"; +static std::string RECENT_ITEM_JS_PREFIX = "JS_"; +static constexpr const uint8_t RECENT_ITEM_PREFIX_LEN = 3; + +class SlipFlowRecentAppFragment : public UIFragment, public UIView::OnClickListener, + public UISlipflowView::OnSlipflowScrollListener { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void OnScrollUpStart() override; + void OnScrollUpEnd() override; + bool OnRemove(UIView* view) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void LoadRecentAppContent(); + void InitRecentApps(); + void AddRecentAppToSlipFlow(); + void AddImageToSlipFlow(int index); + + UILabel* noRecentAppLabel_ = nullptr; + UISlipflowView* slipFlowContainer_ = nullptr; + UILabel* slipUpNoticeLabel_ = nullptr; + Graphic::Vector appNames_; + Graphic::Vector appImgInfos_; +}; +} // namespace OHOS +#endif // SLIPFLOW_RECENT_APP_FRAGMENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingPresenter.h index 16595d225..895037270 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingPresenter.h @@ -1,19 +1,18 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef SETTING_PRESENTER_H -#define SETTING_PRESENTER_H - -#include "Presenter.h" - -namespace OHOS { -class SettingView; -class SettingPresenter : public Presenter { -}; -} - +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPresenter + * Create: 2025-06-01 + */ +#ifndef SETTING_PRESENTER_H +#define SETTING_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class SettingView; +class SettingPresenter : public Presenter { +public: + virtual ~SettingPresenter(); +}; +} #endif // SETTING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingView.h index 2f79acf50..b8e7dc918 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/SettingView.h @@ -1,22 +1,16 @@ -/* - * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. - * Description: SettingPage.h - * Author: - * Create: 2025-04-14 - */ - -#ifndef SETTING_VIEW_H -#define SETTING_VIEW_H - -#include "View.h" -namespace OHOS { -enum SETTING_PAGES { - SETTING_MAIN_PAGE = 1, // 0 is invalid - SETTING_DESKTOP_PAGE = 2, -}; - -class SettingPresenter; -class SettingView : public View { -}; -} +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingView + * Create: 2025-06-01 + */ +#ifndef SETTING_VIEW_H +#define SETTING_VIEW_H + +#include "View.h" + +namespace OHOS { +class SettingPresenter; +class SettingView : public View { +}; +} #endif // SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingBluetoothItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingBluetoothItemGroup.h new file mode 100644 index 000000000..2d510665d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingBluetoothItemGroup.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBluetoothItemGroup + * Created: 2025-06-05 + */ +#ifndef SETTING_BLUETOOTH_ITEM_GROUP_H +#define SETTING_BLUETOOTH_ITEM_GROUP_H + +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_canvas.h" +#include "UiConfig.h" +#include "bts_def.h" +#include "bts_br_gap.h" +#include "settings/model/SettingBluetoothModel.h" + +namespace OHOS { + +class SettingBluetoothItemGroup : public UIViewGroup { +public: + explicit SettingBluetoothItemGroup(); + ~SettingBluetoothItemGroup() override; + void SetItemInfo(const BtCaseInfo* itemInfo); + void SetUpChild(); + BtCaseInfo& GetItem(); +private: + UIImageView background_; + UIImageView icon_; + UIImageView conn_; + UILabel deviceName_; + unsigned char addr_[BD_ADDR_LEN]; + UILabel connectStatus_; + uint32_t index_; + int16_t temp_; + BtCaseInfo itemInfo_ = {{}, {}, "", 0}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardAddItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardAddItemGroup.h new file mode 100644 index 000000000..dbaf092ac --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardAddItemGroup.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardAddItemGroup + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_ADD_ITEM_GROUP_H +#define SETTING_CARD_ADD_ITEM_GROUP_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "UiConfig.h" +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingCardMgrItemGroup.h" + +namespace OHOS { +class SettingCardAddItemGroup : public ItemGroupImageCache, + public UIViewGroup { +public: + explicit SettingCardAddItemGroup(); + virtual ~SettingCardAddItemGroup(); + void UpdateItemGroup(SettingCardItemData* itemData); +private: + const char* imageSrc_ = nullptr; + ImageInfo* imageData_ = nullptr; + UIImageView image_; + UIButton button_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectItemGroup.h new file mode 100644 index 000000000..5f0a86909 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectItemGroup.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffectItemGroup + * Create: 2025-04 + */ +#ifndef SETTING_CARD_EFFECT_ITEM_GROUP_H +#define SETTING_CARD_EFFECT_ITEM_GROUP_H + +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "SettingCardEffectSample.h" + +namespace OHOS { +class SettingCardEffectItemGroup : public UIViewGroup { +public: + explicit SettingCardEffectItemGroup(); + ~SettingCardEffectItemGroup() override; + virtual void SetItemInfo(const SettingCardEffectSample& leftItemInfo, + const SettingCardEffectSample& rightItemInfo); + virtual void SetUpChild(); + CardEffectID GetViewId(const ClickEvent& event); + void SelectedChange(); + void Reset(); +private: + void InitializeAnimator(UIImageAnimatorView& animator, int x, int y, int size); + void InitializeIcon(UIImageView& icon, int x, int y, int size); + void InitializeLabel(UILabel& label, int x, int y, int width, int height); + bool LoadMultiImages(SettingCardEffectSample& itemInfo, bool right); + + UIImageAnimatorView leftAnimator_; + UILabel leftLabel_; + UIImageView leftSelectIcon_; + UIImageView leftPreviewIcon_; + + UIImageAnimatorView rightAnimator_; + UILabel rightLabel_; + UIImageView rightSelectIcon_; + UIImageView rightPreviewIcon_; + + SettingCardEffectSample leftItemInfo_; + SettingCardEffectSample rightItemInfo_; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectResourceImage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectResourceImage.h new file mode 100644 index 000000000..b7563f023 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectResourceImage.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffectResourceImage + * Create: 2025-04 + */ +#ifndef SETTING_CARD_EFFECT_RESOURCE_IMAGE_H +#define SETTING_CARD_EFFECT_RESOURCE_IMAGE_H +#include +#include +#include "ui_resource_settings.h" + +namespace OHOS { + static std::vector UI_3D_FOLD_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_3D_FOLD_01, + IMAGE_3D_FOLD_02, + IMAGE_3D_FOLD_03, + IMAGE_3D_FOLD_04, + IMAGE_3D_FOLD_05, + IMAGE_3D_FOLD_06, + IMAGE_3D_FOLD_07, + IMAGE_3D_FOLD_08, + IMAGE_3D_FOLD_09, + IMAGE_3D_FOLD_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_3D_FOLD_10, + IMAGE_3D_FOLD_09, + IMAGE_3D_FOLD_08, + IMAGE_3D_FOLD_07, + IMAGE_3D_FOLD_06, + IMAGE_3D_FOLD_05, + IMAGE_3D_FOLD_04, + IMAGE_3D_FOLD_03, + IMAGE_3D_FOLD_02, + IMAGE_3D_FOLD_01, + IMAGE_TRAINSTION_START, + }; + + static std::vector UI_CARD_FLIP_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_CARD_FLIP_01, + IMAGE_CARD_FLIP_02, + IMAGE_CARD_FLIP_03, + IMAGE_CARD_FLIP_04, + IMAGE_CARD_FLIP_05, + IMAGE_CARD_FLIP_06, + IMAGE_CARD_FLIP_07, + IMAGE_CARD_FLIP_08, + IMAGE_CARD_FLIP_09, + IMAGE_CARD_FLIP_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_CARD_FLIP_10, + IMAGE_CARD_FLIP_09, + IMAGE_CARD_FLIP_08, + IMAGE_CARD_FLIP_07, + IMAGE_CARD_FLIP_06, + IMAGE_CARD_FLIP_05, + IMAGE_CARD_FLIP_04, + IMAGE_CARD_FLIP_03, + IMAGE_CARD_FLIP_02, + IMAGE_CARD_FLIP_01, + IMAGE_TRAINSTION_START, + }; + + static std::vector UI_PUSH_PRESS_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_PUSH_PRESS_01, + IMAGE_PUSH_PRESS_02, + IMAGE_PUSH_PRESS_03, + IMAGE_PUSH_PRESS_04, + IMAGE_PUSH_PRESS_05, + IMAGE_PUSH_PRESS_06, + IMAGE_PUSH_PRESS_07, + IMAGE_PUSH_PRESS_08, + IMAGE_PUSH_PRESS_09, + IMAGE_PUSH_PRESS_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_PUSH_PRESS_10, + IMAGE_PUSH_PRESS_09, + IMAGE_PUSH_PRESS_08, + IMAGE_PUSH_PRESS_07, + IMAGE_PUSH_PRESS_06, + IMAGE_PUSH_PRESS_05, + IMAGE_PUSH_PRESS_04, + IMAGE_PUSH_PRESS_03, + IMAGE_PUSH_PRESS_02, + IMAGE_PUSH_PRESS_01, + IMAGE_TRAINSTION_START, + }; + + static std::vector UI_TURN_PAGE_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_TURN_PAGE_01, + IMAGE_TURN_PAGE_02, + IMAGE_TURN_PAGE_03, + IMAGE_TURN_PAGE_04, + IMAGE_TURN_PAGE_05, + IMAGE_TURN_PAGE_06, + IMAGE_TURN_PAGE_07, + IMAGE_TURN_PAGE_08, + IMAGE_TURN_PAGE_09, + IMAGE_TURN_PAGE_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TURN_PAGE_10, + IMAGE_TURN_PAGE_09, + IMAGE_TURN_PAGE_08, + IMAGE_TURN_PAGE_07, + IMAGE_TURN_PAGE_06, + IMAGE_TURN_PAGE_05, + IMAGE_TURN_PAGE_04, + IMAGE_TURN_PAGE_03, + IMAGE_TURN_PAGE_02, + IMAGE_TURN_PAGE_01, + IMAGE_TRAINSTION_START, + }; + + static std::vector UI_WINDMILL_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_WINDMILL_01, + IMAGE_WINDMILL_02, + IMAGE_WINDMILL_03, + IMAGE_WINDMILL_04, + IMAGE_WINDMILL_05, + IMAGE_WINDMILL_06, + IMAGE_WINDMILL_07, + IMAGE_WINDMILL_08, + IMAGE_WINDMILL_09, + IMAGE_WINDMILL_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_WINDMILL_10, + IMAGE_WINDMILL_09, + IMAGE_WINDMILL_08, + IMAGE_WINDMILL_07, + IMAGE_WINDMILL_06, + IMAGE_WINDMILL_05, + IMAGE_WINDMILL_04, + IMAGE_WINDMILL_03, + IMAGE_WINDMILL_02, + IMAGE_WINDMILL_01, + IMAGE_TRAINSTION_START, + }; + + static std::vector UI_ZOOM_RESIDS = { + IMAGE_TRAINSTION_START, + IMAGE_ZOOM_01, + IMAGE_ZOOM_02, + IMAGE_ZOOM_03, + IMAGE_ZOOM_04, + IMAGE_ZOOM_05, + IMAGE_ZOOM_06, + IMAGE_ZOOM_07, + IMAGE_ZOOM_08, + IMAGE_ZOOM_09, + IMAGE_ZOOM_10, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_TRAINSTION_END, + IMAGE_ZOOM_10, + IMAGE_ZOOM_09, + IMAGE_ZOOM_08, + IMAGE_ZOOM_07, + IMAGE_ZOOM_06, + IMAGE_ZOOM_05, + IMAGE_ZOOM_04, + IMAGE_ZOOM_03, + IMAGE_ZOOM_02, + IMAGE_ZOOM_01, + IMAGE_TRAINSTION_START, + }; +} // OHOS +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectSample.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectSample.h new file mode 100644 index 000000000..d673759bc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardEffectSample.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffectSample + * Create: 2025-04 + */ +#ifndef SETTING_CARD_EFFECT_SAMPLE_H +#define SETTING_CARD_EFFECT_SAMPLE_H +#include +#include + +namespace OHOS { +enum class CardEffectID { + UI_INVALIDE = -1, + UI_ZOOM = 0, + UI_CARD_FLIP = 1, + UI_CUBE = 2, + UI_TURN_PAGE = 3, + UI_PUSH_PRESS = 4, + UI_WINDMILL = 5, +}; + +struct SettingCardEffectSample { + CardEffectID viewId; + std::vector resIds; + const char* label; + int backgroundImageId; + const char* resourceImage; + bool selected; + + explicit SettingCardEffectSample(CardEffectID viewId = CardEffectID::UI_INVALIDE, std::vector resIds = {}, + const char* label = nullptr, const int backgroundImageId = 0, const char* resourceImage = nullptr, + bool selected = false) + : viewId(viewId), + resIds(std::move(resIds)), + label(label), + backgroundImageId(backgroundImageId), + resourceImage(resourceImage), + selected(selected) + {} +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardMgrItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardMgrItemGroup.h new file mode 100644 index 000000000..2702b7b0d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCardMgrItemGroup.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardMgrItemGroup + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_MGR_ITEM_GROUP_H +#define SETTING_CARD_MGR_ITEM_GROUP_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "UiConfig.h" + +namespace OHOS { +struct SettingCardItemData { + uint8_t index; + uint8_t id; + const char* image = nullptr; + bool isSelect; + void* contextPtr = nullptr; +}; + +class SettingCardMgrItemGroup : public UIViewGroup { +public: + explicit SettingCardMgrItemGroup(); + virtual ~SettingCardMgrItemGroup() override; + void UpdateItemGroup(SettingCardItemData* itemData); +private: + const char* imageSrc_ = nullptr; + ImageInfo* imageData_ = nullptr; + UIImageView image_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCommon.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCommon.h new file mode 100644 index 000000000..95f92a502 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingCommon.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCommon + * Create: 2025-06-01 + */ +#ifndef SETTING_COMMON_H +#define SETTING_COMMON_H + +#include +#include +#include "gfx_utils/vector.h" +#include "components/ui_view.h" +#include "components/ui_toggle_button.h" +#include "common/image_cache_manager.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "ui_resource_settings.h" + +namespace OHOS { +enum SettingPageId : uint16_t { + INVAILPAGE = 0, // 无效页面 + MAIN_PAGE = 1, // 主页面 + BLUETOOTH_PAGE = 2, // 蓝牙界面 + DISPLAY_PAGE = 3, // 显示与亮度界面 + DESKTOP_PAGE = 4, // 表盘与桌面界面 + POWER_PAGE = 5, // 电池界面 + CARD_PAGE = 6, // 卡片界面 + SYSTEM_PAGE = 7, // 系统与升级界面 + ABOUT_PAGE = 8, // 关于界面 + DISPLAY_BRIGHTNESS_PAGE = 9, // 显示与亮度 调节亮度界面 + DISPLAY_SCREEN_OFF_PAGE = 10, // 显示与亮度 熄屏时间界面 + DISPLAY_STEADY_ON_PAGE = 11, // 显示与亮度 长亮时刻界面 + DESKTOP_HOME_PAGE = 12, // 表盘与桌面 桌面界面 + DESKTOP_DIAL_PAGE = 13, // 表盘与桌面 表盘界面 + DESKTOP_DIAL_STYLE_PAGE = 14, // 表盘与桌面 表盘风格界面 + CARD_EFFECT_PAGE = 15, // 卡片管理 卡片动效页面 + CARD_MGR_PAGE = 16, // 卡片管理 卡片管理页面 + CARD_ADD_PAGE = 17, // 卡片管理 卡片添加页面 + SYSTEM_OPERATION_PAGE = 18, // 系统与升级 关机、重启、恢复出厂设置界面 + SYSTEM_OTA_PAGE = 19, // 系统与升级 OTA界面 + CONNECT_NEW_PHONE_PAGE = 20, // 蓝牙 连接新手机界面 + CONNECT_OPEN_PAGE = 21, // 蓝牙 连接新手机连接已打开界面 + CONNECT_BLUE_SUCCESS_PAGE = 22, // 蓝牙 连接耳机蓝牙成功界面 + CONNECT_BLUE_FAIL_PAGE = 23, // 蓝牙 连接耳机蓝牙失败界面 + RECONNECTION_PAGE = 24, // 蓝牙 重连耳机和取消配对界面 + RECONNECT_SECOND_CONFIRM_PAGE = 25, // 蓝牙 重连耳机二次确认界面 + UNPAIR_SECOND_CONFIRM_PAGE = 26, // 蓝牙 取消配对耳机二次确认界面 + QRCODE_CONN_PAGE = 27, // 蓝牙 二维码连接 +}; + +#define SETTING_LIST_DEFAULT_BG_COLOR Color::GetColorFromRGB(32, 32, 32) // 0xFF202020 +#define SETTING_LIST_BLUETOOTH_BG_COLOR Color::GetColorFromRGB(2, 142, 247) // 0xFF028EF7 +#define SETTING_LIST_DISPLAY_BG_COLOR Color::GetColorFromRGB(253, 200, 42) // 0xFFFDC82A +#define SETTING_LIST_DESKTOP_BG_COLOR Color::GetColorFromRGB(98, 87, 251) // 0xFF6257FB +#define SETTING_LIST_POWER_BG_COLOR Color::GetColorFromRGB(102, 192, 94) // 0xFF66C05 +#define SETTING_LIST_CARD_BG_COLOR Color::GetColorFromRGB(255, 128, 102) // 0xFFFF8066 +#define SETTING_LIST_SYSTEM_BG_COLOR Color::GetColorFromRGB(0, 210, 185) // 0xFF00D2B9 +#define SETTING_LIST_ABOUT_BG_COLOR Color::GetColorFromRGB(255, 255, 255) // 0xFFFFFFFF + +#define SETTING_LIST_DEFAULT_BG_COLOR_OPA 255 // 100% +#define SETTING_LIST_BLUETOOTH_BG_COLOR_OPA 63 // 24.61 +#define SETTING_LIST_DISPLAY_BG_COLOR_OPA 63 // 24.85% +#define SETTING_LIST_DESKTOP_BG_COLOR_OPA 65 // 25.42% +#define SETTING_LIST_POWER_BG_COLOR_OPA 65 // 25.33% +#define SETTING_LIST_CARD_BG_COLOR_OPA 64 // 25.24% +#define SETTING_LIST_SYSTEM_BG_COLOR_OPA 63 // 24.66% +#define SETTING_LIST_ABOUT_BG_COLOR_OPA 38 // 14.85% + +// 记录ItemGroup类中所有加载过的图片, 确保所有图片资源释放 +class ItemGroupImageCache { +public: + inline virtual ~ItemGroupImageCache() + { + for (auto imageId: imageIdList) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(imageId, SETTING_IMAGE); + } + } + + inline ImageInfo* CacheImage(uint32_t imageId) + { + imageIdList.push_back(imageId); + return ImageCacheManager::GetInstance().LoadOneInMultiRes(imageId, SETTING_IMAGE); + } +private: + std::vector imageIdList; +}; + +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingDesktopHomeItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingDesktopHomeItemGroup.h new file mode 100644 index 000000000..2cf1fc440 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingDesktopHomeItemGroup.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopHomeItemGroup + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_HOME_ITEM_GROUP_H +#define SETTING_DESKTOP_HOME_ITEM_GROUP_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_radio_button.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +struct SettingDesktopHomeItemData { + uint8_t style; // 风格 + uint32_t selectIcon; // 选中图标 + uint32_t unSelectIcon; // 未选中图标 + const char* label; // 文本内容 + bool isSelect; // 是否选中 + void* contextPtr; // 上下文指针,内部使用 +}; + +class SettingDesktopHomeItemGroup : public ItemGroupImageCache, + public UIViewGroup { +public: + explicit SettingDesktopHomeItemGroup(); + ~SettingDesktopHomeItemGroup() override; + void UpdateItemGroup(SettingDesktopHomeItemData* itemData); +private: + UIImageView image_; + UILabel label_; + UIRadioButton button_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingRefSingleton.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingRefSingleton.h new file mode 100644 index 000000000..1e07c6e48 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingRefSingleton.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingRefSingleton + * Create: 2025-06-01 + */ +#ifndef SETTING_REF_SINGLETON_H +#define SETTING_REF_SINGLETON_H + +namespace OHOS { +template +class SettingRefSingleton { +public: + static T& GetInstance() + { + static T instance; + return instance; + } +protected: + SettingRefSingleton() = default; + virtual ~SettingRefSingleton() = default; + SettingRefSingleton(const SettingRefSingleton&) = delete; + SettingRefSingleton& operator=(const SettingRefSingleton&) = delete; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingToggleButton.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingToggleButton.h new file mode 100644 index 000000000..730ba7558 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingToggleButton.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingToggleButton + * Create: 2025-06-01 + */ +#ifndef SETTING_TOGGLE_BUTTON_H +#define SETTING_TOGGLE_BUTTON_H + +#include "components/ui_toggle_button.h" + +namespace OHOS { +/* + * UIToggleButton的宽高比绑定, SettingToggleButton通过重写UIToggleButton的方法提供松散的宽高比 + */ +class SettingToggleButton : public UIToggleButton { +public: + SettingToggleButton(); + virtual ~SettingToggleButton() = default; + void SetTrackPadding(int16_t padding); + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; +protected: + void CalculateSize() override; +#if DEFAULT_ANIMATION + void Callback(UIView* view) override; + void OnStop(UIView& view) override; +#endif +private: + uint16_t trackCorner_ = 0; // 轨道圆角半径 + int16_t trackPadding_ = 0; // 轨道内边距 + uint16_t thumbRadius_ = 0; // 滑块半径 + Point leftCenter_ = {0, 0}; + Point rightCenter_ = {0, 0}; + Point currentCenter_ = {0, 0}; + ColorType bgColor_ = Color::White(); + Rect rectMid_ = {0, 0, 0, 0}; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingUnionItemGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingUnionItemGroup.h new file mode 100644 index 000000000..0b5c7ddfd --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/common/SettingUnionItemGroup.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingUnionItemGroup + * Create: 2025-06-01 + */ +#ifndef SETTING_UNION_ITEM_GROUP_H +#define SETTING_UNION_ITEM_GROUP_H + +#include +#include +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingToggleButton.h" + +namespace OHOS { +enum SettingUnionItemType : uint16_t { + PLAIN_TEXT, // 纯文本类型的item + ICON_TEXT_TOGGLE, // 按钮切换类型item + ICON_TEXT_NAVIGATION, // 页面切换类型item +}; + +struct PlainTextItemData { + const char* textContent; // 文本内容 +}; + +struct IconTextToggleItemData { + uint32_t icon; // 图标 + const char* textContent; // 文本内容 + bool selected; // 是否选择 + ColorType bgColor; // item背景色 + uint8_t bgOpa; // item背景透明度 +}; + +struct IconTextNavigationItemData { + SettingPageId pageId; // 页面ID + uint32_t icon; // 图标 + const char* textContent; // 固定文本内容 + const char* dataContent; // 动态数据内容 + bool hasSecondMenu; // 是否有二级页面 + ColorType bgColor; // item背景色 + uint8_t bgOpa; // item背景透明度 +}; + +class SettingUnionItemData { +public: + SettingUnionItemType GetUnionItemType(); + void* GetUnionItemData(); + + // 新增加到union的data类型请在这里注册 + SettingUnionItemData(const PlainTextItemData& itemData); + SettingUnionItemData(const IconTextToggleItemData& itemData); + SettingUnionItemData(const IconTextNavigationItemData& itemData); + + // 新增加到union的data类型请在这里注册 + union { + PlainTextItemData plainTextItemData; + IconTextToggleItemData iconTextToggleItemData; + IconTextNavigationItemData iconTextNavigationItemData; + } unionItemData_; +private: + SettingUnionItemType type_; + void* contextPtr_ = nullptr; // 用于SimpleList的Create和Update静态函数中使用 +}; + +class PlainTextItemView : public UIViewGroup, public ItemGroupImageCache { +public: + explicit PlainTextItemView(); + ~PlainTextItemView() override; + void UpdateViewData(PlainTextItemData* data); +private: + UILabel label_; +}; + +class IconTextToggleItemView : public UIViewGroup, public ItemGroupImageCache { +public: + explicit IconTextToggleItemView(); + ~IconTextToggleItemView() override; + void UpdateViewData(IconTextToggleItemData* data); +private: + UIImageView icon_; + UILabel label_; + SettingToggleButton toggleButton_; +}; + +class IconTextNavigationItemView : public UIViewGroup, public ItemGroupImageCache { +public: + explicit IconTextNavigationItemView(); + ~IconTextNavigationItemView() override; + void UpdateViewData(IconTextNavigationItemData* data); +private: + UIImageView icon_; + UILabel textLabel_; + UILabel dataLabel_; + UIImageView nextImage_; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingAboutModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingAboutModel.h new file mode 100644 index 000000000..6c4fde5c9 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingAboutModel.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingAboutModel + * Create: 2025-06-01 + */ +#ifndef SETTING_ABOUT_MODEL_H +#define SETTING_ABOUT_MODEL_H + +#include +#include +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +class SettingAboutModel : public SettingRefSingleton { +public: + std::string GetSystemName(); + std::string GetSystemType(); +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothHeadsetEvent.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothHeadsetEvent.h new file mode 100644 index 000000000..360a344c1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothHeadsetEvent.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBluetoothHeadsetEvent. + */ +#ifndef SETTING_BLUETOOTH_HEADSET_EVENT_H +#define SETTING_BLUETOOTH_HEADSET_EVENT_H + +#include "bts_def.h" +#include "bts_br_gap.h" +#include "td_type.h" +#include "bt_audio.h" +#ifdef __cplusplus +extern "C" { +#endif + +enum { + SETTING_AVRCP_SRV_PRESS_VALUE, + SETTING_AVRCP_SRV_RELEASED_VALUE, + SETTING_AVRCP_SRV_INIT_VALUE +}; + +typedef struct { + td_pvoid stream_hdl; + uint8_t loc_volume; + uint8_t play_stat; + uint8_t dir_forward; + uint8_t avrcp_button_flag; + bd_addr_t bd_addr; + uint8_t reg_cap_auto; + uint8_t resrv; + profile_connect_state_t avrcp_srv_conn_stat; +} SettingBtAvrcpTgInf; + +void SettingUsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue); +void SettingMediaStatusCallback(bt_avrcp_tg_evt_status_param *eventStatusParam); +void SettingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue); +void SettingConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); +void SettingConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); +void SettingInitBtHeadsetEvent(void); + +#ifdef __cplusplus +} +#endif + +#endif // SETTING_BLUETOOTH_HEADSET_EVENT_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothModel.h new file mode 100644 index 000000000..657f7c7ed --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingBluetoothModel.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBuletoothModel + * Create: 2025-06-01 + */ +#ifndef SETTING_BLUETOOTH_MODEL_H +#define SETTING_BLUETOOTH_MODEL_H + +#include +#include +#include +#include +#include "gfx_utils/list.h" +#include "bts_def.h" +#include "bts_br_gap.h" +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +typedef struct { + unsigned char deviceName[BD_NAME_LEN]; /* Name of the device record, must be in UTF-8 */ + unsigned char addr[BD_ADDR_LEN]; + std::string connect_status; + int16_t rssi; // 蓝牙信号强弱 +} BtCaseInfo; + +typedef enum { + BT_MAIN_PAGE = 0, + RECONNECT_FRAGMENT, + RECONNECT_SECOND_CONFIRM_FRAGMENT, + UNPAIR_CONFIRM_FRAGMENT, + CONNECT_NEW_PHONE_FRAGMENT, + CONNECT_OPEN_FRAGMENT, + CONNECT_BLUETOOTH_SUCCESS_FRAGMENT, + CONNECT_BLUETOOTH_FAIL_FRAGMENT, +} BtGroupId; + +class SettingBluetoothModel { +public: + ~SettingBluetoothModel(){}; + static SettingBluetoothModel *GetInstance(void); + void Init(); + std::list& GetScansDevicesList(); // 获取扫描到的设备列表 + void ScansDevicesListAddCase(BtCaseInfo caseInfo); // 设备列表新增数据 + void SetScansCaseRssi(const bd_addr_t *bdAddr, int rssi); // 设置设备的信号值 + void SortScansCaseRssi(); // 根据信号值对设备列表进行排序 + void ClearScansDevicesList(); + bool CheckExistScanList(BtCaseInfo caseInfo); // 去重检查 + void ResetScanDevicesCase(const BtCaseInfo& caseInfo); // 刷新名称变化的设备信息 + // 已配对蓝牙设备 + void SetPairedDevicesListClear(); + void AddPairedDevicesCase(BtCaseInfo caseInfo); + bool CheckExistPairedList(BtCaseInfo caseInfo); + List& GetPairedDevicesCase(); + // 被选中的设备信息 + void SetSelectedDeviceInfo(BtCaseInfo *caseInfo); + BtCaseInfo *GetSelectedDeviceInfo(void); + // 最后连接的设备地址 + void SetLastConnedAddr(const bd_addr_t *addr); + bd_addr_t *GetLastConnedAddr(void); + void SetAclConnected(bool tag); + bool GetAclConnected(void); + void UpdateAclConnectStatus(bool status); + void SettingBtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr); + void SettingBtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr); + bool GetAdvStartState(void); + void SetAdvStartState(bool state); + int ConnectRemoteDevice(const bd_addr_t *addr); + bool ConnectRemoteCheck(const bd_addr_t *addr); + char* GetWatchName(void); + void ChangeBleConnectToMax(); + void ChangeBleConnectToDefault(); + // 耳机蓝牙连接状态 + void SetBlueToothConnectStatus(bool status); + bool GetBlueToothConnectStatus(); + void SetDeviceName(std::string deviceName_); + std::string GetDeviceName(); + void SetEarPhoneListHasData(bool status); + uint32_t GetEarPhoneListHasData(); + void MoveMatchingDeviceToFront(); + // 更新UI上设备列表的信息 + void UpdateConnectStatusForDevice(); + void UpdateDisconnectStatusForDevice(const bd_addr_t &bdAddr); + void UpdateConnectedStatusForDevice(const bd_addr_t &bdAddr); + // 设置是否展示成功或失败的页面 + void SetConnectResultPage(bool redirct); + bool GetConnectResultPage(); + // 取消配对 + void HandleUnpairRequest(void); + void AddNodeFromPairListToScanList(const bd_addr_t &bdAddr); + void SetConnectFragmentStatus(bool status); + bool GetConnectFragmentStatus(); +private: + SettingBluetoothModel(); + void SetUpPairedDevicesList(); + void InitBluetoothInfo(void); + bool aclConnected_{false}; + BtCaseInfo selectedDeviceInfo_{}; + bd_addr_t lastConnedAddr_{0}; + bd_addr_t remoteConnectAddr_{0}; + std::list btScansDevicesList_{}; + List *btPairedDevicesList_{nullptr}; + bool advStartState_{false}; + char watchName_[BD_NAME_LEN] = { 0 }; + bool btConnectStatus_{false}; + std::string deviceName_; + uint32_t EarPhoneListHasData_ = 0; + bool redirct_ = false; + bool connectFragmentStatus_ = false; +}; + +#ifdef __cplusplus +extern "C" { +#endif +void SettingBtGapReadRemoteRssiEventCallback(const bd_addr_t *bdAddr, int rssi, int status); +void SettingBtGapDiscoveryStateChangedCallback(int status); +void SettingBtGapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason); +void SettingBtRemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *deviceName, unsigned char length); +void SettingBtIsAcceptConnOnSafeModeCallback(const bd_addr_t *bd_addr, bool *res); +void SettingBtInitCallBacks(void); +void SettingBtInitCallBacksEx(void); +void SettingBtInitGatts(void); +void SettingBtInitSpp(void); +void BleSettingAdvStart(void); +#ifdef __cplusplus +} +#endif +} + +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingCardModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingCardModel.h new file mode 100644 index 000000000..74127fa28 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingCardModel.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardModel + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_MODEL_H +#define SETTING_CARD_MODEL_H + +#include +#include +#include "settings/common/SettingCardEffectSample.h" +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingCardAddItemGroup.h" +#include "settings/common/SettingCardMgrItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +class SettingCardModel : public SettingRefSingleton { +public: + SettingCardModel(); + std::vector& GetCardUnionData(); + std::vector& GetCardData(); + void RefreshCardData(); + void AddCard(uint8_t cardId); + void DeleteCard(uint8_t cardId); + void SetSelectedCard(uint8_t cardId); + uint8_t GetSelectedCard(void); + // 卡片动效 + CardEffectID GetSwipeEffectStyle(void); + void SetSwipeEffectStyle(CardEffectID style); + void InitEffectItem(void); + std::map& GetEffectListItems(void); +private: + std::vector cardUnionData_; + std::vector cardData_; + uint8_t selectedCardId_ = MAX_CARD; + std::map effects_; + CardEffectID selectStyle_; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDesktopModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDesktopModel.h new file mode 100644 index 000000000..70584d54d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDesktopModel.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopModel + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_MODEL_H +#define SETTING_DESKTOP_MODEL_H + +#include +#include +#include "gfx_utils/image_info.h" +#include "main/MainModel.h" +#include "settings/common/SettingDesktopHomeItemGroup.h" +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +typedef enum { + APPLIST_STYLE, + HEXAGONS_STYLE, + FOOTBALL_STYLE, + WATERFALL_STYLE, + PLANET_STYLE, + SPHERE_STYLE +} DesktopStyle; + +namespace OHOS { +typedef struct { + uint8_t dialFlag; /* 1:离线表盘 0:预制表盘 */ + uint8_t id; /* 仅预制表盘使用 */ + uint32_t resId; /* 仅离线表盘使用 */ + std::string dialFullName; /* 仅离线表盘使用 */ + std::string imageFullName; /* 仅预制表盘使用 */ + std::string dialName; + std::string description; /* 仅离线表盘使用 */ + ImageInfo* preImageInfo; + uint8_t capability; +} SetDialInfo; + +enum class DialStyle { + COVERFLOW = 0, + ROLLER, + STYLE_NUM +}; + +class SettingDesktopModel : public SettingRefSingleton { +public: + SettingDesktopModel(); + std::vector& GetDesktopUnionData(); + std::vector& GetDesktopHomeData(); + std::vector& GetDialStyleUnionData(); + void RefreshDialStyleUnionDataForStyle(); + void RefreshDialStyleUnionDataForAod(); + // 桌面 + DesktopStyle GetDesktopStyle(void); + void SetDesktopStyle(DesktopStyle style); + uint8_t GetDesktopHomeDataSelect(); + void SetDesktopHomeDataSelect(DesktopStyle style); + // 表盘风格 + DialStyle GetDialStyle(); + void SetDialStyle(DialStyle style); + void SetDialStyleDataSelect(const char* DialStyleName); + // 表盘 + void LoadAllDial(void); + std::vector& GetDialInfo(void); // 表盘信息 + std::vector& GetAmbientDialInfo(void); // 息屏显示表盘信息 AOD(always-on display) + void SaveDialSetting(uint8_t pageIndex); + void SetSpecifyDialSetting(const DialSetting &setting); // 设置指定的dial + void ClearDialInfo(void); + uint8_t GetPageIndex(void); +protected: + void LoadAllDialFromRam(); + void LoadAllDialFromFs(); + int32_t ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo); +private: + std::vector desktopUnionData_; + std::vector desktopHomeData_; + std::vector dialStyleUnionData_; + std::vector dialInfos_; + std::vector aodDialInfos_; + bool hasSpecificDial_ = false; + DialSetting specificDialSetting_; +}; +} + +#endif // SET_DESKTOP_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDisplayModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDisplayModel.h new file mode 100644 index 000000000..775037fca --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingDisplayModel.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayModel + * Create: 2025-06-01 + */ +#ifndef SETTING_DISPLAY_MODEL_H +#define SETTING_DISPLAY_MODEL_H + +#include +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +// 息屏时间 (单位:ms) +enum class ScreenOffTime : uint32_t { + SECONDS_5 = 5000u, + SECONDS_10 = 10000u, + SECONDS_15 = 15000u, + SECONDS_30 = 30000u, + MINUTE_1 = 60000u, + MINUTE_5 = 300000u, +}; + +// 常亮时间 (单位:ms) +enum class SteadyOnTime : uint32_t { + MINUTE_5 = 300000u, + MINUTE_10 = 600000u, + MINUTE_20 = 1200000u, + MINUTE_30 = 1800000u, + HOUR_1 = 3600000u, + HOUR_2 = 7200000u, +}; + +class SettingDisplayModel : public SettingRefSingleton { +public: + SettingDisplayModel(); + std::vector& GetDisplayUnionData(); + void RefreshDisplayUnionDataForAutoAdjustBrightness(); + void RefreshDisPlayUnionDataForScreenOffDataContext(); + void RefreshDisplayUnionDataForSteadyOnDataContext(); + void InitDisplayModel(); + void EnableSteadyOn(); // 打开常亮 + void DisableSteadyOn(); // 关闭常亮 + bool GetAutoAdjustBrightness(); + uint8_t GetBrightness(); + ScreenOffTime GetScreenOffTime(); + SteadyOnTime GetSteadyOnTime(); + void SetAutoAdjustBrightness(bool isAuto); + void SetBrightness(uint8_t brightness); + void SetScreenOffTime(ScreenOffTime blinkFrequency); + void SetSteadyOnTime(SteadyOnTime blinkFrequency); + const char** GetScreenOffTimeAllStr(); + const char** GetSteadyOnTimeAllStr(); + uint8_t GetScreenOffTimeAllStrSize(); + uint8_t GetSteadyOnTimeAllStrSize(); + uint8_t GetScreenOffTimeIndex(); + uint8_t GetSteadyOnTimeIndex(); + void SetScreenOffTimeIndex(uint8_t index); + void SetSteadyOnTimeIndex(uint8_t index); +protected: + const char* GetScreenOffTimeShortStr(ScreenOffTime screenOffTime); + const char* GetSteadyOnTimeShortStr(SteadyOnTime steadyOnTime); + uint8_t TransBriValueToPercent(uint8_t value); + uint8_t TransBriPercentToValue(uint8_t percent); +private: + std::vector displayUnionData_; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingMainModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingMainModel.h new file mode 100644 index 000000000..b45ff4db4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingMainModel.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainModel + * Create: 2025-06-01 + */ +#ifndef SETTING_MAIN_MODEL_H +#define SETTING_MAIN_MODEL_H + +#include +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +class SettingMainModel : public SettingRefSingleton { +public: + SettingMainModel(); + void InitSettingsData(); + std::vector& GetMainUnionData(); + static UIView* OnSimpleListCreate(uint8_t type); +private: + std::vector mainUnionData_; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingPowerModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingPowerModel.h new file mode 100644 index 000000000..70bd8033f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingPowerModel.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPowerModel + * Create: 2025-06-01 + */ +#ifndef SETTING_POWER_MODEL_H +#define SETTING_POWER_MODEL_H + +#include +#if !defined(_WIN32) +#include "adc.h" +#include "tcxo.h" +#include "pinctrl.h" +#include "hal_adc.h" +#endif +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +#if !defined(_WIN32) +class SettingPowerModel : public SettingRefSingleton { +public: + SettingPowerModel(); + ~SettingPowerModel(); + uint8_t GetBatteryPowerLevel(); + const char* GetPowerModelNotify(); +protected: + bool adc_context_init(); + bool adc_context_startup(); + void adc_context_shutdown(); + uint8_t calc_percentage(uint32_t voltage); + uint32_t calc_voltage(); + uint32_t adc_trans_sytick_to_voltages(uint32_t sytick); +private: + adc_channel_t channel_; // ADC信道 + pin_t analog_pin_; // ADC输入引脚 + pin_mode_t mode_; // ADC管脚工作模式 + uint32_t samples_to_keep_; // 总采样次数 + uint32_t samples_to_discard_; // 丢弃的初始样本数 + uint32_t adc_max_range_mv_; // ADC原始值上限(单位:毫伏) + uint32_t adc_min_range_mv_; // ADC原始值下限(单位:毫伏) +}; +#else +class SettingPowerModel : public SettingRefSingleton { +public: + uint8_t GetBatteryPowerLevel(); + const char* GetPowerModelNotify(); +}; +#endif +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingQrcodeConnModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingQrcodeConnModel.h new file mode 100644 index 000000000..cc1ff2678 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingQrcodeConnModel.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingQrcodeConnModel + * Create: 2025-06-01 + */ +#ifndef SETTING_QRCODE_CONN_MODEL_H +#define SETTING_QRCODE_CONN_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "settings/common/SettingRefSingleton.h" +#include "UiConfig.h" + +namespace OHOS { +class SettingQrcodeConnModel : public SettingRefSingleton { +public: + static SettingQrcodeConnModel &GetInstance(void); +private: + SettingQrcodeConnModel(); + SettingQrcodeConnModel(const SettingQrcodeConnModel &); + SettingQrcodeConnModel &operator=(const SettingQrcodeConnModel &); + virtual ~SettingQrcodeConnModel(); +}; +} + +#endif // SETTING_QRCODE_CONN_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingSystemModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingSystemModel.h new file mode 100644 index 000000000..63a023c32 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/model/SettingSystemModel.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemModel + * Create: 2025-06-01 + */ +#ifndef SETTING_SYSTEM_MODEL_H +#define SETTING_SYSTEM_MODEL_H + +#include +#include +#include +#ifndef _WIN32 +#include "osal_task.h" +#endif +#include "settings/common/SettingUnionItemGroup.h" +#include "settings/common/SettingRefSingleton.h" + +namespace OHOS { +class SettingSystemModel : public SettingRefSingleton { +public: + SettingSystemModel(); + virtual ~SettingSystemModel(); + std::vector& GetSystemUnionData(); + void SystemOperation(const char* operationName); + // OTA + bool GetOtaIsUpgrade(); + uint32_t GetOtaPackageSize(); + void StartOtaNativeUpgrade(); + void StopOtaNativeUpgrade(); + uint8_t GetOtaNativeUpgradePercent(); + std::string GetOtaNativeUpgradeMessage(); +protected: + void RestoreJSApplication(); + void RestoreNativeApplication(); + void RestoreKvstore(); + void SetOtaNativeUpgradePercent(uint8_t percent); + void SetOtaNativeUpgradeMessage(std::string message); + static int SystemOta(void *data); + static void UninstallCallback(const uint8_t resultCode, const void *resultMessage); +private: + std::vector systemUnionData_; + std::mutex otaOSALMtx_; +#ifndef _WIN32 + osal_task* systemOtaTask_ = nullptr; +#endif + uint8_t otaUpgradePrecent_ = 0; + std::string otaUpgradeMessage_; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingAboutPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingAboutPage.h new file mode 100644 index 000000000..dac649f0d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingAboutPage.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingAboutPage + * Create: 2025-06-01 + */ +#ifndef SETTING_ABOUT_PAGE_H +#define SETTING_ABOUT_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingAboutPage : public SlicePage { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; +protected: + void InitTitle(); + void InitDeviceTypeView(); + void InitDeviceNameView(); +private: + UILabel* title_ = nullptr; + UILabel* deviceNameTitle_ = nullptr; + UILabel* deviceTypeTitle_ = nullptr; + UILabel* deviceName_ = nullptr; + UILabel* deviceType_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingBluetoothPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingBluetoothPage.h new file mode 100644 index 000000000..7a053185f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingBluetoothPage.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBuletoothPage + * Created: 2025-06-05 + */ +#ifndef SETTING_BLUETOOTH_PAGE_H +#define SETTING_BLUETOOTH_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "SlicePage.h" +#include "common/image_cache_manager.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "graphic_timer.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingConnectNewPhone.h" +#include "settings/page/SettingReconnection.h" +#include "settings/page/SettingConnectBlueFail.h" +#include "settings/page/SettingConnectBlueSuccess.h" + +namespace OHOS { +static constexpr uint16_t SEARCH_IMAGE_COUNT = 31; + +class SettingBluetoothPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SettingBluetoothPage(); + ~SettingBluetoothPage() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + static SettingBluetoothPage *GetInstance(void); + void InitSearchAni(void); + void InitImageAnimator(); + void InitContentList(); + void BtScan(); + void StartBtScan(); + void StopBtScan(); + bool GetScanStatus(void); + void BtAnimatorStart(); + void BtAnimatorStop(); + void SetScanStatus(bool value); + void InitPageView(); + void DestoryPageView(); + void NotFindDevice(); + void LoadFindDeviceList(); + void UpdataImageAnimatorAndList(); + void TimerFindDevice(); + void UpdateBtListContent(int16_t viewIndex); + bool IsDeviceConnect(); + bool GetImageAnimatorState(); + void ChangeView(int16_t value); + void ShowResultGroup(int16_t value); + +protected: + static UIView* CreateForContent(uint8_t type); + static void UpdateForContent(UIView* view, void* data, uint8_t type); + static UIView* CreateForBtList(uint8_t type); + static void UpdateForBtList(UIView* view, void* data, uint8_t type); + +private: + bool scanStart_{0}; + UIScrollViewNested *scroll_ = nullptr; + UILabel *titleLabel_ = nullptr; + UILabel *noDeviceLabel_ = nullptr; + UILabel *availableDeviceLabel_ = nullptr; + UILabel *searchBtnTextLabel_ = nullptr; + UILabelButton *resetResearchButton_ = nullptr; + UIImageAnimatorView *imageAnimator_; + ImageAnimatorInfo searchImageInfo_[SEARCH_IMAGE_COUNT]; + UISimpleList *optionList_ = nullptr; + UISimpleList *btEarPhoneList_ = nullptr; + SettingConnectNewPhone *connectNewPhoneFragment_ = nullptr; + SettingConnectionOpen* connectOpenFragment_ = nullptr; + SettingReconnection *reconnectionFragment_ = nullptr; + SettingReconnectSecondConfirm* secondConfirmFragment_ = nullptr; + UnPairSecondConfirm* unPairFragment_ = nullptr; + SettingConnectBlueSuccess *successFragment_ = nullptr; + SettingConnectBlueFail *failFragment_ = nullptr; +}; + +#ifdef __cplusplus +extern "C" { +#endif +void ScanTimerCallback(int data); +void SettingCancelBrScanHandle(void); +void SettingEndScanHandle(void); +#ifdef __cplusplus +} +#endif +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardAddPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardAddPage.h new file mode 100644 index 000000000..de918e5aa --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardAddPage.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardAddPage + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_ADD_PAGE_H +#define SETTING_CARD_ADD_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "components/ui_label.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingCardAddPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static UIView* OnSimpleListCreate(uint8_t type); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UISimpleList* list_ = nullptr; + UILabel* title_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardEffectPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardEffectPage.h new file mode 100644 index 000000000..fb9693dab --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardEffectPage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffectPage + * Create: 2025-04 + */ +#ifndef SETTING_CARD_EFFECT_PAGE_H +#define SETTING_CARD_EFFECT_PAGE_H + +#include +#include "View.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCardEffectSample.h" +#include "settings/model/SettingCardModel.h" +#include "settings/common/SettingCardEffectItemGroup.h" + +namespace OHOS { +using CardEffectPair = std::pair; + +class SettingCardEffecPage : public SlicePage, + public UIView::OnClickListener, + public ListScrollListener { +public: + SettingCardEffecPage(); + ~SettingCardEffecPage() override; + void OnStart(void* data) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + void OnItemSelected(int16 index, UIView* view) override; + void SetCardEffectListData(const std::map &effectMap); +protected: + static UIView* OnSimpleListCreate(uint8_t type); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UILabel* titleText_{nullptr}; + UISimpleList* contentList_{nullptr}; + std::list effectListDatas_; + SettingCardEffectItemGroup* itemGroupSele_{nullptr}; + SettingCardEffectItemGroup* preItemGroupSele_{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardMgrPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardMgrPage.h new file mode 100644 index 000000000..ede943182 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardMgrPage.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardMgrPage + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_MGR_PAGE_H +#define SETTING_CARD_MGR_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "components/ui_label.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingCardMgrPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + void InitListView(); + void InitButtonView(); + static UIView* OnSimpleListCreate(uint8_t type); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UISimpleList* list_ = nullptr; + UIButton* addButton_ = nullptr; + UIButton* delButton_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardPage.h new file mode 100644 index 000000000..71a72ab24 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingCardPage.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardPage + * Create: 2025-06-01 + */ +#ifndef SETTING_CARD_PAGE_H +#define SETTING_CARD_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingCardPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scroll_ = nullptr; + UISimpleList* content_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueFail.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueFail.h new file mode 100644 index 000000000..58a842915 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueFail.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectBlueFail + * Created: 2025-06-05 + */ +#ifndef SETTING_CONNECT_BLUE_FAIL_H +#define SETTING_CONNECT_BLUE_FAIL_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingConnectBlueFail : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitFailFragment(); + UIImageView* img_ = nullptr; + UILabel* watchNameLabel_ = nullptr; + UILabel* connectStatusLabel_ = nullptr; + UILabelButton* confirmButton_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueSuccess.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueSuccess.h new file mode 100644 index 000000000..4f3daa848 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectBlueSuccess.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectBlueSuccess + * Created: 2025-06-05 + */ +#ifndef SETTING_CONNECT_BLUE_SUCCESS_H +#define SETTING_CONNECT_BLUE_SUCCESS_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class SettingConnectBlueSuccess : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitSuccessFragment(); + UIImageView* img_ = nullptr; + UILabel* watchNameLabel_ = nullptr; + UILabel* connectStatusLabel_ = nullptr; + UILabelButton* confirmButton_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectNewPhone.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectNewPhone.h new file mode 100644 index 000000000..e65849fb7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectNewPhone.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectNewPhone + * Created: 2025-06-05 + */ +#ifndef SETTING_CONNECT_NEW_PHONE_H +#define SETTING_CONNECT_NEW_PHONE_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" +#include "settings/page/SettingConnectionOpen.h" + +namespace OHOS { +class SettingConnectNewPhone : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + bool OnClick(UIView &view, const ClickEvent &event); + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitNewPhoneFragment(); + UILabel* textFirst_ = nullptr; + UILabel* textSecond_ = nullptr; + UILabel* textThird_ = nullptr; + UIImageView* cancel_ = nullptr; + UIButton* confirm_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectionOpen.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectionOpen.h new file mode 100644 index 000000000..f5cc3c7af --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingConnectionOpen.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectionOpen + * Created: 2025-06-05 + */ +#ifndef SETTING_CONNECTION_OPEN_H +#define SETTING_CONNECTION_OPEN_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class SettingConnectionOpen : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event); + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitConnectionOpenFragment(); + UIImageView* img_ = nullptr; + UILabel* watchNameLabel_ = nullptr; + UILabel* connectStatusLabel_ = nullptr; + UILabelButton* confirmButton_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialPage.h new file mode 100644 index 000000000..eba25f513 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialPage.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopDialPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_DIAL_PAGE_H +#define SETTING_DESKTOP_DIAL_PAGE_H + +#include +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_coverflow_view.h" +#include "components/ui_roller_view.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDesktopDialPage : public SlicePage, + public UIView::OnClickListener, + public UICoverflowView::OnCoverflowScrollListener, + public UIRollerView::OnScrollListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnScroll() override; + void OnScroll(UIRollerView* roller, std::string currentItemName, float currentItemAngle) override; +protected: + void InitDialView(); + void InitCtrlView(); +private: + UILabel* itemLabel_ = nullptr; + UICoverflowView* coverflow_ = nullptr; + UIRollerView* rollerView_ = nullptr; + uint8_t itemCount_ = 0; + uint8_t itemIndex_ = 0; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialStylePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialStylePage.h new file mode 100644 index 000000000..99882c772 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopDialStylePage.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopDialStylePage + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_DIAL_STYLE_PAGE_H +#define SETTING_DESKTOP_DIAL_STYLE_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDesktopDialStylePage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + void DestoryPageView(); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scroll_ = nullptr; + UISimpleList* content_ = nullptr; +}; +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopHomePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopHomePage.h new file mode 100644 index 000000000..1b79a59cf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopHomePage.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopHomePage + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_HOME_PAGE_H +#define SETTING_DESKTOP_HOME_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "components/ui_label.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDesktopHomePage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static UIView* OnSimpleListCreate(uint8_t type); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UISimpleList* list_ = nullptr; + UILabel* title_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopPage.h new file mode 100644 index 000000000..ddb164f3d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDesktopPage.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DESKTOP_PAGE_H +#define SETTING_DESKTOP_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDesktopPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scroll_ = nullptr; + UISimpleList* content_ = nullptr; +}; +} +#endif // SETTING_DESKTOP_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayBrightnessPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayBrightnessPage.h new file mode 100644 index 000000000..54d154076 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayBrightnessPage.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayBrightnessPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DISPLAY_BRIGHTNESS_PAGE_H +#define SETTING_DISPLAY_BRIGHTNESS_PAGE_H + +#include "components/ui_view_group.h" +#include "components/ui_circle_progress.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDisplayBrightnessPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnLongPressListener, + public UIView::OnTouchListener, + public UIView::OnDragListener, + public AnimatorCallback { +public: + using SlicePage::OnStop; + using AnimatorCallback::OnStop; + void OnStart(void* data) override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + void Callback(UIView* view) override; + bool OnLongPress(UIView& view, const LongPressEvent& event) override; + bool OnRelease(UIView& view, const ReleaseEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; +protected: + void InitProgressView(); + void InitButtonView(); +private: + UILabel* title_ = nullptr; + UICircleProgress* progress_ = nullptr; + UILabel* progressNum_ = nullptr; + UIButton* add_ = nullptr; + UIButton* sub_ = nullptr; + Animator* animator_ = nullptr; + UIButton* curLongPressButton_ = nullptr; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayPage.h new file mode 100644 index 000000000..d19f4c5e3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayPage.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DISPLAY_PAGE_H +#define SETTING_DISPLAY_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDisplayPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scroll_ = nullptr; + UISimpleList* content_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayScreenOffPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayScreenOffPage.h new file mode 100644 index 000000000..71c902d2a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplayScreenOffPage.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayScreenOffPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DISPLAY_SCREEN_OFF_PAGE_H +#define SETTING_DISPLAY_SCREEN_OFF_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_picker.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDisplayScreenOffPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; +private: + UILabel* title_ = nullptr; + UIPicker* picker_ = nullptr; + UIButton* button_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplaySteadyOnPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplaySteadyOnPage.h new file mode 100644 index 000000000..9d6d0eb8c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingDisplaySteadyOnPage.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplaySteadyOnPage + * Create: 2025-06-01 + */ +#ifndef SETTING_DISPLAY_STEADY_ON_PAGE_H +#define SETTING_DISPLAY_STEADY_ON_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_picker.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingDisplaySteadyOnPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; +private: + UILabel* title_ = nullptr; + UIPicker* picker_ = nullptr; + UIButton* button_ = nullptr; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingMainPage.h new file mode 100644 index 000000000..e4fda2357 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingMainPage.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainPage + * Create: 2025-06-01 + */ +#ifndef SETTING_MAIN_PAGE_H +#define SETTING_MAIN_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "components/ui_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingMainPage : public SlicePage, + public UIView::OnDragListener, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + void InitPageView(); + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scrollView_ = nullptr; + UISimpleList* simpleList_ = nullptr; +}; +} +#endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingPowerPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingPowerPage.h new file mode 100644 index 000000000..163ac8e87 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingPowerPage.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPowerPage + * Create: 2025-06-01 + */ +#ifndef SETTING_POWER_PAGE_H +#define SETTING_POWER_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingPowerPage : public SlicePage, + public AnimatorCallback { +public: + using SlicePage::OnStop; + using AnimatorCallback::OnStop; + void OnStart(void* data) override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + void Callback(UIView* view) override; +protected: + void InitPowerView(); + void InitBatteryStatusView(); + void InitNotify(); +private: + UIScrollView* scrollView_ = nullptr; + UILabel* title_ = nullptr; + UILabel* powerDesc_ = nullptr; + UILabel* batteryPercentage_ = nullptr; + UILabel* timeLabel_ = nullptr; + UIViewGroup* batteryStatusGroup_ = nullptr; + UILabel* batteryLabel_ = nullptr; + UILabel* batteryLevel_ = nullptr; + UILabel* detailsDesc_ = nullptr; + Animator* timeAnimator_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingQrcodeConnPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingQrcodeConnPage.h new file mode 100644 index 000000000..75e6140b1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingQrcodeConnPage.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingQrcodeConnPage + * Created: 2025-06-05 + */ +#ifndef SETTING_QRCODE_CONN_PAGE_H +#define SETTING_QRCODE_CONN_PAGE_H + +#include +#include "View.h" +#include "SlicePage.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "UiConfig.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_view.h" +#include "components/ui_qrcode.h" +#include "components/ui_label.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { + +class SettingQrcodeConnPage : public SlicePage, + public UIView::OnDragListener { +public: + SettingQrcodeConnPage(); + ~SettingQrcodeConnPage() override; + void OnStart(void* data) override; + void InitView(); +private: + UIScrollViewNested *group_ = nullptr; + UIQrcode *qrcode_ = nullptr; + UILabel *content_ = nullptr; +}; +} +#endif // SETTING_QRCODE_CONN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnectSecondConfirm.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnectSecondConfirm.h new file mode 100644 index 000000000..6ebda6c9f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnectSecondConfirm.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingReconnectSecondConfirm + * Created: 2025-06-05 + */ +#ifndef SETTING_RECONNECT_SECOND_CONFIRM_H +#define SETTING_RECONNECT_SECOND_CONFIRM_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class SettingReconnectSecondConfirm : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event); + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitSecondConfirmFragment(); + UILabel* title_ = nullptr; + UILabel* contentFirst_ = nullptr; + UILabel* contentSecond_ = nullptr; + UILabel* contentThird_ = nullptr; + UIImageView* cancel_ = nullptr; + UILabelButton* confirm_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnection.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnection.h new file mode 100644 index 000000000..8ef1a5380 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingReconnection.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingReconnection + * Created: 2025-06-05 + */ +#ifndef SETTING_RECONNECTION_H +#define SETTING_RECONNECTION_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" +#include "settings/page/SettingReconnectSecondConfirm.h" +#include "settings/page/UnPairSecondConfirm.h" + +namespace OHOS { +class SettingReconnection : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event); + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitReconnectionFragment(); + UILabel* watchNameLabel_ = nullptr; + UILabel* connectStatusLabel_ = nullptr; + UILabelButton* reconnectionButton_ = nullptr; + UIImageView* unpair_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOperationPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOperationPage.h new file mode 100644 index 000000000..d69af8b9b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOperationPage.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemOperationPage + * Create: 2025-06-01 + */ +#ifndef SETTING_SYSTEM_OPERATION_PAGE_H +#define SETTING_SYSTEM_OPERATION_PAGE_H + +#include +#include +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_slider.h" +#include "components/ui_view_group.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +struct OperationData { + ColorType sliderBgColor; + uint32_t sliderKnobImage; +}; + +class SettingSystemOperationPage : public SlicePage, + public UIView::OnClickListener, + public UISlider::UISliderEventListener { +public: + SettingSystemOperationPage(); + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + void OnChange(int32_t value) override; + void OnRelease(int32_t value) override; +protected: + void InitSliderView(); + void InitButtonView(); + void RefreshSlider(); +private: + UISlider* slider_ = nullptr; + UILabel* sliderLabel_ = nullptr; + UIButton* button_ = nullptr; + UILabel* buttonDescription_ = nullptr; + std::string operationName_; + std::map operationData_; + bool sliderBegin_ = false; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOtaPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOtaPage.h new file mode 100644 index 000000000..b68e3cf23 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemOtaPage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemOTAPage + * Create: 2025-06-01 + */ +#ifndef SETTING_SYSTEM_OTA_PAGE_H +#define SETTING_SYSTEM_OTA_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_slider.h" +#include "components/ui_view_group.h" +#include "components/ui_circle_progress.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingSystemOtaPage : public SlicePage, + public UIView::OnClickListener, + public AnimatorCallback { +public: + using SlicePage::OnStop; + using AnimatorCallback::OnStop; + void OnStart(void* data) override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + void Callback(UIView* view) override; +protected: + void InitPreGroupView(); + void InitMidCircleView(); + void InitMidMessageView(); +private: + Animator* upgradeAnimator_ = nullptr; + UIViewGroup* preUpgradeGroup_ = nullptr; + UIViewGroup* midUpgradeGroup_ = nullptr; + UIButton* preUpgradeButton_ = nullptr; + UILabel* preUpgradeLabel_ = nullptr; + UICircleProgress* midUpgradeProress_ = nullptr; + UILabel* midUpgradeLabel_ = nullptr; + UILabel* midUpgradePercent_ = nullptr; + UILabel* midUpgradeMessage_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemPage.h new file mode 100644 index 000000000..e6322bce3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/SettingSystemPage.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemPage + * Create: 2025-06-01 + */ +#ifndef SETTING_SYSTEM_PAGE_H +#define SETTING_SYSTEM_PAGE_H + +#include "components/ui_scroll_view_nested.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "settings/SettingPresenter.h" +#include "settings/common/SettingCommon.h" + +namespace OHOS { +class SettingSystemPage : public SlicePage, + public UIView::OnClickListener { +public: + void OnStart(void* data) override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; +protected: + static void OnSimpleListUpdate(UIView* view, void* data, uint8_t type); +private: + UIScrollViewNested* scroll_ = nullptr; + UISimpleList* content_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/UnPairSecondConfirm.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/UnPairSecondConfirm.h new file mode 100644 index 000000000..4eaa0cd69 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/settings/page/UnPairSecondConfirm.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UnPairSecondConfirm + * Created: 2025-06-05 + */ +#ifndef UNPAIR_SECOND_CONFIRM_H +#define UNPAIR_SECOND_CONFIRM_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_fragment.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class UnPairSecondConfirm : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void RefreshFragment(); + bool OnClick(UIView &view, const ClickEvent &event); + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + void InitUnpairFragment(); + UILabel* title_ = nullptr; + UILabel* contentFirst_ = nullptr; + UILabel* contentSecond_ = nullptr; + UILabel* watchNameLabel_ = nullptr; + UIImageView* cancel_ = nullptr; + UILabelButton* confirm_ = nullptr; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepDetailsPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepDetailsPage.h new file mode 100644 index 000000000..142d71352 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepDetailsPage.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepDetailsPage + * Created: 2025-06-05 + */ +#ifndef SLEEP_DETAILS_PAGE_H +#define SLEEP_DETAILS_PAGE_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "main/LoadImg.h" +#include "ui_resource_sleep.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepModel.h" + +namespace OHOS { +class SleepPresenter; +class SleepDetailsPage : public SlicePage, + public UIView::OnDragListener { +public: + SleepDetailsPage(); + ~SleepDetailsPage() override; + + void OnStart(void* data) override; + void InitPage(); + void InitNoDeatilPage(); + void InitDetailPage(); + void InitSoberingTime(); + void InitRapidEyeMovement(); + void InitLightSleepTime(); + void InitDeepSleepTime(); + bool OnDrag(UIView &view, const DragEvent &event) override; + bool GetRecord(); + std::string SetTimeUnit(std::tuple timeTuple); + void InitActualSleepTime(std::tuple timeTuple); + void LoadDeatilActualSleepTime(); + +private: + UIScrollView *group_{nullptr}; + UILabel *sleepTitleLabel_{nullptr}; + UILabel *actualSleepNorecordTimeLabel_{nullptr}; // norecord + UILabel *actualSleepTimeHoursLabel_{nullptr}; + UILabel *actualSleepTimeHoursUnitLabel_{nullptr}; + UILabel *actualSleepTimeMinutesLabel_{nullptr}; + UILabel *actualSleepTimeMinutesUnitLabel_{nullptr}; + + UIImageView *bgImg_{nullptr}; + UIImageView *grayBgImg_{nullptr}; + UIImageView *redPointImg_{nullptr}; + UILabel *soberingTimeLabel_{nullptr}; + UILabel *soberingTimeUnitLabel_{nullptr}; + UIImageView *orangePointImg_{nullptr}; + UILabel *rapidEyeMovementLabel_ {nullptr}; + UILabel *rapidEyeMovementUnitLabel_{nullptr}; + UIImageView *greenPointImg_{nullptr}; + UILabel *lightSleepTimeLabel_{nullptr}; + UILabel *lightSleepTimeUnitLabel_{nullptr}; + UIImageView *bluePointImg_{nullptr}; + UILabel *deepSleepTimeLabel_{nullptr}; + UILabel *deepSleepTimeUnitLabel_{nullptr}; +}; +} + +#endif // SLEEP_DETAILS_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepMainPage.h new file mode 100644 index 000000000..99469f1dc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepMainPage.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepMainPage + * Created: 2025-06-05 + */ +#ifndef SLEEP_MAIN_PAGE_H +#define SLEEP_MAIN_PAGE_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_circle_progress.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_sleep.h" +#include "main/LoadImg.h" +#include "sleep/SleepTargetTime.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepModel.h" + + +namespace OHOS { +class SleepPresenter; +class SleepMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SleepMainPage(); + ~SleepMainPage() override; + + void OnStart(void* data) override; + void InitNoRecordPage(); + void InitRecordPage(); + void LoadActualSleepTime(std::tuple timeTuple); + void LoadTargetTimeButton(std::tuple timeTuple); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void InitCircleProgress(); + uint32_t GetSleepingScores(); + void InitSleepTimeLabel(); + void ScoreDisplay(); + bool GetRecord(); + void InitScoreDisplayPicture(); +private: + UIScrollView *group_{nullptr}; + UIImageView *imageViewMain_{nullptr}; + // noRecord页面控件 + UILabel *sleepTitleLabel_{nullptr}; + UIImageView *moonNoRecordImg_{nullptr}; + UILabel *noRecordLabel_{nullptr}; + UILabel *tipsLabel_{nullptr}; + // Record页面控件 + UIImageView *moonImg_{nullptr}; + UILabel *sleepScoreTextLabel_{nullptr}; + UILabel *sleepScoresLabel_{nullptr}; + UILabel *scoreUnitLabel_{nullptr}; + UIImageView *scoreStarImg1_{nullptr}; + UIImageView *scoreStarImg2_{nullptr}; + UIImageView *scoreStarImg3_{nullptr}; + UIImageView *scoreStarImg4_{nullptr}; + UIImageView *scoreStarImg5_{nullptr}; + UILabel *targetSleepTimeHoursLabel_{nullptr}; + UILabel *targetSleepTimeHoursUnitLabel_{nullptr}; + UILabel *targetSleepTimeMinutesLabel_{nullptr}; + UILabel *targetSleepTimeMinutesUnitLabel_{nullptr}; + UILabel *targetTimeLabel_{nullptr}; + UILabelButton *targetTimeButton_{nullptr}; + UIImageView *settingImg_{nullptr}; + UICircleProgress* circleProgress_{nullptr}; +}; +} + +#endif // SLEEP_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepModel.h new file mode 100644 index 000000000..78b9e7d92 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepModel.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepModel + * Created: 2025-06-05 + */ +#ifndef SLEEP_MODEL_H +#define SLEEP_MODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "graphic_timer.h" +#include "ohos_timer.h" +#include "wearable_log.h" +#include "diag_service.h" +#include "msg_center_device.h" +#include "diag_common.h" +#include "sleep/SleepPresenter.h" + +namespace OHOS { + enum SleepType : uint8_t { + SLEEP_TYPE_DEEP = 1, // 深睡 + SLEEP_TYPE_LIGHT = 2, // 浅睡 + SLEEP_TYPE_EYEMOVE = 3, // 快速动眼 + SLEEP_TYPE_SOBER = 4, // 清醒 + }; + static const uint16_t SLEEP_DATA_DATE_RANGE = 11; + static const uint16_t SLEEP_DATA_START_DATA_RANGE = 20; + + #pragma pack(1) + struct SleepData { + bool isSended; + char date[SLEEP_DATA_DATE_RANGE]; + SleepType type; + char typeSleepStart[SLEEP_DATA_START_DATA_RANGE]; + char typeSleepEnd[SLEEP_DATA_START_DATA_RANGE]; + char sleepStart[SLEEP_DATA_START_DATA_RANGE]; + char sleepEnd[SLEEP_DATA_START_DATA_RANGE]; + + SleepData( + bool isSended, + const char* date, + SleepType type, + const char* typeSleepStart, + const char* typeSleepEnd, + const char* sleepStart, + const char* sleepEnd) + { + this->isSended = isSended; + strncpy_s(this->date, SLEEP_DATA_DATE_RANGE, date, SLEEP_DATA_DATE_RANGE - 1); + this->type = type; + strncpy_s(this->typeSleepStart, SLEEP_DATA_START_DATA_RANGE, typeSleepStart, + SLEEP_DATA_START_DATA_RANGE - 1); + strncpy_s(this->typeSleepEnd, SLEEP_DATA_START_DATA_RANGE, typeSleepEnd, SLEEP_DATA_START_DATA_RANGE - 1); + strncpy_s(this->sleepStart, SLEEP_DATA_START_DATA_RANGE, sleepStart, SLEEP_DATA_START_DATA_RANGE - 1); + strncpy_s(this->sleepEnd, SLEEP_DATA_START_DATA_RANGE, sleepEnd, SLEEP_DATA_START_DATA_RANGE - 1); + } + }; + #pragma pack() + + class SleepModel { + public: + static SleepModel &GetInstance(void); + void SendData(); + uint8_t* SerializeSleepData(const SleepData* sleepData, size_t* outSize); + void SetSleepDataVec(); // 存入睡眠数据接口 + void SetTargetTime(uint32_t minute); + std::tuple GetTargetTime(); + void SetData(); + std::tuple GetSoberingTime(); + std::tuple GetRapidEyeMovementTime(); + std::tuple GetLightSleepTime(); + std::tuple GetDeepSleepTime(); + std::tuple GetSleepTime(); + void SetSoberingTime(); + void SetRapidEyeMovementTime(); + void SetLightSleepTime(); + void SetDeepSleepTime(); + bool GetRecord(); + uint32_t GetSleepTimeHours(); + uint32_t GetSleepTimeMinutes(); + std::tuple MinutesToHours(uint32_t minutes); + uint32_t TimeDiffInMinutes(const std::string& timeStr1, const std::string& timeStr2); + uint32_t GetDetailData(int type); + uint32_t GetTotalSleepTime(); + void LoadData(); + std::string GetTodayDate(); + + private: + SleepModel(); + virtual ~SleepModel(); + uint32_t sleepTarget_ = 0; + std::vector sleepDataVector_; + uint32_t soberingTime_; + uint32_t eyeMoveTime_; + uint32_t lightTime_; + uint32_t deepTime_; + }; +} + +#endif // SLEEP_MODEL_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepPresenter.h new file mode 100644 index 000000000..7e8d0e538 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepPresenter.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepPresenter + * Created: 2025-06-05 + */ + +#ifndef SLEEP_PRESENTER_H +#define SLEEP_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class SleepView; +class SleepPresenter : public Presenter { +}; +} + +#endif // SLEEP_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepSleepingPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepSleepingPage.h new file mode 100644 index 000000000..5abcd7b42 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepSleepingPage.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepSleepingPage + * Created: 2025-06-05 + */ +#ifndef SLEEP_SLEEPING_PAGE_H +#define SLEEP_SLEEPING_PAGE_H + +#include +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_circle_progress.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_sleep.h" +#include "main/LoadImg.h" +#include "sleep/SleepTargetTime.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepModel.h" + + +namespace OHOS { +class SleepPresenter; +class SleepSleepingPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SleepSleepingPage(); + ~SleepSleepingPage() override; + + void OnStart(void* data) override; + void OnPause() override; + void InitCircleProgress(); + void InitSleepTimeLabel(); + void LoadTargetTimeForHourAndMin(std::tuple timeTuple); + void StopAnimator(); +private: + UIScrollView *group_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *moonImg_{nullptr}; + UILabel *sleepTitleLabel_{nullptr}; + UILabel *sleepingLabel_{nullptr}; + UILabel *targetSleepTimeHoursLabel_{nullptr}; + UILabel *targetSleepTimeHoursUnitLabel_{nullptr}; + UILabel *targetSleepTimeMinutesLabel_{nullptr}; + UILabel *targetSleepTimeMinutesUnitLabel_{nullptr}; + UIImageView *sleepTimeBgImg_{nullptr}; + UICircleProgress* circleProgress_{nullptr}; + +class SleepAnimatorCallback : public AnimatorCallback { +public: + explicit SleepAnimatorCallback(SleepSleepingPage* page) : page_(page) {} + ~SleepAnimatorCallback() override {} + void Callback(UIView *view) override; + +private: + SleepSleepingPage* page_{nullptr}; +}; + Animator *animator_ = nullptr; + SleepAnimatorCallback *callBack_ = nullptr; + struct timeval startTime_ = {0}; +}; +} + +#endif // SLEEP_SLEEPING_PAGE_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepTargetTime.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepTargetTime.h new file mode 100644 index 000000000..fea647661 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepTargetTime.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepTargetTime + * Created: 2025-06-05 + */ + +#ifndef SLEEP_TARGET_TIME_H +#define SLEEP_TARGET_TIME_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_picker.h" +#include "components/ui_scroll_view.h" +#include "main/LoadImg.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +namespace OHOS { +static constexpr int16_t PICKER_COUNT = 2; + +class SleepTargetTime : public SlicePage, + public UIPicker::SelectedListener, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SleepTargetTime(); + ~SleepTargetTime() override; + + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnPickerStoped(UIPicker& picker) override; + void InitStartButton(); + void CreatePicker(); + void CreateLabel(); + void SetPickerTime(); +private: + UIScrollView *group_{nullptr}; + UILabel* targetTitleLabel_{nullptr}; + UILabel* timerUnitLabel_{nullptr}; + UILabelButton *startButton_{nullptr}; + UIPicker* timerPicker_[PICKER_COUNT]{nullptr}; +}; +} +#endif // TARGET_SLEEP_TIME_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepView.h new file mode 100644 index 000000000..01c9a7f7b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sleep/SleepView.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepView + * Created: 2025-06-05 + */ + +#ifndef SLEEP_VIEW_H +#define SLEEP_VIEW_H + +#include "View.h" +namespace OHOS { +enum SLEEPING_PAGES { + SLEEPING_MAIN_PAGE = 1, // 0 is invalid + SLEEPING_DEATIL_PAGE = 2, + SLEEPING_TARGET_PAGE = 3, + SLEEPING_SLEEP_PAGE = 4, +}; +class SleepPresenter; +class SleepView : public View { +}; +} +#endif // SLEEP_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportCountdownPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportCountdownPage.h new file mode 100644 index 000000000..5a94db86b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportCountdownPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportCountdownPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_COUNTDOWN_PAGE_H +#define SPORT_COUNTDOWN_PAGE_H + +#include "animator/animator.h" +#include "components/ui_label.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +class SportCountdownPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportCountdownPage() {} + ~SportCountdownPage(); + void OnStart(void* data) override; + void OnPause() override; + void OnResume() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void UpdateCountdownView(uint64_t time); + class SportCountdownAnimatorCallback : public AnimatorCallback { + public: + SportCountdownAnimatorCallback(SportCountdownPage* page):page_(page) {} + virtual ~SportCountdownAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + SportCountdownPage* page_{nullptr}; + }; + Animator* animator_{nullptr}; + SportCountdownAnimatorCallback* callback_{nullptr}; + UIViewGroup *group_{nullptr}; + UILabel *countdownText_{nullptr}; + UICircleProgress *countdownProgress_{nullptr}; + struct timeval startTime_{0}; +}; +} // namespace OHOS +#endif // SPORT_COUNTDOWN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportDataPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportDataPage.h new file mode 100644 index 000000000..ae650c8fa --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportDataPage.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportDataPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_DATA_PAGE_H +#define SPORT_DATA_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_sweep_clock.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +class SportDataPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportDataPage() {} + ~SportDataPage(); + void OnStart(void* data) override; + void OnPause() override; + void OnResume() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBatteryView(); + void InitTimeLableVIew(); + void ShowUpHeartRate(); + void ShowUpTopView(); + void ShowUpLeftView(); + void ShowUpRightView(); + void ShowUpBottomView(); + void ShowUpSeparateLine(); + void UpdateDataViewByType(); + void CheckTarget(); + void CheckRemind(); + class SportDataAnimatorCallback : public AnimatorCallback { + public: + SportDataAnimatorCallback(SportDataPage* page):page_(page) {} + virtual ~SportDataAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + SportDataPage* page_{nullptr}; + }; + Animator* animator_{nullptr}; + SportDataAnimatorCallback* callback_{nullptr}; + Image *secondHand_{nullptr}; + UISweepClock *sweepClock_{nullptr}; + UIImageView *heartRateScale_{nullptr}; + UIImageView *heartRatePointer_{nullptr}; + UICanvas *separateLine_{nullptr}; + UILabel *topValueLabel_{nullptr}; + UILabel *topUnitLabel_{nullptr}; + UILabel *leftValueLabel_{nullptr}; + UILabel *leftUnitLabel_{nullptr}; + UILabel *rightValueLabel_{nullptr}; + UILabel *rightUnitLabel_{nullptr}; + UILabel *bottomValueLabel_{nullptr}; + UILabel *bottomUnitLabel_{nullptr}; + UILabel *timeLabel_{nullptr}; + UIImageView *batteryIcon_{nullptr}; + UILabel *batteryLabel_{nullptr}; +}; +} // namespace OHOS +#endif // SPORT_DATA_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangeItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangeItemView.h new file mode 100644 index 000000000..b4e20f700 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangeItemView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportHeartRateRangeItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_HEART_RATE_RANGE_ITEM_VIEW_H +#define SPORT_HEART_RATE_RANGE_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_radio_button.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + const char *title; + const char *viewId; +} SportHeartRateRangeItem; + +class SportHeartRateRangeItemView : public UIViewGroup { +public: + SportHeartRateRangeItemView(); + ~SportHeartRateRangeItemView() override; + + virtual void SetItemInfo(const SportHeartRateRangeItem &itemInfo); + +private: + UIImageView bgImage_; + UILabel title_; + UILabel range_; + UIRadioButton button_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangePage.h new file mode 100644 index 000000000..a71eac74b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportHeartRateRangePage.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportHeartRateRangePage + * Create: 2025-06-06 + */ + +#ifndef SPORT_HEART_RATE_RANGE_PAGE_H +#define SPORT_HEART_RATE_RANGE_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportHeartRateRangeItemView.h" + +namespace OHOS { +const char* SPORT_HEARTRATE_RANGE_ITEM_1 = "sportHeartRateRangeItem1"; +const char* SPORT_HEARTRATE_RANGE_ITEM_2 = "sportHeartRateRangeItem2"; +const char* SPORT_HEARTRATE_RANGE_ITEM_3 = "sportHeartRateRangeItem3"; +const char* SPORT_HEARTRATE_RANGE_ITEM_4 = "sportHeartRateRangeItem4"; + +class SportHeartRateRangePage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportHeartRateRangePage(); + ~SportHeartRateRangePage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void CreateUILabel(void); + void CreateUIList(void); + UIScrollView *group_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *heartRateRangeList_{nullptr}; + SportHeartRateRangeItem heartRateRanges_[SPORT_HEARTRATE_RANGE_MAX] = { + {SPORT_HEARTRATE_RANGE_ITEM1, "热身燃脂", SPORT_HEARTRATE_RANGE_ITEM_1}, + {SPORT_HEARTRATE_RANGE_ITEM2, "有氧耐力", SPORT_HEARTRATE_RANGE_ITEM_2}, + {SPORT_HEARTRATE_RANGE_ITEM3, "无氧耐力", SPORT_HEARTRATE_RANGE_ITEM_3}, + {SPORT_HEARTRATE_RANGE_ITEM4, "极限训练", SPORT_HEARTRATE_RANGE_ITEM_4}}; +}; +} // namespace OHOS +#endif // SPORT_HEART_RATE_RANGE_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuItemView.h new file mode 100644 index 000000000..0ed753dca --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuItemView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMenuItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_MENU_ITEM_VIEW_H +#define SPORT_MENU_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + int bgId; + int iconId; + const char *label; + const char *viewId; +} SportMenuItem; + +class SportMenuItemView : public UIViewGroup { +public: + SportMenuItemView(); + ~SportMenuItemView() override; + + virtual void SetItemInfo(const SportMenuItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UIImageView settingImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuPage.h new file mode 100644 index 000000000..95e9f3007 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMenuPage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMenuPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_MENU_PAGE_H +#define SPORT_MENU_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_sport.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportMenuItemView.h" + +namespace OHOS { +const char* SPORT_ITEM_OUTDOOR_RUNNING = "sportItemOutdoorRunning"; +const char* SPORT_ITEM_INDOOR_RUNNING = "sportItemIndoorRunning"; +const char* SPORT_ITEM_CYCLING = "sportItemCycling"; +const char* SPORT_ITEM_CLIMBING = "sportItemClimbing"; +const char* SPORT_ITEM_INDOOR_SWIMMING = "sportItemIndoorSwimming"; +const char* SPORT_ITEM_OUTDOOR_SWIMMING = "sportItemOutdoorSwimming"; + +class SportMenuPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportMenuPage(); + ~SportMenuPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIScrollView *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *sportList_{nullptr}; + SportMenuItem sportMenu_[SPORT_TYPE_MAX] = { + {IMAGE_SPORT_ITEMBG1, IMAGE_SPORT_OUTDOOR_RUNNING1, "户外跑步", SPORT_ITEM_OUTDOOR_RUNNING}, + {IMAGE_SPORT_ITEMBG2, IMAGE_SPORT_INDOOR_RUNNING1, "室内跑步", SPORT_ITEM_INDOOR_RUNNING}, + {IMAGE_SPORT_ITEMBG3, IMAGE_SPORT_CYCLING1, "骑行", SPORT_ITEM_CYCLING}, + {IMAGE_SPORT_ITEMBG4, IMAGE_SPORT_CLIMBING1, "登山", SPORT_ITEM_CLIMBING}, + {IMAGE_SPORT_ITEMBG6, IMAGE_SPORT_INDOOR_SWIMMING1, "室内游泳", SPORT_ITEM_INDOOR_SWIMMING}, + {IMAGE_SPORT_ITEMBG5, IMAGE_SPORT_OUTDOOR_SWIMMING1, "户外游泳", SPORT_ITEM_OUTDOOR_SWIMMING}}; +}; +} // namespace OHOS +#endif // SPORT_MENU_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMistouchPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMistouchPage.h new file mode 100644 index 000000000..6dbea19f1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportMistouchPage.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMistouchPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_MISTOUCH_PAGE_H +#define SPORT_MISTOUCH_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_toggle_button.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +const char* SPORT_MISTOUCH_SCREEN_BUTTON = "sportMistouchScreenButton"; +const char* SPORT_MISTOUCH_CROWN_BUTTON = "sportMistouchCrownButton"; + +class SportMistouchPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportMistouchPage() {} + ~SportMistouchPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + UIScrollView* group_ = nullptr; + UILabel* title_ = nullptr; + UIImageView* bgScreen_ = nullptr; + UIToggleButton* buttonScreen_ = nullptr; + UILabel* titleScreen_ = nullptr; + UIImageView* imageScreen_ = nullptr; + UIImageView* bgCrown_ = nullptr; + UIToggleButton* buttonCrown_ = nullptr; + UILabel* titleCrown_ = nullptr; + UIImageView* imageCrown_ = nullptr; + UILabel* textScreen_ = nullptr; + UILabel* textCrown_ = nullptr; +}; +} // namespace OHOS +#endif // SPORT_MISTOUCH_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportModel.h new file mode 100644 index 000000000..6832bdd3a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportModel.h @@ -0,0 +1,199 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportModel + * Create: 2025-06-06 + */ + +#ifndef SPORT_MODEL_H +#define SPORT_MODEL_H + +#include +#if defined(_WIN32) +#include "animator/animator.h" +#define SPORT_CONFIG_PATH +#else +#define SPORT_CONFIG_PATH "/user/data/" +#include "ohos_timer.h" +#include "graphic_timer.h" +#endif + +namespace OHOS { +enum SportType : uint8_t { + SPORT_TYPE_OUTDOOR_RUNNING = 0, + SPORT_TYPE_INDOOR_RUNNING, + SPORT_TYPE_CYCLING, + SPORT_TYPE_CLIMBING, + SPORT_TYPE_INDOOR_SWIMMING, + SPORT_TYPE_OUTDOOR_SWIMMING, + SPORT_TYPE_MAX, +}; + +enum SportSetType : uint8_t { + SPORT_SET_TYPE_TARGET = 0, // 设置项(目标)和提示类型共用 + SPORT_SET_TYPE_REMIND, // 设置项(提醒)和提示类型共用 + SPORT_SET_TYPE_MISTOUCH, // 设置项(防误触) + SPORT_SET_TYPE_MAX = 3, // 设置项最大值 + SPORT_SET_TYPE_HEARTRATE, // 只用于心率提示类型 +}; + +enum SportTarget : uint8_t { + SPORT_TARGET_DISTANCE = 0, + SPORT_TARGET_TIME, + SPORT_TARGET_CALORIE, + SPORT_TARGET_MAX, +}; + +enum SportRemind : uint8_t { + SPORT_REMIND_INTERVAL = 0, + SPORT_REMIND_HEARTRATE, + SPORT_REMIND_MAX, +}; + +enum SportRemindInterval : uint8_t { + SPORT_REMIND_INTERVAL_NONE = 0, + SPORT_REMIND_INTERVAL_DISTANCE, + SPORT_REMIND_INTERVAL_TIME, + SPORT_REMIND_INTERVAL_MAX, +}; + +enum SportRemindHeartRate : uint8_t { + SPORT_REMIND_HEARTRATE_ENABLE = 0, + SPORT_REMIND_HEARTRATE_RANGE, + SPORT_REMIND_HEARTRATE_MAX, +}; + +enum SportHeartRateRange : uint8_t { + SPORT_HEARTRATE_RANGE_ITEM1 = 0, + SPORT_HEARTRATE_RANGE_ITEM2, + SPORT_HEARTRATE_RANGE_ITEM3, + SPORT_HEARTRATE_RANGE_ITEM4, + SPORT_HEARTRATE_RANGE_MAX, +}; + +enum GpsSignal : uint8_t { + SPORT_GPS_SIGNAL0 = 0, + SPORT_GPS_SIGNAL1, + SPORT_GPS_SIGNAL2, + SPORT_GPS_SIGNAL3, +}; + +enum SportAction : uint8_t { + SPORT_ACTION_START = 1, + SPORT_ACTION_PAUSE = 2, + SPORT_ACTION_RESUME = 3, + SPORT_ACTION_STOP = 4, +}; + +enum SportConfig : uint8_t { + SPORT_CONFIG_INFO = 1, + SPORT_CONFIG_RECORD = 2, +}; + +typedef struct sport_control { + uint8_t action; + uint8_t type; +} sport_control_t; + +typedef struct sport_data { + uint8_t type; // 运动类型 + uint16_t heartRate; // 心率 + uint16_t calorie; // 卡路里 + uint16_t altitude; // 高度 + uint16_t ascent; // 海拔上升 + uint16_t descent; // 海拔下降 + uint32_t distance; // 运动距离 + uint32_t lap; // 室内游泳趟数 + uint32_t startTime; // 运动开始时间 + uint32_t endTime; // 运动结束时间 + uint32_t elapsedTime; // 运动总耗时 +} sport_data_t; + +typedef struct sport_info { + SportSetType setType; // 当前设置项类型(目标或提醒) + SportSetType promptType; // 当前提醒项类型 + bool isTargetSetted; // 是否已设置过目标 + SportTarget targetType; // 目标类型 + SportTarget targetTypeTemp; // 临时目标类型,用于恢复没有成功设置目标类型时 + uint16_t targetValue; // 设置的目标值,在Picker中选择的值 + bool targetHalf; // 是否达到一半目标 + bool targetComplete; // 是否达成半目标 + bool isRemindSetted; // 是否已设置过提醒 + SportRemindInterval remindType; // 提醒类型 + SportRemindInterval remindTypeTemp; // 临时提醒类型,用于恢复没有成功设置提醒类型时 + uint16_t remindIndex; // 提醒的索引值,在Picker中的索引值 + uint16_t remindValue; // 设置的提醒值,在Picker中选择的值 + uint16_t remindTimes; // 已经提醒的次数 + bool enableHeartRemind; // 是否开启心率提醒 + bool isHeartReminded; // 同区间的心率值是否已经提醒过 + SportHeartRateRange heartRange; // 设置的心率提醒区间 + bool enableScreenLock; // 是否开启屏幕锁定 + bool enableCrownLock; // 是否开启表冠锁定 + uint32_t startTimeTemp; // 用于暂停时再继续运动时计算运动耗时 + sport_data_t data; // 各项运动数据 +} sport_info_t; + +std::string GetCurrentTimeStr(); +std::string ConvertDistance(uint32_t distance); +std::string FormatSportTime(uint32_t uiSportTime); +std::string CalculateSpeed(uint32_t distance, uint32_t time); +const char *GetHeartRateRangeDescription(uint8_t range); +uint16_t GetHeartRateRangeBounder(uint8_t index); + +class SportModel { +public: + enum class SportState : uint8_t { STOPPED, RUNNING, PAUSED }; + static SportModel &GetInstance(void); + void SetSportType(SportType sportType); + SportType GetSportType(void); + void SetTargetValue(uint16_t index); + void SetRemindValue(uint16_t index); + void SetGpsSignal(GpsSignal gpsSignal); + GpsSignal GetGpsSignal(void); + uint16_t GetHeartRate(void); + sport_info_t *GetSportInfo(SportType type); + sport_info_t *GetCurrSportInfo(); + uint32_t GetElapsedTime(); + void StartSport(bool startedByWatch); + void PauseAndReport(bool isReport); + void ResumeAndReport(bool isReport); + void StopAndReport(bool isReport); + void AddRecord(); + void ClearRecord(); + std::vector &GetRecord(); + bool IsStartByWatch(); + void LoadConfig(); + void SaveConfig(uint8_t config); + void ClearData(); + +private: + SportModel(); + SportModel(const SportModel &); + SportModel &operator=(const SportModel &); + virtual ~SportModel(); + SportType curSport_; + sport_info_t info_[SPORT_TYPE_MAX]; + GpsSignal gpsSignal_; + bool isStartByWatch_{false}; + SportState state_; + std::vector records_; +#if defined(_WIN32) + class SportAnimatorCallback : public AnimatorCallback { + public: + SportAnimatorCallback() {} + virtual ~SportAnimatorCallback() override {} + void Callback(UIView *view) override; + + private: + }; + SportAnimatorCallback *callback_{nullptr}; + Animator *animator_{nullptr}; +#else + GraphicTimer *generateDataHandle_{nullptr}; + void InitGenerateSportData(); + void StartGenerateSportData(); + void StopGenerateSportData(); +#endif +}; +} + +#endif // SPORT_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPausePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPausePage.h new file mode 100644 index 000000000..232b06ac9 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPausePage.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPausePage + * Create: 2025-06-06 + */ + +#ifndef SPORT_PAUSE_PAGE_H +#define SPORT_PAUSE_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +const char* SPORT_PAUSE_CONTINUE_BUTTON = "sportPauseContinueButton"; +const char* SPORT_PAUSE_FINISH_BUTTON = "sportPauseFinishButton"; + +class SportPausePage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportPausePage() {} + ~SportPausePage(); + void OnStart(void* data) override; + void OnPause() override; + void OnResume() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void CreateUILabel(void); + void CreateUIButton(void); + class SportPauseAnimatorCallback : public AnimatorCallback { + public: + SportPauseAnimatorCallback() {} + virtual ~SportPauseAnimatorCallback() override {} + void Callback(UIView* view) override; + }; + SportPauseAnimatorCallback* callback_{nullptr}; + Animator* animator_{nullptr}; + UIViewGroup *group_{nullptr}; + UILabel *timeLabel_{nullptr}; + UILabel *textLabel_{nullptr}; + UILabelButton *continueButton_{nullptr}; + UILabelButton *finishButton_{nullptr}; +}; +} // namespace OHOS +#endif // SPORT_PAUSE_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPreparePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPreparePage.h new file mode 100644 index 000000000..20756b503 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPreparePage.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPreparePage + * Create: 2025-06-06 + */ + +#ifndef SPORT_PREPARE_PAGE_H +#define SPORT_PREPARE_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +const char* SPORT_PREPARE_GO_BUTTON = "sportPrepareGoButton"; + +class SportPreparePage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportPreparePage() {} + ~SportPreparePage(); + void OnStart(void* data) override; + void OnPause() override; + void OnResume() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitGpsSignalImage(); + void InitBackgroundView(); + void InitBatteryView(); + void InitHeartbeatView(); + void InitTimeLableVIew(); + void InitCenterView(); + void InitGPSView(); + void InitHeartRateView(); + void InitGoButtonView(); + class SportPrepareAnimatorCallback : public AnimatorCallback { + public: + SportPrepareAnimatorCallback(SportPreparePage* page):page_(page) {} + virtual ~SportPrepareAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + SportPreparePage* page_{nullptr}; + }; + SportPrepareAnimatorCallback* callback_{nullptr}; + Animator* animator_{nullptr}; + UIViewGroup *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *timeLabel_{nullptr}; + UIImageView *batteryIcon_{nullptr}; + UILabel *batteryLabel_{nullptr}; + UILabel *locatingLabel_{nullptr}; + UIImageView *gpsImageView_{nullptr}; + UIImageView *gpsSignalView_{nullptr}; + UIImageView *heartRateImageView_{nullptr}; + UILabel *heartRateLabel_{nullptr}; + UILabelButton *goButton_{nullptr}; + UIImageView *iconImageView_{nullptr}; + time_t startTime_{0}; + bool isOverTime_{false}; +}; +} // namespace OHOS +#endif // SPORT_PREPARE_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPresenter.h new file mode 100644 index 000000000..bad4570b5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPresenter.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPresenter + * Create: 2025-06-06 + */ + +#ifndef SPORT_PRESENTER_H +#define SPORT_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class SportView; +class SportPresenter : public Presenter {}; +} + +#endif // SPORT_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPromptPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPromptPage.h new file mode 100644 index 000000000..cbd9fefdf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportPromptPage.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPromptPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_PROMPT_PAGE_H +#define SPORT_PROMPT_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "SlicePage.h" +#include "SportPresenter.h" + +namespace OHOS { +const char* SPORT_PROMPT_CANCEL_BUTTON = "sportPromptCancelButton"; +const char* SPORT_PROMPT_CONFIRM_BUTTON = "sportPromptConfirmButton"; + +class SportPromptPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportPromptPage() {} + ~SportPromptPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void CreateUILabel(void); + void CreateUIButton(void); + UIViewGroup *group_{nullptr}; + UIImageView *promptIcon_{nullptr}; + UILabel *promptLabel_{nullptr}; + UIButton *cancelButton_{nullptr}; + UIButton *confirmButton_{nullptr}; +}; +} // namespace OHOS +#endif // SPORT_PROMPT_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRateItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRateItemView.h new file mode 100644 index 000000000..12e7d909d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRateItemView.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindHeartRateItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_HEART_RATE_ITEM_VIEW_H +#define SPORT_REMIND_HEART_RATE_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + int iconId; + const char *label; + const char *viewId; +} SportRemindHeartRateItem; + +class SportRemindHeartRateItemView : public UIViewGroup { +public: + SportRemindHeartRateItemView(); + ~SportRemindHeartRateItemView() override; + + virtual void SetItemInfo(const SportRemindHeartRateItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UILabel hits_; + UIToggleButton button_; + UIImageView nextImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRatePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRatePage.h new file mode 100644 index 000000000..34ebec7b5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindHeartRatePage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindHeartRatePage + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_HEART_RATE_PAGE_H +#define SPORT_REMIND_HEART_RATE_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_view_group.h" +#include "UiConfig.h" +#include "ui_resource_sport.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportRemindHeartRateItemView.h" + +namespace OHOS { +const char* SPORT_REMIND_HEARTRATE_ITEM_ENABLE = "sportRemindHeartRateItemEnable"; +const char* SPORT_REMIND_HEARTRATE_ITEM_RANGE = "sportRemindHeartRateItemRange"; + +class SportRemindHeartRatePage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportRemindHeartRatePage(); + ~SportRemindHeartRatePage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void CreateUILabel(void); + void CreateUIList(void); + UIViewGroup *group_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *remindHeartRateList_{nullptr}; + SportRemindHeartRateItem remindHeartRates_[SPORT_REMIND_HEARTRATE_MAX] = { + {SPORT_REMIND_HEARTRATE_ENABLE, IMAGE_SPORT_HEARTRATE, "心率提醒", SPORT_REMIND_HEARTRATE_ITEM_ENABLE}, + {SPORT_REMIND_HEARTRATE_RANGE, IMAGE_SPORT_HEARTRATE, "心率范围", SPORT_REMIND_HEARTRATE_ITEM_RANGE}}; +}; +} // namespace OHOS +#endif // SPORT_REMIND_HEART_RATE_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalItemView.h new file mode 100644 index 000000000..4ad204c9c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalItemView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindIntervalItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_INTERVAL_ITEM_VIEW_H +#define SPORT_REMIND_INTERVAL_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + int iconId; + const char *label; + const char *viewId; +} SportRemindIntervalItem; + +class SportRemindIntervalItemView : public UIViewGroup { +public: + SportRemindIntervalItemView(); + ~SportRemindIntervalItemView() override; + + virtual void SetItemInfo(const SportRemindIntervalItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UIImageView nextImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalPage.h new file mode 100644 index 000000000..08d7f5006 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindIntervalPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindIntervalPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_INTERVAL_PAGE_H +#define SPORT_REMIND_INTERVAL_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "ui_resource_sport.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportRemindIntervalItemView.h" + +namespace OHOS { +const char* SPORT_REMIND_INTERVAL_ITEM_DISTANCE = "sportRemindIntervalItemDistance"; +const char* SPORT_REMIND_INTERVAL_ITEM_TIME = "sportRemindIntervalItemTime"; +const char* SPORT_REMIND_INTERVAL_ITEM_NONE = "sportRemindIntervalItemNone"; + +class SportRemindIntervalPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportRemindIntervalPage(); + ~SportRemindIntervalPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIScrollView *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *remindIntervalList_{nullptr}; + SportRemindIntervalItem remindIntervals_[SPORT_REMIND_INTERVAL_MAX] = { + {SPORT_REMIND_INTERVAL_DISTANCE, IMAGE_SPORT_DISTANCE, "距离", SPORT_REMIND_INTERVAL_ITEM_DISTANCE}, + {SPORT_REMIND_INTERVAL_TIME, IMAGE_SPORT_TIME, "时间", SPORT_REMIND_INTERVAL_ITEM_TIME}, + {SPORT_REMIND_INTERVAL_NONE, IMAGE_SPORT_NONE, "无提醒", SPORT_REMIND_INTERVAL_ITEM_NONE}}; +}; +} // namespace OHOS +#endif // SPORT_REMIND_INTERVAL_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindItemView.h new file mode 100644 index 000000000..9c3368eb0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindItemView.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_ITEM_VIEW_H +#define SPORT_REMIND_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + int iconId; + const char *label; + const char *viewId; +} SportRemindItem; + +class SportRemindItemView : public UIViewGroup { +public: + SportRemindItemView(); + ~SportRemindItemView() override; + + virtual void SetItemInfo(const SportRemindItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UILabel hits_; + UIImageView nextImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindPage.h new file mode 100644 index 000000000..7b5b4d06b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportRemindPage.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_REMIND_PAGE_H +#define SPORT_REMIND_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "SlicePage.h" +#include "ui_resource_sport.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportRemindItemView.h" + +namespace OHOS { +const char* SPORT_REMIND_ITEM_INTERVAL = "sportRemindItemInterval"; +const char* SPORT_REMIND_ITEM_HEARTRATE = "sportRemindItemHeartRate"; + +class SportRemindPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportRemindPage(); + ~SportRemindPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIViewGroup *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *remindList_{nullptr}; + SportRemindItem reminds_[SPORT_REMIND_MAX] = { + {SPORT_REMIND_INTERVAL, IMAGE_SPORT_INTERVAL, "间隔提醒", SPORT_REMIND_ITEM_INTERVAL}, + {SPORT_REMIND_HEARTRATE, IMAGE_SPORT_HEARTRATE, "心率提醒", SPORT_REMIND_ITEM_HEARTRATE}}; +}; +} // namespace OHOS +#endif // SPORT_REMIND_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsItemView.h new file mode 100644 index 000000000..124719e04 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsItemView.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportSettingsItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_SETTINGS_ITEM_VIEW_H +#define SPORT_SETTINGS_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + int iconId; + const char *label; + const char *viewId; +} SportSettingsItem; + +class SportSettingsItemView : public UIViewGroup { +public: + SportSettingsItemView(); + ~SportSettingsItemView() override; + + virtual void SetItemInfo(const SportSettingsItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UILabel hits_; + UIImageView nextImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsPage.h new file mode 100644 index 000000000..50f41dd52 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportSettingsPage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportSettingsPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_SETTINGS_PAGE_H +#define SPORT_SETTINGS_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "ui_resource_sport.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportSettingsItemView.h" + +namespace OHOS { +const char* SETTINGS_ITEM_TARGET = "settingsItemTarget"; +const char* SETTINGS_ITEM_REMIND = "settingsItemTargetRemind"; +const char* SETTINGS_ITEM_MISTOUCH = "settingsItemTargetMistouch"; + +class SportSettingsPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportSettingsPage(); + ~SportSettingsPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIScrollView *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *settingList_{nullptr}; + SportSettingsItem settings_[SPORT_SET_TYPE_MAX] = { + {SPORT_SET_TYPE_TARGET, IMAGE_SPORT_TARGET, "目标", SETTINGS_ITEM_TARGET}, + {SPORT_SET_TYPE_REMIND, IMAGE_SPORT_REMIND, "提醒", SETTINGS_ITEM_REMIND}, + {SPORT_SET_TYPE_MISTOUCH, IMAGE_SPORT_MISTOUCH, "防误触", SETTINGS_ITEM_MISTOUCH}, + }; +}; +} // namespace OHOS +#endif // SPORT_SETTINGS_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetItemView.h new file mode 100644 index 000000000..e36075a3f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetItemView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetItemView + * Create: 2025-06-06 + */ + +#ifndef SPORT_TARGET_ITEM_VIEW_H +#define SPORT_TARGET_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t itemId; + int iconId; + const char *label; + const char *viewId; +} SportTargetItem; + +class SportTargetItemView : public UIViewGroup { +public: + SportTargetItemView(); + ~SportTargetItemView() override; + + virtual void SetItemInfo(const SportTargetItem &itemInfo); + +private: + UIImageView bgImage_; + UIImageView icon_; + UILabel label_; + UIImageView nextImage_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPage.h new file mode 100644 index 000000000..00e7fd885 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_TARGET_PAGE_H +#define SPORT_TARGET_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "ui_resource_sport.h" +#include "SportPresenter.h" +#include "SportModel.h" +#include "SportTargetItemView.h" + +namespace OHOS { +const char* SPORT_TARGET_ITEM_DISTANCE = "sportTargetItemDistance"; +const char* SPORT_TARGET_ITEM_TIME = "sportTargetItemTime"; +const char* SPORT_TARGET_ITEM_CALORIE = "sportTargetItemCalorie"; + +class SportTargetPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportTargetPage(); + ~SportTargetPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIScrollView *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *targetList_{nullptr}; + SportTargetItem targets_[SPORT_TARGET_MAX] = { + {SPORT_TARGET_DISTANCE, IMAGE_SPORT_DISTANCE, "距离", SPORT_TARGET_ITEM_DISTANCE}, + {SPORT_TARGET_TIME, IMAGE_SPORT_TIME, "时间", SPORT_TARGET_ITEM_TIME}, + {SPORT_TARGET_CALORIE, IMAGE_SPORT_CALORIE, "热量", SPORT_TARGET_ITEM_CALORIE}}; +}; +} // namespace OHOS +#endif // SPORT_TARGET_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPromptPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPromptPage.h new file mode 100644 index 000000000..964a59077 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetPromptPage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetPromptPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_TARGET_PROMPT_PAGE_H +#define SPORT_TARGET_PROMPT_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "animator/animator.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { + +class SportTargetPromptPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SportTargetPromptPage() {} + ~SportTargetPromptPage(); + void OnStart(void* data) override; + void OnPause() override; + void OnResume() override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void CreatePromptView(void); + class SportPromptAnimatorCallback : public AnimatorCallback { + public: + SportPromptAnimatorCallback(SportTargetPromptPage* page):page_(page) {} + virtual ~SportPromptAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + SportTargetPromptPage* page_{nullptr}; + }; + SportPromptAnimatorCallback* callback_{nullptr}; + Animator* animator_{nullptr}; + UIViewGroup *group_{nullptr}; + UIImageView *promptIcon_{nullptr}; + UILabel *promptLabel_{nullptr}; + time_t startTime_{0}; +}; +} // namespace OHOS +#endif // SPORT_TARGET_PROMPT_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetSettingPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetSettingPage.h new file mode 100644 index 000000000..3fec391f7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportTargetSettingPage.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetSettingPage + * Create: 2025-06-06 + */ + +#ifndef SPORT_TARGET_SETTING_PAGE_H +#define SPORT_TARGET_SETTING_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "components/ui_picker.h" +#include "SlicePage.h" +#include "SportPresenter.h" +#include "SportModel.h" + +namespace OHOS { +const char* TARGET_SETTING_CONFIRM_BUTTON = "targetSettingConfirmButton"; + +class SportTargetSettingPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIPicker::SelectedListener { +public: + SportTargetSettingPage() {} + ~SportTargetSettingPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void UpdateViewByTargetType(); + void UpdateViewByRemindType(); + void CreateUILabel(void); + void CreateUIPicker(void); + void CreateUIButton(void); + UIViewGroup *group_{nullptr}; + UILabel *titleLabel_{nullptr}; + UIPicker *picker_{nullptr}; + UILabelButton *confirmButton_{nullptr}; +}; +} // namespace OHOS +#endif // SPORT_TARGET_SETTING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportView.h new file mode 100644 index 000000000..96bbf81c0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/sport/SportView.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportView + * Create: 2025-06-06 + */ + +#ifndef SPORT_VIEW_H +#define SPORT_VIEW_H + +#include "View.h" + +namespace OHOS { +enum SportPages : uint8_t { + SPORT_PAGE_MENU = 1, + SPORT_PAGE_PREPARE, + SPORT_PAGE_COUNTDOWN, + SPORT_PAGE_DATA, + SPORT_PAGE_PAUSE, + SPORT_PAGE_PROMPT, + SPORT_PAGE_SETTINGS, + SPORT_PAGE_TARGET, + SPORT_PAGE_TARGET_SETTING, + SPORT_PAGE_TARGET_PROMPT, + SPORT_PAGE_REMIND, + SPORT_PAGE_REMIND_INTERVAL, + SPORT_PAGE_REMIND_HEARTRATE, + SPORT_PAGE_HEARTRATE_RANGE, + SPORT_PAGE_MISTOUCH, + SPORT_PAGE_MAX, +}; + +class SportPresenter; +class SportView : public View {}; +} +#endif // SPORT_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h index b4a48db38..11c891e90 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h @@ -13,6 +13,7 @@ namespace OHOS { typedef struct { + uint8_t index; std::string record; bool isLatest; } StopwatchItem; @@ -21,7 +22,7 @@ class StopwatchItemView : public UIViewGroup { public: explicit StopwatchItemView(); virtual ~StopwatchItemView() override; - void SetItemInfo(int16_t index, const StopwatchItem &itemInfo); + void SetItemInfo(const StopwatchItem &itemInfo); private: UILabel nameLabel_; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchModel.h index 41c75f093..faaad0943 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchModel.h @@ -7,11 +7,11 @@ #ifndef STOPWATCH_MODEL_H #define STOPWATCH_MODEL_H -#include "stopwatch/StopwatchItemView.h" #include "gfx_utils/list.h" #ifndef _WIN32 #include "time64.h" #endif +#include "StopwatchItemView.h" namespace OHOS { class StopwatchModel { @@ -24,37 +24,28 @@ public: uint64_t GetElapsedTime(); uint64_t UpdateElapsedTime(); void ResetCounter(); - bool GetActiveState(); - void SetActiveState(); - void SetInactiveState(); + bool GetRunningState(); + void SetRunningState(bool isRunning); + bool GetRecordListVisible(); + void SetRecordListVisible(bool isVisible); + bool GetTimeOverRangeState(); + void SetTimeOverRangeState(bool isTimeOverRange); List &GetRecordsList(); void AddRecordToList(const StopwatchItem &record); - void ClearData(); - bool IsInRecordView(); - void SetRecordViewState(bool state); - bool GetOverflowState() - { - return isOverflow_; - } - void SetOverflowState(bool state) - { - isOverflow_ = state; - } - private: StopwatchModel(); StopwatchModel(const StopwatchModel &); StopwatchModel &operator=(const StopwatchModel &); #ifdef _WIN32 - struct timeval startTime_ {0}; + struct timeval startTime_{0}; #else - struct timeval64 startTime_ {0}; + struct timeval64 startTime_{0}; #endif - bool isOverflow_{false}; - uint64_t uiElapsedTime_{0}; - uint64_t uiSavedElapsedTime_{0}; - bool bIsActive_{false}; - bool bIsRecordView_{false}; + uint64_t elapsedTime_{0}; + uint64_t savedElapsedTime_{0}; + bool isTimeOverRange_{false}; + bool isRunning_{false}; + bool isRecordListVisible_{false}; List records_; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchPage.h index 9568a306c..00ba72952 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchPage.h @@ -7,23 +7,19 @@ #ifndef STOPWATCH_PAGE_H #define STOPWATCH_PAGE_H -#include "UiConfig.h" -#include "SlicePage.h" -#include "stopwatch/StopwatchPresenter.h" -#include "stopwatch/StopwatchAdapter.h" -#include "NativeRegisterManager.h" #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_list.h" +#include "components/ui_simple_list.h" #include "components/ui_label_button.h" #include "components/ui_image_view.h" #include "components/ui_sweep_clock.h" #include "animator/animator.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "NativeRegisterManager.h" +#include "StopwatchPresenter.h" namespace OHOS { - -#define STOPWATCH_APP_NAME "秒表" - class StopwatchPresenter; class StopwatchPage : public SlicePage, public UIView::OnClickListener, @@ -38,20 +34,18 @@ public: void OnResume() override; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; - void Overflowing(void); - UISweepClock* GetSweepClock(){return sweepClock_;} - UILabel* GetElapsedTimeLabel(){return elapsedTime_;} private: - void DrawButtonStatusView(bool isActive); - void DrawContainRecordListView(bool isContainRecordList); + void TimeOverRange(void); + void DrawButtonStatusView(bool isRunning); + void DrawRecordListVisibleView(bool isRecordListVisible); void RefreshRecordsList(void); class StopwatchAnimatorCallback : public AnimatorCallback { public: - StopwatchAnimatorCallback(StopwatchPage* page) : stopwatchPage(page) {} + StopwatchAnimatorCallback(StopwatchPage* page) : page_(page) {} virtual ~StopwatchAnimatorCallback() override {} void Callback(UIView* view) override; private: - StopwatchPage* stopwatchPage{nullptr}; + StopwatchPage* page_{nullptr}; }; class TimeAnimatorCallback : public AnimatorCallback { public: @@ -59,17 +53,16 @@ private: virtual ~TimeAnimatorCallback() override {} void Callback(UIView* view) override; }; - Animator* animator_{nullptr}; - StopwatchAnimatorCallback* animatorCallback_{nullptr}; - TimeAnimatorCallback* timeCallback_{nullptr}; + Animator* stopwatchAnimator_{nullptr}; + StopwatchAnimatorCallback* stopwatchAnimatorCallback_{nullptr}; Animator* timeAnimator_{nullptr}; + TimeAnimatorCallback* timeCallback_{nullptr}; UISweepClock *sweepClock_{nullptr}; Image *secondHand_{nullptr}; UILabel *currentTime_{nullptr}; UILabel *appName_{nullptr}; UILabel *elapsedTime_{nullptr}; - UIList *recordsList_{nullptr}; - StopwatchAdapter *listAdapter_{nullptr}; + UISimpleList *recordsList_{nullptr}; UILabelButton *startButton_{nullptr}; UILabelButton *resetButton_{nullptr}; UIImageView *backGround_{nullptr}; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchRecordPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchRecordPage.h new file mode 100644 index 000000000..4678ce1a4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchRecordPage.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchRecordPage + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_RECORD_PAGE_H +#define STOPWATCH_RECORD_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_simple_list.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "SlicePage.h" +#include "ui_resource_stopwatch.h" +#include "StopwatchPresenter.h" +#include "StopwatchModel.h" + +namespace OHOS { +class StopwatchRecordPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + StopwatchRecordPage() {} + ~StopwatchRecordPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; +private: + void InitBackgroundView(); + void CreateUILabel(void); + void CreateUIList(void); + UIViewGroup *group_{nullptr}; + UIImageView *background_{nullptr}; + UILabel *titleLabel_{nullptr}; + UISimpleList *recordList_{nullptr}; +}; +} // namespace OHOS +#endif // STOPWATCH_RECORD_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchView.h index c35a5709c..b9d468f08 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/stopwatch/StopwatchView.h @@ -10,7 +10,8 @@ #include "View.h" namespace OHOS { enum STOPWATCH_PAGES { - STOPWATCH_MAIN_PAGE = 1, // 0 is invalid + STOPWATCH_MAIN_PAGE = 1, + STOPWATCH_RECORD_PAGE, }; class StopwatchPresenter; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerCountDown.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerCountDown.h new file mode 100644 index 000000000..dbfe8d1d2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerCountDown.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerCountDown + * Create: 2025-06-09 + */ + +#ifndef TIMER_COUNT_DOWN_H +#define TIMER_COUNT_DOWN_H + +#include +#include "View.h" +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "components/ui_fragment.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_view.h" +#include "components/ui_circle_progress.h" +#include "UiConfig.h" +#include "TimerModel.h" +#include "TimerPresenter.h" +#include "SlicePage.h" +#include "ChangeSliceListener.h" +#include "components/ui_sweep_clock.h" +#include "main/LoadImg.h" +#include "ui_resource_timer.h" + +namespace OHOS { +class TimerCountDown : public UIFragment, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void OnResume(); + void OnPause(); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStart(UIView& view, const DragEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + void CreateButton(); + void CreateTimerTime(); + void CircleProgress(); + void SetTimerTime(int64_t durationTime); + void InitAnimator(); + void SetAnimatorStatus(bool status); + void RefreshFragment(); + +private: + void OnCreateView(void* data) override; + void OnDestroyView() override; + class TimeAnimatorCallback : public AnimatorCallback { + public: + TimeAnimatorCallback() {} + virtual ~TimeAnimatorCallback() override {} + void Callback(UIView *view) override; + }; + + class TimerCountDownCallback : public AnimatorCallback { + public: + explicit TimerCountDownCallback(TimerCountDown *page) : page_(page) {} + ~TimerCountDownCallback() override {} + void Callback(UIView *view) override; + + private: + TimerCountDown *page_{nullptr}; + }; + + UILabel *labelTitle_{nullptr}; + UIDigitalClock *timerClock_{nullptr}; + UIImageView *startOrPauseImg_{nullptr}; + UIImageView *resetOrExitImg_{nullptr}; + UICircleProgress *circleProgress_{nullptr}; + UILabel *currentTime_{nullptr}; + TimeAnimatorCallback *currentTimeCallback_{nullptr}; + Animator *currentTimeAnimator_{nullptr}; + TimerCountDownCallback *countDownTimecallBack_ = nullptr; + Animator *countDownTimeanimator_ = nullptr; + UIImageView *bgImg_{nullptr}; +}; +} +#endif // TIMER_TIMING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerMainPage.h index 417b92b68..8472f054d 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerMainPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerMainPage.h @@ -17,33 +17,41 @@ #include "UiConfig.h" #include "ChangeSliceListener.h" #include "components/ui_image_view.h" -#include "timers/TimerPresenter.h" -#include "timers/TimerModel.h" +#include "TimerPresenter.h" +#include "TimerModel.h" #include "SlicePage.h" #include "common/image_cache_manager.h" +#include "main/LoadImg.h" #include "ui_resource_timer.h" +#include "timers/TimerCountDown.h" namespace OHOS { +static constexpr uint8_t SELECT_IMAGE_COUNT = 4; + class TimerMainPage : public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - TimerMainPage() = default; + TimerMainPage(); ~TimerMainPage() override; - + void OnResume() override; + void OnPause() override; void OnStart(void *data) override; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + static TimerMainPage *GetInstance(void); + void ShowMainPage(); void LabelTitle(); void CreateButton(); void InitView(); private: - UIScrollView *group{nullptr}; - UIImageView *selectMin[4]{nullptr}; // 分钟计时 - UIImageView *addButton{nullptr}; // 自定义按钮 - UILabel *title{nullptr}; // 计时器 - UIImageView *backround{nullptr}; + UIScrollView *group_{nullptr}; + UIImageView *selectMin_[SELECT_IMAGE_COUNT]{nullptr}; + UIImageView *addButton_{nullptr}; + UILabel *labelTitle_{nullptr}; + UIImageView *bgImg_{nullptr}; + TimerCountDown *countDownFragment_{nullptr}; }; } #endif // TIMER_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerModel.h index fee8cd676..9b5a601dd 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerModel.h @@ -13,44 +13,77 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "timers/TimerPresenter.h" +#include "TimerPresenter.h" #include "graphic_timer.h" #include "ohos_timer.h" namespace OHOS { - class TimerModel { - public: - static TimerModel &GetInstance(void); +class TimerModel { +public: + static TimerModel &GetInstance(void); - void SetDurationTime(uint32_t time); // 设置计时器的总时间 - uint32_t GetDurationTime(); // 获取计时器的总时间 - bool GetIsTiming() { return isTiming; } - void SetIsTiming(bool value) { isTiming = value; } - bool GetIsPause() { return isPause; } - void SetIsPause(bool value) { isPause = value; } - uint32_t GetStartTime() { return start_time; }; - void SetStartTime(uint32_t value) { start_time = value; }; - uint32_t GetSaveTime(); - void SetSaveTime(bool falg, uint32_t value); - - void InitTimer(); - void DisableTimer(); - bool GetExistTimer() { return haveTimer; }; - void SetExistTimer(bool value) { haveTimer = value; }; + void SetTotalTime(uint64_t time); // 设置计时器的总时间 + uint64_t GetTotalTime(); // 获取计时器的总时间 + bool GetIsShowFragment() + { + return isShowFragment_; + } + void SetIsShowFragment(bool value) + { + isShowFragment_ = value; + } + bool GetIsCountDown() + { + return isCountDown_; + } + void SetIsCountDown(bool value) + { + isCountDown_ = value; + } + bool GetIsPause() + { + return isPause_; + } + void SetIsPause(bool value) + { + isPause_ = value; + } + uint64_t GetStartTime() + { + return startTime_; + }; + void SetStartTime(uint64_t value) + { + startTime_ = value; + }; + uint64_t GetEclipseTime(); + void SetEclipseTime(bool flag, uint64_t value); - private: - TimerModel(); - virtual ~TimerModel(); - TimerModel(const TimerModel &) = delete; - TimerModel &operator=(const TimerModel &) = delete; - uint32_t start_time; - uint32_t save_time; - uint32_t durationTime = 0; - GraphicTimer *g_startCounting = nullptr; // 定时器 - bool haveTimer = false; - bool isTiming = false; - bool isPause = false; + void InitTimer(); + void DisableTimer(); + bool GetExistTimer() + { + return haveTimer_; }; + void SetExistTimer(bool value) + { + haveTimer_ = value; + }; + +private: + TimerModel(); + virtual ~TimerModel(); + TimerModel(const TimerModel &) = delete; + TimerModel &operator=(const TimerModel &) = delete; + uint64_t startTime_; + uint64_t eclipseTime_; + uint64_t totalTime_ = 0; + GraphicTimer *startCounting_ = nullptr; // 定时器 + bool haveTimer_ = false; + bool isCountDown_ = false; + bool isPause_ = false; + bool isShowFragment_ = false; +}; } #endif // TIMER_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerPresenter.h index e2d42aef7..216373c4b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerPresenter.h @@ -11,21 +11,8 @@ #include "components/ui_view.h" namespace OHOS { - -#define SETTING_TIMER "setting_timer" -#define STOPWATCH_RESET "stopwatch_reset" -#define ONE_MIN "onemine" -#define THREE_MIN "threemine" -#define FIFTY_MIN "fiftymine" -#define THIRTY_MIN "thirtymine" -#define BACK_TIMER "backtimer" -#define RESET "reset" -#define START_PAUSE "start_pause" -#define START_TIMING "start_timing" - - class TimerView; - class TimerPresenter : public Presenter { - }; +class TimerView; +class TimerPresenter : public Presenter {}; } -#endif // TIMER_PRESENTER_H \ No newline at end of file +#endif // TIMER_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerSettingPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerSettingPage.h index 1ede0c7ea..a8af96bfa 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerSettingPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerSettingPage.h @@ -14,19 +14,21 @@ #include "components/ui_label_button.h" #include "components/ui_scroll_view.h" #include "UiConfig.h" -#include "timers/TimerPresenter.h" -#include "timers/TimerModel.h" +#include "TimerPresenter.h" +#include "TimerModel.h" #include "SlicePage.h" #include "ChangeSliceListener.h" +#include "main/LoadImg.h" #include "ui_resource_timer.h" namespace OHOS { +static constexpr uint8_t PICKER_COUNT = 3; class TimerSettingPage : public UIPicker::SelectedListener, public SlicePage, public UIView::OnClickListener, public UIView::OnDragListener { public: - TimerSettingPage() = default; + TimerSettingPage(); ~TimerSettingPage() override; void OnStart(void *data) override; @@ -40,15 +42,11 @@ namespace OHOS { void OnPickerStoped(UIPicker& picker) override; private: - UIScrollView *group{nullptr}; - UIButton *back{nullptr}; - UILabel *title{nullptr}; - UIImageView *start{nullptr}; - - UILabel *timerLabel{nullptr}; - UIPicker *timerPicker[3]{nullptr}; - ImageInfo *image1 = nullptr; - ImageInfo *image2 = nullptr; + UIScrollView *group_{nullptr}; + UILabel *labelTitle_{nullptr}; + UIImageView *startImg_{nullptr}; + UILabel *labelUnit_{nullptr}; + UIPicker *timerPicker_[PICKER_COUNT]{nullptr}; }; } #endif // TIMER_SETTING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerView.h index 2849c441e..951a6a09a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/timers/TimerView.h @@ -10,15 +10,14 @@ #include "View.h" namespace OHOS { - enum TIMER_PAGES { - TIMER_MAIN_PAGE = 1, // 主页面 - TIMER_SETTING_PAGE, // 自定义页面 - TIMER_TIMING_PAGE, // 显示计时页面 - TIMER_ALL_VIEW, - }; +enum TIMER_PAGES { + TIMER_MAIN_PAGE = 1, // 主页面 + TIMER_SETTING_PAGE, // 自定义页面 + TIMER_TIMING_PAGE, // 显示计时页面 + TIMER_ALL_VIEW, +}; - class TimerPresenter; - class TimerView : public View { - }; +class TimerPresenter; +class TimerView : public View {}; } -#endif // TIMER_VIEW_H +#endif // TIMER_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleMainPage.h new file mode 100644 index 000000000..2252f2340 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleMainPage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_MAIN_PAGE_H +#define UISAMPLE_MAIN_PAGE_H + +#include +#include "ChangeSliceListener.h" +#include "components/root_view.h" +#include "components/ui_label.h" +#include "components/ui_scroll_view.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "ui_resource_timer.h" +#include "uisample/UISamplePresenter.h" +#include "ui_test_group.h" +#include "View.h" + +namespace OHOS { +class UISampleMainPage : public SlicePage, public UIView::OnClickListener, + public UIView::OnDragListener { +public: + UISampleMainPage(); + ~UISampleMainPage() override; + static UISampleMainPage* GetInstance(void); + + void OnStart(void *data) override;; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; +private: + void CreateTitle(); + void CreateMainList(); + + UIScrollView* container_ = nullptr; + UILabel *title_ = nullptr; + UISimpleList* mainList_ = nullptr; +}; +} // OHOS +#endif // UISAMPLE_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleModel.h index ea285b540..4c9d1724a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleModel.h @@ -1,30 +1,30 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef UISAMPLE_MODEL_H -#define UISAMPLE_MODEL_H - -#include -#include -#include "AppViewIDs.h" -#include "UiConfig.h" -#include "uisample/UISamplePresenter.h" - -namespace OHOS { - class UISampleModel { - public: - static UISampleModel &GetInstance(void); - - private: - UISampleModel(); - UISampleModel(const UISampleModel &); - UISampleModel &operator=(const UISampleModel &); - virtual ~UISampleModel(); - }; -} - +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_MODEL_H +#define UISAMPLE_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "uisample/UISamplePresenter.h" + +namespace OHOS { + class UISampleModel { + public: + static UISampleModel &GetInstance(void); + + private: + UISampleModel(); + UISampleModel(const UISampleModel &); + UISampleModel &operator=(const UISampleModel &); + virtual ~UISampleModel(); + }; +} + #endif // UISAMPLE_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleNativeTestCasePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleNativeTestCasePage.h new file mode 100644 index 000000000..2025bf1f0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleNativeTestCasePage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_OPEN_HARMONY_PAGE_H +#define UISAMPLE_OPEN_HARMONY_PAGE_H + +#include +#include "ChangeSliceListener.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_scroll_view.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "ui_resource_timer.h" +#include "uisample/UISamplePresenter.h" +#include "ui_test_group.h" +#include "View.h" + +namespace OHOS { +class UISampleNativeTestCasePage : public SlicePage, public UIView::OnClickListener, + public UIView::OnDragListener { +public: + UISampleNativeTestCasePage(); + ~UISampleNativeTestCasePage() override; + static UISampleNativeTestCasePage *GetInstance(void); + void OnStart(void *data) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + +private: + void CreateTitle(); + void CreateMainList(); + void CreateBackButton(); + bool BackMenuPage(UIView& view); + + UIScrollView* container_ = nullptr; + UILabel *title_{nullptr}; + UISimpleList* mainList_ = nullptr; + UIButton* backBtn_{nullptr}; + bool isInTestCase_ = false; +}; +} // OHOS +#endif // UISAMPLE_OPEN_HARMONY_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISamplePresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISamplePresenter.h index 03d4e1342..9f071803c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISamplePresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISamplePresenter.h @@ -1,30 +1,30 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef UISAMPLE_PRESENTER_H -#define UISAMPLE_PRESENTER_H - -#include "Presenter.h" -#include "components/ui_view.h" - -namespace OHOS { -class UISampleView; -class UISampleModel; -class UISamplePresenter : public Presenter { -public: - UISamplePresenter(); - ~UISamplePresenter() override; - - void OnResume() override; - void OnPause() override; - -private: - UISampleModel *uisampleModel; -}; -} - +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_PRESENTER_H +#define UISAMPLE_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +class UISampleView; +class UISampleModel; +class UISamplePresenter : public Presenter { +public: + UISamplePresenter(); + ~UISamplePresenter() override; + + void OnResume() override; + void OnPause() override; + +private: + UISampleModel *uisampleModel_; +}; +} + #endif // UISAMPLE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleProprietaryTestCasePage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleProprietaryTestCasePage.h new file mode 100644 index 000000000..28814f512 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleProprietaryTestCasePage.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_HISI_PAGE_H +#define UISAMPLE_HISI_PAGE_H + +#include +#include "ChangeSliceListener.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_simple_list.h" +#include "SlicePage.h" +#include "ui_resource_timer.h" +#include "uisample/UISamplePresenter.h" +#include "ui_test_group.h" +#include "View.h" + +namespace OHOS { +class UISampleProprietaryTestCasePage : public SlicePage, public UIView::OnClickListener, + public UIView::OnDragListener { +public: + UISampleProprietaryTestCasePage(); + ~UISampleProprietaryTestCasePage() override; + static UISampleProprietaryTestCasePage *GetInstance(void); + void OnStart(void *data) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + +private: + void CreateTitle(); + void CreateMainList(); + void CreateBackButton(); + bool BackMenuPage(UIView& view); + + UIViewGroup* container_ = nullptr; + UILabel *title_ = nullptr; + UISimpleList* mainList_ = nullptr; + UIButton* backBtn_ = nullptr; + bool isInTestCase_ = false; +}; +} // OHOS +#endif // UISAMPLE_HISI_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleView.h index 4a9b74c00..ccff650d9 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/uisample/UISampleView.h @@ -1,60 +1,24 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingView.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef UISAMPLE_VIEW_H -#define UISAMPLE_VIEW_H - -#include "View.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" -#include "components/ui_label.h" -#include "components/ui_list.h" -#include "ChangeSliceListener.h" -#include "test_case_list_adapter.h" -#include "UiConfig.h" - -namespace OHOS { - -class UISamplePresenter; - -class UISampleOnDragListener : public UIView::OnDragListener { -public: - UISampleOnDragListener() {} - ~UISampleOnDragListener() override {} - - bool OnDrag(UIView& view, const DragEvent& event) override - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UISampleOnDragListener::OnDrag"); - UNUSED(view); - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && - (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UISampleOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } - return false; - } -}; - -class UISampleView : public View { -public: - UISampleView(); - ~UISampleView() override; - - static UISampleView *GetInstance(); - - void OnStart() override; - void OnStop() override; - void InitView(); - -private: - UIView::OnDragListener *dragListener_ = nullptr; - UIList* mainList_ = nullptr; - TestCaseListAdapter* adapter_ = nullptr; -}; -} -#endif // UISAMPLE_VIEW_H +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#ifndef UISAMPLE_VIEW_H +#define UISAMPLE_VIEW_H + +#include "View.h" + +namespace OHOS { +enum SAMPLE_PAGES { + SAMPLE_MAIN_PAGE = 1, + SAMPLE_PROPRIETARY_TESTCASE_PAGE = 2, + SAMPLE_NATIVE_TESTCASE_PAGE = 3, +}; + +class UISamplePresenter; +class UISampleView : public View { +}; +} +#endif // UISAMPLE_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherItemView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherItemView.h index 13c19fa16..d2a6bf0c4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherItemView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherItemView.h @@ -11,9 +11,8 @@ #include "components/ui_view_group.h" #include "components/ui_image_view.h" #include "components/ui_canvas.h" - #include "UiConfig.h" -#include "weather/WeatherModel.h" +#include "WeatherModel.h" namespace OHOS { class WeatherItemView : public UIViewGroup { @@ -21,15 +20,13 @@ public: explicit WeatherItemView(); ~WeatherItemView() override; virtual void SetItemInfo(const WeatherItem itemInfo); - virtual void SetUpChild(); private: - UILabel sLabel_1; - UIImageView sIcon; - UILabel sLabel_2; - UICanvas chartLine; - UIImageView sNextImage; - WeatherItem sItemInfo = {nullptr, nullptr, nullptr, false}; + UILabel labelDay_; + UIImageView icon_; + UILabel labelTmp_; + UICanvas chartLine_; + UIImageView bgImg_; }; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherMainPage.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherMainPage.h index 31a9ea0a5..e88f4d8ed 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherMainPage.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherMainPage.h @@ -12,13 +12,20 @@ #include "components/ui_scroll_view.h" #include "components/ui_label.h" #include "components/ui_list.h" -#include "weather/WeatherAdapter.h" -#include "weather/WeatherPresenter.h" +#include "WeatherPresenter.h" #include "SlicePage.h" #include "UiConfig.h" -#include "weather/WeatherView.h" +#include "WeatherView.h" + namespace OHOS { +static constexpr int16_t LABEL_ADDRESS = 0; +static constexpr int16_t LABEL_TEMP = 1; +static constexpr int16_t LABEL_AIR = 2; +static constexpr int16_t LABEL_HUMIDITY = 3; +static constexpr int16_t LABEL_UPDATETIME = 4; +static constexpr int16_t LABEL_CURRENT_TEMP = 5; static constexpr int16_t LABEL_COUNT = 6; + class WeatherPresenter; class WeatherMainPage : public SlicePage, public UIView::OnClickListener, @@ -26,29 +33,31 @@ class WeatherMainPage : public SlicePage, public: WeatherMainPage(); ~WeatherMainPage() override; - + static WeatherMainPage *GetInstance(); void OnStart(void* data) override; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; - std::string FormatTime(bool falg, const std::string& inputStr); - void InitLabel(); - void InitImage(); - void InitWeatherImage(); + std::string FormatTime(const std::string& inputStr); + void InitWeatherImage1(); + void InitWeatherImage2(); + void InitWeatherLabel1(); + void InitWeatherLabel2(); + uint8_t GetConnectStatus(); + void ReloadPage(); private: - bool flag = false; - int curWeather_code = 0; - CurWeather cur{nullptr}; - UIViewGroup *group = nullptr; - WeatherModel *weatherModel = nullptr; - UILabel *title[LABEL_COUNT]{nullptr}; - UILabel *labelTitle{nullptr}; - UIImageView *mainImg{nullptr}; - UIImageView *addressImg{nullptr}; - UIImageView *aroundImg = nullptr; - UIImageView *weatherImg{nullptr}; - UIImageView *ImageAir{nullptr}; - UIImageView *ImageHumidity{nullptr}; - UIImageView *ImagePageKey{nullptr}; + bool flag_ = false; + int curWeatherCode_ = 0; + CurWeather cur_{nullptr}; + UIViewGroup *group_ = nullptr; + UILabel *title_[LABEL_COUNT]{nullptr}; + UILabel *labelTitle_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *addressImg_{nullptr}; + UIImageView *airQualityAndHumidityBgImg_{nullptr}; + UIImageView *weatherImg_{nullptr}; + UIImageView *airQulityImgIcon_{nullptr}; + UIImageView *humidityImgIcon_{nullptr}; + UIImageView *pageIdxImg_{nullptr}; }; } #endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherModel.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherModel.h index 55d135a42..886b2bfd5 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherModel.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherModel.h @@ -11,126 +11,83 @@ #include #include #include +#include #include #include #include #include #include -#include +#include +#include "hal_tick.h" #include "AppViewIDs.h" #include "UiConfig.h" #include "cJSON.h" #include "components/ui_image_view.h" +#include "components/ui_label.h" #include "common/image_cache_manager.h" #include "main/LoadImg.h" #include "ui_resource_weather.h" #ifndef _WIN32 #include "time64.h" +#define WEATHER_PATH "/user/app/user/ace/data/com.vendor.Weather/" +#else +#define WEATHER_PATH APP_RES_PATH #endif + namespace OHOS { static constexpr int16_t MIN_TO_HOUR = 60; static constexpr int16_t HOURLY_SYSTEM = 24; -static constexpr int16_t WEATHER_COUNT = 24; +static constexpr int16_t ALL_HOURS_WEATHER_COUNT = 24; static constexpr int16_t WEATHER_HOUR = 12; -static constexpr int16_t SET_ZERO = 0; -static constexpr int16_t SET_ONE = 1; -static constexpr int16_t SET_TWO = 2; -static constexpr int16_t SET_THREE = 3; -static constexpr int16_t SET_FOUR = 4; -static constexpr int16_t SET_FIVE = 5; -static constexpr int16_t SET_SIX = 6; -static constexpr int16_t SET_SEVEN = 7; -static constexpr int16_t SET_EIGHT = 8; -static constexpr int16_t SET_NINE = 9; -static constexpr int16_t SET_TEN = 10; -static constexpr int16_t SET_TWELVE = 12; -static constexpr int16_t SET_FOURTEEN = 14; -static constexpr int16_t SET_HUNDRED = 100; static constexpr int16_t START_YEAR = 1900; -static constexpr int16_t ARRAY_SIZE = 31; -static const uint16_t WEATHER_ITEM_COUNT = 10; +static constexpr int16_t ARRAY_SIZE = 32; +static constexpr uint16_t WEATHER_ITEM_COUNT = 10; +static constexpr uint16_t ONE_WEEK_DYAS = 7; +static constexpr int16_t INDEX_0 = 0; +static constexpr int16_t INDEX_1 = 1; +static constexpr int16_t INDEX_2 = 2; +static constexpr int16_t INDEX_3 = 3; +static constexpr int16_t INDEX_4 = 4; +static constexpr int16_t INDEX_5 = 5; +static constexpr int16_t INDEX_6 = 6; +static constexpr int16_t INDEX_7 = 7; +static constexpr int16_t INDEX_8 = 8; +static constexpr int16_t INDEX_12 = 12; +static constexpr int16_t NUMBER_10 = 10; const int bigWeatherImage[ARRAY_SIZE] = { - IMAGE_CONVERTER_TOOL_WEATHER00, // 0 - IMAGE_CONVERTER_TOOL_WEATHER01, // 1 - IMAGE_CONVERTER_TOOL_WEATHER02, // 2 - IMAGE_CONVERTER_TOOL_WEATHER03, // 3 - IMAGE_CONVERTER_TOOL_WEATHER04, // 4 - IMAGE_CONVERTER_TOOL_WEATHER05, // 5 - IMAGE_CONVERTER_TOOL_WEATHER06, // 6 - IMAGE_CONVERTER_TOOL_WEATHER07, // 7 - IMAGE_CONVERTER_TOOL_WEATHER08, // 8 - IMAGE_CONVERTER_TOOL_WEATHER09, // 9 - IMAGE_CONVERTER_TOOL_WEATHER10, // 10 - IMAGE_CONVERTER_TOOL_WEATHER11, // 11 - IMAGE_CONVERTER_TOOL_WEATHER12, // 12 - IMAGE_CONVERTER_TOOL_WEATHER13, // 13 - IMAGE_CONVERTER_TOOL_WEATHER14, // 14 - IMAGE_CONVERTER_TOOL_WEATHER15, // 15 - IMAGE_CONVERTER_TOOL_WEATHER16, // 16 - IMAGE_CONVERTER_TOOL_WEATHER17, // 17 - IMAGE_CONVERTER_TOOL_WEATHER18, // 18 - IMAGE_CONVERTER_TOOL_WEATHER19, // 19 - IMAGE_CONVERTER_TOOL_WEATHER20, // 20 - IMAGE_CONVERTER_TOOL_WEATHER21, // 21 - IMAGE_CONVERTER_TOOL_WEATHER22, // 22 - IMAGE_CONVERTER_TOOL_WEATHER23, // 23 - IMAGE_CONVERTER_TOOL_WEATHER24, // 24 - IMAGE_CONVERTER_TOOL_WEATHER25, // 25 - IMAGE_CONVERTER_TOOL_WEATHER26, // 26 - IMAGE_CONVERTER_TOOL_WEATHER27, // 27 - IMAGE_CONVERTER_TOOL_WEATHER28, // 28 - IMAGE_CONVERTER_TOOL_WEATHER29, // 29 - IMAGE_CONVERTER_TOOL_WEATHER31 // 30 -}; + IMAGE_WEATHER_WEATHER00, IMAGE_WEATHER_WEATHER01, IMAGE_WEATHER_WEATHER02, IMAGE_WEATHER_WEATHER03, + IMAGE_WEATHER_WEATHER04, IMAGE_WEATHER_WEATHER05, IMAGE_WEATHER_WEATHER06, IMAGE_WEATHER_WEATHER07, + IMAGE_WEATHER_WEATHER08, IMAGE_WEATHER_WEATHER09, IMAGE_WEATHER_WEATHER10, IMAGE_WEATHER_WEATHER11, + IMAGE_WEATHER_WEATHER12, IMAGE_WEATHER_WEATHER13, IMAGE_WEATHER_WEATHER14, IMAGE_WEATHER_WEATHER15, + IMAGE_WEATHER_WEATHER16, IMAGE_WEATHER_WEATHER17, IMAGE_WEATHER_WEATHER18, IMAGE_WEATHER_WEATHER19, + IMAGE_WEATHER_WEATHER20, IMAGE_WEATHER_WEATHER21, IMAGE_WEATHER_WEATHER22, IMAGE_WEATHER_WEATHER23, + IMAGE_WEATHER_WEATHER24, IMAGE_WEATHER_WEATHER25, IMAGE_WEATHER_WEATHER26, IMAGE_WEATHER_WEATHER27, + IMAGE_WEATHER_WEATHER28, IMAGE_WEATHER_WEATHER29, IMAGE_WEATHER_WEATHER30, IMAGE_WEATHER_WEATHER31}; const int smallWeatherImage[ARRAY_SIZE] = { - IMAGE_CONVERTER_TOOL_WEATHER32, // 32 - IMAGE_CONVERTER_TOOL_WEATHER33, // 33 - IMAGE_CONVERTER_TOOL_WEATHER34, // 34 - IMAGE_CONVERTER_TOOL_WEATHER35, // 35 - IMAGE_CONVERTER_TOOL_WEATHER36, // 36 - IMAGE_CONVERTER_TOOL_WEATHER37, // 37 - IMAGE_CONVERTER_TOOL_WEATHER38, // 38 - IMAGE_CONVERTER_TOOL_WEATHER39, // 39 - IMAGE_CONVERTER_TOOL_WEATHER40, // 40 - IMAGE_CONVERTER_TOOL_WEATHER41, // 41 - IMAGE_CONVERTER_TOOL_WEATHER42, // 42 - IMAGE_CONVERTER_TOOL_WEATHER43, // 43 - IMAGE_CONVERTER_TOOL_WEATHER44, // 44 - IMAGE_CONVERTER_TOOL_WEATHER45, // 45 - IMAGE_CONVERTER_TOOL_WEATHER46, // 46 - IMAGE_CONVERTER_TOOL_WEATHER47, // 47 - IMAGE_CONVERTER_TOOL_WEATHER48, // 48 - IMAGE_CONVERTER_TOOL_WEATHER49, // 49 - IMAGE_CONVERTER_TOOL_WEATHER50, // 50 - IMAGE_CONVERTER_TOOL_WEATHER51, // 51 - IMAGE_CONVERTER_TOOL_WEATHER52, // 52 - IMAGE_CONVERTER_TOOL_WEATHER53, // 53 - IMAGE_CONVERTER_TOOL_WEATHER54, // 54 - IMAGE_CONVERTER_TOOL_WEATHER55, // 55 - IMAGE_CONVERTER_TOOL_WEATHER56, // 56 - IMAGE_CONVERTER_TOOL_WEATHER57, // 57 - IMAGE_CONVERTER_TOOL_WEATHER58, // 58 - IMAGE_CONVERTER_TOOL_WEATHER59, // 59 - IMAGE_CONVERTER_TOOL_WEATHER60, // 60 - IMAGE_CONVERTER_TOOL_WEATHER61, // 61 - IMAGE_CONVERTER_TOOL_WEATHER62 // 62 -}; + IMAGE_WEATHER_WEATHER32, IMAGE_WEATHER_WEATHER33, IMAGE_WEATHER_WEATHER34, IMAGE_WEATHER_WEATHER35, + IMAGE_WEATHER_WEATHER36, IMAGE_WEATHER_WEATHER37, IMAGE_WEATHER_WEATHER38, IMAGE_WEATHER_WEATHER39, + IMAGE_WEATHER_WEATHER40, IMAGE_WEATHER_WEATHER41, IMAGE_WEATHER_WEATHER42, IMAGE_WEATHER_WEATHER43, + IMAGE_WEATHER_WEATHER44, IMAGE_WEATHER_WEATHER45, IMAGE_WEATHER_WEATHER46, IMAGE_WEATHER_WEATHER47, + IMAGE_WEATHER_WEATHER48, IMAGE_WEATHER_WEATHER49, IMAGE_WEATHER_WEATHER50, IMAGE_WEATHER_WEATHER51, + IMAGE_WEATHER_WEATHER52, IMAGE_WEATHER_WEATHER53, IMAGE_WEATHER_WEATHER54, IMAGE_WEATHER_WEATHER55, + IMAGE_WEATHER_WEATHER56, IMAGE_WEATHER_WEATHER57, IMAGE_WEATHER_WEATHER58, IMAGE_WEATHER_WEATHER59, + IMAGE_WEATHER_WEATHER60, IMAGE_WEATHER_WEATHER61, IMAGE_WEATHER_WEATHER62, IMAGE_WEATHER_WEATHER63}; typedef struct { - const char *label_1; - const ImageInfo *icon; - const char *label_2; + const char *weatherWeek; + int image; + const char *weatherTemp; bool hasSecondMenu; } WeatherItem; typedef struct { - const char *min_degree; - const char *max_degree; + const char *min_temp; + const char *max_temp; const char *address; const char *weather_code; - const char *degree; + const char *temp; const char *updateTime; const char *humidity; std::string sunSet; @@ -139,47 +96,82 @@ typedef struct { typedef struct { const char *hour; - const char *degree; + const char *temp; const char *weather; } HourWeather; + +typedef struct { + const char *sunRise; + const char *sunSet; + const char *weekTime; +} SunStruct; + +typedef struct { + const char *monthRise; + const char *monthSet; + const char *weekTime; +} MonthStruct; + +typedef struct { + const char *phase; + int image; + const char *lightTime; + const char *monthDay; + const char *weekTime; +} LunarPhaseStruct; + class WeatherModel { public: static WeatherModel &GetInstance(void); + virtual ~WeatherModel(); bool InitWeatherItem(); - WeatherItem *GetWeatherlistItems(); - uint8_t GetWeatherListNum(); - CurWeather GetCurWeather(); - std::vector GetHourWeather(); - void InitFirstPageData(); - void InitSecondPageData(); - void InitThirdPageData(); + void InitMainPageData(); + void InitHoursPageData(); + void InitDaysPageData(); void UpdateTemp(); + void InitStringData(); bool InitVecForecast(cJSON *root); bool InitVecObserve(cJSON *root); bool InitVecRise(cJSON *root); bool InitVecWeek(cJSON *root); bool InitVecAddress(cJSON *root); - virtual ~WeatherModel(); + WeatherItem *GetWeatherlistItems(); + uint8_t GetWeatherListNum(); + CurWeather GetCurWeather(); + SunStruct *GetSunData(); + MonthStruct *GetMonthData(); + LunarPhaseStruct *GetLunarPhaseData(); + std::vector GetHourWeather(); void SetDayStatus(const std::string &timeRise, const std::string &timeSet); - bool GetDayStatus(); + void ClearData(); + int index_ = 0; + void LoadImageOfDayNight(UIImageView *view, uint32_t resDayId, uint32_t resNightId); + void LoadTextColorOfDayNight(UILabel *view, uint32_t colorDay, uint32_t colorNight); private: WeatherModel(); WeatherModel(const WeatherModel &); WeatherModel &operator=(const WeatherModel &); - int usedLen{0}; - int tempMinArray[WEATHER_ITEM_COUNT] = {0}; - int tempMaxArray[WEATHER_ITEM_COUNT] = {0}; - bool isDay; - CurWeather curWeather{nullptr}; - std::vector houWeather; - WeatherItem weather[WEATHER_ITEM_COUNT] = {nullptr, nullptr, nullptr, false}; - std::vector> vec_forecast_1h; - std::vector> vec_forecast_24h; - std::vector> vec_rise; - std::map map_observe; - std::map map_address; + CurWeather curWeather_{nullptr}; + std::vector houWeather_; + WeatherItem weather_[ONE_WEEK_DYAS] = {nullptr, 0, nullptr, false}; + std::string strTmp_[ONE_WEEK_DYAS]; + std::string minTemp_[ONE_WEEK_DYAS]; + std::string maxTemp_[ONE_WEEK_DYAS]; + std::string currentWeek_[ONE_WEEK_DYAS]; + std::string strRise_[ONE_WEEK_DYAS]; + std::string strSet_[ONE_WEEK_DYAS]; + int weatherValue_[ONE_WEEK_DYAS]; + SunStruct sunData_[ONE_WEEK_DYAS] = {nullptr, nullptr, nullptr}; + MonthStruct monthData_[ONE_WEEK_DYAS] = {nullptr, nullptr, nullptr}; + LunarPhaseStruct parseData_[ONE_WEEK_DYAS] = {nullptr, 0, nullptr, nullptr, nullptr}; + std::vector> vec_forecast_1h_; + std::vector> vec_forecast_24h_; + std::map map_observe_; + std::map map_address_; + int usedLen_{0}; + bool isDay_{0}; }; } -#endif // Weather_MODEL_H \ No newline at end of file +#endif // Weather_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageDays.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageDays.h new file mode 100644 index 000000000..d34c77b55 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageDays.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageDays + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_DAYS_H +#define WEATHER_PAGE_DAYS_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_simple_list.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherItemView.h" +#include "WeatherPresenter.h" + +namespace OHOS { +class WeatherPageDays : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener { +public: + WeatherPageDays(); + ~WeatherPageDays() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnSwipe(UISwipeView &view) override; + void InitScrollView(); + bool InitScrollData(); + void RefreshWeathersList(WeatherItem *item, uint8_t count); +private: + UIViewGroup *group_{nullptr}; + UISimpleList *contentList_{nullptr}; + UILabel *title_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *pageIdxImg_{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHours.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHours.h new file mode 100644 index 000000000..7c3e6d238 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHours.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageHours + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_HOURS_H +#define WEATHER_PAGE_HOURS_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherPresenter.h" +#include "WeatherView.h" +#include "WeatherPageHoursGroup.h" + +namespace OHOS { +static constexpr int16_t GROUP_24H_COUNT = 3; + +class WeatherPresenter; +class WeatherPageHours : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener { +public: + WeatherPageHours(); + ~WeatherPageHours() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnSwipe(UISwipeView &view) override; +private: + UISwipeView *weatherSwipeGroup_{nullptr}; + WeatherPageHoursGroup *hoursGroup_[GROUP_24H_COUNT]{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHoursGroup.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHoursGroup.h new file mode 100644 index 000000000..d26f0e885 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageHoursGroup.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageHoursGroup + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_HOURS_GROUP_H +#define WEATHER_PAGE_HOURS_GROUP_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherPresenter.h" +#include "WeatherView.h" + +namespace OHOS { +static constexpr int16_t WEATHER_24H_PER_8H = 8; + +class WeatherPresenter; +class WeatherPageHoursGroup : public UIViewGroup { +public: + WeatherPageHoursGroup(); + ~WeatherPageHoursGroup() override; + void WeatherInit(int index); + void InitLabel(int index); + void InitImage(int index); +private: + std::vector houWeather_; + UILabel *labelTime_[WEATHER_24H_PER_8H]{nullptr}; + UILabel *labelTemp_[WEATHER_24H_PER_8H]{nullptr}; + UIImageView *imgBack_[WEATHER_24H_PER_8H]{nullptr}; + UIImageView *imgWeather_[WEATHER_24H_PER_8H]{nullptr}; + UILabel *topLabel_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *pageIdxImg_{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageLunarPhase.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageLunarPhase.h new file mode 100644 index 000000000..9ed9a3968 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageLunarPhase.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageLunarPhase + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_LUNARPHASE_H +#define WEATHER_PAGE_LUNARPHASE_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherPresenter.h" +#include "WeatherView.h" + +namespace OHOS { +static constexpr int16_t BUTTON_CHANGE_END = 6; + +class WeatherPresenter; +class WeatherPageLunarPhase : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + WeatherPageLunarPhase(); + ~WeatherPageLunarPhase() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void InitLabel(); + void InitImage(); + void InitButton(); + void InitMonthLabel(); +private: + UIViewGroup *group_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *drawImg_{nullptr}; + UILabel *labelTitle_{nullptr}; + UILabel *labelDay_{nullptr}; + UILabel *labelLunarPhase_{nullptr}; + UILabel *labelMonthLight_{nullptr}; + UILabel *labelMonthDay_{nullptr}; + UIButton *buttonChangeLeft_{nullptr}; + UIButton *buttonChangeRight_{nullptr}; + LunarPhaseStruct *phase_ = nullptr; + int index_ = 0; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageMonthRise.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageMonthRise.h new file mode 100644 index 000000000..7abb646e8 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageMonthRise.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageMonthRise + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_MONTHRISE_H +#define WEATHER_PAGE_MONTHRISE_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherPresenter.h" +#include "WeatherView.h" + +namespace OHOS { +static constexpr int16_t MONTHRISE_TIME_LABEL_COUNT = 2; +static constexpr int16_t BUTTON_CHANGE_END = 6; + +class WeatherPresenter; +class WeatherPageMonthRise : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + WeatherPageMonthRise(); + ~WeatherPageMonthRise() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void InitLabel(); + void InitLabelMonth(); + void InitImage(); + void InitButton(); +private: + UIViewGroup *group_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *drawImg_{nullptr}; + UIImageView *monthImg_{nullptr}; + UILabel *labelTitle_{nullptr}; + UILabel *labelDay_{nullptr}; + UILabel *labelMonth_[MONTHRISE_TIME_LABEL_COUNT]{nullptr}; + UIButton *buttonChangeLeft_{nullptr}; + UIButton *buttonChangeRight_{nullptr}; + MonthStruct *month_ = nullptr; + int index_ = 0; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageSunRise.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageSunRise.h new file mode 100644 index 000000000..88c13ce6f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPageSunRise.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageSunRise + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGE_SUNRISE_H +#define WEATHER_PAGE_SUNRISE_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "WeatherPresenter.h" +#include "WeatherView.h" + +namespace OHOS { +static constexpr int16_t SUNRISE_TIME_LABEL_COUNT = 2; +static constexpr int16_t BUTTON_CHANGE_END = 6; + +class WeatherPresenter; +class WeatherPageSunRise : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + WeatherPageSunRise(); + ~WeatherPageSunRise() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void InitLabel(); + void InitLabelSun(); + void InitImage(); + void InitButton(); +private: + UIViewGroup *group_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *drawImg_{nullptr}; + UIImageView *sunImg_{nullptr}; + UILabel *labelTitle_{nullptr}; + UILabel *labelDay_{nullptr}; + UILabel *labelSun_[SUNRISE_TIME_LABEL_COUNT]{nullptr}; + UIButton *buttonChangeLeft_{nullptr}; + UIButton *buttonChangeRight_{nullptr}; + SunStruct *sun_ = nullptr; + int index_ = 0; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPresenter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPresenter.h index 6cb6bf1ad..f6cdcf8e9 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPresenter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherPresenter.h @@ -9,10 +9,11 @@ #include "Presenter.h" #include "components/ui_view.h" -#include "weather/WeatherModel.h" +#include "WeatherModel.h" + namespace OHOS { class WeatherView; class WeatherPresenter : public Presenter {}; } -#endif // Weather_PRESENTER_H \ No newline at end of file +#endif // WEATHER_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherView.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherView.h index 4c2e46906..e33739941 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherView.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/include/weather/WeatherView.h @@ -8,14 +8,18 @@ #define WEATHER_VIEW_H #include "View.h" + namespace OHOS { enum WEATHER_PAGES { WEATHER_MAIN_PAGE = 1, // 0 is invalid - WEATHER_SECOND_PAGE = 2, - WEATHER_THIRD_PAGE = 3, + WEATHER_HOURS_PAGE = 2, + WEATHER_DAYS_PAGE = 3, + WEATHER_SUNRISE_PAGE = 4, + WEATHER_MONTHRISE_PAGE = 5, + WEATHER_LUNARPHASE_PAGE = 6, }; class WeatherPresenter; class WeatherView : public View {}; } -#endif // Weather_VIEW_H +#endif // WEATHER_VIEW_H diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/key/src/KeyInputListener.cpp index 9f8ecd313..8d6dc8d87 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/key/src/KeyInputListener.cpp @@ -15,11 +15,33 @@ #include "dock/input_device.h" #include "notification_manager.h" #include "alarm/AlarmPopUpPresenter.h" -#include "callerlog/CallerLogModel.h" -#include "makephone/MainCallingPresenter.h" -#include "applist/ApplistModel.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" +#include "settings/model/SettingDesktopModel.h" +#include "quickaccess/FloatAccessView.h" namespace OHOS { +// 可以弹窗快捷应用的应用页 +static uint16_t g_viewIds[] = { + VIEW_MAIN_SAMPLE, // 主表盘 + VIEW_APPLIST, // 菜单页 +}; + +static void PressQuickApp(uint16_t viewId) +{ + if (FloatAccessView::GetInstance()->IsShowView()) { + FloatAccessView::GetInstance()->ExitView(); + } else { + int len = sizeof(g_viewIds) / sizeof(uint16_t); + for (int i = 0 ; i < len; i++) { + if (viewId == g_viewIds[i]) { + FloatAccessView::GetInstance()->ShowView(); + return; + } + } + } +} + static bool IsNotifyCallStatus() { uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId(); @@ -63,7 +85,7 @@ void KeyInputListener::OnKeyLongPress(const KeyEvent& event) // 切换到关机/重启卡片 NativeAbility::GetInstance().ChangeSlice(VIEW_REBOOT); } else if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键 - // 切换到查看系统版本卡片 + PressQuickApp(NativeAbility::GetInstance().GetCurSliceId()); } return; } @@ -71,9 +93,9 @@ void KeyInputListener::OnKeyLongPress(const KeyEvent& event) void KeyInputListener::CallVolumeDipSwitchControl(uint8_t status) { VolumeSliderEventListener *volumeSliderEventListener = nullptr; - if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) { - if (CallerLogModel::GetInstance()->GetVolumeScreenStatus()) { - VolumeSettingView *settingView = MainCallingPresenter::GetInstance()->GetvolumeSetting(); + if (PhoneMenuCallerLogModel::GetInstance()->GetCallStatus()) { + if (PhoneMenuCallerLogModel::GetInstance()->GetVolumeScreenStatus()) { + VolumeSettingView *settingView = GetvolumeSetting(); if (settingView == nullptr) { return; } @@ -83,8 +105,8 @@ void KeyInputListener::CallVolumeDipSwitchControl(uint8_t status) } volumeSliderEventListener->ChangeVolume(static_cast(status)); } else { - MainCallingPresenter::GetInstance()->HonrsViewChange(); - CallerLogModel::GetInstance()->SetVolumeScreenStatus(true); + HonrsViewChange(); + PhoneMenuCallerLogModel::GetInstance()->SetVolumeScreenStatus(true); } } if (IsNotifyCallStatus()) { @@ -107,24 +129,31 @@ void KeyInputListener::CallVolumeDipSwitchControl(uint8_t status) void KeyInputListener::OnKeyRelease(const KeyEvent& event) { - uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId(); + uint32_t targetId = NativeAbility::GetInstance().GetCurTargetId(); + uint16_t curSlice = static_cast(targetId & SLICE_MASK); + uint16_t curPage = static_cast(targetId >> PAGE_OFFSET); uint16 keyID = event.GetKeyId(); if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键 if (longPressFlag == 0 && pressFlag == 1) { // 短按电源键 - if (currentViewId == VIEW_MAEKPHONE_SAMPLE || + // 先关闭快捷应用悬浮框再处理事件 + if (FloatAccessView::GetInstance()->IsShowView()) { + FloatAccessView::GetInstance()->CleanView(); + } + if ((curSlice == VIEW_PHONE_MENU && curPage == PhoneMenuPages::PHONE_MENU_CALLING_PAGE) || NotificationManager::GetInstance()->GetWatchCallStatus()) { // 音量卡片 // 音量+ CallVolumeDipSwitchControl(VOLUMEUP); - } else if (currentViewId != VIEW_MAIN_SAMPLE) { // 主表盘 + } else if (curSlice != VIEW_MAIN_SAMPLE) { // 主表盘 PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面 - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TransitionType::TRANSITION_ZOOM); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TransitionType::TRANSITION_ZOOM_OUT); } else { PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面 if (!MainViewSample::GetInstance()->IsMainClockPage()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面 MainViewSample::GetInstance()->SwitchToClockPage(); } else { - if (ApplistModel::GetInstance().GetCurrentStyle() == AppListStyle::WATERFALL_STYLE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ENTER_WATERFALL); + if (SettingDesktopModel::GetInstance().GetDesktopStyle() == DesktopStyle::WATERFALL_STYLE) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, + TransitionType::TRANSITION_ENTER_WATERFALL); } else { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); } @@ -133,11 +162,11 @@ void KeyInputListener::OnKeyRelease(const KeyEvent& event) } } else if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键 if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键 - if (currentViewId == VIEW_MAEKPHONE_SAMPLE || + if ((curSlice == VIEW_PHONE_MENU && curPage == PhoneMenuPages::PHONE_MENU_CALLING_PAGE) || NotificationManager::GetInstance()->GetWatchCallStatus()) { // 音量卡片 // 音量- CallVolumeDipSwitchControl(VOLUMEDOWN); - } else if (currentViewId != VIEW_RECENT_APP) { + } else if (curSlice != VIEW_RECENT_APP) { NativeAbility::GetInstance().ChangeSlice(VIEW_RECENT_APP); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/HealthModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/HealthModel.cpp index 5f0b22d3a..afb3f12f8 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/HealthModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/HealthModel.cpp @@ -1,160 +1,160 @@ -/* - * Copyright (c) 2020-2021 CompanyNameMagicTag. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "main/HealthModel.h" -#include -#include -#include -#include -#include "securec.h" -#include "message.h" -#include "wearable_log.h" -#include "iostream" -#include -#include "graphic_mutex.h" - -namespace OHOS { -HealthAllData g_healthData; - -static GraphicMutex g_healthDataMutex; -static constexpr const char *HEALTH_DATA_PATH = "/user/res/health.bin"; -static constexpr uint16_t LIST_HEALTH_LENGTH = 30; - -HealthModel::HealthModel() -{ -} - -HealthModel::~HealthModel() -{ - listHealth.Clear(); - listHealthNum = 0; -} - -HealthModel *HealthModel::GetInstance(void) -{ - static HealthModel healthModel; - return &healthModel; -} - -int HealthModel::SaveGlobalHealthToFile(void) -{ - std::ofstream outHealthFile; - outHealthFile.open(HEALTH_DATA_PATH, std::ios::out); - if (outHealthFile.is_open() == 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "open HEALTH_DATA_PATH failure!"); - outHealthFile.close(); - return -1; - } else { - outHealthFile.write((const char*)&g_healthData, sizeof(HealthAllData)); - if (outHealthFile.fail()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveGlobalHealthToFile fail"); - return -1; - } - outHealthFile.close(); - return 0; - } -} - -int HealthModel::GetHealthGlobalData(DataDistribute type, uint32_t *value) -{ - switch (type) { - case HEALTH_SLEEP: - *value = g_healthData.healthSleep; - break; - case BATTERY_LIFE: - break; - default: - return -1; - break; - } - return 0; -} - -void HealthModel::PushHealthData(HealthMsg healthMsg) -{ - uint16_t tmp; - if (listHealthNum >= LIST_HEALTH_MAX) { - return; - } - g_healthDataMutex.Lock(); - listHealthNum++; - listHealth.PushBack(healthMsg); - g_healthDataMutex.Unlock(); - switch (healthMsg.type) { - case HEALTH_SLEEP: - g_healthData.healthSleep = healthMsg.value; - break; - case BATTERY_LIFE: - break; - default: - break; - } -} - -bool HealthModel::FetchedHealthData(HealthMsg *healthMsg) -{ - if (listHealth.IsEmpty()) { - return false; - } else { - g_healthDataMutex.Lock(); - listHealthNum--; - *healthMsg = listHealth.Front(); - listHealth.PopFront(); - g_healthDataMutex.Unlock(); - } - return true; -} - -bool HealthModel::InitHealthData(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HealthModel::InitHealthData start"); - (void)memset_s(&g_healthData, sizeof(HealthAllData), 0, sizeof(HealthAllData)); - std::ifstream inHealthFile; - inHealthFile.open(HEALTH_DATA_PATH, std::ios::in); - if (!inHealthFile.is_open()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "open HEALTH_DATA_PATH failure!"); - inHealthFile.close(); - return false; - } else { - inHealthFile.read((char*)&g_healthData, sizeof(HealthAllData)); - if (inHealthFile.fail()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitHealthData fail"); - inHealthFile.close(); - return false; - } - inHealthFile.close(); - } - return true; -} - -int HealthModel::GetBriScrStatus(void) -{ - return briScreenStatus; -} - -int HealthModel::GetDntDistStatus(void) -{ - return dntDisturbStatus; -} - -void HealthModel::UpdateBriScrStatus(uint16_t status) -{ - briScreenStatus = status; -} - -void HealthModel::UpdateDntDistStatus(uint16_t status) -{ - dntDisturbStatus = status; -} -} +/* + * Copyright (c) 2020-2021 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "main/HealthModel.h" +#include +#include +#include +#include +#include "securec.h" +#include "message.h" +#include "wearable_log.h" +#include "iostream" +#include +#include "graphic_mutex.h" + +namespace OHOS { +HealthAllData g_healthData; + +static GraphicMutex g_healthDataMutex; +static constexpr const char *HEALTH_DATA_PATH = "/user/res/health.bin"; +static constexpr uint16_t LIST_HEALTH_LENGTH = 30; + +HealthModel::HealthModel() +{ +} + +HealthModel::~HealthModel() +{ + listHealth.Clear(); + listHealthNum = 0; +} + +HealthModel *HealthModel::GetInstance(void) +{ + static HealthModel healthModel; + return &healthModel; +} + +int HealthModel::SaveGlobalHealthToFile(void) +{ + std::ofstream outHealthFile; + outHealthFile.open(HEALTH_DATA_PATH, std::ios::out); + if (outHealthFile.is_open() == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "open HEALTH_DATA_PATH failure!"); + outHealthFile.close(); + return -1; + } else { + outHealthFile.write((const char*)&g_healthData, sizeof(HealthAllData)); + if (outHealthFile.fail()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveGlobalHealthToFile fail"); + return -1; + } + outHealthFile.close(); + return 0; + } +} + +int HealthModel::GetHealthGlobalData(DataDistribute type, uint32_t *value) +{ + switch (type) { + case HEALTH_SLEEP: + *value = g_healthData.healthSleep; + break; + case BATTERY_LIFE: + break; + default: + return -1; + break; + } + return 0; +} + +void HealthModel::PushHealthData(HealthMsg healthMsg) +{ + uint16_t tmp; + if (listHealthNum >= LIST_HEALTH_MAX) { + return; + } + g_healthDataMutex.Lock(); + listHealthNum++; + listHealth.PushBack(healthMsg); + g_healthDataMutex.Unlock(); + switch (healthMsg.type) { + case HEALTH_SLEEP: + g_healthData.healthSleep = healthMsg.value; + break; + case BATTERY_LIFE: + break; + default: + break; + } +} + +bool HealthModel::FetchedHealthData(HealthMsg *healthMsg) +{ + if (listHealth.IsEmpty()) { + return false; + } else { + g_healthDataMutex.Lock(); + listHealthNum--; + *healthMsg = listHealth.Front(); + listHealth.PopFront(); + g_healthDataMutex.Unlock(); + } + return true; +} + +bool HealthModel::InitHealthData(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HealthModel::InitHealthData start"); + (void)memset_s(&g_healthData, sizeof(HealthAllData), 0, sizeof(HealthAllData)); + std::ifstream inHealthFile; + inHealthFile.open(HEALTH_DATA_PATH, std::ios::in); + if (!inHealthFile.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "open HEALTH_DATA_PATH failure!"); + inHealthFile.close(); + return false; + } else { + inHealthFile.read((char*)&g_healthData, sizeof(HealthAllData)); + if (inHealthFile.fail()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitHealthData fail"); + inHealthFile.close(); + return false; + } + inHealthFile.close(); + } + return true; +} + +int HealthModel::GetBriScrStatus(void) +{ + return briScreenStatus; +} + +int HealthModel::GetDntDistStatus(void) +{ + return dntDisturbStatus; +} + +void HealthModel::UpdateBriScrStatus(uint16_t status) +{ + briScreenStatus = status; +} + +void HealthModel::UpdateDntDistStatus(uint16_t status) +{ + dntDisturbStatus = status; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/LoadImg.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/LoadImg.cpp index 5586182b5..1c0ffd5db 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/LoadImg.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/LoadImg.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: LoadImg + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: LoadImg.cpp * Author: * Create: 2025-06-05 */ @@ -9,18 +9,17 @@ namespace OHOS { namespace LOADIMG { - // 加载图片资源 void LoadBtnImage(UIButton *btn, std::string file, uint32_t resId1, uint32_t resId2) { ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId1, file); if (image1 == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); return; } ImageInfo *image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId2, file); if (image2 == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); return; } btn->SetImageSrc(image1, image2); @@ -30,7 +29,18 @@ void LoadImageViewImg(UIImageView *view, std::string file, uint32_t resId) { ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); if (image == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadImageViewImg %x fail", resId); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadImageViewImg %x fail", resId); + return; + } + view->SetSrc(image); + return; +} + +void LoadImageImg(Image *view, std::string file, uint32_t resId) +{ + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadImageImg %x fail", resId); return; } view->SetSrc(image); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainModel.cpp index a84d1d7d5..369284fba 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainModel.cpp @@ -12,12 +12,12 @@ #include "wearable_log.h" #include "main/DialBinTypesV2.h" #include "power_display_service.h" +#include "UIWatchDialFactory.h" namespace OHOS { static const int CARD_SETTING_VALUE_LEN = 32; static const int DIAL_SETTING_VALUE_LEN = 64; const CardInfo cardInfoMap[] = { - { HEART_RATE, PNG_SET_CARD_HEART }, { COMPASS, PNG_SET_CARD_COMPASS }, { ACTIVITY, PNG_SET_CARD_ACTIVITY }, { MUSIC_PLAYER, PNG_SET_CARD_PLAYER }, @@ -26,11 +26,6 @@ namespace OHOS { { VIDEO_CARD3, PNG_SET_CARD_VIDEO }, }; - const DialInfo dialInfoMap[] = { - { 0, "扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY}, - { 1, "aod扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY}, - }; - MainModel::MainModel() { power_display_gui_enable_aod(IsAodEnabled()); @@ -56,17 +51,12 @@ namespace OHOS { const DialInfo *MainModel::GetDialInfo(uint8_t dialId) const { - for (uint8_t i = 0; i < (sizeof(dialInfoMap) / sizeof(dialInfoMap[0])); i++) { - if (dialId == dialInfoMap[i].id) { - return &dialInfoMap[i]; - } - } - return nullptr; + return UIWatchDialFactory::GetInstance().GetNormalDialInfo(dialId); } uint8_t MainModel::GetDialInfoNum() const { - return sizeof(dialInfoMap) / sizeof(dialInfoMap[0]); + return UIWatchDialFactory::GetInstance().GetNormalDialInfoNum(); } void MainModel::InitCardSettings(void) @@ -95,7 +85,6 @@ namespace OHOS { } else { /* 使用默认card配置 */ cardSettings[index++] = WATCH_FACE; - cardSettings[index++] = HEART_RATE; cardSettings[index++] = COMPASS; cardSettings[index++] = ACTIVITY; cardSettings[index++] = MUSIC_PLAYER; @@ -180,40 +169,38 @@ namespace OHOS { { char temp[DIAL_SETTING_VALUE_LEN] = { 0 }; int32_t len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); - if (len >= 0) { - char *setBuffer = nullptr; - char *setValue = strtok_s(temp, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialFlag = atoi(setValue); - } else { - InitDialSettingDefault(); - return; - } + if (len < 0) { + InitDialSettingDefault(); + return; + } + char* setBuffer = nullptr; + char* setValue = strtok_s(temp, ",", &setBuffer); + if (!setValue) { + InitDialSettingDefault(); + return; + } + dialSetting.dialFlag = atoi(setValue); - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialId = atoi(setValue); - } else { - InitDialSettingDefault(); - return; - } + setValue = strtok_s(nullptr, ",", &setBuffer); + if (!setValue) { + InitDialSettingDefault(); + return; + } + dialSetting.dialId = atoi(setValue); - if (dialSetting.dialFlag == 0) { - return; - } - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialFullName = setValue; - if (!((dialSetting.dialFullName.length() > 0) && - (access(dialSetting.dialFullName.c_str(), F_OK) == 0))) { - InitDialSettingDefault(); - return; - } - } else { - InitDialSettingDefault(); - return; - } - } else { + if (dialSetting.dialFlag == 0) { + dialSetting.dialFullName = ""; + return; + } + + setValue = strtok_s(nullptr, ",", &setBuffer); + if (!setValue) { + InitDialSettingDefault(); + return; + } + dialSetting.dialFullName = setValue; + + if (access(dialSetting.dialFullName.c_str(), F_OK) != 0) { InitDialSettingDefault(); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainPresenterSample.cpp index 434c85e11..a19c72dbc 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -1,323 +1,293 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainPresenterSample - * Author: - * Create: 2021-10-18 - */ - -#include "main/MainPresenterSample.h" -#include "common/task_manager.h" -#include "heartrate/HeartRateView.h" -#include "player/PlayersModel.h" -#include "player/PlayersPresenter.h" -#include "NativeRegisterManager.h" -#include "compass/CompassModel.h" -#include "drag_event.h" -#include "graphic_service.h" -#include "wearable_log.h" -#include "UiConfig.h" -#include "ui_resource_image.h" -#include -#include -#include "main/dial/ModelDialDataFactory.h" -#include "main/dial/DialModelTime.h" -#include "main/dial/DialViewGroup.h" -#include "uiservice/ui_service.h" -#include "PageTransitionMgr.h" - -namespace OHOS { - -REGIST_SLICE(VIEW_MAIN_SAMPLE, MainViewSample, MainPresenterSample); - -std::map g_jumpView = { { MAIN_CLICK_WEATHER, VIEW_MAIN_SAMPLE }, // 天气界面 - { MAIN_CLICK_ACTIVITY, VIEW_MAIN_ACTIVITY }, // 活动记录界面 - { MAIN_CLICK_MESSAGE, VIEW_MAIN_SAMPLE }, // 消息app - { MAIN_CLICK_HEARTRATE, VIEW_MAIN_SAMPLE }, // 心率界面 - { DROPDOWN_CLICK_ALARM, VIEW_MAIN_ALARM }, // 闹钟app - { DROPDOWN_CLICK_SETTING, VIEW_SETTING } }; // 设置界面 - -std::map g_chanColor = { { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B }, - { DROPDOWN_CLICK_ALARM, DROPDOWN_DROPDOWN_ALARM_B }, - { DROPDOWN_CLICK_SETTING, DROPDOWN_DROPDOWN_SETTING_B } }; - -static MainPresenterSample *g_pMainPresenterSample = nullptr; - -static constexpr uint16_t DROP_X_MAX = 360; -static constexpr uint16_t PROGRESS_PERCENTAGE = 100; -static constexpr uint16_t HORIZONTAL_SWIPE = 1; -static constexpr uint16_t PLAYER_PERIOD = 500; -static constexpr uint16_t MAX_PERIOD = 1000; - -MainPresenterSample::MainPresenterSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this); - g_pMainPresenterSample = this; -} - -MainPresenterSample::~MainPresenterSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample"); -} - -MainPresenterSample *MainPresenterSample::GetInstance(void) -{ - return g_pMainPresenterSample; -} - -void MainPresenterSample::OnStart() -{ - mainPresenterState_ = MainPresenterState::START; -} - -void MainPresenterSample::OnPause() -{ - // Save watchface content for slide back - UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent(); - uint8_t opaScale = watchFace->GetOpaScale(); - watchFace->SetOpaScale(OPA_OPAQUE); - PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace); - watchFace->SetOpaScale(opaScale); - - uint8_t curCardId = view_->GetHorCurrentCard(); - UICardPage *card = view_->GetViewById(curCardId); - if (card != nullptr) { - card->OnPause(); - } - mainPresenterState_ = MainPresenterState::PAUSE; -} - -void MainPresenterSample::OnResume(void) -{ - mainPresenterState_ = MainPresenterState::RESUME; - // Set current page again to invoke OnActive method. - uint8_t curCardId = view_->GetHorCurrentCard(); - view_->SwitchToCard(curCardId); -} - -void MainPresenterSample::OnStop(void) -{ - mainPresenterState_ = MainPresenterState::STOP; - if (isCompassSensorOpened_) { - CompassModel::GetInstance()->CloseCompassSensor(); - } -} - -MainPresenterState MainPresenterSample::GetMainPresenterState(void) -{ - return mainPresenterState_; -} - -bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) -{ - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId()); - std::string curViewId = view.GetViewId(); - - UIImageView *imgView = static_cast(&view); - if (HealthModel::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); - return false; - } - if (curViewId == DROPDOWN_CLICK_DONOTDISTURB) { - if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB_B); - HealthModel::GetInstance()->UpdateDntDistStatus(1); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB); - HealthModel::GetInstance()->UpdateDntDistStatus(0); - } - } - if (curViewId == DROPDOWN_CLICK_BRIGHTENSCREEN) { - if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN_B); - HealthModel::GetInstance()->UpdateBriScrStatus(1); - ScreenOffEnable(0); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN); - HealthModel::GetInstance()->UpdateBriScrStatus(0); - ScreenOffEnable(1); - } - } - - if (g_jumpView.count(curViewId) != 0) { - if (g_jumpView[curViewId] == VIEW_SETTING) { - NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId], TransitionType::TRANSITION_INVALID, - gSliceDefaultPriority, true); - } else { - NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]); - } - } - return true; -} - -bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event) -{ - UNUSED(event); - 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_SET_CARD); - } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); - } - return true; -} - -void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent) -{ - if (view_ != nullptr) { - view_->SetPage(id, loadAdjacent); - } -} - -void MainPresenterSample::SetTaskPeroid(CardId cardId) -{ - SetLastRun(0); // refresh entering card in time - if (cardId == COMPASS) { - SetPeriod(DEFAULT_TASK_PERIOD); - } else if (cardId == WATCH_FACE) { - uint32_t time; - DialSetting &setting = GetDialSetting(); - if (setting.dialFlag) { - time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); - } else { - time = DEFAULT_TASK_PERIOD; - } - SetPeriod(time); - } else if (cardId == MUSIC_PLAYER) { - SetPeriod(PLAYER_PERIOD); - } else { - SetPeriod(MAX_PERIOD); - } -} - -void MainPresenterSample::OnSwipe(UISwipeView &view) -{ - UNUSED(view); - CardId cardId = view_->GetHorCurrentCard(); - SetTaskPeroid(cardId); - if (cardId == COMPASS) { - if (!isCompassSensorOpened_) { - CompassModel::GetInstance()->OpenCompassSensor(); - isCompassSensorOpened_ = true; - } - } else if (isCompassSensorOpened_) { - CompassModel::GetInstance()->CloseCompassSensor(); - isCompassSensorOpened_ = false; - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); - return; -} - -void MainPresenterSample::ProcessDataNotify(void) -{ - HealthMsg healthMsg; - uint16_t len; - - while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg))) { - switch (healthMsg.type) { - case BATTERY_LIFE: - break; - default: - break; - } - } -} - -void MainPresenterSample::SetCircleProgress() -{ - PlayersView *playersView = dynamic_cast(view_->GetViewById(MUSIC_PLAYER)); - if (playersView == nullptr) { - return; - } - UICircleProgress *playbackProgress = playersView->GetPlaybackProgress(); - if (playbackProgress == nullptr) { - return; - } - int32_t playerState; - PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); - state_ = playersView->GetPlayerButtonState(); - if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED)) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED)) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } - if (state_ == UICheckBox::UICheckBoxState::SELECTED) { - PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); - PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); - if (playerMusicDuration_ != 0) { - playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); - } else { - playerProgressValue_ = 100; // 100: max progress value - } - PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_); - PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_); - } -} - -void MainPresenterSample::Notify(void) -{ - CardId cardId = view_->GetHorCurrentCard(); - if (cardId == MUSIC_PLAYER) { - SetCircleProgress(); - } else if (cardId == WATCH_FACE) { - DialSetting &setting = GetDialSetting(); - if (setting.dialFlag) { - DialModelTime::GetInstance()->UpdateTime(); - DialViewGroup* group = dynamic_cast(view_->GetViewById(WATCH_FACE)); - if (group != nullptr) { - group->UpdateViewsByPeriodicUpdateData(); - } - } else { - MainClockView* clock = dynamic_cast(view_->GetViewById(WATCH_FACE)); - if (clock != nullptr) { - clock->UpdateTime(); - } - } - } -} - -void MainPresenterSample::InitCardSettings(void) -{ - MainModel::GetInstance().InitCardSettings(); -} - -uint8_t MainPresenterSample::GetCardSettingCount(void) -{ - return MainModel::GetInstance().GetCardSettingCount(); -} - -CardId *MainPresenterSample::GetCardSettings(void) -{ - return MainModel::GetInstance().GetCardSettings(); -} - -void MainPresenterSample::InitDialSettings(void) -{ - return MainModel::GetInstance().InitDialSettings(); -} -DialSetting& MainPresenterSample::GetDialSetting() -{ - return MainModel::GetInstance().GetDialSetting(); -} - -bool MainPresenterSample::IsFromSetCardView(void) const -{ - return MainModel::GetInstance().IsFromSetCardView(); -} - -void MainPresenterSample::SetFromSetCardView(bool isFrom) -{ - MainModel::GetInstance().SetFromSetCardView(isFrom); -} - -uint8_t MainPresenterSample::GetFromCardId(void) -{ - return MainModel::GetInstance().GetFromCardId(); -} - -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainPresenterSample + * Author: + * Create: 2021-10-18 + */ + +#include "main/MainPresenterSample.h" +#include "common/task_manager.h" +#include "player/PlayersModel.h" +#include "player/PlayersPresenter.h" +#include "NativeRegisterManager.h" +#include "compass/CompassModel.h" +#include "drag_event.h" +#include "graphic_service.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include +#include "main/dial/ModelDialDataFactory.h" +#include "main/dial/DialModelTime.h" +#include "main/dial/DialViewGroup.h" +#include "uiservice/ui_service.h" +#include "PageTransitionMgr.h" +#include "findphone/FindPhoneView.h" +#include "settings/model/SettingCardModel.h" +#include "clock/GradientClockView.h" +#include "common/periodicupdate_interface.h" + +namespace OHOS { + +REGIST_SLICE(VIEW_MAIN_SAMPLE, MainViewSample, MainPresenterSample); + +std::map g_jumpView = { { MAIN_CLICK_WEATHER, VIEW_MAIN_SAMPLE }, // 天气界面 + { MAIN_CLICK_ACTIVITY, VIEW_MAIN_ACTIVITY }, // 活动记录界面 + { MAIN_CLICK_MESSAGE, VIEW_MAIN_SAMPLE }, // 消息app + { DROPDOWN_CLICK_ALARM, VIEW_MAIN_ALARM }, // 闹钟app + { DROPDOWN_CLICK_SETTING, VIEW_SETTING } }; // 设置界面 + +std::map g_chanColor = { { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B }, + { DROPDOWN_CLICK_ALARM, DROPDOWN_DROPDOWN_ALARM_B }, + { DROPDOWN_CLICK_SETTING, DROPDOWN_DROPDOWN_SETTING_B } }; + +static MainPresenterSample *g_pMainPresenterSample = nullptr; + +static constexpr uint16_t DROP_X_MAX = 360; +static constexpr uint16_t HORIZONTAL_SWIPE = 1; +static constexpr uint16_t MAX_PERIOD = 1000; + +MainPresenterSample::MainPresenterSample() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this); + g_pMainPresenterSample = this; +} + +MainPresenterSample::~MainPresenterSample() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample"); +} + +MainPresenterSample *MainPresenterSample::GetInstance(void) +{ + return g_pMainPresenterSample; +} + +void MainPresenterSample::OnStart() +{ + mainPresenterState_ = MainPresenterState::START; +} + +void MainPresenterSample::OnPause() +{ + // Save watchface content for slide back + UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent(); + uint8_t opaScale = watchFace->GetOpaScale(); + watchFace->SetOpaScale(OPA_OPAQUE); + PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace); + watchFace->SetOpaScale(opaScale); + + uint8_t curCardId = view_->GetHorCurrentCard(); + UICardPage *card = view_->GetViewById(curCardId); + if (card != nullptr) { + card->OnPause(); + } + mainPresenterState_ = MainPresenterState::PAUSE; + Deinit(); +} + +void MainPresenterSample::OnResume(void) +{ + mainPresenterState_ = MainPresenterState::RESUME; + // Set current page again to invoke OnActive method. + uint8_t curCardId = view_->GetHorCurrentCard(); + view_->SwitchToCard(curCardId); + Init(); +} + +void MainPresenterSample::OnStop(void) +{ + mainPresenterState_ = MainPresenterState::STOP; + if (isCompassSensorOpened_) { + CompassModel::GetInstance()->CloseCompassSensor(); + } +} + +MainPresenterState MainPresenterSample::GetMainPresenterState(void) +{ + return mainPresenterState_; +} + +bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId()); + std::string curViewId = view.GetViewId(); + + UIImageView *imgView = static_cast(&view); + if (HealthModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); + return false; + } + if (curViewId == DROPDOWN_CLICK_DONOTDISTURB) { + if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB_B); + HealthModel::GetInstance()->UpdateDntDistStatus(1); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB); + HealthModel::GetInstance()->UpdateDntDistStatus(0); + } + } + if (curViewId == DROPDOWN_CLICK_BRIGHTENSCREEN) { + if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN_B); + HealthModel::GetInstance()->UpdateBriScrStatus(1); + ScreenOffEnable(0); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN); + HealthModel::GetInstance()->UpdateBriScrStatus(0); + ScreenOffEnable(1); + } + } + if (curViewId == DROPDOWN_CLICK_FINDMYPHONE) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FIND_PHONE, FIND_PHONE_PAGES::FIND_PHONE_MAIN_PAGE); + } + + if (g_jumpView.count(curViewId) != 0) { + if (g_jumpView[curViewId] == VIEW_SETTING) { + NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId], TransitionType::TRANSITION_INVALID, + gSliceDefaultPriority, true); + } else { + NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]); + } + } + return true; +} + +bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event) +{ + UNUSED(event); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); + uint8_t cardId = view_->GetHorCurrentCard(); + if (cardId != WATCH_FACE) { + SettingCardModel::GetInstance().SetSelectedCard(cardId); + NativeAbility::GetInstance().SwitchSlice(VIEW_SETTING, SettingPageId::CARD_MGR_PAGE, + TransitionType::TRANSITION_INVALID, true); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_SETTING, SettingPageId::DESKTOP_DIAL_PAGE, + TransitionType::TRANSITION_INVALID, true); + } + return true; +} + +void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent) +{ + if (view_ != nullptr) { + view_->SetPage(id, loadAdjacent); + } +} + +void MainPresenterSample::SetTaskPeroid(CardId cardId) +{ + SetLastRun(0); // refresh entering card in time + PeriodicUpdateInterface* page = dynamic_cast(view_->GetViewById(cardId)); + if (page != nullptr) { + page->Update(); + SetPeriod(page->GetPeriod()); + } else if (cardId == WATCH_FACE) { + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) { + SetPeriod(dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod()); + } + } else { + SetPeriod(MAX_PERIOD); + } +} + +void MainPresenterSample::OnSwipe(UISwipeView &view) +{ + if (view.GetDirection()) { + view_->GetVerCurrentCard(); + } else { + CardId cardId = view_->GetHorCurrentCard(); + SetTaskPeroid(cardId); + if (cardId == COMPASS) { + if (!isCompassSensorOpened_) { + CompassModel::GetInstance()->OpenCompassSensor(); + isCompassSensorOpened_ = true; + } + } else if (isCompassSensorOpened_) { + CompassModel::GetInstance()->CloseCompassSensor(); + isCompassSensorOpened_ = false; + } + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); + return; +} + +void MainPresenterSample::ProcessDataNotify(void) +{ + HealthMsg healthMsg; + uint16_t len; + + while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg))) { + switch (healthMsg.type) { + case BATTERY_LIFE: + break; + default: + break; + } + } +} + +void MainPresenterSample::Callback(void) +{ + CardId cardId = view_->GetHorCurrentCard(); + PeriodicUpdateInterface* page = dynamic_cast(view_->GetViewById(cardId)); + if (page != nullptr) { + page->Update(); + } else if (cardId == WATCH_FACE) { + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) { + DialModelTime::GetInstance()->UpdateTime(); + DialViewGroup* group = dynamic_cast(view_->GetViewById(WATCH_FACE)); + if (group != nullptr) { + group->UpdateViewsByPeriodicUpdateData(); + } + } + } +} + +void MainPresenterSample::InitCardSettings(void) +{ + MainModel::GetInstance().InitCardSettings(); +} + +uint8_t MainPresenterSample::GetCardSettingCount(void) +{ + return MainModel::GetInstance().GetCardSettingCount(); +} + +CardId *MainPresenterSample::GetCardSettings(void) +{ + return MainModel::GetInstance().GetCardSettings(); +} + +void MainPresenterSample::InitDialSettings(void) +{ + return MainModel::GetInstance().InitDialSettings(); +} +DialSetting& MainPresenterSample::GetDialSetting() +{ + return MainModel::GetInstance().GetDialSetting(); +} + +bool MainPresenterSample::IsFromSetCardView(void) const +{ + return MainModel::GetInstance().IsFromSetCardView(); +} + +void MainPresenterSample::SetFromSetCardView(bool isFrom) +{ + MainModel::GetInstance().SetFromSetCardView(isFrom); +} + +uint8_t MainPresenterSample::GetFromCardId(void) +{ + return MainModel::GetInstance().GetFromCardId(); +} + +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainViewSample.cpp index 0133239e3..98fef5396 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -1,436 +1,456 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainViewSample - * Author: - * Create: 2021-10-18 - */ -#include "wearable_log.h" -#include "main/MainViewSample.h" -#include "graphic_service.h" -#include "common/image_cache_manager.h" -#include "UICardPageFactory.h" - -namespace OHOS { -static MainViewSample *g_pMainView = nullptr; -static constexpr uint16_t MESLABLE_X_TMP = 177; -static constexpr uint16_t MESLABLE_Y_TMP = 212; -static constexpr uint16_t MESLABLE_WIDTH_TMP = 100; -static constexpr uint16_t MESLABLE_HEIGHT_TMP = 30; -static constexpr uint8_t FONT_SIZE_TMP = 24; -static constexpr uint8_t PULL_MIDDLE_VIEW_OPA = 0; - -struct MainViewMapper { - CardId id; - UICardPage *(MainViewSample::*func)(void); -}; - -static const MainViewMapper CardMapper[] = { - {WATCH_FACE, &MainViewSample::InitWatchFacePage}, - {HEART_RATE, &MainViewSample::InitHeartRatePage}, - {COMPASS, &MainViewSample::InitCompassPage}, - {ACTIVITY, &MainViewSample::InitActivityPage}, - {MUSIC_PLAYER, &MainViewSample::InitMusicPlayerPage}, - {VIDEO_CARD1, &MainViewSample::InitVideoCardPage1}, - {VIDEO_CARD2, &MainViewSample::InitVideoCardPage2}, - {VIDEO_CARD3, &MainViewSample::InitVideoCardPage3}, -}; - -MainViewSample::MainViewSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::MainViewSample"); - g_pMainView = this; -} - -MainViewSample::~MainViewSample() -{ - dropDownView->ClearBackgroundBlur(); - messageView->ClearBackgroundBlur(); - - for (int32_t i = 0; i < MAX_CARD; i++) { - recordCard[i] = nullptr; - pageStatus[i] = false; - } - - if (mainSwipeGroup != nullptr) { - delete mainSwipeGroup; - mainSwipeGroup = nullptr; - } - - if (mainClockView != nullptr) { - delete mainClockView; - mainClockView = nullptr; - } - - if (activityWeekView != nullptr) { - delete activityWeekView; - activityWeekView = nullptr; - } - - if (playersView != nullptr) { - delete playersView; - playersView = nullptr; - } - - bool hasVideo = false; - if (videoCard1 != nullptr) { - hasVideo = true; - delete videoCard1; - videoCard1 = nullptr; - } - - if (videoCard2 != nullptr) { - hasVideo = true; - delete videoCard2; - videoCard2 = nullptr; - } - - if (videoCard3 != nullptr) { - hasVideo = true; - delete videoCard3; - videoCard3 = nullptr; - } - - if (hasVideo) { - ImageCacheManager::GetInstance().UnloadSingleRes(PNG_PREVIEW_CARD_VIDEO); - } - - if (heartRateView != nullptr) { - delete heartRateView; - heartRateView = nullptr; - } - - if (dropDownView != nullptr) { - delete dropDownView; - dropDownView = nullptr; - } - - if (messageView != nullptr) { - messageView->RemoveAll(); - delete messageView; - messageView = nullptr; - } - - if (messageLable != nullptr) { - delete messageLable; - messageLable = nullptr; - } - - if (compassControlView != nullptr) { - delete compassControlView; - compassControlView = nullptr; - } - - if (callback != nullptr) { - delete callback; - callback = nullptr; - } - - g_pMainView = nullptr; -} - -MainViewSample *MainViewSample::GetInstance(void) -{ - return g_pMainView; -} - -void MainViewSample::OnStart() -{ - mainSwipeGroup = new UICrossView(); - if (mainSwipeGroup == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail"); - return; - } - - if (callback == nullptr) { - callback = new ZoomEffect(); - if (callback == nullptr) { - delete mainSwipeGroup; - mainSwipeGroup = nullptr; - GRAPHIC_LOGE("SwipeCallback new fail\n"); - return; - } - } - callback->SetContainer(mainSwipeGroup); - - HorizontalViewInit(); - HorViewLoad(); - 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); - if (presenter_->IsFromSetCardView()) { - presenter_->SetFromSetCardView(false); - SwitchToCard(presenter_->GetFromCardId(), false); - } else { - SwitchToClockPage(false); - } - AddViewToRootContainer(mainSwipeGroup); -} - -bool MainViewSample::HorizontalViewInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); - presenter_->InitDialSettings(); - presenter_->InitCardSettings(); - uint8_t cardSettingNum = presenter_->GetCardSettingCount(); - CardId *cardSettings = presenter_->GetCardSettings(); - uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); - for (int16_t i = 0; i < cardSettingNum; i++) { - for (uint8_t j = 0; j < cardMapNumber; j++) { - if (cardSettings[i] == CardMapper[j].id) { - recordCard[j] = (this->*(CardMapper[j].func))(); - if (recordCard[j] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "MainViewSample:: recordCard %d error", j); - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); - break; - } - } - } - mainSwipeGroup->SetOnSwipeListener(presenter_); - mainSwipeGroup->SetOnLongPressListener(presenter_); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); - return true; -} - -void MainViewSample::HorViewLoad(void) -{ - uint8_t cardSettingNum = presenter_->GetCardSettingCount(); - CardId *cardSettings = presenter_->GetCardSettings(); - for (int16_t i = 0; i < cardSettingNum; i++) { - CardId cardId = cardSettings[i]; - if (recordCard[cardId] != nullptr) { - mainSwipeGroup->HorAdd(recordCard[cardId]); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", - cardId, recordCard[cardId]->GetViewIndex()); - } - } -} - -void MainViewSample::VerticalViewInit(void) -{ - dropDownView = new PullUpDownView(); - if (dropDownView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropDownView new fail"); - return; - } - dropDownView->PreLoad(); - dropDownView->SetViewId("dropDownView"); - dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - - messageView = new UICardPage(); - if (messageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); - return; - } - messageView->SetPosition(0, 0); - messageView->SetWidth(Screen::GetInstance().GetWidth()); - messageView->SetHeight(Screen::GetInstance().GetHeight()); - messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - messageView->SetViewId("messageView"); - messageView->SetTouchable(true); - messageView->SetIntercept(true); - messageLable = new UILabel(); - if (messageLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLable new fail"); - return; - } - messageLable->SetPosition(MESLABLE_X_TMP, MESLABLE_Y_TMP, MESLABLE_WIDTH_TMP, MESLABLE_HEIGHT_TMP); - messageLable->SetText("无消息"); - messageLable->SetAlign(TEXT_ALIGNMENT_CENTER); - messageLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_SIZE_TMP); - messageLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - messageView->Add(messageLable); -} - -void MainViewSample::VertViewLoad(void) -{ - mainSwipeGroup->VerAdd(dropDownView, UICrossView::VPage::UP_PAGE); - mainSwipeGroup->VerAdd(messageView, UICrossView::VPage::DOWN_PAGE); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::PullViewLoad::Pull View Load complete"); -} - -void MainViewSample::OnStop() -{ - messageView->RemoveAll(); - return; -} - -UICardPage *MainViewSample::InitWatchOffDial(DialSetting &setting) -{ - DialViewGroup *dial = new DialViewGroup(); - dial->SetDial(setting.dialFullName); - return dial; -} - -UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) -{ - return UICardPageFactory::GetInstance().CreateWatchDial(DIAL_DISPLAY_MODE_MAIN, setting.dialId); -} - -UICardPage *MainViewSample::InitWatchFacePage(void) -{ - DialSetting &setting = presenter_->GetDialSetting(); - if (setting.dialFlag) { - mainClockView = InitWatchOffDial(setting); - } else { - mainClockView = InitWatchDial(setting); - } - - if (mainClockView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); - return nullptr; - } - return mainClockView; -} - -UICardPage *MainViewSample::InitHeartRatePage(void) -{ - heartRateView = new HeartRateView(); - if (heartRateView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateView new fail"); - return nullptr; - } - return heartRateView; -} - -UICardPage *MainViewSample::InitActivityPage(void) -{ - activityWeekView = new ActivityWeekView(); - if (activityWeekView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "activityWeekView new fail"); - return nullptr; - } - return activityWeekView; -} - -UICardPage *MainViewSample::InitCompassPage(void) -{ - compassControlView = new CompassControlView(); - if (compassControlView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassControlView new fail"); - return nullptr; - } - return compassControlView; -} - -UICardPage *MainViewSample::InitMusicPlayerPage(void) -{ - playersView = new PlayersView(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail"); - return nullptr; - } - return playersView; -} - -UICardPage *MainViewSample::InitVideoCardPage1(void) -{ - videoCard1 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); - return videoCard1; -} - -UICardPage *MainViewSample::InitVideoCardPage2(void) -{ - videoCard2 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); - return videoCard2; -} - -UICardPage *MainViewSample::InitVideoCardPage3(void) -{ - videoCard3 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); - return videoCard3; -} - -UICardPage *MainViewSample::InitVideoCardPage(const std::string &video, const std::string &preview) -{ - VideoCard *page = new VideoCard; - if (page == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "videocard new fail"); - return nullptr; - } - page->SetFilePath(video); - page->SetPreviewFile(preview); - return page; -} - -void MainViewSample::SetPage(int16_t page, bool loadAdjacent) -{ - if (mainSwipeGroup != nullptr) { - mainSwipeGroup->SetHorCurrentPage(page, loadAdjacent); - } - - if (presenter_ != nullptr) { - CardId *cardSettings = presenter_->GetCardSettings(); - /* page 与CardId 没有对应关系,需要一次转换 */ - CardId id = MAX_CARD; - for (uint8_t i = 0; i < presenter_->GetCardSettingCount(); ++i) { - if (cardSettings[i] < MAX_CARD && recordCard[cardSettings[i]] != nullptr && - recordCard[cardSettings[i]]->GetViewIndex() == page) { - id = cardSettings[i]; - } - } - presenter_->SetTaskPeroid(id); - } -} - -void MainViewSample::ReloadWatchFace() -{ - if (mainSwipeGroup == nullptr) { - return; - } - mainSwipeGroup->Remove(mainClockView, UISwipeView::HORIZONTAL); - - delete mainClockView; - mainClockView = nullptr; - recordCard[WATCH_FACE] = InitWatchFacePage(); - if (recordCard[WATCH_FACE] == nullptr) { - GRAPHIC_LOGE("failed to reload main clock"); - return; - } - mainSwipeGroup->HorInsert(nullptr, mainClockView); - - SwitchToCard(WATCH_FACE); - Draw(); -} - -bool MainViewSample::IsMainClockPage(void) -{ - if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && - mainSwipeGroup->GetCurrentPageId(1) == 1) { // 0: horizontal; 1: vertical - return true; - } else { - return false; - } -} - -CardId MainViewSample::GetHorCurrentCard() const -{ - CardId *cardSettings = presenter_->GetCardSettings(); - int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical - /* pageId 与CardId 没有对应关系,需要一次转换 */ - for (uint8_t i = 0; i < presenter_->GetCardSettingCount(); ++i) { - if (cardSettings[i] < MAX_CARD && recordCard[cardSettings[i]] != nullptr && - recordCard[cardSettings[i]]->GetViewIndex() == pageId) { - return cardSettings[i]; - } - } - return MAX_CARD; -} - -void MainViewSample::SwitchToCard(uint8_t cardId, bool loadAdjacent) -{ - if ((cardId < MAX_CARD) && (recordCard[cardId] != nullptr)) { - SetPage(recordCard[cardId]->GetViewIndex(), loadAdjacent); - } else { - SwitchToClockPage(loadAdjacent); - } -} -} // OHOS +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainViewSample + * Author: + * Create: 2021-10-18 + */ +#include "wearable_log.h" +#include "main/MainViewSample.h" +#include "graphic_service.h" +#include "common/image_cache_manager.h" +#include "swipe_effect/turn_page_effect.h" +#include "swipe_effect/push_press_effect.h" +#include "swipe_effect/cube_effect.h" +#include "swipe_effect/windmill_effect.h" +#include "swipe_effect/card_flip_effect.h" +#include "swipe_effect/zoom_effect.h" +#include "settings/model/SettingCardModel.h" +#include "clock/GradientClockView.h" +#include "UIWatchDialFactory.h" + +namespace OHOS { +static MainViewSample *g_pMainView = nullptr; +static constexpr uint16_t MESLABLE_X_TMP = 177; +static constexpr uint16_t MESLABLE_Y_TMP = 212; +static constexpr uint16_t MESLABLE_WIDTH_TMP = 100; +static constexpr uint16_t MESLABLE_HEIGHT_TMP = 30; +static constexpr uint8_t FONT_SIZE_TMP = 24; +static constexpr uint8_t PULL_MIDDLE_VIEW_OPA = 0; +static constexpr uint8_t PAGE_ID = 2; + +struct MainViewMapper { + CardId id; + UICardPage *(MainViewSample::*func)(void); +}; + +static const MainViewMapper CardMapper[] = { + {WATCH_FACE, &MainViewSample::InitWatchFacePage}, + {COMPASS, &MainViewSample::InitCompassPage}, + {ACTIVITY, &MainViewSample::InitActivityPage}, + {MUSIC_PLAYER, &MainViewSample::InitMusicPlayerPage}, + {VIDEO_CARD1, &MainViewSample::InitVideoCardPage1}, + {VIDEO_CARD2, &MainViewSample::InitVideoCardPage2}, + {VIDEO_CARD3, &MainViewSample::InitVideoCardPage3}, +}; + +MainViewSample::MainViewSample() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::MainViewSample"); + g_pMainView = this; +} + +MainViewSample::~MainViewSample() +{ + dropDownView->ClearBackgroundBlur(); + messageView->ClearBackgroundBlur(); + + for (int32_t i = 0; i < MAX_CARD; i++) { + recordCard[i] = nullptr; + pageStatus[i] = false; + } + + if (mainSwipeGroup != nullptr) { + delete mainSwipeGroup; + mainSwipeGroup = nullptr; + } + + if (mainClockView != nullptr) { + delete mainClockView; + mainClockView = nullptr; + } + + if (activityWeekView != nullptr) { + delete activityWeekView; + activityWeekView = nullptr; + } + + if (playersView != nullptr) { + delete playersView; + playersView = nullptr; + } + + bool hasVideo = false; + if (videoCard1 != nullptr) { + hasVideo = true; + delete videoCard1; + videoCard1 = nullptr; + } + + if (videoCard2 != nullptr) { + hasVideo = true; + delete videoCard2; + videoCard2 = nullptr; + } + + if (videoCard3 != nullptr) { + hasVideo = true; + delete videoCard3; + videoCard3 = nullptr; + } + + if (hasVideo) { + ImageCacheManager::GetInstance().UnloadSingleRes(PNG_PREVIEW_CARD_VIDEO); + } + + if (dropDownView != nullptr) { + delete dropDownView; + dropDownView = nullptr; + } + + if (messageView != nullptr) { + messageView->RemoveAll(); + delete messageView; + messageView = nullptr; + } + + if (compassControlView != nullptr) { + delete compassControlView; + compassControlView = nullptr; + } + + if (callback != nullptr) { + delete callback; + callback = nullptr; + } + + g_pMainView = nullptr; +} + +MainViewSample *MainViewSample::GetInstance(void) +{ + return g_pMainView; +} + +bool MainViewSample::SetCardEffect(CardEffectID style) +{ + if (mainSwipeGroup == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup is nullptr"); + return false; + } + if (callback != nullptr) { + delete callback; + callback = nullptr; + } + + std::map> effectMap = { + {CardEffectID::UI_CARD_FLIP, []{ return new CardFlipEffect(); }}, + {CardEffectID::UI_ZOOM, []{ return new ZoomEffect(); }}, + {CardEffectID::UI_CUBE, []{ return new CubeEffect(); }}, + {CardEffectID::UI_TURN_PAGE, []{ return new TurnPageEffect(); }}, + {CardEffectID::UI_PUSH_PRESS, []{ return new PushPressEffect(); }}, + {CardEffectID::UI_WINDMILL, []{ return new WindmillEffect(); }}, + }; + auto it = effectMap.find(style); + if (it != effectMap.end()) { + callback = it->second(); + } else { + callback = new ZoomEffect(); // ZoomEffect is used by default + } + + if (callback == nullptr) { + delete mainSwipeGroup; + mainSwipeGroup = nullptr; + GRAPHIC_LOGE("Effect new fail\n"); + return false; + } + + callback->SetContainer(mainSwipeGroup); + mainSwipeGroup->RegisterSwipeCallback(callback); + return true; +} + +void MainViewSample::OnStart() +{ + mainSwipeGroup = new UICrossView(); + if (mainSwipeGroup == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail"); + return; + } + + SettingCardModel& swipeEffectModel = SettingCardModel::GetInstance(); + if (!SetCardEffect(swipeEffectModel.GetSwipeEffectStyle())) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetCardEffect fail"); + return; + } + + HorizontalViewInit(); + HorViewLoad(); + 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); + if (presenter_->IsFromSetCardView()) { + presenter_->SetFromSetCardView(false); + SwitchToCard(presenter_->GetFromCardId(), false); + } else { + SwitchToClockPage(false); + } + AddViewToRootContainer(mainSwipeGroup); +} + +bool MainViewSample::HorizontalViewInit(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); + presenter_->InitDialSettings(); + presenter_->InitCardSettings(); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); + for (int16_t i = 0; i < cardSettingNum; i++) { + for (uint8_t j = 0; j < cardMapNumber; j++) { + if (cardSettings[i] == CardMapper[j].id) { + recordCard[j] = (this->*(CardMapper[j].func))(); + if (recordCard[j] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard %d error", j); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); + break; + } + } + } + mainSwipeGroup->SetOnSwipeListener(presenter_); + mainSwipeGroup->SetOnLongPressListener(presenter_); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); + return true; +} + +void MainViewSample::HorViewLoad(void) +{ + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + for (int16_t i = 0; i < cardSettingNum; i++) { + CardId cardId = cardSettings[i]; + if (recordCard[cardId] != nullptr) { + mainSwipeGroup->HorAdd(recordCard[cardId]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", + cardId, recordCard[cardId]->GetViewIndex()); + } + } +} + +void MainViewSample::VerticalViewInit(void) +{ + dropDownView = new PullUpDownView(); + if (dropDownView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropDownView new fail"); + return; + } + dropDownView->PreLoad(); + dropDownView->SetViewId("dropDownView"); + dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + messageView = new MessageMainPage(); + if (messageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); + return; + } + messageView->PreLoad(); + messageView->SetPosition(0, 0); + messageView->SetWidth(Screen::GetInstance().GetWidth()); + messageView->SetHeight(Screen::GetInstance().GetHeight()); + messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + messageView->SetViewId("messageView"); + messageView->SetTouchable(true); + messageView->SetIntercept(true); +} + +void MainViewSample::VertViewLoad(void) +{ + mainSwipeGroup->VerAdd(dropDownView, UICrossView::VPage::UP_PAGE); + mainSwipeGroup->VerAdd(messageView, UICrossView::VPage::DOWN_PAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::PullViewLoad::Pull View Load complete"); +} + +void MainViewSample::OnStop() +{ + messageView->RemoveAll(); + return; +} + +UICardPage *MainViewSample::InitWatchOffDial(DialSetting &setting) +{ + DialViewGroup *dial = new DialViewGroup(); + dial->SetDial(setting.dialFullName); + return dial; +} + +UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) +{ + return dynamic_cast(UIWatchDialFactory::GetInstance().CreateNormalDial(setting.dialId)); +} + +UICardPage *MainViewSample::InitWatchFacePage(void) +{ + DialSetting &setting = presenter_->GetDialSetting(); + if (setting.dialFlag) { + mainClockView = InitWatchOffDial(setting); + } else { + mainClockView = InitWatchDial(setting); + } + + if (mainClockView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); + return nullptr; + } + return mainClockView; +} + +UICardPage *MainViewSample::InitActivityPage(void) +{ + activityWeekView = new ActivityWeekView(); + if (activityWeekView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "activityWeekView new fail"); + return nullptr; + } + return activityWeekView; +} + +UICardPage *MainViewSample::InitCompassPage(void) +{ + compassControlView = new CompassControlView(); + if (compassControlView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassControlView new fail"); + return nullptr; + } + return compassControlView; +} + +UICardPage *MainViewSample::InitMusicPlayerPage(void) +{ + playersView = new PlayersView(); + if (playersView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail"); + return nullptr; + } + return playersView; +} + +UICardPage *MainViewSample::InitVideoCardPage1(void) +{ + videoCard1 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); + return videoCard1; +} + +UICardPage *MainViewSample::InitVideoCardPage2(void) +{ + videoCard2 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); + return videoCard2; +} + +UICardPage *MainViewSample::InitVideoCardPage3(void) +{ + videoCard3 = dynamic_cast(InitVideoCardPage(APP_VIDEO_PATH"/noaudio_05.mp4", PNG_PREVIEW_CARD_VIDEO)); + return videoCard3; +} + +UICardPage *MainViewSample::InitVideoCardPage(const std::string &video, const std::string &preview) +{ + VideoCard *page = new VideoCard; + if (page == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "videocard new fail"); + return nullptr; + } + page->SetFilePath(video); + page->SetPreviewFile(preview); + return page; +} + +void MainViewSample::SetPage(int16_t page, bool loadAdjacent) +{ + if (mainSwipeGroup != nullptr) { + mainSwipeGroup->SetHorCurrentPage(page, loadAdjacent); + } + + if (presenter_ != nullptr) { + CardId *cardSettings = presenter_->GetCardSettings(); + /* page 与CardId 没有对应关系,需要一次转换 */ + CardId id = MAX_CARD; + for (uint8_t i = 0; i < presenter_->GetCardSettingCount(); ++i) { + if (cardSettings[i] < MAX_CARD && recordCard[cardSettings[i]] != nullptr && + recordCard[cardSettings[i]]->GetViewIndex() == page) { + id = cardSettings[i]; + } + } + presenter_->SetTaskPeroid(id); + } +} + +void MainViewSample::ReloadWatchFace() +{ + if (mainSwipeGroup == nullptr) { + return; + } + mainSwipeGroup->Remove(mainClockView, UISwipeView::HORIZONTAL); + + delete mainClockView; + mainClockView = nullptr; + recordCard[WATCH_FACE] = InitWatchFacePage(); + if (recordCard[WATCH_FACE] == nullptr) { + GRAPHIC_LOGE("failed to reload main clock"); + return; + } + mainSwipeGroup->HorInsert(nullptr, mainClockView); + + SwitchToCard(WATCH_FACE); + Draw(); +} + +bool MainViewSample::IsMainClockPage(void) +{ + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 1) { // 0: horizontal; 1: vertical + return true; + } else { + return false; + } +} + +CardId MainViewSample::GetHorCurrentCard() const +{ + CardId *cardSettings = presenter_->GetCardSettings(); + int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical + /* pageId 与CardId 没有对应关系,需要一次转换 */ + for (uint8_t i = 0; i < presenter_->GetCardSettingCount(); ++i) { + if (cardSettings[i] < MAX_CARD && recordCard[cardSettings[i]] != nullptr && + recordCard[cardSettings[i]]->GetViewIndex() == pageId) { + return cardSettings[i]; + } + } + return MAX_CARD; +} + +void MainViewSample::GetVerCurrentCard() const +{ + int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::VERTICAL); + if (pageId == PAGE_ID) { + MessageModel::GetInstance().SetTime(); + std::vector &itemInfo = MessageModel::GetInstance().GetMsgListItems(); + MessageMainPage::GetInstance()->RefreshMsgList(itemInfo); + } +} + +void MainViewSample::SwitchToCard(uint8_t cardId, bool loadAdjacent) +{ + if ((cardId < MAX_CARD) && (recordCard[cardId] != nullptr)) { + SetPage(recordCard[cardId]->GetViewIndex(), loadAdjacent); + } else { + SwitchToClockPage(loadAdjacent); + } +} +} // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageDetailsGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageDetailsGroup.cpp new file mode 100644 index 000000000..9d53fcb40 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageDetailsGroup.cpp @@ -0,0 +1,198 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageDetailsGroup + * Created: 2025-06 + */ + +#include +#include "common/image_cache_manager.h" +#include "NativeAbility.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "main/MessageDetailsGroup.h" + +namespace OHOS { +static constexpr int16_t MESSAGE_ICON_X = 130; +static constexpr int16_t MESSAGE_ICON_Y = 50; +static constexpr int16_t MESSAGE_ICON_SIZE = 40; +static constexpr int16_t MESSAGE_TITLES_X = 170; +static constexpr int16_t MESSAGE_TITLES_Y = 40; +static constexpr int16_t MESSAGE_TITLES_WIDTH = 160; +static constexpr int16_t MESSAGE_TITLES_HEIGHT = 53; +static constexpr int16_t MESSAGE_TITLES_FONT_SIZE = 38; +static constexpr int16_t MESSAGE_CONTACTS_X = 15; +static constexpr int16_t MESSAGE_CONTACTS_Y = 138; +static constexpr int16_t MESSAGE_CONTACTS_WIDTH = 370; +static constexpr int16_t MESSAGE_CONTACTS_HEIGHT = 50; +static constexpr int16_t MESSAGE_CONTACTA_FONT_SIZE = 36; +static constexpr int16_t MESSAGE_CONTENTS_X = 15; +static constexpr int16_t MESSAGE_CONTENTS_Y = 201; +static constexpr int16_t MESSAGE_CONTENTS_WIDTH = 370; +static constexpr int16_t MESSAGE_CONTENTS_HEIGHT = 200; +static constexpr int16_t MESSAGE_CONTENTA_FONT_SIZE = 36; +static constexpr int16_t MESSAGE_TIME_X = 77; +static constexpr int16_t MESSAGE_TIME_Y = 385; +static constexpr int16_t MESSAGE_TIME_WIDTH = 300; +static constexpr int16_t MESSAGE_TIME_HEIGHT = 40; +static constexpr int16_t MESSAGE_TIME_FONT_SIZE = 36; +constexpr int16_t PAGE_WIDTH = 454; + +DetailsGroup::DetailsGroup() +{ + InitDetailsPage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DetailsGroup::DetailsGroup"); +} + +DetailsGroup::~DetailsGroup() +{ + RemoveAll(); + if (detailsMsgIcon_ != nullptr) { + delete detailsMsgIcon_; + detailsMsgIcon_ = nullptr; + } + if (detailsMsgTitle_ != nullptr) { + delete detailsMsgTitle_; + detailsMsgTitle_ = nullptr; + } + if (detailsMsgContacts_ != nullptr) { + delete detailsMsgContacts_; + detailsMsgContacts_ = nullptr; + } + if (detailsMsgContents_ != nullptr) { + delete detailsMsgContents_; + detailsMsgContents_ = nullptr; + } + if (detailsMsgTime_ != nullptr) { + delete detailsMsgTime_; + detailsMsgTime_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DetailsGroup::~DetailsGroup"); +} + +void DetailsGroup::InitDetailsPage() +{ + SetPosition(0, 0, HORIZONTAL_RESOLUTION, HORIZONTAL_RESOLUTION); + SetViewId("detail"); + SetThrowDrag(true); + SetScrollBlankSize(31); + + detailsMsgIcon_ = new UIImageView; + if (detailsMsgIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsMsgIcon_ fail"); + return; + } + detailsMsgIcon_->SetPosition(MESSAGE_ICON_X, MESSAGE_ICON_Y); + + detailsMsgTitle_ = new UILabel; + if (detailsMsgTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsMsgTitle_ fail"); + return; + } + detailsMsgTitle_->SetPosition(MESSAGE_TITLES_X, MESSAGE_TITLES_Y, MESSAGE_TITLES_WIDTH, MESSAGE_TITLES_HEIGHT); + detailsMsgTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, MESSAGE_TITLES_FONT_SIZE); + detailsMsgTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + detailsMsgTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + detailsMsgTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + detailsMsgTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + detailsMsgTitle_->SetVisible(true); + + detailsMsgContacts_ = new UILabel; + if (detailsMsgContacts_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsMsgContacts_ fail"); + return; + } + detailsMsgContacts_->SetPosition(MESSAGE_CONTACTS_X, MESSAGE_CONTACTS_Y, + MESSAGE_CONTACTS_WIDTH, MESSAGE_CONTACTS_HEIGHT); + detailsMsgContacts_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MESSAGE_CONTACTA_FONT_SIZE); + detailsMsgContacts_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + detailsMsgContacts_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + detailsMsgContacts_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + detailsMsgContacts_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + detailsMsgContacts_->SetVisible(true); + + detailsMsgContents_ = new UILabel; + if (detailsMsgContents_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsMsgContents_ fail"); + return; + } + detailsMsgContents_->SetPosition(MESSAGE_CONTENTS_X, MESSAGE_CONTENTS_Y, + MESSAGE_CONTENTS_WIDTH, MESSAGE_CONTENTS_HEIGHT); + detailsMsgContents_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MESSAGE_CONTENTA_FONT_SIZE); + detailsMsgContents_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); + detailsMsgContents_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + detailsMsgContents_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + detailsMsgContents_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + detailsMsgContents_->SetVisible(true); + + detailsMsgTime_ = new UILabel; + if (detailsMsgTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsMsgTime_ fail"); + return; + } + detailsMsgTime_->SetPosition(MESSAGE_TIME_X, MESSAGE_TIME_Y, MESSAGE_TIME_WIDTH, MESSAGE_TIME_HEIGHT); + detailsMsgTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MESSAGE_TIME_FONT_SIZE); + detailsMsgTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + detailsMsgTime_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + detailsMsgTime_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + detailsMsgTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + detailsMsgTime_->SetVisible(true); + + Add(detailsMsgIcon_); + Add(detailsMsgTitle_); + Add(detailsMsgContacts_); + Add(detailsMsgContents_); + Add(detailsMsgTime_); +} + +void DetailsGroup::RefreshNotify() +{ + detailsMsgTitle_->SetText(detailsMsg_.appName.c_str()); + if (strcmp(detailsMsg_.appName.c_str(), "微信") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WX); + } else if (strcmp(detailsMsg_.appName.c_str(), "QQ") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_QQ); + } else if (strcmp(detailsMsg_.appName.c_str(), "抖音") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DY); + } else if (strcmp(detailsMsg_.appName.c_str(), "日历") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_CALENDAR); + } else if (strcmp(detailsMsg_.appName.c_str(), "信息") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(detailsMsg_.appName.c_str(), "短信") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(detailsMsg_.appName.c_str(), "今日头条") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_TOUTIAO); + } else if (strcmp(detailsMsg_.appName.c_str(), "微博") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WB); + } else if (strcmp(detailsMsg_.appName.c_str(), "小红书") == 0) { + LOADIMG::LoadImageViewImg(detailsMsgIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_XHS); + } + int controlOffset = 10; + int cut = 2; + int posX = (PAGE_WIDTH - detailsMsgTitle_->GetTextWidth() - detailsMsgIcon_->GetWidth() - controlOffset) / cut; + detailsMsgIcon_->SetX(posX); + detailsMsgTitle_->SetWidth(detailsMsgTitle_->GetTextWidth()); + detailsMsgTitle_->SetX(posX + detailsMsgIcon_->GetWidth() + controlOffset); + + std::string str = detailsMsg_.appContact + ":"; + detailsMsgContacts_->SetText(str.c_str()); + if (detailsMsgContacts_->GetTextWidth() > MESSAGE_CONTACTS_WIDTH) { + detailsMsgContacts_->SetWidth(MESSAGE_CONTACTS_WIDTH); + } else { + detailsMsgContacts_->SetWidth(detailsMsgContacts_->GetTextWidth()); + } + posX = (PAGE_WIDTH - detailsMsgContacts_->GetWidth()) / cut; + detailsMsgContacts_->SetX(posX); + + detailsMsgContents_->SetText(detailsMsg_.appContents.c_str()); + int height = detailsMsgContents_->GetTextHeight(); + detailsMsgContents_->SetHeight(height); + posX = (PAGE_WIDTH - detailsMsgContents_->GetWidth()) / cut; + detailsMsgContents_->SetX(posX); + + detailsMsgTime_->SetText(detailsMsg_.time.c_str()); + int posY = detailsMsgContents_->GetY() + height + (cut * controlOffset); + detailsMsgTime_->SetY(posY); + posX = (PAGE_WIDTH - detailsMsgTime_->GetWidth()) / cut; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageItemView.cpp index db7e81e5d..8f05bf013 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageItemView.cpp @@ -1,96 +1,242 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MessageItemView.cpp - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageItemView + * Create: 2025-06-29 */ #include "wearable_log.h" +#include "ui_resource_message.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" +#include "main/MessageMainPage.h" #include "main/MessageItemView.h" namespace OHOS { - static constexpr int16 SETTING_ICON_X = 20; - static constexpr int16 NUM_22 = 22; - static constexpr int16_t SETTING_ITEM_BUTTON_HEIGHT = 80; - static constexpr int16_t SETTING_ITEM_LABEL_WIDTH = 155; - static constexpr int16_t SETTING_ITEM_LABEL_HEIGHT = 100; - static constexpr int16 SETTING_ITEM_FONT_SIZE = 35; - static constexpr int16_t SETTINGS_RESIZE_SIZE = 100; - static constexpr int16_t SETTING_SICON_Y = 15; - static constexpr int16 NUMS_2 = 2; - static constexpr int16 NUMS_50 = 50; - - MessageItemView::MessageItemView() - { - SetPosition(0, 0, HORIZONTAL_RESOLUTION, 200); - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - SetTouchable(true); - SetUpChild(); - - Add(&sback); - Add(&sLabel_1); - Add(&sIcon); - Add(&sLabel_2); - Add(&sLabel_3); - } +static constexpr int16_t MESSAGE_ITEM_GROUP_X = 30; +static constexpr int16_t MESSAGE_ITEM_GROUP_EX = -100; +static constexpr int16_t MESSAGE_ITEM_GROUP_MOVEX = 100; +static constexpr int16_t MESSAGE_ITEM_GROUP_WIDTH = 454; +static constexpr int16_t MESSAGE_ITEM_GROUP_HEIGHT = 130; +static constexpr int16_t MESSAGE_ITEM_DELETE_X = 283; +static constexpr int16_t MESSAGE_ITEM_DELETE_SIZE = 36; +static constexpr int16_t MESSAGE_ITEM_APPNAME_X = 60; +static constexpr int16_t MESSAGE_ITEM_APPNAME_Y = 15; +static constexpr int16_t MESSAGE_ITEM_APPNAME_WIDTH = 131; +static constexpr int16_t MESSAGE_ITEM_APPNAME_HEIGHT = 45; +static constexpr int16_t ITEM_APPNAME_FONT_SIZE = 32; +static constexpr int16_t MESSAGE_ITEM_APPICON_X = 10; +static constexpr int16_t MESSAGE_ITEM_APPICON_Y = 15; +static constexpr int16_t MESSAGE_ITEM_APPICON_SIZE = 30; +static constexpr int16_t MESSAGE_ITEM_CONTACT_X = 10; +static constexpr int16_t MESSAGE_ITEM_CONTACT_Y = 73; +static constexpr int16_t MESSAGE_ITEM_CONTACT_WIDTH = 95; +static constexpr int16_t MESSAGE_ITEM_CONTACT_HEIGHT = 42; +static constexpr int16_t ITEM_CONTACT_FONT_SIZE = 30; +static constexpr int16_t MESSAGE_ITEM_INFOR_X = 110; +static constexpr int16_t MESSAGE_ITEM_INFOR_Y = 73; +static constexpr int16_t MESSAGE_ITEM_INFOR_WIDTH = 156; +static constexpr int16_t MESSAGE_ITEM_INFOR_HEIGHT = 42; +static constexpr int16_t ITEM_INFOR_FONT_SIZE = 30; +static constexpr int16_t MESSAGE_ITEM_TIME_X = 270; +static constexpr int16_t MESSAGE_ITEM_TIME_Y = 75; +static constexpr int16_t MESSAGE_ITEM_TIME_WIDTH = 100; +static constexpr int16_t MESSAGE_ITEM_TIME_HEIGHT = 36; +static constexpr int16_t ITEM_TIME_FONT_SIZE = 26; +static constexpr char *DELETE_BUTTON = "deleteButton"; + +MessageItemView::MessageItemView() +{ + appName_.SetPosition(MESSAGE_ITEM_APPNAME_X, MESSAGE_ITEM_APPNAME_Y, + MESSAGE_ITEM_APPNAME_WIDTH, MESSAGE_ITEM_APPNAME_HEIGHT); + appName_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_APPNAME_FONT_SIZE); + appName_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + appName_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + appName_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + appName_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + appIcon_.SetPosition(MESSAGE_ITEM_APPICON_X, MESSAGE_ITEM_APPICON_Y, + MESSAGE_ITEM_APPICON_SIZE, MESSAGE_ITEM_APPICON_SIZE); + appIcon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + appContact_.SetPosition(MESSAGE_ITEM_CONTACT_X, MESSAGE_ITEM_CONTACT_Y, + MESSAGE_ITEM_CONTACT_WIDTH, MESSAGE_ITEM_CONTACT_HEIGHT); + appContact_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_CONTACT_FONT_SIZE); + appContact_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + appContact_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + appContact_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + appContact_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + appContents_.SetPosition(MESSAGE_ITEM_INFOR_X, MESSAGE_ITEM_INFOR_Y, + MESSAGE_ITEM_INFOR_WIDTH, MESSAGE_ITEM_INFOR_HEIGHT); + appContents_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_INFOR_FONT_SIZE); + appContents_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + appContents_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + appContents_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + appContents_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + msgTime_.SetPosition(MESSAGE_ITEM_TIME_X, MESSAGE_ITEM_TIME_Y, + MESSAGE_ITEM_TIME_WIDTH, MESSAGE_ITEM_TIME_HEIGHT); + msgTime_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_TIME_FONT_SIZE); + msgTime_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + msgTime_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + msgTime_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + msgTime_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + LOADIMG::LoadImageViewImg(&bgImg_, MESSAGE_IMAGE, IMAGE_MESSAGE_BG); + + group_.SetPosition(MESSAGE_ITEM_GROUP_X, 0, MESSAGE_ITEM_GROUP_WIDTH, MESSAGE_ITEM_GROUP_HEIGHT); + group_.SetViewId("message"); + group_.SetDraggable(true); + group_.SetTouchable(true); + + deleteImg_.SetPosition(MESSAGE_ITEM_DELETE_X, 0, MESSAGE_ITEM_DELETE_SIZE, MESSAGE_ITEM_DELETE_SIZE); + LOADIMG::LoadImageViewImg(&deleteImg_, MESSAGE_IMAGE, IMAGE_MESSAGE_SINGLE_DELETE); + deleteImg_.SetViewId(DELETE_BUTTON); + deleteImg_.SetTouchable(true); + deleteImg_.SetOnClickListener(this); - MessageItemView::~MessageItemView() - { - Remove(&sIcon); - Remove(&sLabel_1); - Remove(&sLabel_2); - Remove(&sLabel_3); - Remove(&sback); + group_.Add(&bgImg_); + group_.Add(&appName_); + group_.Add(&appIcon_); + group_.Add(&appContact_); + group_.Add(&appContents_); + group_.Add(&msgTime_); + Add(&group_); + Add(&deleteImg_); + +} + +MessageItemView::~MessageItemView() +{ + group_.RemoveAll(); + Remove(&appIcon_); + Remove(&appName_); + Remove(&appContact_); + Remove(&appContents_); + Remove(&bgImg_); + Remove(&msgTime_); + Remove(&group_); + Remove(&deleteImg_); +} + +void MessageItemView::SetItemInfo(const MessageItem itemInfo) +{ + msgItemInfo_ = itemInfo; + appName_.SetText(itemInfo.appName.c_str()); + appContact_.SetText(itemInfo.appContact.c_str()); + appContents_.SetText(itemInfo.appContents.c_str()); + msgTime_.SetText(itemInfo.time.c_str()); + // 获取label1的内容更改图标 + if (strcmp(msgItemInfo_.appName.c_str(), "微信") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WX); + } else if (strcmp(msgItemInfo_.appName.c_str(), "QQ") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_QQ); + } else if (strcmp(msgItemInfo_.appName.c_str(), "抖音") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DY); + } else if (strcmp(msgItemInfo_.appName.c_str(), "日历") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_CALENDAR); + } else if (strcmp(msgItemInfo_.appName.c_str(), "信息") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(msgItemInfo_.appName.c_str(), "短信") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(msgItemInfo_.appName.c_str(), "今日头条") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_TOUTIAO); + } else if (strcmp(msgItemInfo_.appName.c_str(), "微博") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WB); + } else if (strcmp(msgItemInfo_.appName.c_str(), "小红书") == 0) { + LOADIMG::LoadImageViewImg(&appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_XHS); } + if (msgItemInfo_.status == false) { + group_.SetPosition(MESSAGE_ITEM_GROUP_X, 0, MESSAGE_ITEM_GROUP_WIDTH, MESSAGE_ITEM_GROUP_HEIGHT); + } else { + group_.SetPosition(MESSAGE_ITEM_GROUP_EX, 0, MESSAGE_ITEM_GROUP_WIDTH, MESSAGE_ITEM_GROUP_HEIGHT); + } + deleteImg_.SetVisible(msgItemInfo_.status); +} + +MessageItem MessageItemView::GetItem() +{ + return msgItemInfo_; +} - void MessageItemView::SetItemInfo(const MessageItem itemInfo) - { - sItemInfo = itemInfo; - sLabel_1.SetText(itemInfo.label_1.c_str()); - sIcon.SetSrc(itemInfo.icon.c_str()); - sLabel_2.SetText(itemInfo.label_2.c_str()); - sLabel_3.SetText(itemInfo.label_3.c_str()); +void MessageItemView::SetIndex(uint16_t index) +{ + itemIndex_ = index; +} + +uint16_t MessageItemView ::GetIndex() +{ + return itemIndex_; +} + +bool MessageItemView::OnDragStartEvent(const DragEvent& event) +{ + return false; +} + +bool MessageItemView::OnDragEvent(const DragEvent& event) +{ + // 检查拖拽方向是否为左到右,并且X坐标在允许范围内(0到100之间) + if ((event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT && + (((0 - group_.GetX()) <= MESSAGE_ITEM_GROUP_MOVEX)))) { + int pox = group_.GetX() + event.GetDeltaX(); + group_.SetX(pox); + group_.Invalidate(); + Invalidate(); + return true; + } else if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + group_.SetX(MESSAGE_ITEM_GROUP_X); + group_.Invalidate(); + deleteImg_.SetVisible(false); + return true; } + return false; +} - void MessageItemView::SetUpChild() - { - sLabel_1.SetPosition(50, 10); - sLabel_1.Resize(SETTING_ITEM_LABEL_WIDTH, 50); - sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); - sLabel_1.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel_1.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel_1.SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); - sLabel_1.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - sIcon.SetPosition(15, SETTING_SICON_Y); - sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - - sLabel_2.SetPosition(15, 78); - sLabel_2.Resize(100, 50); - sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); - sLabel_2.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel_2.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel_2.SetStyle(STYLE_BACKGROUND_COLOR, Color::Orange().full); - sLabel_2.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - sLabel_3.SetPosition(150, 78, 100, 50); - sLabel_3.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); - sLabel_3.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel_3.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel_3.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel_3.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - sLabel_3.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - sback.SetPosition(0, 0, 450, 180); - sback.SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); - sback.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); +bool MessageItemView::OnDragEndEvent(const DragEvent& event) +{ + // 超出一定距离 显示X按钮 + if ((0 - group_.GetX()) >= MESSAGE_ITEM_GROUP_MOVEX) { + group_.SetX(MESSAGE_ITEM_GROUP_EX); + group_.Invalidate(); + deleteImg_.SetVisible(true); + msgItemInfo_.status = true; + SetIndex(msgItemInfo_.index); + // 恢复其它item位置 + UpdateItemStatus(); + Invalidate(); + return true; + } else { + group_.SetPosition(MESSAGE_ITEM_GROUP_X, 0, + MESSAGE_ITEM_GROUP_WIDTH, MESSAGE_ITEM_GROUP_HEIGHT); + group_.Invalidate(); + } + return false; +} +bool MessageItemView::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), DELETE_BUTTON) == 0) { + deleteImg_.SetVisible(false); + // 单项删除 + MessageModel::GetInstance().DeleteItem(msgItemInfo_); + return true; } + return false; +} -} \ No newline at end of file +// 恢复item的位置 +void MessageItemView::UpdateItemStatus() +{ + std::vector &vecMsg = MessageModel::GetInstance().GetMsgListItems(); + for (int i = 0; i < vecMsg.size(); ++i) { + if (vecMsg[i].index == itemIndex_) { + vecMsg[i].status = true; + } else { + vecMsg[i].status = false; + } + } + MessageMainPage::GetInstance()->RefreshMsgList(vecMsg); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageMainPage.cpp new file mode 100644 index 000000000..d90e88634 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageMainPage.cpp @@ -0,0 +1,485 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MessageMainPage + * Create: 2025-06-29 + */ + +#include "wearable_log.h" +#include "common/screen.h" +#include "ui_resource_image.h" +#include "ui_resource_message.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" +#include "UiConfig.h" +#include "main/MainPresenterSample.h" +#include "main/MessageMainPage.h" + +namespace OHOS { + +static constexpr int16_t MESSAGE_TITLE_X = 97; +static constexpr int16_t MESSAGE_TITLE_Y = 31; +static constexpr int16_t MESSAGE_TITLE_WIDTH = 260; +static constexpr int16_t MESSAGE_TITLE_HEIGHT = 53; +static constexpr int16_t MESSAGE_TITLE_FONT_SIZE = 38; +static constexpr int16_t NOTICE_IMAGE_X = 191; +static constexpr int16_t NOTICE_IMAGE_Y = 361; +static constexpr int16_t NOTICE_IMAGE_SIZE = 85; +static constexpr int16_t MESAGE_LIST_X = 5; +static constexpr int16_t MESAGE_LIST_Y = 100; +static constexpr int16_t MESSAGE_LIST_WIDTH = 454; +static constexpr int16_t MESSAGE_LIST_HEIGHT = 354; +static constexpr int16_t MESSAGE_SCORLL_BAR_X = 222; +static constexpr int16_t MESSAGE_SCORLL_BAR_Y = 129; +static constexpr int16_t MESSAGE_SCORLL_BLANK_SIZE = 70; +static constexpr int16_t MESSAGE_DELETE_REMINDER_X = 21; +static constexpr int16_t MESSAGE_DELETE_REMINDER_Y = 158; +static constexpr int16_t MESSAGE_DELETE_REMINDER_WIDTH = 424; +static constexpr int16_t MESSAGE_DELETE_REMINDER_HEIGHT = 50; +static constexpr int16_t DELETE_REMINDER_FONT_SIZE = 36; +static constexpr int16_t MESSAGE_DELETE_CONFIRM_X = 260; +static constexpr int16_t MESSAGE_DELETE_CONFIRM_Y = 300; +static constexpr int16_t MESSAGE_DELETE_CONFIRM_SIZE = 85; +static constexpr int16_t MESSAGE_DELETE_CANCEL_X = 110; +static constexpr int16_t MESSAGE_DELETE_CANCEL_Y = 300; +static constexpr int16_t MESSAGE_DELETE_CANCEL_SIZE = 85; +static constexpr int16_t NOMESSAGE_TITLE_X = 45; +static constexpr int16_t NOMESSAGE_TITLE_Y = 341; +static constexpr int16_t NOMESSAGE_TITLE_WIDTH = 364; +static constexpr int16_t NOMESSAGE_TITLE_HEIGHT = 50; +static constexpr int16_t NOMESSAGE_TITLE_FONT_SIZE = 36; +static constexpr int16_t NOMESSAGE_ICON_X = 154; +static constexpr int16_t NOMESSAGE_ICON_Y = 154; +static constexpr int16_t NOMESSAGE_ICON_SIZE = 146; +static constexpr int16_t MOVE_DISTANCE = 30; +static constexpr int16_t MESSAGE_ITEM_HEIGHT = 130; +static constexpr char *DELETE_BUTTON = "deleteButton"; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; +static constexpr char *CANCEL_BUTTON = "cancelButton"; + +static MessageMainPage *g_pMessageMainView = nullptr; + +MessageMainPage::MessageMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainPage::MessageMainPage"); + g_pMessageMainView = this; +} + +MessageMainPage::~MessageMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainPage::~MessageMainPage"); + RemoveAll(); + if (detailsGroup_ != nullptr) { + delete detailsGroup_; + detailsGroup_ = nullptr; + } + if (deleteGroup_ != nullptr) { + deleteGroup_->RemoveAll(); + delete deleteGroup_; + deleteGroup_ = nullptr; + } + if (noMsgLable_ != nullptr) { + delete noMsgLable_; + noMsgLable_ = nullptr; + } + if (msgLable_ != nullptr) { + delete msgLable_; + msgLable_ = nullptr; + } + if (noMsgImage_ != nullptr) { + delete noMsgImage_; + noMsgImage_ = nullptr; + } + if (deleteTips_ != nullptr) { + delete deleteTips_; + deleteTips_ = nullptr; + } + if (confirm_ != nullptr) { + delete confirm_; + confirm_ = nullptr; + } + if (cancel_ != nullptr) { + delete cancel_; + cancel_ = nullptr; + } + if (deleteImage_ != nullptr) { + delete deleteImage_; + deleteImage_ = nullptr; + } + if (msgList_ != nullptr) { + delete msgList_; + msgList_ = nullptr; + } + + g_pMessageMainView = nullptr; + ImageCacheManager::GetInstance().UnloadAllInMultiRes(MESSAGE_IMAGE); + MessageModel::GetInstance().SetViewStatus(false); +} + +MessageMainPage *MessageMainPage::GetInstance(void) +{ + return g_pMessageMainView; +} + +bool MessageMainPage::InitView() +{ + msgLable_ = new UILabel(); + if (msgLable_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "msgLable_ new fail"); + return false; + } + msgLable_->SetPosition(MESSAGE_TITLE_X, MESSAGE_TITLE_Y, MESSAGE_TITLE_WIDTH, MESSAGE_TITLE_HEIGHT); + msgLable_->SetText("通知"); + msgLable_->SetAlign(TEXT_ALIGNMENT_CENTER); + msgLable_->SetFont(BOLD_VECTOR_FONT_FILENAME, MESSAGE_TITLE_FONT_SIZE); + msgLable_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + msgLable_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + + // 删除图标 + deleteImage_ = new UIImageView(); + if (deleteImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new deleteImage_ fail"); + return false; + } + deleteImage_->SetPosition(NOTICE_IMAGE_X, NOTICE_IMAGE_Y, NOTICE_IMAGE_SIZE, NOTICE_IMAGE_SIZE); + LOADIMG::LoadImageViewImg(deleteImage_, MESSAGE_IMAGE, IMAGE_MESSAGE_DELETE); + deleteImage_->SetViewId(DELETE_BUTTON); + deleteImage_->SetTouchable(true); + deleteImage_->SetOnClickListener(this); + InitMsgList(); + InitScrollData(); + Add(msgLable_); + Add(deleteImage_); + return true; +} + +void MessageMainPage::PreLoad(void) +{ + if (! MessageModel::GetInstance().GetViewStatus()) { + DeleteView(); + NoNotify(); + InitView(); + const std::vector &itemInfo = MessageModel::GetInstance().GetMsgListItems(); + if (itemInfo.size() == 0) { + msgLable_->SetVisible(true); + deleteImage_->SetVisible(false); + msgList_->SetVisible(false); + deleteGroup_->SetVisible(false); + noMsgLable_->SetVisible(true); + noMsgImage_->SetVisible(true); + } else { + msgLable_->SetVisible(true); + deleteImage_->SetVisible(true); + msgList_->SetVisible(true); + deleteGroup_->SetVisible(false); + noMsgLable_->SetVisible(false); + noMsgImage_->SetVisible(false); + } + MessageModel::GetInstance().SetViewStatus(true); + } +} + +void MessageMainPage::InitMsgList(void) +{ + msgList_ = new UISimpleList(); + if (msgList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new msgList_ is nullptr"); + return; + } + msgList_->SetPosition(MESAGE_LIST_X, MESAGE_LIST_Y, MESSAGE_LIST_WIDTH, MESSAGE_LIST_HEIGHT); + msgList_->SetScrollBlankSize(MESSAGE_SCORLL_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + msgList_->SetDraggable(true); + msgList_->SetThrowDrag(true); + msgList_->EnableAutoAlign(true); + msgList_->SetYScrollBarVisible(true); + Point scorllBarPoint = {MESSAGE_SCORLL_BAR_X, MESSAGE_SCORLL_BAR_Y}; + msgList_->SetScrollBarCenter(scorllBarPoint); + msgList_->SetOnDragListener(this); + Add(msgList_); +} + +void MessageMainPage::ConfirmDelete(void) +{ + if (deleteImage_->IsVisible()) { + deleteImage_->SetVisible(false); + } + if (msgLable_->IsVisible()) { + msgLable_->SetVisible(false); + } + if (msgList_->IsVisible()) { + msgList_->SetVisible(false); + } + if (noMsgLable_->IsVisible()) { + noMsgLable_->SetVisible(false); + } + if (noMsgImage_->IsVisible()) { + noMsgImage_->SetVisible(false); + } + deleteGroup_->SetVisible(true); +} + +void MessageMainPage::NewNotify(void) +{ + if (noMsgLable_->IsVisible()) { + noMsgLable_->SetVisible(false); + } + if (noMsgImage_->IsVisible()) { + noMsgImage_->SetVisible(false); + } + if (! deleteImage_->IsVisible()) { + deleteImage_->SetVisible(true); + } + if (! msgLable_->IsVisible()) { + msgLable_->SetVisible(true); + } + if (! msgList_->IsVisible()) { + msgList_->SetVisible(true); + } +} + +void MessageMainPage::DeleteView(void) +{ + // deleteGroup_这个页面会多次创建,防止new多次 加入判空处理 + if (deleteGroup_ == nullptr) { + deleteGroup_ = new UIScrollView; + if (deleteGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new deleteGroup_ is nullptr"); + return; + } + } + deleteGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, HORIZONTAL_RESOLUTION); + // 标题 + deleteTips_ = new UILabel(); + if (deleteTips_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new deleteTips_ is nullptr"); + return; + } + deleteTips_->SetPosition(MESSAGE_DELETE_REMINDER_X, MESSAGE_DELETE_REMINDER_Y, + MESSAGE_DELETE_REMINDER_WIDTH, MESSAGE_DELETE_REMINDER_HEIGHT); + deleteTips_->SetText("是否清空消息通知?"); + deleteTips_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DELETE_REMINDER_FONT_SIZE); + deleteTips_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deleteTips_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + + // 确认按钮 + confirm_ = new UIImageView(); + if (confirm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new confirm_ is nullptr"); + return; + } + confirm_->SetPosition(MESSAGE_DELETE_CONFIRM_X, MESSAGE_DELETE_CONFIRM_Y, + MESSAGE_DELETE_CONFIRM_SIZE, MESSAGE_DELETE_CONFIRM_SIZE); + LOADIMG::LoadImageViewImg(confirm_, MESSAGE_IMAGE, IMAGE_MESSAGE_CONFIRM); + confirm_->SetViewId(CONFIRM_BUTTON); + confirm_->SetTouchable(true); + confirm_->SetOnClickListener(this); + + // 取消按钮 + cancel_ = new UIImageView(); + if (cancel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new cancel_ is nullptr"); + return; + } + cancel_->SetPosition(MESSAGE_DELETE_CANCEL_X, MESSAGE_DELETE_CANCEL_Y, + MESSAGE_DELETE_CANCEL_SIZE, MESSAGE_DELETE_CANCEL_SIZE); + LOADIMG::LoadImageViewImg(cancel_, MESSAGE_IMAGE, IMAGE_MESSAGE_CANCEL); + cancel_->SetViewId(CANCEL_BUTTON); + cancel_->SetTouchable(true); + cancel_->SetOnClickListener(this); + + deleteGroup_->Add(deleteTips_); + deleteGroup_->Add(confirm_); + deleteGroup_->Add(cancel_); + Add(deleteGroup_); +} + +void MessageMainPage::VerticalViewInits(void) +{ + deleteGroup_->SetVisible(false); + if (! noMsgLable_->IsVisible()) { + noMsgLable_->SetVisible(true); + } + if (! noMsgImage_->IsVisible()) { + noMsgImage_->SetVisible(true); + } + if (! msgLable_->IsVisible()) { + msgLable_->SetVisible(true); + } +} + +void MessageMainPage::NoNotify(void) +{ + noMsgLable_ = new UILabel(); + if (noMsgLable_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new noMsgLable_ fail"); + return; + } + noMsgLable_->SetPosition(NOMESSAGE_TITLE_X, NOMESSAGE_TITLE_Y, + NOMESSAGE_TITLE_WIDTH, NOMESSAGE_TITLE_HEIGHT); + noMsgLable_->SetText("没有通知"); + noMsgLable_->SetAlign(TEXT_ALIGNMENT_CENTER); + noMsgLable_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, NOMESSAGE_TITLE_FONT_SIZE); + noMsgLable_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + + noMsgImage_ = new UIImageView(); + if (noMsgImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new noMsgImage_ is nullptr"); + return; + } + noMsgImage_->SetPosition(NOMESSAGE_ICON_X, NOMESSAGE_ICON_Y, NOMESSAGE_ICON_SIZE, NOMESSAGE_ICON_SIZE); + LOADIMG::LoadImageViewImg(noMsgImage_, MESSAGE_IMAGE, IMAGE_MESSAGE_RING); + Add(noMsgLable_); + Add(noMsgImage_); +} + +void MessageMainPage::CancelDelete(void) +{ + deleteGroup_->SetVisible(false); + if (! msgLable_->IsVisible()) { + msgLable_->SetVisible(true); + } + if (! deleteImage_->IsVisible()) { + deleteImage_->SetVisible(true); + } + if (! msgList_->IsVisible()) { + msgList_->SetVisible(true); + } +} + +static UIView* CreateViewCb(uint8_t type) +{ + MessageItemView* item = new MessageItemView(); + if (item == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new item is nullptr"); + return nullptr; + } + item->SetPosition(0, 0, HORIZONTAL_RESOLUTION, MESSAGE_ITEM_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + item->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + item->SetTouchable(true); + item->SetOnClickListener(g_pMessageMainView); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + MessageItemView* item = dynamic_cast(view); + if (data == nullptr || item == nullptr) { + return; + } + MessageItem* content = static_cast(data); + item->SetItemInfo(*content); +} + +void MessageMainPage::RefreshMsgList(std::vector &item) +{ + if (item.size() == 0) { + msgLable_->SetVisible(true); + deleteImage_->SetVisible(false); + msgList_->SetVisible(false); + deleteGroup_->SetVisible(false); + noMsgLable_->SetVisible(true); + noMsgImage_->SetVisible(true); + return; + } + // 设置msgList_数据 + msgList_->ClearAll(); + for (size_t i = 0; i < item.size(); ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 1; + content.data = reinterpret_cast(&item[i]); + msgList_->AddContent(content); + } + msgList_->RefreshList(); +} + +bool MessageMainPage::InitScrollData() +{ + std::vector &itemInfo = MessageModel::GetInstance().GetMsgListItems(); + RefreshMsgList(itemInfo); + return true; +} + +bool MessageMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), DELETE_BUTTON) == 0) { + ConfirmDelete(); + } else if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + VerticalViewInits(); + MessageModel::GetInstance().ClearListItem(); + MessageModel::GetInstance().SetIndex(0); + } else if (strcmp(view.GetViewId(), CANCEL_BUTTON) == 0) { + CancelDelete(); + } else { + // 点击的是消息item条目 + MessageItemView *MessageItemViewID = static_cast(&view); + noMsgLable_->SetVisible(false); + msgLable_->SetVisible(false); + noMsgImage_->SetVisible(false); + deleteImage_->SetVisible(false); + msgList_->SetVisible(false); + LoadDetailsView(); + detailsGroup_->detailsMsg_ = MessageItemViewID->GetItem(); + detailsGroup_->RefreshNotify(); + } + return true; +} + +bool MessageMainPage::OnDragStartEvent(const DragEvent &event) +{ + UNUSED(event); + return true; +} + +bool MessageMainPage::OnDragEvent(const DragEvent &event) +{ + int16_t deltaX = event.GetDeltaX(); + int16_t deltaY = event.GetDeltaY(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > MOVE_DISTANCE)) { + // 返回主页面 + DeleteDetailsView(); + noMsgLable_->SetVisible(true); + msgLable_->SetVisible(true); + noMsgImage_->SetVisible(true); + deleteImage_->SetVisible(true); + msgList_->SetVisible(true); + return true; + } + return true; +} + +void MessageMainPage::LoadDetailsView(void) +{ + detailsGroup_ = new DetailsGroup(); + if (detailsGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new detailsGroup_ is nullptr"); + return; + } + Add(detailsGroup_); +} + +void MessageMainPage::DeleteDetailsView(void) +{ + if (detailsGroup_ != nullptr) { + Remove(detailsGroup_); + delete detailsGroup_; + detailsGroup_ = nullptr; + } +} + +bool MessageMainPage::OnDragEndEvent(const DragEvent &event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM || + event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + std::vector &itemInfo = MessageModel::GetInstance().GetMsgListItems(); + for (size_t i = 0; i < itemInfo.size(); ++i) { + itemInfo[i].status = false; + } + RefreshMsgList(itemInfo); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageModel.cpp index 8bbdf47f9..7c938c48e 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/MessageModel.cpp @@ -1,107 +1,175 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainModel.cpp - * Author: - * Create: 2021-11-23 - */ +* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. +* Description: MessageModel +* Create: 2025-06-29 +*/ #include "unistd.h" -#include "main/MessageModel.h" -#include "main/MessageMainView.h" +#include #include "kv_store.h" +#include +#include +#include +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif #include "securec.h" #include "wearable_log.h" #include "main/DialBinTypesV2.h" #include "power_display_service.h" -#include -#include -#include +#include "main/MessageMainPage.h" +#include "main/MessageModel.h" + namespace OHOS { - MessageModel::MessageModel() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::MessageModel"); - } - MessageModel::~MessageModel() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::~MessageModel"); - } +static constexpr int16_t MESSAGE_MAX = 20; +static constexpr int32_t SECONDS = 60; +static constexpr int32_t HOURS = 3600; +static constexpr int32_t ONE_DAY = 86400; +static constexpr int16_t BUFFER_MAX = 6; - MessageModel &MessageModel::GetInstance() - { - static MessageModel instance; - return instance; - } +MessageModel::MessageModel() {} + +MessageModel::~MessageModel() {} + +MessageModel &MessageModel::GetInstance() +{ + static MessageModel instance; + return instance; +} - void MessageModel::GetMessageInfo(std::string app, std::string contact, std::string information) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::GetMessageInfo"); - //保存数据 - mes.label_1 = app; // 应用 - mes.label_2 = contact; // 联系人 - mes.label_3 = information; // 内容 - mes.icon = "默认"; - // if (app == 微信) { - // mes1.icon = 微信图标; - // } - // if (app == 信息) { - // mes1.icon = 信息图标; - // } - InitMessageItem(); - if (GetViewStatus()) { - if (! MessageMainView::GetInstance()->contentList->IsVisible()) { - MessageMainView::GetInstance()->NewNotify(); - } - MessageMainView::GetInstance()->InitScrollData(); +// 将数据转换,保存到model模块 +void MessageModel::SaveMsgToModel(std::string app, std::string contact, std::string information) +{ + mes_.appName = app; // 应用 + mes_.appContact = contact; // 联系人 + mes_.appContents = information; // 内容 + mes_.time = "现在"; + for (int i = 0; i < vecMsg_.size(); ++i) { + if (vecMsg_[i].appName == mes_.appName && vecMsg_[i].appContact == mes_.appContact) { + mes_.index = index_; + indexAdd_ = false; + break; } + indexAdd_ = true; + continue; } + if (indexAdd_) { + mes_.index = index_++; + } + gettimeofday(¤tTime_, nullptr); + mes_.initialTime = currentTime_.tv_sec; +} - void MessageModel::InitMessageItem() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem"); - if (vecMsg.size() != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg.size() != 0"); - size_t i = 0; - for (i; i < vecMsg.size(); ++i) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,for()"); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_1 = %s", vecMsg[i].label_1.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_2 = %s", vecMsg[i].label_2.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_3 = %s", vecMsg[i].label_3.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_1 = %s", mes.label_1.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_2 = %s", mes.label_2.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_3 = %s", mes.label_3.c_str()); - if (vecMsg[i].label_1 == mes.label_1 && vecMsg[i].label_2 == mes.label_2) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,if()"); - vecMsg[i].label_3 = mes.label_3; - break; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,else(break)"); - continue; - } - if (i == vecMsg.size()) { - vecMsg.push_back(mes); - } - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,else()"); - vecMsg.push_back(mes); +// 将转换好的数据存到vecMsg_ +void MessageModel::SetMsgListItems() +{ + for (size_t i = 0; i < vecMsg_.size(); ++i) { + if (vecMsg_[i].appName == mes_.appName && vecMsg_[i].appContact == mes_.appContact) { + vecMsg_[i].appContents = mes_.appContents; + vecMsg_[i].time = "现在"; + return; } } + if (vecMsg_.size() < MESSAGE_MAX) { + vecMsg_.push_back(mes_); + } else { + vecMsg_.erase(vecMsg_.begin()); + vecMsg_.push_back(mes_); + int j = 0; + for (j; j < vecMsg_.size(); ++j) { + vecMsg_[j].index = j; + } + SetIndex(j); + } + // 收到新的消息后,需要同步将消息进行展示 + if (MessageModel::GetInstance().GetViewStatus()) { + if (! MessageMainPage::GetInstance()->msgList_->IsVisible()) { + MessageMainPage::GetInstance()->NewNotify(); + } + MessageMainPage::GetInstance()->InitScrollData(); + } +} + +std::vector &MessageModel::GetMsgListItems() +{ + return vecMsg_; +} + +void MessageModel::ClearListItem() +{ + vecMsg_.clear(); +} + +void MessageModel::SetViewStatus(bool viewStatus) +{ + viewInitStatus_ = viewStatus; +} + +bool MessageModel::GetViewStatus(void) +{ + return viewInitStatus_; +} - const std::vector MessageModel::GetMessagelistItems() const - { - return vecMsg; +void MessageModel::SetTime(void) +{ + if (vecMsg_.size() != 0) { + for (size_t i = 0; i < vecMsg_.size(); ++i) { + durTime_ = UpdateTime(vecMsg_[i].initialTime); + vecMsg_[i].time = durTime_; + } } + return; +} + +std::string MessageModel::UpdateTime(long time) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + auto now = tv.tv_sec; + auto seconds = now - time; - void MessageModel::ClearListItem() - { - vecMsg.clear(); + if (seconds < 0) { + return "未来时间"; } - void MessageModel::SetViewStatus(bool viewStatus) - { - viewInitStatus = viewStatus; + if (seconds < SECONDS) { + return "现在"; + } else if (seconds < HOURS) { + long minutes = seconds / SECONDS; + return std::to_string(minutes) + "分钟前"; + } else if (seconds < ONE_DAY) { + long hours = seconds / HOURS; + return std::to_string(hours) + "小时前"; + } else { + struct tm timeinfo; + time_t t = static_cast(time); + localtime_r(&t, &timeinfo); + char buffer[BUFFER_MAX]; + snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%02d/%02d", timeinfo.tm_mon + 1, timeinfo.tm_mday); + return std::string(buffer); } +} - bool MessageModel::GetViewStatus(void) - { - return viewInitStatus; +void MessageModel::DeleteItem(MessageItem itemInfo) +{ + for (int i = 0; i < vecMsg_.size(); ++i) { + if (vecMsg_[i].appName == itemInfo.appName && vecMsg_[i].appContact == itemInfo.appContact) { + vecMsg_.erase(vecMsg_.begin() + i); + break; + } + continue; } + int j = 0; + for (j; j < vecMsg_.size(); ++j) { + vecMsg_[j].index = j; + } + MessageMainPage::GetInstance()->RefreshMsgList(vecMsg_); + SetIndex(j); +} + +void MessageModel::SetIndex(uint16_t itemIndex) +{ + index_ = itemIndex; +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/ModelListenerSample.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/ModelListenerSample.cpp index 5971ec477..1f59286f1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/ModelListenerSample.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/ModelListenerSample.cpp @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2020-2021 CompanyNameMagicTag. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "main/ModelListenerSample.h" - -#include "wearable_log.h" -namespace OHOS { -ModelListenerSample::ModelListenerSample() -{ - Init(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModelListenerSample::ModelListenerSample"); -} -ModelListenerSample::~ModelListenerSample() -{ - Deinit(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModelListenerSample::~ModelListenerSample"); -} - -void ModelListenerSample::Callback() -{ - Notify(); - OnTickEvent(); -} -} +/* + * Copyright (c) 2020-2021 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "main/ModelListenerSample.h" + +#include "wearable_log.h" +namespace OHOS { +ModelListenerSample::ModelListenerSample() +{ + Init(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModelListenerSample::ModelListenerSample"); +} +ModelListenerSample::~ModelListenerSample() +{ + Deinit(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModelListenerSample::~ModelListenerSample"); +} + +void ModelListenerSample::Callback() +{ + Notify(); + OnTickEvent(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/PullUpDownView.cpp index 810d3ab07..7a2870038 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -1,330 +1,329 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: WeekStep - * Author: - * Create: 2021-09-11 - */ - -#include "main/PullUpDownView.h" -#include "wearable_log.h" -#include "UiConfig.h" -#include "common/screen.h" -#include "main/MainPresenterSample.h" -#include "screensetting/ScreenModels.h" -#include "settings/SettingModel.h" -#include "ui_resource_image.h" - -namespace OHOS { - -static PullUpDownView *g_pPullUpDownView = nullptr; - -constexpr int16_t DISTURB_IMG_X = 117; -constexpr int16_t DISTURB_IMG_Y = 50; -constexpr int16_t SCREEN_IMG_X = 251; -constexpr int16_t SCREEN_IMG_Y = 50; -constexpr int16_t PHONE_IMG_X = 49; -constexpr int16_t PHONE_IMG_Y = 184; -constexpr int16_t ALARM_IMG_X = 184; -constexpr int16_t ALARM_IMG_Y = 184; -constexpr int16_t SETTING_IMG_X = 319; -constexpr int16_t SETTING_IMG_Y = 184; - -constexpr int16_t BLUETOOTH_IMG_X = 145; -constexpr int16_t BLUETOOTH_IMG_Y = 335; -constexpr int16_t BATTERY_IMG_X = 195; -constexpr int16_t BATTERY_IMG_Y = 340; - -constexpr int16_t DISTURB_LABEL_X = 136; -constexpr int16_t DISTURB_LABEL_Y = 145; -constexpr int16_t SCREEN_LABEL_X = 270; -constexpr int16_t SCREEN_LABEL_Y = 145; -constexpr int16_t PHONE_LABEL_X = 68; -constexpr int16_t PHONE_LABEL_Y = 279; -constexpr int16_t ALARM_LABEL_X = 203; -constexpr int16_t ALARM_LABEL_Y = 279; -constexpr int16_t SETTING_LABEL_X = 338; -constexpr int16_t SETTING_LABEL_Y = 279; - -constexpr int16_t BATTERY_LABEL_X = 247; -constexpr int16_t BATTERY_LABEL_Y = 335; -constexpr int16_t DATE_LABEL_X = 173; -constexpr int16_t DATE_LABEL_Y = 374; - -constexpr int16_t FONT_DEFAULT_SIZE = 24; -constexpr int16_t TEXT_WIDTH = 86; -constexpr int16_t TEXT_HEIGHT = 30; - -constexpr int16_t NONOTICE_LABLE_X = 141; -constexpr int16_t NONOTICE_LABLE_Y = 212; - -PullUpDownView::PullUpDownView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PullUpDownView"); - g_pPullUpDownView = this; -} - -PullUpDownView::~PullUpDownView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView"); - RemoveAll(); - delete dnotDisturb; - dnotDisturb = nullptr; - delete briScreen; - briScreen = nullptr; - delete finPhone; - finPhone = nullptr; - delete droAlarm; - droAlarm = nullptr; - delete droSetting; - droSetting = nullptr; - delete dnotDisturbLable; - dnotDisturbLable = nullptr; - delete briScreenLable; - briScreenLable = nullptr; - delete finPhoneLable; - finPhoneLable = nullptr; - delete droAlarmLable; - droAlarmLable = nullptr; - delete droSettingLable; - droSettingLable = nullptr; - delete bluetooth; - bluetooth = nullptr; - delete battery; - battery = nullptr; - delete batteryLable; - batteryLable = nullptr; - delete dateLable; - dateLable = nullptr; - g_pPullUpDownView = nullptr; -} - -PullUpDownView *PullUpDownView::GetInstance(void) -{ - return g_pPullUpDownView; -} - -void PullUpDownView::InitSubViewImg(void) -{ - if (HealthModel::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); - return; - } - - dnotDisturb = new UIImageView(); - if (dnotDisturb == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturb new fail"); - return; - } - dnotDisturb->SetPosition(DISTURB_IMG_X, DISTURB_IMG_Y); - if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB_B); - } - dnotDisturb->SetViewId(DROPDOWN_CLICK_DONOTDISTURB); - dnotDisturb->SetTouchable(true); - dnotDisturb->SetOnClickListener(clickListener); // 进入勿扰模式 - - briScreen = new UIImageView(); - if (briScreen == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreen new fail"); - return; - } - briScreen->SetPosition(SCREEN_IMG_X, SCREEN_IMG_Y); - if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN_B); - } - briScreen->SetViewId(DROPDOWN_CLICK_BRIGHTENSCREEN); - briScreen->SetTouchable(true); - briScreen->SetOnClickListener(clickListener); // 进入亮屏模式 -} - -void PullUpDownView::InitViewImg(void) -{ - InitSubViewImg(); - - finPhone = new UIImageView(); - if (finPhone == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhone new fail"); - return; - } - finPhone->SetPosition(PHONE_IMG_X, PHONE_IMG_Y); - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, finPhone, DROPDOWN_DROPDOWN_FIND_PHONE); - finPhone->SetViewId(DROPDOWN_CLICK_FINDMYPHONE); // 找手机界面 DROP_DOWN_FIND_PHONE - finPhone->SetTouchable(true); - finPhone->SetOnClickListener(clickListener); - - droAlarm = new UIImageView(); - if (droAlarm == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droAlarm new fail"); - return; - } - droAlarm->SetPosition(ALARM_IMG_X, ALARM_IMG_Y); - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droAlarm, DROPDOWN_DROPDOWN_ALARM); - droAlarm->SetViewId(DROPDOWN_CLICK_ALARM); // 进入闹钟App DROP_DOWN_ALARM - droAlarm->SetTouchable(true); - droAlarm->SetOnClickListener(clickListener); - - droSetting = new UIImageView(); - if (droSetting == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSetting new fail"); - return; - } - droSetting->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droSetting, DROPDOWN_DROPDOWN_SETTING); - droSetting->SetViewId(DROPDOWN_CLICK_SETTING); // 进入设置界面 DROP_DOWN_SETTING - droSetting->SetTouchable(true); - droSetting->SetOnClickListener(clickListener); -} - -void PullUpDownView::InitViewLable(void) -{ - dnotDisturbLable = new UILabel(); - if (dnotDisturbLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturbLable new fail"); - return; - } - dnotDisturbLable->SetPosition(DISTURB_LABEL_X, DISTURB_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - dnotDisturbLable->SetText("勿扰"); - dnotDisturbLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - dnotDisturbLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - briScreenLable = new UILabel(); - if (briScreenLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreenLable new fail"); - return; - } - briScreenLable->SetPosition(SCREEN_LABEL_X, SCREEN_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - briScreenLable->SetText("亮屏"); - briScreenLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - briScreenLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - finPhoneLable = new UILabel(); - if (finPhoneLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); - return; - } - finPhoneLable->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - finPhoneLable->SetText("找手机"); - finPhoneLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - finPhoneLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - droAlarmLable = new UILabel(); - if (finPhoneLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); - return; - } - droAlarmLable->SetPosition(ALARM_LABEL_X, ALARM_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - droAlarmLable->SetText("闹钟"); - droAlarmLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - droAlarmLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - droSettingLable = new UILabel(); - if (droSettingLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSettingLable new fail"); - return; - } - droSettingLable->SetPosition(SETTING_LABEL_X, SETTING_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - droSettingLable->SetText("设置"); - droSettingLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - droSettingLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); -} - -void PullUpDownView::InitViewInfo(void) -{ - bluetooth = new UIImageView(); // 蓝牙状态显示 - if (bluetooth == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth new fail"); - return; - } - bluetooth->SetPosition(BLUETOOTH_IMG_X, BLUETOOTH_IMG_Y); - if (BluetoothModel::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth model nullptr"); - return; - } - - if (SettingModel::GetInstance().GetBlueToothConnectStatus()) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); - } - - battery = new UIImageView(); // 电量状态显示 - if (battery == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery new fail"); - return; - } - battery->SetPosition(BATTERY_IMG_X, BATTERY_IMG_Y); - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); - batteryLable = new UILabel(); - if (batteryLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLable new fail"); - return; - } - batteryLable->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - batteryLable->SetText("90%"); - batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - batteryLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - dateLable = new UILabel(); - if (dateLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dateLable new fail"); - return; - } - dateLable->SetPosition(DATE_LABEL_X, DATE_LABEL_Y, 192, TEXT_HEIGHT); // TEXT_WIDTH = 192 - dateLable->SetText("10/23 星期五"); - dateLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - dateLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); -} - -bool PullUpDownView::InitView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView"); - clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); - - InitViewImg(); - InitViewLable(); - InitViewInfo(); - - Add(dnotDisturb); - Add(dnotDisturbLable); - Add(briScreen); - Add(briScreenLable); - Add(finPhone); - Add(finPhoneLable); - Add(droAlarm); - Add(droAlarmLable); - Add(droSetting); - Add(droSettingLable); - Add(bluetooth); - Add(battery); - Add(batteryLable); - Add(dateLable); - - SetTouchable(true); - SetIntercept(true); - - return true; -} - -void PullUpDownView::PreLoad(void) -{ - if (!viewiInitStatus) { - InitView(); - viewiInitStatus = true; - } -} - -void PullUpDownView::UpdateBlueToothStatus(int status) -{ - if (bluetooth == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth nullptr"); - return; - } - if (status == 1) { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); - } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); - } - bluetooth->Invalidate(); - return; -} - -} +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PullUpDownView + * Create: 2025-06-29 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/screen.h" +#include "main/MainPresenterSample.h" +#include "screensetting/ScreenModels.h" +#include "settings/model/SettingBluetoothModel.h" +#include "ui_resource_image.h" +#include "main/PullUpDownView.h" + +namespace OHOS { + +static PullUpDownView *g_pPullUpDownView = nullptr; + +constexpr int16_t DISTURB_IMG_X = 117; +constexpr int16_t DISTURB_IMG_Y = 50; +constexpr int16_t SCREEN_IMG_X = 251; +constexpr int16_t SCREEN_IMG_Y = 50; +constexpr int16_t PHONE_IMG_X = 49; +constexpr int16_t PHONE_IMG_Y = 184; +constexpr int16_t ALARM_IMG_X = 184; +constexpr int16_t ALARM_IMG_Y = 184; +constexpr int16_t SETTING_IMG_X = 319; +constexpr int16_t SETTING_IMG_Y = 184; + +constexpr int16_t BLUETOOTH_IMG_X = 145; +constexpr int16_t BLUETOOTH_IMG_Y = 335; +constexpr int16_t BATTERY_IMG_X = 195; +constexpr int16_t BATTERY_IMG_Y = 340; + +constexpr int16_t DISTURB_LABEL_X = 136; +constexpr int16_t DISTURB_LABEL_Y = 145; +constexpr int16_t SCREEN_LABEL_X = 270; +constexpr int16_t SCREEN_LABEL_Y = 145; +constexpr int16_t PHONE_LABEL_X = 68; +constexpr int16_t PHONE_LABEL_Y = 279; +constexpr int16_t ALARM_LABEL_X = 203; +constexpr int16_t ALARM_LABEL_Y = 279; +constexpr int16_t SETTING_LABEL_X = 338; +constexpr int16_t SETTING_LABEL_Y = 279; + +constexpr int16_t BATTERY_LABEL_X = 247; +constexpr int16_t BATTERY_LABEL_Y = 335; +constexpr int16_t DATE_LABEL_X = 173; +constexpr int16_t DATE_LABEL_Y = 374; + +constexpr int16_t FONT_DEFAULT_SIZE = 24; +constexpr int16_t TEXT_WIDTH = 86; +constexpr int16_t TEXT_HEIGHT = 30; + +constexpr int16_t NONOTICE_LABLE_X = 141; +constexpr int16_t NONOTICE_LABLE_Y = 212; + +PullUpDownView::PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PullUpDownView"); + g_pPullUpDownView = this; +} + +PullUpDownView::~PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView"); + RemoveAll(); + delete dnotDisturb; + dnotDisturb = nullptr; + delete briScreen; + briScreen = nullptr; + delete finPhone; + finPhone = nullptr; + delete droAlarm; + droAlarm = nullptr; + delete droSetting; + droSetting = nullptr; + delete dnotDisturbLable; + dnotDisturbLable = nullptr; + delete briScreenLable; + briScreenLable = nullptr; + delete finPhoneLable; + finPhoneLable = nullptr; + delete droAlarmLable; + droAlarmLable = nullptr; + delete droSettingLable; + droSettingLable = nullptr; + delete bluetooth; + bluetooth = nullptr; + delete battery; + battery = nullptr; + delete batteryLable; + batteryLable = nullptr; + delete dateLable; + dateLable = nullptr; + g_pPullUpDownView = nullptr; +} + +PullUpDownView *PullUpDownView::GetInstance(void) +{ + return g_pPullUpDownView; +} + +void PullUpDownView::InitSubViewImg(void) +{ + if (HealthModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); + return; + } + + dnotDisturb = new UIImageView(); + if (dnotDisturb == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturb new fail"); + return; + } + dnotDisturb->SetPosition(DISTURB_IMG_X, DISTURB_IMG_Y); + if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB_B); + } + dnotDisturb->SetViewId(DROPDOWN_CLICK_DONOTDISTURB); + dnotDisturb->SetTouchable(true); + dnotDisturb->SetOnClickListener(clickListener); // 进入勿扰模式 + + briScreen = new UIImageView(); + if (briScreen == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreen new fail"); + return; + } + briScreen->SetPosition(SCREEN_IMG_X, SCREEN_IMG_Y); + if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN_B); + } + briScreen->SetViewId(DROPDOWN_CLICK_BRIGHTENSCREEN); + briScreen->SetTouchable(true); + briScreen->SetOnClickListener(clickListener); // 进入亮屏模式 +} + +void PullUpDownView::InitViewImg(void) +{ + InitSubViewImg(); + + finPhone = new UIImageView(); + if (finPhone == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhone new fail"); + return; + } + finPhone->SetPosition(PHONE_IMG_X, PHONE_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, finPhone, DROPDOWN_DROPDOWN_FIND_PHONE); + finPhone->SetViewId(DROPDOWN_CLICK_FINDMYPHONE); // 找手机界面 DROP_DOWN_FIND_PHONE + finPhone->SetTouchable(true); + finPhone->SetOnClickListener(clickListener); + + droAlarm = new UIImageView(); + if (droAlarm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droAlarm new fail"); + return; + } + droAlarm->SetPosition(ALARM_IMG_X, ALARM_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droAlarm, DROPDOWN_DROPDOWN_ALARM); + droAlarm->SetViewId(DROPDOWN_CLICK_ALARM); // 进入闹钟App DROP_DOWN_ALARM + droAlarm->SetTouchable(true); + droAlarm->SetOnClickListener(clickListener); + + droSetting = new UIImageView(); + if (droSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSetting new fail"); + return; + } + droSetting->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droSetting, DROPDOWN_DROPDOWN_SETTING); + droSetting->SetViewId(DROPDOWN_CLICK_SETTING); // 进入设置界面 DROP_DOWN_SETTING + droSetting->SetTouchable(true); + droSetting->SetOnClickListener(clickListener); +} + +void PullUpDownView::InitViewLable(void) +{ + dnotDisturbLable = new UILabel(); + if (dnotDisturbLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturbLable new fail"); + return; + } + dnotDisturbLable->SetPosition(DISTURB_LABEL_X, DISTURB_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + dnotDisturbLable->SetText("勿扰"); + dnotDisturbLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dnotDisturbLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + briScreenLable = new UILabel(); + if (briScreenLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreenLable new fail"); + return; + } + briScreenLable->SetPosition(SCREEN_LABEL_X, SCREEN_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + briScreenLable->SetText("亮屏"); + briScreenLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + briScreenLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + finPhoneLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + finPhoneLable->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + finPhoneLable->SetText("找手机"); + finPhoneLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + finPhoneLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droAlarmLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + droAlarmLable->SetPosition(ALARM_LABEL_X, ALARM_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droAlarmLable->SetText("闹钟"); + droAlarmLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droAlarmLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droSettingLable = new UILabel(); + if (droSettingLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSettingLable new fail"); + return; + } + droSettingLable->SetPosition(SETTING_LABEL_X, SETTING_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droSettingLable->SetText("设置"); + droSettingLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droSettingLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +void PullUpDownView::InitViewInfo(void) +{ + bluetooth = new UIImageView(); // 蓝牙状态显示 + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth new fail"); + return; + } + bluetooth->SetPosition(BLUETOOTH_IMG_X, BLUETOOTH_IMG_Y); + if (SettingBluetoothModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth model nullptr"); + return; + } + + if (SettingBluetoothModel::GetInstance()->GetAclConnected()) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + + battery = new UIImageView(); // 电量状态显示 + if (battery == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery new fail"); + return; + } + battery->SetPosition(BATTERY_IMG_X, BATTERY_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); + batteryLable = new UILabel(); + if (batteryLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLable new fail"); + return; + } + batteryLable->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + batteryLable->SetText("90%"); + batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + dateLable = new UILabel(); + if (dateLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dateLable new fail"); + return; + } + dateLable->SetPosition(DATE_LABEL_X, DATE_LABEL_Y, 192, TEXT_HEIGHT); // TEXT_WIDTH = 192 + dateLable->SetText("10/23 星期五"); + dateLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dateLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +bool PullUpDownView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView"); + clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + + InitViewImg(); + InitViewLable(); + InitViewInfo(); + + Add(dnotDisturb); + Add(dnotDisturbLable); + Add(briScreen); + Add(briScreenLable); + Add(finPhone); + Add(finPhoneLable); + Add(droAlarm); + Add(droAlarmLable); + Add(droSetting); + Add(droSettingLable); + Add(bluetooth); + Add(battery); + Add(batteryLable); + Add(dateLable); + + SetTouchable(true); + SetIntercept(true); + + return true; +} + +void PullUpDownView::PreLoad(void) +{ + if (!viewiInitStatus) { + InitView(); + viewiInitStatus = true; + } +} + +void PullUpDownView::UpdateBlueToothStatus(int status) +{ + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth nullptr"); + return; + } + if (status == 1) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + bluetooth->Invalidate(); + return; +} + +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp index 1c86925b3..136045cc6 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp @@ -10,13 +10,13 @@ #include "UiConfig.h" #include "ui_resource_image.h" #include "drag_event.h" -#include "makephone/MainCallingView.h" +#include "phonemenu/PhoneMenuView.h" #include "phoneservice/PhoneService.h" -#include "callerlog/CallerLogModel.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" #include "notification_manager.h" -#include "bluetooth/BluetoothHeadsetEvent.h" +#include "settings/model/SettingBluetoothHeadsetEvent.h" #include "bts_avrcp_controller.h" namespace OHOS { @@ -126,7 +126,7 @@ void VolumeSliderEventListener::ChangeVolume(VolumeChangeStatus status) } } -extern BtAvrcpTgInf g_avrcp_srv_inf; +extern SettingBtAvrcpTgInf g_avrcp_srv_inf; void VolumeSliderEventListener::BtAndLocalVolumeSet(int16_t sounding) { if (g_avrcp_srv_inf.avrcp_srv_conn_stat == PROFILE_STATE_CONNECTED) { @@ -170,16 +170,8 @@ bool VolumeSliderEventListener::OnDrag(UIView& view, const DragEvent& event) playersView->SetVisible(true); } if (playerCoefficients == VOLUMEPHONE) { - MainCallingView *mainCallView = MainCallingView::GetInstance(); - if (mainCallView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnDrag:MainCallingView new fail"); - return false; - } volumeSettingView->SetVisible(false); - mainCallView->GetScreenGroup()->SetVisible(false); - mainCallView->GetDisplayGroup()->SetVisible(false); - mainCallView->GetCallingGroup()->SetVisible(true); - CallerLogModel::GetInstance()->SetVolumeScreenStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetVolumeScreenStatus(false); } if (playerCoefficients == VOLUMEPHONENOTIFY) { volumeSettingView->SetVisible(false); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialModelArcProgress.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialModelArcProgress.cpp new file mode 100644 index 000000000..aad2b6734 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialModelArcProgress.cpp @@ -0,0 +1,29 @@ +/* +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: DialModelArcProgress + * Author: Hisi Graphic + * Create: 2025-08 + */ + +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelArcProgress.h" +#include "gfx_utils/graphic_math.h" + +REGIST_DIAL_MODULE(OHOS::DialDataType::ARC_PROGRESS_TEST, OHOS::DialModelArcProgress::GetInstance()); + +namespace OHOS { +DialModelArcProgress* DialModelArcProgress::GetInstance() +{ + static DialModelArcProgress instance; + return &instance; +} + +bool DialModelArcProgress::GetDialFloatData(DialDataType& type, float& out) +{ + (void)type; + out = data_; + data_ = FloatMore(data_, 1.0) ? 0.1 : data_ + 0.01; + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp index 3c52dd760..664333405 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp @@ -12,6 +12,7 @@ #include "screennotify/ui_screennotify.h" #endif #include "main/MainPresenterSample.h" +#include "aod_view/AodPresenter.h" #include "main/dial/DialDigitalImgView.h" #include "common/input_device_manager.h" #include "main/dial/DialSequenceImgView.h" @@ -362,12 +363,11 @@ void DialViewGroup::AddDialClick(Rect& rect, const char* bundleName) if (name == nullptr) { return; } - if (memcpy_s(name, len, bundleName, len) != EOK) { + if (strcpy_s(name, len, bundleName) != EOK) { UIFree(name); name = nullptr; return; } - name[len] = '\0'; DialClick click = {rect, false, {.bundleName = name}}; dialClicks_.PushBack(click); } @@ -450,10 +450,13 @@ void DialViewGroup::CoverEnd(bool isCovered) void DialViewGroup::OnActive(void) { - MainPresenterSample* mainPresenter = MainPresenterSample::GetInstance(); - if ((mainPresenter == nullptr) || (mainPresenter->GetMainPresenterState() != MainPresenterState::RESUME)) { - return; + if (state_ == DisplayState::NORMAL) { + MainPresenterSample* mainPresenter = MainPresenterSample::GetInstance(); + if ((mainPresenter == nullptr) || (mainPresenter->GetMainPresenterState() != MainPresenterState::RESUME)) { + return; + } } + if (!isSeqImgLoaded_) { std::weak_ptr wk = isExists_; GraphicService::GetInstance()->ForceRefreshImmediately(); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/WatchInterface.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/WatchInterface.cpp index 11f98448d..4e8664dde 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/WatchInterface.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/main/src/dial/WatchInterface.cpp @@ -15,12 +15,10 @@ #include "common/screen.h" #include "main/MainModel.h" #include "main/MainViewSample.h" -#include "set_dial/SetDialModel.h" #include "graphic_service.h" #include "NativeAbility.h" #include "graphic_mutex.h" -#include "set_dial/SetDialModel.h" -#include "set_dial/SetDialPresenter.h" +#include "settings/model/SettingDesktopModel.h" #include "power_display_service.h" using namespace OHOS; @@ -336,11 +334,10 @@ bool SetCurrentWatchFace(uint32_t uuid) DialSetting setting = MainModel::GetInstance().GetDialSetting(); setting.dialFlag = 1; setting.dialFullName = g_info[index].fileName; - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_SETTING | static_cast(SettingPageId::DESKTOP_DIAL_PAGE) << PAGE_OFFSET)) { GraphicService::GetInstance()->PostGraphicEvent([setting]() { - if (SetDialPresenter::GetCurrentInstance() != nullptr) { - SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); - } + SettingDesktopModel::GetInstance().SetSpecifyDialSetting(setting); }); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); return true; @@ -382,14 +379,13 @@ bool UninstallWatch(uint32_t uuid) setting.dialFlag = 0; setting.dialId = 0; } - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_SETTING | static_cast(SettingPageId::DESKTOP_DIAL_PAGE) << PAGE_OFFSET)) { if (g_info[index].watchInfo.is_current_watch) { // If it is the current watch face, set it as the default watch face. Otherwise, the configuration remains // unchanged. GraphicService::GetInstance()->PostGraphicEvent([setting]() { - if (SetDialPresenter::GetCurrentInstance() != nullptr) { - SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); - } + SettingDesktopModel::GetInstance().SetSpecifyDialSetting(setting); }); } NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyModel.cpp new file mode 100644 index 000000000..bbb360c71 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyModel.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyModel + * Create: 2025-04-24 + */ +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "NativeAbility.h" +#include "flashlight/FlashLightView.h" +#include "phonemenu/PhoneMenuView.h" +#include "stopwatch/StopwatchView.h" +#include "sport/SportView.h" +#include "timers/TimerView.h" +#include "weather/WeatherView.h" +#include "blood/BloodView.h" +#include "heartrate/HeartRateView.h" +#include "camera/CameraView.h" +#include "findphone/FindPhoneView.h" +#include "sleep/SleepView.h" +#include "settings/common/SettingCommon.h" +#include "date/DateView.h" +#include "monkey/MonkeyModel.h" +#include "cmsis_os.h" + +namespace OHOS { +static constexpr uint8_t TIME_PERIOL = 20; +static std::vector g_page; +static uint8_t g_curTime = 0; +MonkeyModel::MonkeyModel() +{ + g_page.clear(); + // 手电筒 + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_VIEW}); + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_PLAY_VIEW}); + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_SET_VIEW}); + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_COLOR_VIEW}); + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_BLINK_VIEW}); + g_page.push_back({VIEW_FLASHLIGHT, FLASH_LIGHT_RECOVER_VIEW}); + // 通话菜单 + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_MAIN_PAGE}); + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_CONTACTS_PAGE}); + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_DIAL_PAGE}); + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_DISCONNECT_PAGE}); + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_CALLER_LOG_PAGE}); + g_page.push_back({VIEW_PHONE_MENU, PHONE_MENU_CALLING_PAGE}); + // 秒表 + g_page.push_back({VIEW_STOPWATCH, STOPWATCH_MAIN_PAGE}); + g_page.push_back({VIEW_STOPWATCH, STOPWATCH_RECORD_PAGE}); + // 运动 + g_page.push_back({VIEW_SPORT, SPORT_PAGE_MENU}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_PREPARE}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_COUNTDOWN}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_DATA}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_PAUSE}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_PROMPT}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_SETTINGS}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_TARGET}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_TARGET_SETTING}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_TARGET_PROMPT}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_REMIND}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_REMIND_INTERVAL}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_REMIND_HEARTRATE}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_HEARTRATE_RANGE}); + g_page.push_back({VIEW_SPORT, SPORT_PAGE_MISTOUCH}); + // 设置 + g_page.push_back({VIEW_SETTING, MAIN_PAGE}); + g_page.push_back({VIEW_SETTING, BLUETOOTH_PAGE}); + g_page.push_back({VIEW_SETTING, DISPLAY_PAGE}); + g_page.push_back({VIEW_EMPTY, 1}); + g_page.push_back({VIEW_SETTING, DESKTOP_PAGE}); + g_page.push_back({VIEW_SETTING, POWER_PAGE}); + g_page.push_back({VIEW_SETTING, CARD_PAGE}); + g_page.push_back({VIEW_SETTING, SYSTEM_PAGE}); + g_page.push_back({VIEW_SETTING, ABOUT_PAGE}); + g_page.push_back({VIEW_SETTING, DISPLAY_BRIGHTNESS_PAGE}); + g_page.push_back({VIEW_SETTING, DISPLAY_SCREEN_OFF_PAGE}); + g_page.push_back({VIEW_SETTING, DISPLAY_STEADY_ON_PAGE}); + g_page.push_back({VIEW_SETTING, DESKTOP_DIAL_PAGE}); + g_page.push_back({VIEW_EMPTY, 1}); + g_page.push_back({VIEW_SETTING, DESKTOP_DIAL_STYLE_PAGE}); + g_page.push_back({VIEW_SETTING, CARD_EFFECT_PAGE}); + g_page.push_back({VIEW_SETTING, CARD_MGR_PAGE}); + g_page.push_back({VIEW_SETTING, CARD_ADD_PAGE}); + g_page.push_back({VIEW_SETTING, SYSTEM_OPERATION_PAGE}); + g_page.push_back({VIEW_SETTING, SYSTEM_OTA_PAGE}); + g_page.push_back({VIEW_SETTING, CONNECT_NEW_PHONE_PAGE}); + g_page.push_back({VIEW_SETTING, CONNECT_OPEN_PAGE}); + g_page.push_back({VIEW_EMPTY, 1}); + g_page.push_back({VIEW_SETTING, CONNECT_BLUE_SUCCESS_PAGE}); + g_page.push_back({VIEW_SETTING, CONNECT_BLUE_FAIL_PAGE}); + g_page.push_back({VIEW_SETTING, RECONNECTION_PAGE}); + g_page.push_back({VIEW_SETTING, RECONNECT_SECOND_CONFIRM_PAGE}); + g_page.push_back({VIEW_SETTING, UNPAIR_SECOND_CONFIRM_PAGE}); + g_page.push_back({VIEW_SETTING, QRCODE_CONN_PAGE}); + g_page.push_back({VIEW_EMPTY, 1}); + // 计时器 + g_page.push_back({VIEW_TIMER, TIMER_MAIN_PAGE}); + g_page.push_back({VIEW_TIMER, TIMER_TIMING_PAGE}); + g_page.push_back({VIEW_TIMER, TIMER_SETTING_PAGE}); + // 天气 + g_page.push_back({VIEW_WEATHER, WEATHER_MAIN_PAGE}); + g_page.push_back({VIEW_WEATHER, WEATHER_HOURS_PAGE}); + g_page.push_back({VIEW_WEATHER, WEATHER_DAYS_PAGE}); + g_page.push_back({VIEW_WEATHER, WEATHER_SUNRISE_PAGE}); + g_page.push_back({VIEW_WEATHER, WEATHER_MONTHRISE_PAGE}); + g_page.push_back({VIEW_WEATHER, WEATHER_LUNARPHASE_PAGE}); + // 血氧 + g_page.push_back({VIEW_BLOOD, BLOOD_MAIN_PAGE}); + g_page.push_back({VIEW_BLOOD, BLOOD_READY_PAGE}); + g_page.push_back({VIEW_BLOOD, BLOOD_MEASUREMENT_PAGE}); + g_page.push_back({VIEW_BLOOD, BLOOD_RESULT_PAGE}); + g_page.push_back({VIEW_BLOOD, BLOOD_CHART_PAGE}); + g_page.push_back({VIEW_BLOOD, BLOOD_EXPLAIN_PAGE}); + // 心率 + g_page.push_back({VIEW_HEARTRATE, HEARTRATE_MAIN_PAGE}); + g_page.push_back({VIEW_HEARTRATE, HEARTRATE_READY_PAGE}); + g_page.push_back({VIEW_HEARTRATE, HEARTRATE_MEASUREMENT_PAGE}); + // 相机 + g_page.push_back({VIEW_CAMERA, CAMERA_MAIN_PAGE}); + // 寻找手机 + g_page.push_back({VIEW_FIND_PHONE, FIND_PHONE_MAIN_PAGE}); + // 睡眠 + g_page.push_back({VIEW_SLEEPING, SLEEPING_MAIN_PAGE}); + g_page.push_back({VIEW_SLEEPING, SLEEPING_DEATIL_PAGE}); + g_page.push_back({VIEW_SLEEPING, SLEEPING_TARGET_PAGE}); + // 日历 + g_page.push_back({VIEW_DATE, DATE_MAIN_PAGE}); + g_page.push_back({VIEW_DATE, DATE_MESSAGE_PAGE}); + g_page.push_back({VIEW_EMPTY, 1}); + timeCallback_ = new TimeAnimatorCallback(TIME_PERIOL); + if (timeCallback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new timeCallback_ fail"); + return; + } + timeAnimator_ = new Animator(timeCallback_, nullptr, 0, true); + if (timeAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new timeAnimator_ fail"); + return; + } +} + +MonkeyModel::~MonkeyModel() +{ + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } + if (timeCallback_ != nullptr) { + delete timeCallback_; + timeCallback_ = nullptr; + } +} + +MonkeyModel &MonkeyModel::GetInstance() +{ + static MonkeyModel instance; + return instance; +} + +void MonkeyModel::SetStart(bool start) +{ + if (start) { + timeAnimator_->Start(); + } else { + timeAnimator_->Stop(); + } +} + +void MonkeyModel::TimeAnimatorCallback::Callback(UIView *view) +{ + int pageSize = g_page.size(); + static int monkeyId = 0; + static int g_curTime = 0; + g_curTime++; + if (g_curTime > periol_) { + monkeyId = (monkeyId + 1) % pageSize; + std::cout << "sliceId = " << g_page[monkeyId].sliceId << " pageId = " << g_page[monkeyId].pageId << std::endl; + NativeAbility::GetInstance().SwitchSlice(g_page[monkeyId].sliceId, g_page[monkeyId].pageId); + g_curTime = 0; + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPage.cpp new file mode 100644 index 000000000..0428c5bea --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPage.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyPage + * Create: 2025-04-24 + */ +#include +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "monkey/MonkeyPresenter.h" +#include "monkey/MonkeyModel.h" +#include "monkey/MonkeyPage.h" + +namespace OHOS { +static constexpr uint16_t MONKEY_LABEL_POS_X = 137; +static constexpr uint16_t MONKEY_LABEL_POS_Y = 66; +static constexpr uint16_t MONKEY_LABEL_WIDTH = 200; +static constexpr uint16_t MONKEY_LABEL_HEIGHT = 90; +static constexpr uint16_t START_MONKEY_BUTTON_POS_X = 142; +static constexpr uint16_t START_MONKEY_BUTTON_POS_Y = 165; +static constexpr uint16_t START_MONKEY_BUTTON_WIDTH = 182; +static constexpr uint16_t START_MONKEY_BUTTON_HEIGHT = 47; +static constexpr uint16_t END_MONKEY_BUTTON_POS_X = 142; +static constexpr uint16_t END_MONKEY_BUTTON_POS_Y = 247; +static constexpr uint16_t END_MONKEY_BUTTON_WIDTH = 182; +static constexpr uint16_t END_MONKEY_BUTTON_HEIGHT = 47; +static constexpr uint16_t MONKEY_FONT_SIZE = 34; +static constexpr char *START_MONKEY = "startMonkey"; +static constexpr char *END_MONKEY = "endMonkey"; + +REGIST_SLICE_PAGE(VIEW_MONKEY, MONKEY_PAGES::MONKEY_MAIN_PAGE, MonkeyPage, true); + +void MonkeyPage::OnStart(void *data) +{ + container_ = new UIScrollView(); + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new container_ fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + + monkeyLabel_ = new UILabel(); + if (monkeyLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new monkeyLabel_ fail"); + return; + } + monkeyLabel_->SetPosition(MONKEY_LABEL_POS_X, MONKEY_LABEL_POS_Y, MONKEY_LABEL_WIDTH, MONKEY_LABEL_HEIGHT); + monkeyLabel_->SetViewId("label1"); + monkeyLabel_->SetStyle(STYLE_TEXT_FONT, MONKEY_FONT_SIZE); + monkeyLabel_->SetText("Monkey测试"); + monkeyLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + monkeyLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + monkeyLabel_->SetRollSpeed(0); + monkeyLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MONKEY_FONT_SIZE); + container_->Add(monkeyLabel_); + monkeyLabel_->SetVisible(true); + + endMonkeyButton_ = new UILabelButtonExt(); + if (endMonkeyButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new endMonkeyButton_ fail"); + return; + } + endMonkeyButton_->SetPosition(END_MONKEY_BUTTON_POS_X, END_MONKEY_BUTTON_POS_Y, END_MONKEY_BUTTON_WIDTH, + END_MONKEY_BUTTON_HEIGHT); + endMonkeyButton_->SetText("结束测试"); + endMonkeyButton_->SetViewId(END_MONKEY); + endMonkeyButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MONKEY_FONT_SIZE); + endMonkeyButton_->SetStyleForState(STYLE_BORDER_COLOR, Color::Blue().full, UIButton::PRESSED); + container_->Add(endMonkeyButton_); + endMonkeyButton_->SetVisible(true); + + startMonkeyButton_ = new UILabelButtonExt(); + if (startMonkeyButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new startMonkeyButton_ fail"); + return; + } + startMonkeyButton_->SetPosition(START_MONKEY_BUTTON_POS_X, START_MONKEY_BUTTON_POS_Y, START_MONKEY_BUTTON_WIDTH, + START_MONKEY_BUTTON_HEIGHT); + startMonkeyButton_->SetText("开始测试"); + startMonkeyButton_->SetViewId(START_MONKEY); + startMonkeyButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MONKEY_FONT_SIZE); + startMonkeyButton_->SetStyleForState(STYLE_BORDER_COLOR, Color::Blue().full, UIButton::PRESSED); + container_->Add(startMonkeyButton_); + startMonkeyButton_->SetVisible(true); + + endMonkeyButton_->SetOnClickListener(this); + startMonkeyButton_->SetOnClickListener(this); + container_->SetOnDragListener(this); + AddViewToPageContainer(container_); +} + +MonkeyPage::MonkeyPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MonkeyPage::MonkeyPage"); +} + +MonkeyPage::~MonkeyPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (monkeyLabel_ != nullptr) { + delete monkeyLabel_; + monkeyLabel_ = nullptr; + } + if (endMonkeyButton_ != nullptr) { + delete endMonkeyButton_; + endMonkeyButton_ = nullptr; + } + if (startMonkeyButton_ != nullptr) { + delete startMonkeyButton_; + startMonkeyButton_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MonkeyPage::~MonkeyPage"); +} + +bool MonkeyPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + MonkeyModel::GetInstance().SetStart(false); + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return false; +} + +bool MonkeyPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), START_MONKEY) == 0) { + MonkeyModel::GetInstance().SetStart(true); + } else if (strcmp(view.GetViewId(), END_MONKEY) == 0) { + MonkeyModel::GetInstance().SetStart(false); + } + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPresenter.cpp new file mode 100644 index 000000000..fb750b90e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/monkey/src/MonkeyPresenter.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MonkeyPresenter + * Create: 2025-04-24 + */ +#include "NativeRegisterManager.h" +#include "monkey/MonkeyView.h" +#include "monkey/MonkeyPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_MONKEY, MonkeyView, MonkeyPresenter, MONKEY_ICON, MONKEY_ICON, "Monkey"); +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp index 49596a48b..07e8d639b 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp @@ -9,6 +9,7 @@ #include "player/PlayersModel.h" #include "uiservice/ui_service.h" #include "NativeRegisterManager.h" +#include "phonemenu/PhoneMenuView.h" namespace OHOS { @@ -56,7 +57,7 @@ void VocassistPresenter::VocAssistDeal(int flag) VocassistModel::GetInstance()->SetToggleFlag(ALREADY_CLOSE_VOCASSIST_IMAGE); } } - + VocassistModel::GetInstance()->SetExitStatus(CONTINUTE_EXIT_MODE1); VoiceAssistance::GetInstance()->DelayDisplayTime(DELAY_SIX_SECONDS); // 开启定时器,太长时间未操作退出语音助手 } @@ -112,9 +113,9 @@ bool VocassistPresenter::OnDrag(UIView& view, const DragEvent& event) strcmp(view.GetViewId(), VOC_ID) == 0) { // 语音助手右滑退出 int phoneStatus = VocassistModel::GetInstance()->GetPhoneDetailStatus(); // 扫描设置此时通话的状态和个数 if (phoneStatus == ONE_ROAD_AND_INCOMING) { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE); + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } } return true; diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp index e0c2c71d6..729a542a3 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp @@ -10,7 +10,8 @@ #include "graphic_timer.h" #include "AppViewIDs.h" #include "player/PlayersModel.h" -#include "callerlog/CallerLogModel.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" #include "offlinevoice/VocassistModel.h" #include "offlinevoice/VocassistView.h" #include "offlinevoice/VocassistPresenter.h" @@ -624,7 +625,7 @@ void VoiceAssistance::ExitProgress() if (quitStatus == CONTINUTE_EXIT_MODE1) { int phoneStatus = VocassistModel::GetInstance()->GetPhoneDetailStatus(); // 扫描设置此时通话的状态和个数 if (phoneStatus == ONE_ROAD_AND_INCOMING) { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE); // 返回来电界面 + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); return; } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Too long no operate, now exit vocassist"); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogItemView.cpp new file mode 100644 index 000000000..24992a029 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogItemView.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogItemView + * Create: 2025-07-12 + */ + +#include +#include +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "phonemenu/PhoneMenuCallerLogItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_GROUP_W = 418; +static constexpr uint16_t BG_GROUP_H = 128; +static constexpr uint16_t BG_BACKGROUND_OPA = 48; +static constexpr uint16_t BG_BORDER_RADIUS = 65; +static constexpr uint16_t ICON_X = 40; +static constexpr uint16_t ICON_Y = 40; +static constexpr uint16_t PHONE_LABEL_X = 107; +static constexpr uint16_t PHONE_LABEL_Y = 20; +static constexpr uint16_t PHONE_LABEL_W = 230; +static constexpr uint16_t PHONE_LABEL_H = 46; +static constexpr uint16_t PHONE_LABEL_FONT = 36; +static constexpr uint16_t STATUS_LABEL_X = 107; +static constexpr uint16_t STATUS_LABEL_Y = 66; +static constexpr uint16_t STATUS_LABEL_W = 268; +static constexpr uint16_t STATUS_LABEL_H = 42; +static constexpr uint16_t STATUS_LABEL_FONT = 30; +static constexpr uint16_t NUM_10 = 10; + +PhoneMenuCallerLogItemView::PhoneMenuCallerLogItemView() +{ + bg_.SetPosition(0, 0, BG_GROUP_W, BG_GROUP_H); + bg_.SetStyle(STYLE_BACKGROUND_OPA, BG_BACKGROUND_OPA); + bg_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + bg_.SetStyle(STYLE_BORDER_RADIUS, BG_BORDER_RADIUS); + + icon_.SetPosition(ICON_X, ICON_Y); + + phoneLabel_.SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, PHONE_LABEL_W, PHONE_LABEL_H); + phoneLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, PHONE_LABEL_FONT); + phoneLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + + stutasLabel_.SetPosition(STATUS_LABEL_X, STATUS_LABEL_Y, STATUS_LABEL_W, STATUS_LABEL_H); + stutasLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, STATUS_LABEL_FONT); + stutasLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + stutasLabel_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + + Add(&bg_); + Add(&icon_); + Add(&stutasLabel_); + Add(&phoneLabel_); +} + +PhoneMenuCallerLogItemView::~PhoneMenuCallerLogItemView() +{ + Remove(&bg_); + Remove(&icon_); + Remove(&stutasLabel_); + Remove(&phoneLabel_); +} + +void PhoneMenuCallerLogItemView::SetItemInfo(const CallLogInfo &itemInfo) +{ + memset_s(tel_, MAX_PHONE_NUM, 0, MAX_PHONE_NUM); + memcpy_s(tel_, MAX_PHONE_NUM, itemInfo.tel, itemInfo.telLen); + phoneLabel_.SetText(itemInfo.name); + if (strlen(itemInfo.name) == 0 || itemInfo.nameLen == 0) { + phoneLabel_.SetText((const char *)itemInfo.tel); + } + std::string timeStr; + struct tm pTM; + localtime_r((time_t *)&itemInfo.creationTime, &pTM); + if (pTM.tm_mon < NUM_10) { + timeStr += "0"; + } + timeStr += std::to_string(pTM.tm_mon) + "/"; + if (pTM.tm_mday < NUM_10) { + timeStr += "0"; + } + timeStr += std::to_string(pTM.tm_mday); + if (itemInfo.status == CALL_MISSED) { + stutasLabel_.SetText(("未接来电 " + timeStr).c_str()); + phoneLabel_.SetStyle(STYLE_TEXT_COLOR, Color::Red().full); + LOADIMG::LoadImageViewImg(&icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLIN); + } else if (itemInfo.status == CALL_INCOMING) { + stutasLabel_.SetText(("接听 " + timeStr).c_str()); + LOADIMG::LoadImageViewImg(&icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLIN); + } else if (itemInfo.status == CALL_OUTGOING) { + stutasLabel_.SetText(("拨号 " + timeStr).c_str()); + LOADIMG::LoadImageViewImg(&icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLOUT); + } + SetViewId("CallerLogItem"); +} + +unsigned char *PhoneMenuCallerLogItemView::GetItemPhoneNumber() +{ + return tel_; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogModel.cpp new file mode 100644 index 000000000..faf55c8a0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogModel.cpp @@ -0,0 +1,844 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogModel + * Create: 2025-07-12 + */ + +#include +#include +#include "ohos_timer.h" +#include "graphic_timer.h" +#include "samgr_lite.h" +#include "graphic_service.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "NativeAbility.h" +#include "notification_manager.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallingPage.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using namespace OHOS; + +static int g_callTimes{0}; +static constexpr int NO_NUMBER_STATUS = -1; +static int g_phoneStatus = PHONE_SINGLE_STATUS; +static int g_isCall{NO_NUMBER_STATUS}; +static PhoneCallInfo callInfo{}; +static int g_retNum{0}; +static int g_volumeLocal{0}; +GraphicTimer *g_startCounting = nullptr; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +static PhoneCallInfo callList[MULTI_CALL_MAX_NUME]{}; +static int g_firstPriority = NO_NUMBER_STATUS; +static int g_secondPriority = NO_NUMBER_STATUS; +static int g_thirdPriority = NO_NUMBER_STATUS; +static int g_fourthPriority = NO_NUMBER_STATUS; +static bool g_isWatchCallView = false; +static constexpr int16 USLEEP_NUM = 5000; +static constexpr int16 ONE_NUM = 1; + +static void SetPriorityNumber() +{ + time_t seconds; + time(&seconds); + + if (g_firstPriority != NO_NUMBER_STATUS) { + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(callList[g_firstPriority].unitCalls.number, + callList[g_firstPriority].unitCalls.number_len); + g_callTimes = seconds - callList[g_firstPriority].activeTime; + } else if (g_secondPriority != NO_NUMBER_STATUS) { + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(callList[g_secondPriority].unitCalls.number, + callList[g_secondPriority].unitCalls.number_len); + g_callTimes = seconds - callList[g_secondPriority].activeTime; + } else if (g_thirdPriority != NO_NUMBER_STATUS) { + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(callList[g_thirdPriority].unitCalls.number, + callList[g_thirdPriority].unitCalls.number_len); + } else if (g_fourthPriority != NO_NUMBER_STATUS) { + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(callList[g_fourthPriority].unitCalls.number, + callList[g_fourthPriority].unitCalls.number_len); + } + return; +} + +static void DisableCallingTimer() +{ + if (g_startCounting != nullptr) { + delete g_startCounting; + g_startCounting = nullptr; + g_callTimes = 0; + } +} + +static void StatusReset() +{ + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(false); + DisableCallingTimer(); + if (!PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + PhoneMenuCallerLogModel::GetInstance()->BackToPrePage(); + } else { + g_isWatchCallView = false; + } + return; +} + +static void CallTimerCallbackProc(void *data) +{ + g_callTimes++; + + if (PhoneMenuCallingPage::GetInstance() == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallTimerCallbackProc] GetInstance is nullptr"); + return; + } + + if (PhoneMenuCallingPage::GetInstance()->GetCallingStateLabel() == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "[CallTimerCallbackProc] GetInstance()->GetCallingStateLabel is nullptr"); + return; + } + + if (PhoneMenuCallingPage::GetInstance()->GetCallingState() == PhoneMenuCallingPage::CallingState::SESSION) { + PhoneMenuCallingPage::GetInstance()->GetCallingStateLabel()->SetText( + PhoneMenuCallerLogModel::GetInstance()->DisplayCallDuration().c_str()); + } +} + +static void CallTimerCallback(void *data) +{ + GraphicService::GetInstance()->PostGraphicEvent(std::bind(CallTimerCallbackProc, data)); +} + +static void InitCallingTimer() +{ + if (g_startCounting != nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogModel::CallerTimer already exists!!"); + return; + } + uint32 tick = GetOSTick(MS_ONE_SECONDS); + g_startCounting = new GraphicTimer(tick, CallTimerCallback, nullptr, true); + if (g_startCounting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogModel::CallerTimer new GraphicTimer failed!!"); + return; + } + bool retTimer = g_startCounting->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogModel::CallerTimer Start failed!!"); + if (g_startCounting != nullptr) { + delete g_startCounting; + g_startCounting = nullptr; + } + return; + } +} + +bool FindCallListInfoAndSetPriorityNumber() +{ + g_isCall = NO_NUMBER_STATUS; + g_firstPriority = NO_NUMBER_STATUS; + g_secondPriority = NO_NUMBER_STATUS; + g_thirdPriority = NO_NUMBER_STATUS; + g_fourthPriority = NO_NUMBER_STATUS; + (void)memset_s(callList, MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo), 0, + MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo)); + int ret = GetCallInfoInCallList(callList, MULTI_CALL_MAX_NUME, &g_retNum); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindCallListInfoAndSetPriorityNumber Error ret = %d", ret); + return false; + } + if (g_retNum == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindCallListInfoAndSetPriorityNumber no call num"); + return false; + } + + if (g_retNum > 0 && g_retNum <= MULTI_CALL_MAX_NUME) { + for (int i = 0; i < g_retNum; i++) { + if (callList[i].lastStatus == HFP_HF_CALL_STATE_ACTIVE) { + g_firstPriority = i; + g_isCall = callList[i].lastStatus; + break; + } else if (callList[i].lastStatus == HFP_HF_CALL_STATE_HELD) { + g_secondPriority = i; + g_isCall = callList[i].lastStatus; + } else if (callList[i].lastStatus == HFP_HF_CALL_STATE_ALERTING || + callList[i].lastStatus == HFP_HF_CALL_STATE_DIALING) { + if (g_secondPriority == NO_NUMBER_STATUS) { + g_isCall = callList[i].lastStatus; + } + g_thirdPriority = i; + } else if (callList[i].lastStatus == HFP_HF_CALL_STATE_INCOMING || + callList[i].lastStatus == HFP_HF_CALL_STATE_WAITING) { + if (g_isCall == NO_NUMBER_STATUS && callList[i].lastStatus == HFP_HF_CALL_STATE_INCOMING) { + g_isCall = callList[i].lastStatus; + } + g_fourthPriority = i; + } + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindCallListInfoAndSetPriorityNumber] [%d] [%d] [%d] [%d], g_isCall = %d", + g_firstPriority, g_secondPriority, g_thirdPriority, g_fourthPriority, g_isCall); + SetPriorityNumber(); + return true; +} + +static void CallModelResumePlayer(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallModelResumePlayer] [ResumePlayer] start"); + usleep(USLEEP_NUM); +} + +static void CallModelPostGraphicEvent(void (*fun)(void)) +{ + GraphicService::GetInstance()->PostGraphicEvent(*fun); +} + +static int g_callOperate = OPERATE_NO_OPE; + +static void ExitMakePhoneSlice(void) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET)) { + WEARABLE_LOGD(HILOG_MODULE_AAFWK, "ExitMakePhoneSlice"); + + if (GetCurrCallNum() == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + CallModelPostGraphicEvent(CallModelResumePlayer); + } else { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + } + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + DisableCallingTimer(); + if (PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + g_isWatchCallView = false; + } +} + +static void DialingHandle(void) +{ + PhoneMenuCallerLogModel::GetInstance()->SetDialingStatus("正在拨号"); + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(true); +} + +static void AlertingHandle(void) +{ + PhoneMenuCallerLogModel::GetInstance()->SetDialingStatus("正在响铃"); + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(true); +} + +static void IncomingHandle(void) +{ + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(false); +} + +static void WaitingOpreate() +{ + if (!IsCompleteCallFlow()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[UsingPhoneChangeStatusCallback] is not complete call flow"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[WaitingOpreate] WaitingOpreate"); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(true); + if (!PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); + } + } else { + g_isWatchCallView = true; + } +} + +static void WatchActiveHandle(const PhoneCallInfo *phoneCall) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || + NativeAbility::GetInstance().GetCurSliceId() == VIEW_OFFLINEVOICE || + PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + time_t seconds; + time(&seconds); + g_callTimes = seconds - phoneCall->activeTime; + + InitCallingTimer(); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + } + if (PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + g_isWatchCallView = true; + } +} + +static void PhoneActiveHandle(void) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || + g_isWatchCallView) { + if (GetCurrCallNum() > ONE_NUM) { + g_phoneStatus = PHONE_MULTI_STATUS; + if (GetScoConnectState() == HFP_SCO_STATE_DISCONNECTED) { + DisableCallingTimer(); + } + } + TransCallToMobilePhone(); + PhoneMenuCallerLogModel::GetInstance()->BackToPrePage(); + CallModelPostGraphicEvent(CallModelResumePlayer); + } + usleep(USLEEP_NUM); + g_callOperate = OPERATE_WATCH_ACTIVE; +} + +static void OppoActiveHandle(const PhoneCallInfo *phoneCall) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || + g_isWatchCallView) { + if (GetCurrCallNum() > ONE_NUM) { + g_phoneStatus = PHONE_MULTI_STATUS; + return; + } + time_t seconds; + time(&seconds); + g_callTimes = seconds - phoneCall->activeTime; + InitCallingTimer(); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + } +} + +bool MulitplePhoneTextReplaces() +{ + DisableCallingTimer(); + PhoneMenuCallingPage::GetInstance()->GetCallingPhoneNumberLabel()->SetText("正在通话"); + PhoneMenuCallingPage::GetInstance()->GetCallingStateLabel()->SetText(""); + return true; +} + +static bool MultiplePhonesViewDisplay() +{ + if (g_phoneStatus == PHONE_MULTI_STATUS) { + if (NativeAbility::GetInstance().GetCurTargetId() != + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MultiplePhonesViewDisplay]GetCurSliceId no PHONE_MENU_CALLING_PAGE"); + DisableCallingTimer(); + PhoneMenuCallerLogModel::GetInstance()->SetMulitplePhoneStatus(true); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + if (!PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); + } else { + g_isWatchCallView = true; + } + return true; + } + if (!MulitplePhoneTextReplaces()) { + return false; + } + return true; + } + return false; +} + +static void NonWatchFinishHandle(int laststatus) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || + PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + if (GetCurrCallNum() == 0) { + PhoneMenuCallerLogModel::GetInstance()->SetNotifyFlag(false); + StatusReset(); + CallModelPostGraphicEvent(CallModelResumePlayer); + g_phoneStatus = PHONE_SINGLE_STATUS; + } else if (g_phoneStatus == PHONE_MULTI_STATUS) { + MultiplePhonesViewDisplay(); + } else if (FindCallListInfoAndSetPriorityNumber()) { + if (laststatus == HFP_HF_CALL_STATE_ACTIVE || laststatus == HFP_HF_CALL_STATE_HELD) { + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); + } else if (laststatus == HFP_HF_CALL_STATE_WAITING) { + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); + } + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); + } + } + if (GetCurrCallNum() == 0) { + PhoneMenuCallerLogModel::GetInstance()->SetNotifyFlag(false); + } + } + if (GetCurrCallNum() == 0) { + g_phoneStatus = PHONE_SINGLE_STATUS; + } +} + +static void WatchFinishHandle(void) +{ + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || + PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + if (GetCurrCallNum() == 0) { + PhoneMenuCallerLogModel::GetInstance()->SetNotifyFlag(false); + StatusReset(); + } else { + StatusReset(); + for (int i = GetCurrCallNum(); i > 0; i--) { + FinishCall(); + } + } + } + g_phoneStatus = PHONE_SINGLE_STATUS; +} + +static void ChangeStatusScreendisplay(int lastStatus) +{ + if (GetScoConnectState() != HFP_SCO_STATE_CONNECTED) { + if (lastStatus == HFP_HF_CALL_STATE_ACTIVE) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] STATE_ACTIVE"); + StatusReset(); + return; + } else if (lastStatus == HFP_HF_CALL_STATE_INCOMING) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] STATE_INCOMING"); + } else if (GetCurrCallNum() == ONE_NUM && + (lastStatus == HFP_HF_CALL_STATE_DIALING || lastStatus == HFP_HF_CALL_STATE_ALERTING)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] STATE_ALERTING"); + } else if (GetCurrCallNum() > ONE_NUM) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] GetCurrCallNum MULITE"); + DisableCallingTimer(); + return; + } + } + if (!IsCompleteCallFlow()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] is not complete call flow"); + return; + } + if (MultiplePhonesViewDisplay()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ChangeStatusScreendisplay] MultiplePhonesViewDisplay"); + return; + } + if (g_callOperate != OPERATE_PHONE_ACTIVE && (!PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag())) { + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); + } + } +} + +void UsingPhoneChangeStatusCallback(const PhoneCallInfo *phoneCall) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[UsingPhoneChangeStatusCallback] operate:%d, callNUm:%d, call flow:%d", + phoneCall->operate, GetCurrCallNum(), IsCompleteCallFlow()); + + if (phoneCall->operate == OPERATE_WATCH_FINISH && GetCurrCallNum() == 0) { + g_callOperate = OPERATE_WATCH_FINISH; + WatchFinishHandle(); + return; + } + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(phoneCall->unitCalls.number, + phoneCall->unitCalls.number_len); + g_callOperate = phoneCall->operate; + + switch (g_callOperate) { + case OPERATE_DIALING: + DialingHandle(); + break; + case OPERATE_ALERTING: + AlertingHandle(); + break; + case OPERATE_INCOMING: + IncomingHandle(); + break; + case OPERATE_WAITING: + WaitingOpreate(); + return; + case OPERATE_WATCH_ACTIVE: + WatchActiveHandle(phoneCall); + break; + case OPERATE_PHONE_ACTIVE: + PhoneActiveHandle(); + return; + case OPERATE_PEER_ACTIVE: + OppoActiveHandle(phoneCall); + break; + case OPERATE_PHONE_HOLD: + return; + case OPERATE_WATCH_FINISH: + WatchFinishHandle(); + return; + case OPERATE_WATCH_REJECT: + case OPERATE_NON_WATCH_FINISH: + NonWatchFinishHandle(phoneCall->lastStatus); + return; + default: + break; + } + ChangeStatusScreendisplay(phoneCall->lastStatus); +} + +void UsingPhoneErrorCallback(PhoneServiceErrorType type) +{ + if (type == ERROR_DIAL) { + } else if (type == ERROR_BT) { + WEARABLE_LOGD(HILOG_MODULE_AAFWK, "UsingPhoneErrorCallback BT"); + ExitMakePhoneSlice(); + } +} + +static void ScoConnectHandle(void) +{ + if (GetCurrCallNum() == 0) { + return; + } + + if (!FindCallListInfoAndSetPriorityNumber()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScoConnectHandle FindCallListInfoAndSetPriorityNumber false"); + return; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectHandle] g_isCall = %d", g_isCall); + switch (g_isCall) { + case HFP_HF_CALL_STATE_ACTIVE: + if (g_callOperate == OPERATE_PHONE_ACTIVE) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectHandle] OPERATE_PHONE_ACTIVE"); + return; + } + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + InitCallingTimer(); + break; + case HFP_HF_CALL_STATE_ALERTING: + PhoneMenuCallerLogModel::GetInstance()->SetDialingStatus("正在响铃"); + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(true); + break; + case HFP_HF_CALL_STATE_DIALING: + PhoneMenuCallerLogModel::GetInstance()->SetDialingStatus("正在拨号"); + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(true); + break; + case HFP_HF_CALL_STATE_INCOMING: + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(false); + break; + case HFP_HF_CALL_STATE_HELD: + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + InitCallingTimer(); + break; + default: + break; + } + g_isCall = NO_NUMBER_STATUS; + if (!IsCompleteCallFlow()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectHandle] is not complete call flow"); + return; + } + if (MultiplePhonesViewDisplay()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectHandle] MultiplePhonesViewDisplay"); + return; + } + if (!PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); + } + } else { + g_isWatchCallView = true; + } +} + +static void ScoDisconnectHandle(void) +{ + ExitMakePhoneSlice(); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); +} + +void UsingPhoneScoStatausCallback(hfp_sco_connect_state_t state) +{ + WEARABLE_LOGD(HILOG_MODULE_AAFWK, "UsingPhoneScoStatausCallback SOC state: %d", state); + + if (!IsCompleteCallFlow()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[UsingPhoneScoStatausCallback] is not complete call flow"); + return; + } + + if (state == HFP_SCO_STATE_CONNECTED) { + ScoConnectHandle(); + } else if (state == HFP_SCO_STATE_DISCONNECTED) { + ScoDisconnectHandle(); + } +} + +void PhoneChangeStatusCallback(const PhoneCallInfo *phoneCall) +{ + (void)memset_s(&callInfo, sizeof(PhoneCallInfo), 0, sizeof(PhoneCallInfo)); + (void)memcpy_s(&callInfo, sizeof(PhoneCallInfo), phoneCall, sizeof(PhoneCallInfo)); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(UsingPhoneChangeStatusCallback, &callInfo)); +} + +void PhoneErrorCallback(PhoneServiceErrorType type, int volume) +{ + g_volumeLocal = volume; + GraphicService::GetInstance()->PostGraphicEvent(std::bind(UsingPhoneErrorCallback, type)); +} + +void PhoneScoStatausCallback(hfp_sco_connect_state_t state) +{ + GraphicService::GetInstance()->PostGraphicEvent(std::bind(UsingPhoneScoStatausCallback, state)); +} + +namespace OHOS { +static constexpr int32 NUM_TEN = 10; +static constexpr int16 NUM_TIME_MIN = 60; +static constexpr int16 NUM_TIME_HOUR = 3600; +static constexpr int32 NUM_TIME_DAY = 86400; +VolumeSettingView *g_volumeSetting = nullptr; + +void HonrsViewChange(void) +{ + if (g_volumeSetting == nullptr) { + g_volumeSetting = new VolumeSettingView(); + if (g_volumeSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallViewEventListener::g_volumeSetting nullptr err"); + return; + } + if (!g_volumeSetting->SetUpVolume()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallViewEventListener::g_volumeSetting SetUpVolume fail"); + return; + } + g_volumeSetting->GetProgress()->SetValue( + AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_CALL_BT_SCO)); + if (NotificationManager::GetInstance()->screenContainer_ != nullptr) { + NotificationManager::GetInstance()->screenContainer_->Add(g_volumeSetting); + } + } + VolumeSliderEventListener *volumeSliderEventListener = g_volumeSetting->GetVolumeEventListener(); + if (volumeSliderEventListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallViewEventListener::volumeSliderEventListener nullptr err"); + return; + } + + volumeSliderEventListener->SetPlayerCoefficients(VOLUMEPHONENOTIFY); + g_volumeSetting->SetVisible(true); + RootView::GetInstance()->Invalidate(); +} + +VolumeSettingView *GetvolumeSetting(void) +{ + return g_volumeSetting; +} + +PhoneMenuCallerLogModel::PhoneMenuCallerLogModel() +{ + PhoneMenuSync::ReadFileContact(CONTACTS_FILE_PATH); +} + +PhoneMenuCallerLogModel::~PhoneMenuCallerLogModel() {} + +std::list &PhoneMenuCallerLogModel::GetContacts() +{ + return PhoneMenuSync::GetContacts(); +} + +void PhoneMenuCallerLogModel::InitPhoneService() +{ + WEARABLE_LOGD(HILOG_MODULE_AAFWK, "PhoneMenuCallerLogModel::[InitPhoneService]::Init start"); + PhoneServiceInit(); + PhoneServiceCb serviceFoution; + + serviceFoution.callChanged = PhoneChangeStatusCallback; + serviceFoution.phoneServiceErrorCb = PhoneErrorCallback; + serviceFoution.scoStatusCb = PhoneScoStatausCallback; + int ret = RegisterCallChangedCb(&serviceFoution); + WEARABLE_LOGD(HILOG_MODULE_AAFWK, "PhoneMenuCallerLogModel::[InitPhoneService]::Init ret = %d", ret); +} + +std::string PhoneMenuCallerLogModel::InitDateHourTime(void) +{ + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + timers_.erase(); + if (pTM.tm_min < NUM_TEN) { + std::string min = "0" + std::to_string(pTM.tm_min); + timers_ = std::to_string(pTM.tm_hour) + ":" + min; + return timers_; + } + timers_ = std::to_string(pTM.tm_hour) + ":" + std::to_string(pTM.tm_min); + return timers_; +} + +std::string &PhoneMenuCallerLogModel::DisplayCallDuration() +{ + callDuration_.erase(); + std::string hours; + std::string minute; + std::string seconds; + if (g_callTimes >= NUM_TIME_DAY) { + g_callTimes = 0; + } + int hour = g_callTimes / NUM_TIME_HOUR; + int min = (g_callTimes % NUM_TIME_HOUR) / NUM_TIME_MIN; + int sec = (g_callTimes % NUM_TIME_HOUR) % NUM_TIME_MIN; + if (hour >= 0 && hour < NUM_TEN) { + hours = "0" + std::to_string(hour); + } else { + hours = std::to_string(hour); + } + if (min >= 0 && min < NUM_TEN) { + minute = "0" + std::to_string(min); + } else { + minute = std::to_string(min); + } + if (sec >= 0 && sec < NUM_TEN) { + seconds = "0" + std::to_string(sec); + } else { + seconds = std::to_string(sec); + } + + if (hour == 0) { + callDuration_ = "通话中 " + minute + ":" + seconds; + } else { + callDuration_ = "通话中 " + hours + ":" + minute + ":" + seconds; + } + return callDuration_; +} + +void PhoneMenuCallerLogModel::SetDialingStatus(const char *text) +{ + dialingStatus_.clear(); + dialingStatus_.append(reinterpret_cast(text)); +} + +std::string PhoneMenuCallerLogModel::GetDialingStatus(void) +{ + return dialingStatus_; +} + +void PhoneMenuCallerLogModel::SetNotifyFlag(bool flag) +{ + notifyFlag_ = flag; +} + +bool PhoneMenuCallerLogModel::GetNotifyFlag(void) +{ + return notifyFlag_; +} + +bool PhoneMenuCallerLogModel::IsMulitplePhoneStatus(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "IsMulitplePhoneStatus phoneStatus_:%d", g_phoneStatus); + return g_phoneStatus == PHONE_MULTI_STATUS; +} + +void PhoneMenuCallerLogModel::SetMulitplePhoneStatus(bool status) +{ + mulitplePhoneStatus_ = status; +} + +bool PhoneMenuCallerLogModel::GetMulitplePhoneStatus() +{ + return mulitplePhoneStatus_; +} + +bool PhoneMenuCallerLogModel::GetWaitingStatus() +{ + return waitingStatus_; +} +void PhoneMenuCallerLogModel::SetWaitingStatus(bool status) +{ + waitingStatus_ = status; +} + +void PhoneMenuCallerLogModel::SetCallStatus(bool status) +{ + callStatus_ = status; +} + +bool PhoneMenuCallerLogModel::GetCallStatus() +{ + return callStatus_; +} + +void PhoneMenuCallerLogModel::SetVolumeScreenStatus(bool status) +{ + volumeStatus_ = status; +} + +bool PhoneMenuCallerLogModel::GetVolumeScreenStatus() +{ + return volumeStatus_; +} + +void PhoneMenuCallerLogModel::SetoperateNumber(const char *number, char number_len) +{ + phoneNumber_.clear(); + phoneNumber_.append(number, number_len); +} + +std::string PhoneMenuCallerLogModel::GetPhoneNumber(void) +{ + return phoneNumber_; +} + +void PhoneMenuCallerLogModel::SetMakePhoneStatus(bool status) +{ + phoneStatus_ = status; +} + +bool PhoneMenuCallerLogModel::GetPhoneStatus() +{ + return phoneStatus_; +} + +int PhoneMenuCallerLogModel::CurrCallNum(void) +{ + return GetCurrCallNum(); +} + +PhoneMenuCallerLogModel *PhoneMenuCallerLogModel::GetInstance(void) +{ + static PhoneMenuCallerLogModel callLogModel; + return &callLogModel; +} + +void PhoneMenuCallerLogModel::SaveCurPage() +{ + uint32_t targetId = NativeAbility::GetInstance().GetCurTargetId(); + if (targetId == VIEW_AOD) { + preSliceId_ = VIEW_MAIN_SAMPLE; + prePageId_ = 0; + } else { + preSliceId_ = static_cast(targetId & SLICE_MASK); + prePageId_ = static_cast(targetId >> PAGE_OFFSET); + } + WEARABLE_LOGD( + WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogModel SaveCurPage:%d %d %d", targetId, preSliceId_, prePageId_); +} + +void PhoneMenuCallerLogModel::BackToPrePage() +{ + if (prePageId_ != 0) { + NativeAbility::GetInstance().SwitchSlice(preSliceId_, prePageId_); + } else { + NativeAbility::GetInstance().ChangeSlice(preSliceId_); + } +} +} +#ifdef __cplusplus +} +#endif diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogPage.cpp new file mode 100644 index 000000000..4db4739c1 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallerLogPage.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallerLogPage + * Create: 2025-06-06 + */ + +#include +#include "UiConfig.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogItemView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" +#include "phonemenu/PhoneMenuCallerLogPage.h" + +namespace OHOS { +static constexpr uint16_t TITLI_LABEL_X = 97; +static constexpr uint16_t TITLI_LABEL_Y = 31; +static constexpr uint16_t TITLI_LABEL_W = 260; +static constexpr uint16_t TITLI_LABEL_H = 53; +static constexpr uint16_t TITLI_LABEL_FONT = 38; +static constexpr uint16_t NOCALL_LABEL_X = 156; +static constexpr uint16_t NOCALL_LABEL_Y = 202; +static constexpr uint16_t NOCALL_LABEL_W = 148; +static constexpr uint16_t NOCALL_LABEL_H = 50; +static constexpr uint16_t NOCALL_LABEL_FONT = 36; +static constexpr uint16_t CLEAR_LABEL_X = 156; +static constexpr uint16_t CLEAR_LABEL_W = 148; +static constexpr uint16_t CLEAR_LABEL_H = 50; +static constexpr uint16_t CLEAR_LABEL_FONT = 36; +static constexpr uint16_t LIST_X = 17; +static constexpr uint16_t LIST_Y = 110; +static constexpr uint16_t LIST_W = 418; +static constexpr uint16_t LIST_H = 344; +static constexpr uint16_t LIST_ITEM_W = 418; +static constexpr uint16_t LIST_ITEM_H = 143; +static constexpr uint16_t TOP_BLANK_SIZE = 31; +static constexpr uint16_t BOTTOM_BLANK_SIZE = 80; +const char *PHONE_MENU_CLEAR_BUTTON = "phoneMenuClearButton"; + +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLER_LOG_PAGE, PhoneMenuCallerLogPage, false); + +static PhoneMenuCallerLogPage *g_PhoneMenuCallerLogPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + PhoneMenuCallerLogItemView *item = new PhoneMenuCallerLogItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_PhoneMenuCallerLogPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + PhoneMenuCallerLogItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + CallLogInfo *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +PhoneMenuCallerLogPage::PhoneMenuCallerLogPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage::PhoneMenuCallerLogPage"); + g_PhoneMenuCallerLogPageInstance = this; +} + +PhoneMenuCallerLogPage::~PhoneMenuCallerLogPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (noCallLabel_ != nullptr) { + delete noCallLabel_; + noCallLabel_ = nullptr; + } + if (clearButton_ != nullptr) { + delete clearButton_; + clearButton_ = nullptr; + } + if (callerLogList_ != nullptr) { + delete callerLogList_; + callerLogList_ = nullptr; + } + if (info_ != nullptr) { + delete[] info_; + info_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage::~PhoneMenuCallerLogPage"); +} + +void PhoneMenuCallerLogPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(TITLI_LABEL_X, TITLI_LABEL_Y, TITLI_LABEL_W, TITLI_LABEL_H); + titleLabel_->SetText("最近通话"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, TITLI_LABEL_FONT); + group_->Add(titleLabel_); + + noCallLabel_ = new UILabel(); + if (noCallLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage noCallLabel_ new fail"); + return; + } + noCallLabel_->SetPosition(NOCALL_LABEL_X, NOCALL_LABEL_Y, NOCALL_LABEL_W, NOCALL_LABEL_H); + noCallLabel_->SetText("暂无通话"); + noCallLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + noCallLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, NOCALL_LABEL_FONT); + group_->Add(noCallLabel_); + + clearButton_ = new UILabelButton(); + if (clearButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage clearButton_ new fail"); + return; + } + clearButton_->SetText("全部清除"); + clearButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CLEAR_LABEL_FONT); + clearButton_->SetViewId(PHONE_MENU_CLEAR_BUTTON); + clearButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + clearButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + clearButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + clearButton_->SetOnClickListener(this); + group_->Add(clearButton_); + + callerLogList_ = new UISimpleList(); + if (callerLogList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage callerLogList_ new fail"); + return; + } + callerLogList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + callerLogList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + callerLogList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + callerLogList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + int num = 0; + if (GetCallLog(&info_, &num) == -1) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage GetCallLog fail"); + } + + for (int i = num - 1; i >= 0; i--) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&info_[i]); + callerLogList_->AddContent(content); + } + callerLogList_->RefreshList(); + group_->Add(callerLogList_); + + if (num == 0) { + noCallLabel_->SetVisible(true); + callerLogList_->SetVisible(false); + clearButton_->SetVisible(false); + } else { + group_->SetYScrollBarVisible(true); + group_->SetScrollBlankSize(TOP_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + group_->SetScrollBlankSize(BOTTOM_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + noCallLabel_->SetVisible(false); + callerLogList_->SetVisible(true); + callerLogList_->Resize(LIST_W, LIST_ITEM_H * num); + clearButton_->SetVisible(true); + clearButton_->SetPosition(CLEAR_LABEL_X, LIST_Y + LIST_ITEM_H * num, CLEAR_LABEL_W, CLEAR_LABEL_H); + } + + AddViewToPageContainer(group_); +} + +bool PhoneMenuCallerLogPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool PhoneMenuCallerLogPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), PHONE_MENU_CLEAR_BUTTON) == 0) { + if (ClearCallLogFile() == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage ClearCallLogFile success"); + } + callerLogList_->ClearAll(); + callerLogList_->RefreshList(); + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLER_LOG_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else { + if (GetBtConnectStatus() != PROFILE_STATE_CONNECTED) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_DISCONNECT_PAGE, + TransitionType::TRANSITION_INVALID, false); + return true; + } + + PhoneMenuCallerLogItemView *itemView = dynamic_cast(&view); + if (itemView == nullptr) { + return false; + } + unsigned char *phoneNumber = itemView->GetItemPhoneNumber(); + SetMicMute(false); + PhoneMenuCallerLogModel::GetInstance()->SetMicMute(false); + if (DialCall(phoneNumber, strlen((const char *)phoneNumber)) != OHOS_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallerLogPage DialCall fail"); + return false; + } + PhoneMenuCallerLogModel::GetInstance()->SaveCurPage(); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallingPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallingPage.cpp new file mode 100644 index 000000000..903089e26 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuCallingPage.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuCallingPage + * Create: 2025-06-06 + */ + +#include "AppViewIDs.h" +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "ui_resource_phonemenu.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" +#include "phonemenu/PhoneMenuCallingPage.h" + +namespace OHOS { +static constexpr uint16_t PHONE_LABEL_X = 74; +static constexpr uint16_t PHONE_LABEL_Y = 143; +static constexpr uint16_t PHONE_LABEL_W = 320; +static constexpr uint16_t PHONE_LABEL_H = 46; +static constexpr uint16_t PHONE_LABEL_FONT = 46; +static constexpr uint16_t STATE_LABEL_X1 = 185; +static constexpr uint16_t STATE_LABEL_X2 = 125; +static constexpr uint16_t STATE_LABEL_Y = 204; +static constexpr uint16_t STATE_LABEL_W = 238; +static constexpr uint16_t STATE_LABEL_H = 46; +static constexpr uint16_t STATE_LABEL_FONT = 34; +static constexpr uint16_t ICON_X = 142; +static constexpr uint16_t ICON_Y = 214; +static constexpr uint16_t BUTTON_X1 = 109; +static constexpr uint16_t BUTTON_X2 = 249; +static constexpr uint16_t BUTTON_X3 = 186; +static constexpr uint16_t BUTTON_Y = 300; +static constexpr uint16_t BUTTON_W = 85; +static constexpr uint16_t BUTTON_H = 85; +static const char *HANG_UP_BUTTON_ID = "callingHangUp"; +static const char *ANSWER_BUTTON_ID = "callingAnswer"; +static const char *VOLUME_BUTTON_ID = "microphoneChange"; +static PhoneMenuCallingPage *g_phoneMenuCallingPage = nullptr; + +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE, PhoneMenuCallingPage, false); + +PhoneMenuCallingPage::PhoneMenuCallingPage() +{ + g_phoneMenuCallingPage = this; +} + +PhoneMenuCallingPage::~PhoneMenuCallingPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (icon_ != nullptr) { + delete icon_; + icon_ = nullptr; + } + if (phoneNumber_ != nullptr) { + delete phoneNumber_; + phoneNumber_ = nullptr; + } + if (stateLabel_ != nullptr) { + delete stateLabel_; + stateLabel_ = nullptr; + } + if (answerButton_ != nullptr) { + delete answerButton_; + answerButton_ = nullptr; + } + if (hangUpButton_ != nullptr) { + delete hangUpButton_; + hangUpButton_ = nullptr; + } + if (volumeButton_ != nullptr) { + delete volumeButton_; + volumeButton_ = nullptr; + } + g_phoneMenuCallingPage = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage::~PhoneMenuCallingPage"); +} + +PhoneMenuCallingPage *PhoneMenuCallingPage::GetInstance() +{ + return g_phoneMenuCallingPage; +} + +UILabel *PhoneMenuCallingPage::GetCallingPhoneNumberLabel() +{ + return phoneNumber_; +} + +UILabel *PhoneMenuCallingPage::GetCallingStateLabel() +{ + return stateLabel_; +} + +PhoneMenuCallingPage::CallingState PhoneMenuCallingPage::GetCallingState() +{ + return state_; +} + +void PhoneMenuCallingPage::CreateUILabel() +{ + phoneNumber_ = new UILabel(); + if (phoneNumber_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage phoneNumber_ new fail"); + return; + } + phoneNumber_->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, PHONE_LABEL_W, PHONE_LABEL_H); + phoneNumber_->SetText(PhoneMenuCallerLogModel::GetInstance()->GetPhoneNumber().c_str()); + phoneNumber_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, PHONE_LABEL_FONT); + phoneNumber_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(phoneNumber_); + + stateLabel_ = new UILabel(); + if (stateLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage stateLabel_ new fail"); + return; + } + stateLabel_->SetPosition(STATE_LABEL_X1, STATE_LABEL_Y, STATE_LABEL_W, STATE_LABEL_H); + stateLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STATE_LABEL_FONT); + stateLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + stateLabel_->SetTextColor(Color::Green()); + group_->Add(stateLabel_); + + icon_ = new UIImageView(); + if (icon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage icon_ new fail"); + return; + } + icon_->SetPosition(ICON_X, ICON_Y); + group_->Add(icon_); +} + +void PhoneMenuCallingPage::CreateUIButton() +{ + answerButton_ = new UIButton(); + if (answerButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage answerButton_ new fail"); + return; + } + answerButton_->SetPosition(BUTTON_X2, BUTTON_Y, BUTTON_W, BUTTON_H); + answerButton_->SetViewId(ANSWER_BUTTON_ID); + answerButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + answerButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + answerButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(answerButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_ANSWER, IMAGE_PHONEMENU_ANSWER); + answerButton_->SetOnClickListener(this); + group_->Add(answerButton_); + + hangUpButton_ = new UIButton(); + if (hangUpButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage hangUpButton_ new fail"); + return; + } + hangUpButton_->SetViewId(HANG_UP_BUTTON_ID); + hangUpButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + hangUpButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + hangUpButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(hangUpButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_HANGUP, IMAGE_PHONEMENU_HANGUP); + hangUpButton_->SetOnClickListener(this); + group_->Add(hangUpButton_); + + volumeButton_ = new UIButton(); + if (volumeButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage volumeButton_ new fail"); + return; + } + volumeButton_->SetPosition(BUTTON_X2, BUTTON_Y, BUTTON_W, BUTTON_H); + volumeButton_->SetViewId(VOLUME_BUTTON_ID); + volumeButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + volumeButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + volumeButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + bool isMicMute = PhoneMenuCallerLogModel::GetInstance()->GetMicMute(); + if (isMicMute) { + LOADIMG::LoadBtnImage(volumeButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_MIC_MUTE, IMAGE_PHONEMENU_MIC_MUTE); + } else { + LOADIMG::LoadBtnImage(volumeButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_MIC, IMAGE_PHONEMENU_MIC); + } + volumeButton_->SetOnClickListener(this); + group_->Add(volumeButton_); +} + +void PhoneMenuCallingPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreateUILabel(); + CreateUIButton(); + AddViewToPageContainer(group_); + + if (PhoneMenuCallerLogModel::GetInstance()->GetCallStatus()) { + state_ = CallingState::SESSION; + stateLabel_->SetPosition(STATE_LABEL_X2, STATE_LABEL_Y, STATE_LABEL_W, STATE_LABEL_H); + stateLabel_->SetText(PhoneMenuCallerLogModel::GetInstance()->DisplayCallDuration().c_str()); + icon_->SetVisible(false); + hangUpButton_->SetVisible(true); + hangUpButton_->SetPosition(BUTTON_X1, BUTTON_Y, BUTTON_W, BUTTON_H); + answerButton_->SetVisible(false); + volumeButton_->SetVisible(true); + } else if (PhoneMenuCallerLogModel::GetInstance()->GetWaitingStatus()) { + state_ = CallingState::WAITING; + stateLabel_->SetText("新来电..."); + icon_->SetVisible(true); + LOADIMG::LoadImageViewImg(icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLIN_ICON); + hangUpButton_->SetVisible(true); + hangUpButton_->SetPosition(BUTTON_X3, BUTTON_Y, BUTTON_W, BUTTON_H); + answerButton_->SetVisible(false); + volumeButton_->SetVisible(false); + } else if (PhoneMenuCallerLogModel::GetInstance()->GetPhoneStatus()) { + state_ = CallingState::OUTGOING; + stateLabel_->SetText("正在呼叫..."); + icon_->SetVisible(true); + LOADIMG::LoadImageViewImg(icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLOUT_ICON); + hangUpButton_->SetVisible(true); + hangUpButton_->SetPosition(BUTTON_X3, BUTTON_Y, BUTTON_W, BUTTON_H); + answerButton_->SetVisible(false); + volumeButton_->SetVisible(false); + } else { + state_ = CallingState::INCOMING; + stateLabel_->SetText("手机来电"); + icon_->SetVisible(true); + LOADIMG::LoadImageViewImg(icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALLIN_ICON); + hangUpButton_->SetVisible(true); + hangUpButton_->SetPosition(BUTTON_X1, BUTTON_Y, BUTTON_W, BUTTON_H); + answerButton_->SetVisible(true); + volumeButton_->SetVisible(false); + } + + PhoneMenuCallerLogModel::GetInstance()->SetVolumeScreenStatus(false); + if (PhoneMenuCallerLogModel::GetInstance()->GetMulitplePhoneStatus()) { + MulitplePhoneTextReplaces(); + PhoneMenuCallerLogModel::GetInstance()->SetMulitplePhoneStatus(false); + } +} + +bool PhoneMenuCallingPage::OnDrag(UIView &view, const DragEvent &event) +{ + return false; +} + +bool PhoneMenuCallingPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), VOLUME_BUTTON_ID) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage VOLUME_BUTTON_ID"); + bool isMicMute = PhoneMenuCallerLogModel::GetInstance()->GetMicMute(); + if (!isMicMute) { + LOADIMG::LoadBtnImage(volumeButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_MIC_MUTE, IMAGE_PHONEMENU_MIC_MUTE); + } else { + LOADIMG::LoadBtnImage(volumeButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_MIC, IMAGE_PHONEMENU_MIC); + } + PhoneMenuCallerLogModel::GetInstance()->SetMicMute(!isMicMute); + SetMicMute(!isMicMute); + return true; + } else if (strcmp(view.GetViewId(), ANSWER_BUTTON_ID) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage ANSWER_BUTTON_ID"); + if (AcceptIncomingCall() != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage AcceptIncomingCall() fail"); + return false; + } + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + } else if (strcmp(view.GetViewId(), HANG_UP_BUTTON_ID) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage HANG_UP_BUTTON_ID"); + if (state_ == CallingState::WAITING) { + if (RejectIncomingCall() != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage RejectIncomingCall error"); + return false; + } + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(true); + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (state_ == CallingState::INCOMING) { + if (RejectIncomingCall() != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage RejectIncomingCall fail"); + return false; + } + PhoneMenuCallerLogModel::GetInstance()->BackToPrePage(); + } else { + if (FinishCall() != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuCallingPage FinishCall fail"); + return false; + } + PhoneMenuCallerLogModel::GetInstance()->SetMakePhoneStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + PhoneMenuCallerLogModel::GetInstance()->BackToPrePage(); + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsItemView.cpp new file mode 100644 index 000000000..b6ce0e9b0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsItemView.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuContactsItemView + * Create: 2025-07-12 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "phonemenu/PhoneMenuContactsItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_GROUP_X = 0; +static constexpr uint16_t BG_GROUP_Y = 7; +static constexpr uint16_t BG_GROUP_W = 383; +static constexpr uint16_t BG_GROUP_H = 88; +static constexpr uint16_t BG_BACKGROUND_OPA = 48; +static constexpr uint16_t BG_BORDER_RADIUS = 45; +static constexpr uint16_t ICON_X = 33; +static constexpr uint16_t ICON_Y = 26; +static constexpr uint16_t LABEL_X = 89; +static constexpr uint16_t LABEL_Y = 30; +static constexpr uint16_t LABEL_W = 294; +static constexpr uint16_t LABEL_H = 35; +static constexpr uint16_t LABEL_FONT = 32; + +PhoneMenuContactsItemView::PhoneMenuContactsItemView() +{ + bg_.SetPosition(BG_GROUP_X, BG_GROUP_Y, BG_GROUP_W, BG_GROUP_H); + bg_.SetStyle(STYLE_BACKGROUND_OPA, BG_BACKGROUND_OPA); + bg_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + bg_.SetStyle(STYLE_BORDER_RADIUS, BG_BORDER_RADIUS); + + icon_.SetPosition(ICON_X, ICON_Y); + LOADIMG::LoadImageViewImg(&icon_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CONTACTS); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + Add(&bg_); + Add(&icon_); + Add(&label_); +} + +PhoneMenuContactsItemView::~PhoneMenuContactsItemView() +{ + Remove(&bg_); + Remove(&icon_); + Remove(&label_); +} + +void PhoneMenuContactsItemView::SetItemInfo(const PhoneMenuContactsItem &itemInfo) +{ + itemInfo_ = itemInfo; + label_.SetText(itemInfo.name.c_str()); +} + +const char *PhoneMenuContactsItemView::GetContactsName() const +{ + return itemInfo_.name.c_str(); +} + +const char *PhoneMenuContactsItemView::GetContactsCid() const +{ + return itemInfo_.cid.c_str(); +} + +const char *PhoneMenuContactsItemView::GetContactsPhoneNumber() const +{ + return itemInfo_.phoneNumber.c_str(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsPage.cpp new file mode 100644 index 000000000..985f091ac --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuContactsPage.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuContactsPage + * Create: 2025-07-12 + */ + +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" +#include "phonemenu/PhoneMenuContactsItemView.h" +#include "phonemenu/PhoneMenuContactsPage.h" + +namespace OHOS { +static constexpr uint16_t LABEL_POS_X = 97; +static constexpr uint16_t LABEL_POS_Y = 31; +static constexpr uint16_t LABEL_WIDTH = 260; +static constexpr uint16_t LABEL_HEIGHT = 53; +static constexpr uint16_t LABEL_FONT_SIZE = 38; +static constexpr uint16_t IMAGE_POS_X = 174; +static constexpr uint16_t IMAGE_POS_Y = 111; +static constexpr uint16_t LABEL_POS_X_NO_CONTACTS = 104; +static constexpr uint16_t LABEL_POS_Y_NO_CONTACTS = 257; +static constexpr uint16_t LABEL_WIDTH_NO_CONTACTS = 246; +static constexpr uint16_t LABEL_HEIGHT_NO_CONTACTS = 100; +static constexpr uint16_t LABEL_FONT_NO_CONTACTS = 34; +static constexpr uint16_t LIST_POS_X = 35; +static constexpr uint16_t LIST_POS_Y = 104; +static constexpr uint16_t LIST_WIDTH = 383; +static constexpr uint16_t LIST_HEIGHT = 350; +static constexpr uint16_t LIST_ITEM_W = 383; +static constexpr uint16_t LIST_ITEM_H = 102; +static constexpr uint16_t CONTAINER_TOP_BLANK_SIZE = 31; +static constexpr uint16_t CONTAINER_BOTTOM_BLANK_SIZE = 100; + +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CONTACTS_PAGE, PhoneMenuContactsPage, false); + +static PhoneMenuContactsPage *g_PhoneMenuContactsPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + PhoneMenuContactsItemView *item = new PhoneMenuContactsItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_PhoneMenuContactsPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + PhoneMenuContactsItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + PhoneMenuContactsItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +void PhoneMenuContactsPage::OnStart(void *data) +{ + container_ = new UIScrollView(); + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage container_ new fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetOnDragListener(this); + container_->SetScrollBlankSize(CONTAINER_TOP_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + container_->SetScrollBlankSize(CONTAINER_BOTTOM_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + contactsLabel_ = new UILabel(); + if (contactsLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage contactsLabel_ new fail"); + return; + } + contactsLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(contactsLabel_); + + auto list = PhoneMenuCallerLogModel::GetInstance()->GetContacts(); + if (list.empty()) { + image_ = new UIImageView(); + if (image_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage image_ new fail"); + return; + } + image_->SetPosition(IMAGE_POS_X, IMAGE_POS_Y); + LOADIMG::LoadImageViewImg(image_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_PHONE); + container_->Add(image_); + + contactsLabel_->SetPosition(LABEL_POS_X_NO_CONTACTS, LABEL_POS_Y_NO_CONTACTS, + LABEL_WIDTH_NO_CONTACTS, LABEL_HEIGHT_NO_CONTACTS); + contactsLabel_->SetText("请前往手机APP\n同步常用联系人"); + contactsLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_NO_CONTACTS); + } else { + contactsLabel_->SetPosition(LABEL_POS_X, LABEL_POS_Y, LABEL_WIDTH, LABEL_HEIGHT); + contactsLabel_->SetText("通讯录"); + contactsLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + + contactsList_ = new UISimpleList(); + if (contactsList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage contactsList_ new fail"); + return; + } + contactsList_->SetPosition(LIST_POS_X, LIST_POS_Y, LIST_WIDTH, LIST_HEIGHT); + contactsList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + contactsList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + contactsList_->Resize(LIST_WIDTH, LIST_ITEM_H * list.size()); + for (auto &contacts : list) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&contacts); + contactsList_->AddContent(content); + } + contactsList_->RefreshList(); + container_->Add(contactsList_); + } + AddViewToPageContainer(container_); +} + +PhoneMenuContactsPage::PhoneMenuContactsPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage::PhoneMenuContactsPage"); + g_PhoneMenuContactsPageInstance = this; +} + +PhoneMenuContactsPage::~PhoneMenuContactsPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (image_ != nullptr) { + delete image_; + image_ = nullptr; + } + if (contactsLabel_ != nullptr) { + delete contactsLabel_; + contactsLabel_ = nullptr; + } + if (contactsList_ != nullptr) { + delete contactsList_; + contactsList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage::~PhoneMenuContactsPage"); +} + +bool PhoneMenuContactsPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool PhoneMenuContactsPage::OnClick(UIView &view, const ClickEvent &event) +{ + PhoneMenuContactsItemView *itemView = dynamic_cast(&view); + if (itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage::OnClick dynamic_cast view fail"); + return false; + } + std::string phoneNumber = itemView->GetContactsPhoneNumber(); + if (GetBtConnectStatus() != PROFILE_STATE_CONNECTED) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_DISCONNECT_PAGE, + TransitionType::TRANSITION_INVALID, false); + return true; + } + SetMicMute(false); + PhoneMenuCallerLogModel::GetInstance()->SetMicMute(false); + if (DialCall((unsigned char *)phoneNumber.c_str(), phoneNumber.size()) != OHOS_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuContactsPage::OnClick DialCall[fail]"); + } + PhoneMenuCallerLogModel::GetInstance()->SaveCurPage(); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDialPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDialPage.cpp new file mode 100644 index 000000000..c9f77185c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDialPage.cpp @@ -0,0 +1,441 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuDialPage + * Create: 2025-07-12 + */ + +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "ui_resource_phonemenu.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" +#include "phonemenu/PhoneMenuDialPage.h" + +static constexpr uint16_t DIAL_NORMAL_BUTTON_WIDTH = 88; +static constexpr uint16_t DIAL_NORMAL_BUTTON_HEIGHT = 64; +static constexpr uint16_t DIAL_WIDE_BUTTON_WIDTH = 180; +static constexpr uint16_t DIAL_WIDE_BUTTON_HEIGHT = 64; +static constexpr uint16_t FIRST_ROW_COLOR_BUTTON_POS_Y = 115; +static constexpr uint16_t SECOND_ROW_COLOR_BUTTON_POS_Y = 183; +static constexpr uint16_t THIRD_ROW_COLOR_BUTTON_POS_Y = 251; +static constexpr uint16_t FOUR_ROW_COLOR_BUTTON_POS_Y = 319; +static constexpr uint16_t FIRST_COLUMN_COLOR_BUTTON_POS_X = 45; +static constexpr uint16_t SECOND_COLUMN_COLOR_BUTTON_POS_X = 137; +static constexpr uint16_t THIRD_COLUMN_COLOR_BUTTON_POS_X = 229; +static constexpr uint16_t FOUR_COLUMN_COLOR_BUTTON_POS_X = 321; +static constexpr uint16_t NUMBER_LABEL_POS_X = 93; +static constexpr uint16_t NUMBER_LABEL_POS_Y = 53; +static constexpr uint16_t NUMBER_LABEL_WIDTH = 268; +static constexpr uint16_t NUMBER_LABEL_HEIGHT = 48; +static constexpr uint16_t NUMBER_LABEL_FONT_SIZE = 30; +static constexpr uint16_t DIAL_FONT_SIZE = 40; +static constexpr uint16_t DIAL_BUTTON_BORDER_RADIUS = 20; +static constexpr uint16_t BUTTON_BACKGROUND_OPA = 80; +static constexpr char *KEY_0_BUTTON_ID = "key0Button"; +static constexpr char *KEY_1_BUTTON_ID = "key1Button"; +static constexpr char *KEY_2_BUTTON_ID = "key2Button"; +static constexpr char *KEY_3_BUTTON_ID = "key3Button"; +static constexpr char *KEY_4_BUTTON_ID = "key4Button"; +static constexpr char *KEY_5_BUTTON_ID = "key5Button"; +static constexpr char *KEY_6_BUTTON_ID = "key6Bbutton"; +static constexpr char *KEY_7_BUTTON_ID = "key7Button"; +static constexpr char *KEY_8_BUTTON_ID = "key8Button"; +static constexpr char *KEY_9_BUTTON_ID = "key9Button"; +static constexpr char *KEY_STAR_BUTTON_ID = "keyStarButton"; +static constexpr char *KEY_POUND_BUTTON_ID = "keyPoundButton"; +static constexpr char *DELETE_BUTTON_ID = "deleteButton"; +static constexpr char *DIAL_BUTTON_ID = "dialButton"; + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_DIAL_PAGE, PhoneMenuDialPage, false); + +void PhoneMenuDialPage::OnStart(void *data) +{ + container_ = new UIScrollView(); + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage container_ new fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetOnDragListener(this); + + dialNumberLabel_ = new UILabel(); + if (dialNumberLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage dialNumberLabel_ new fail"); + return; + } + dialNumberLabel_->SetPosition(NUMBER_LABEL_POS_X, NUMBER_LABEL_POS_Y, NUMBER_LABEL_WIDTH, NUMBER_LABEL_HEIGHT); + dialNumberLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + dialNumberLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, NUMBER_LABEL_FONT_SIZE); + container_->Add(dialNumberLabel_); + + key1Button_ = new UILabelButton(); + if (key1Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key1Button_ new fail"); + return; + } + key1Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key1Button_->SetViewId(KEY_1_BUTTON_ID); + key1Button_->SetText("1"); + key1Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key1Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key1Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key1Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key1Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key1Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key1Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key1Button_->SetOnClickListener(this); + container_->Add(key1Button_); + + key2Button_ = new UILabelButton(); + if (key2Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key2Button_ new fail"); + return; + } + key2Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key2Button_->SetViewId(KEY_2_BUTTON_ID); + key2Button_->SetText("2"); + key2Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key2Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key2Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key2Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key2Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key2Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key2Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key2Button_->SetOnClickListener(this); + container_->Add(key2Button_); + + key3Button_ = new UILabelButton(); + if (key3Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key3Button_ new fail"); + return; + } + key3Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key3Button_->SetViewId(KEY_3_BUTTON_ID); + key3Button_->SetText("3"); + key3Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key3Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key3Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key3Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key3Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key3Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key3Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key3Button_->SetOnClickListener(this); + container_->Add(key3Button_); + + deleteButton_ = new UILabelButton(); + if (deleteButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage deleteButton_ new fail"); + return; + } + deleteButton_->SetPosition(FOUR_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + deleteButton_->SetViewId(DELETE_BUTTON_ID); + LOADIMG::LoadBtnImage(deleteButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_DEL, IMAGE_PHONEMENU_DEL); + deleteButton_->SetOnClickListener(this); + container_->Add(deleteButton_); + + key4Button_ = new UILabelButton(); + if (key4Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key4Button_ new fail"); + return; + } + key4Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key4Button_->SetViewId(KEY_4_BUTTON_ID); + key4Button_->SetText("4"); + key4Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key4Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key4Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key4Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key4Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key4Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key4Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key4Button_->SetOnClickListener(this); + container_->Add(key4Button_); + + key5Button_ = new UILabelButton(); + if (key5Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key5Button_ new fail"); + return; + } + key5Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key5Button_->SetViewId(KEY_5_BUTTON_ID); + key5Button_->SetText("5"); + key5Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key5Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key5Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key5Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key5Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key5Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key5Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key5Button_->SetOnClickListener(this); + container_->Add(key5Button_); + + key6Button_ = new UILabelButton(); + if (key6Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key6Button_ new fail"); + return; + } + key6Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key6Button_->SetViewId(KEY_6_BUTTON_ID); + key6Button_->SetText("6"); + key6Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key6Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key6Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key6Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key6Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key6Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key6Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key6Button_->SetOnClickListener(this); + container_->Add(key6Button_); + + keyStarButton_ = new UILabelButton(); + if (keyStarButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage keyStarButton_ new fail"); + return; + } + keyStarButton_->SetPosition(FOUR_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + keyStarButton_->SetViewId(KEY_STAR_BUTTON_ID); + LOADIMG::LoadBtnImage(keyStarButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_STAR_KEY, IMAGE_PHONEMENU_STAR_KEY); + keyStarButton_->SetOnClickListener(this); + container_->Add(keyStarButton_); + + key7Button_ = new UILabelButton(); + if (key7Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key7Button_ new fail"); + return; + } + key7Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key7Button_->SetViewId(KEY_7_BUTTON_ID); + key7Button_->SetText("7"); + key7Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key7Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key7Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key7Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key7Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key7Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key7Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key7Button_->SetOnClickListener(this); + container_->Add(key7Button_); + + key8Button_ = new UILabelButton(); + if (key8Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key8Button_ new fail"); + return; + } + key8Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key8Button_->SetViewId(KEY_8_BUTTON_ID); + key8Button_->SetText("8"); + key8Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key8Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key8Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key8Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key8Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key8Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key8Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key8Button_->SetOnClickListener(this); + container_->Add(key8Button_); + + key9Button_ = new UILabelButton(); + if (key9Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key9Button_ new fail"); + return; + } + key9Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + key9Button_->SetViewId(KEY_9_BUTTON_ID); + key9Button_->SetText("9"); + key9Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key9Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key9Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key9Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key9Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key9Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key9Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key9Button_->SetOnClickListener(this); + container_->Add(key9Button_); + + keyPoundButton_ = new UILabelButton(); + if (keyPoundButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage keyPoundButton_ new fail"); + return; + } + keyPoundButton_->SetPosition(FOUR_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, DIAL_NORMAL_BUTTON_WIDTH, + DIAL_NORMAL_BUTTON_HEIGHT); + keyPoundButton_->SetViewId(KEY_POUND_BUTTON_ID); + LOADIMG::LoadBtnImage(keyPoundButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_POUND_KEY, IMAGE_PHONEMENU_POUND_KEY); + keyPoundButton_->SetOnClickListener(this); + container_->Add(keyPoundButton_); + + key0Button_ = new UILabelButton(); + if (key0Button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage key0Button_ new fail"); + return; + } + key0Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, FOUR_ROW_COLOR_BUTTON_POS_Y, DIAL_WIDE_BUTTON_WIDTH, + DIAL_WIDE_BUTTON_HEIGHT); + key0Button_->SetViewId(KEY_0_BUTTON_ID); + key0Button_->SetText("0"); + key0Button_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIAL_FONT_SIZE); + key0Button_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + key0Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + key0Button_->SetStyle(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA); + key0Button_->SetStyleForState(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS, UIButton::PRESSED); + key0Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Gray().full, UIButton::PRESSED); + key0Button_->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_BACKGROUND_OPA, UIButton::PRESSED); + key0Button_->SetOnClickListener(this); + container_->Add(key0Button_); + + diagButton_ = new UILabelButton(); + if (diagButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage diagButton_ new fail"); + return; + } + diagButton_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, FOUR_ROW_COLOR_BUTTON_POS_Y, DIAL_WIDE_BUTTON_WIDTH, + DIAL_WIDE_BUTTON_HEIGHT); + diagButton_->SetViewId(DIAL_BUTTON_ID); + diagButton_->SetStyle(STYLE_BORDER_RADIUS, DIAL_BUTTON_BORDER_RADIUS); + LOADIMG::LoadBtnImage(diagButton_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_CALL, IMAGE_PHONEMENU_CALL); + diagButton_->SetOnClickListener(this); + container_->Add(diagButton_); + + AddViewToPageContainer(container_); +} + +PhoneMenuDialPage::PhoneMenuDialPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage::PhoneMenuDialPage"); +} + +PhoneMenuDialPage::~PhoneMenuDialPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (dialNumberLabel_ != nullptr) { + delete dialNumberLabel_; + dialNumberLabel_ = nullptr; + } + if (deleteButton_ != nullptr) { + delete deleteButton_; + deleteButton_ = nullptr; + } + if (diagButton_ != nullptr) { + delete diagButton_; + diagButton_ = nullptr; + } + if (keyStarButton_ != nullptr) { + delete keyStarButton_; + keyStarButton_ = nullptr; + } + if (keyPoundButton_ != nullptr) { + delete keyPoundButton_; + keyPoundButton_ = nullptr; + } + if (key0Button_ != nullptr) { + delete key0Button_; + key0Button_ = nullptr; + } + if (key1Button_ != nullptr) { + delete key1Button_; + key1Button_ = nullptr; + } + if (key2Button_ != nullptr) { + delete key2Button_; + key2Button_ = nullptr; + } + if (key3Button_ != nullptr) { + delete key3Button_; + key3Button_ = nullptr; + } + if (key4Button_ != nullptr) { + delete key4Button_; + key4Button_ = nullptr; + } + if (key5Button_ != nullptr) { + delete key5Button_; + key5Button_ = nullptr; + } + if (key6Button_ != nullptr) { + delete key6Button_; + key6Button_ = nullptr; + } + if (key7Button_ != nullptr) { + delete key7Button_; + key7Button_ = nullptr; + } + if (key8Button_ != nullptr) { + delete key8Button_; + key8Button_ = nullptr; + } + if (key9Button_ != nullptr) { + delete key9Button_; + key9Button_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage::~PhoneMenuDialPage"); +} + +bool PhoneMenuDialPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool PhoneMenuDialPage::OnClick(UIView &view, const ClickEvent &event) +{ + UILabelButton *button = dynamic_cast(&view); + if (button == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage::OnClick dynamic_cast view fail"); + return false; + } + if (strcmp(view.GetViewId(), DELETE_BUTTON_ID) == 0) { + if (!dialNumber_.empty()) { + dialNumber_.pop_back(); + dialNumberLabel_->SetText(dialNumber_.c_str()); + dialNumberLabel_->Invalidate(); + } + } else if (strcmp(view.GetViewId(), DIAL_BUTTON_ID) == 0) { + if (GetBtConnectStatus() != PROFILE_STATE_CONNECTED) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_DISCONNECT_PAGE, + TransitionType::TRANSITION_INVALID, false); + return false; + } + SetMicMute(false); + PhoneMenuCallerLogModel::GetInstance()->SetMicMute(false); + if (DialCall((unsigned char *)dialNumber_.c_str(), dialNumber_.size()) != OHOS_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDialPage::OnClick DialCall[fail]"); + } + PhoneMenuCallerLogModel::GetInstance()->SaveCurPage(); + } else { + if (strcmp(view.GetViewId(), KEY_STAR_BUTTON_ID) == 0) { + dialNumber_ += "*"; + } else if (strcmp(view.GetViewId(), KEY_POUND_BUTTON_ID) == 0) { + dialNumber_ += "#"; + } else { + dialNumber_ += button->GetText(); + } + dialNumberLabel_->SetText(dialNumber_.c_str()); + dialNumberLabel_->Invalidate(); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDisconnectPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDisconnectPage.cpp new file mode 100644 index 000000000..1b46710ed --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuDisconnectPage.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuDisconnectPage + * Create: 2025-07-12 + */ +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuDisconnectPage.h" + +namespace OHOS { +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t LABEL_XPOS = 30; +static constexpr uint16_t LABEL_YPOS = 257; +static constexpr uint16_t LABEL_WIDTH = 396; +static constexpr uint16_t LABEL_HEIGHT = 50; +static constexpr uint16_t IMAGE_XPOS = 176; +static constexpr uint16_t IMAGE_YPOS = 115; + +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_DISCONNECT_PAGE, PhoneMenuDisconnectPage, false); + +void PhoneMenuDisconnectPage::OnStart(void *data) +{ + container_ = new UIScrollView(); + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDisconnectPage container_ new fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetOnDragListener(this); + + text_ = new UILabel(); + if (text_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDisconnectPage text_ new fail"); + return; + } + text_->SetPosition(LABEL_XPOS, LABEL_YPOS, LABEL_WIDTH, LABEL_HEIGHT); + text_->SetText("设备未连接,请连接设备!"); + text_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + text_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + container_->Add(text_); + + image_ = new UIImageView(); + if (image_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuDisconnectPage image_ new fail"); + return; + } + image_->SetPosition(IMAGE_XPOS, IMAGE_YPOS); + LOADIMG::LoadImageViewImg(image_, PHONEMENU_IMAGE, IMAGE_PHONEMENU_DISCONNECT); + container_->Add(image_); + + AddViewToPageContainer(container_); +} + +PhoneMenuDisconnectPage::PhoneMenuDisconnectPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuDisconnectPage::PhoneMenuDisconnectPage"); +} + +PhoneMenuDisconnectPage::~PhoneMenuDisconnectPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (text_ != nullptr) { + delete text_; + text_ = nullptr; + } + if (image_ != nullptr) { + delete image_; + image_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuDisconnectPage::~PhoneMenuDisconnectPage"); +} + +bool PhoneMenuDisconnectPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool PhoneMenuDisconnectPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainItemView.cpp new file mode 100644 index 000000000..d80c76ef3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainItemView.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuMainItemView + * Create: 2025-07-12 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "phonemenu/PhoneMenuMainItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_GROUP_X = 0; +static constexpr uint16_t BG_GROUP_Y = 0; +static constexpr uint16_t BG_GROUP_W = 426; +static constexpr uint16_t BG_GROUP_H = 96; +static constexpr uint16_t BG_BACKGROUND_OPA = 80; +static constexpr uint16_t BG_BORDER_RADIUS = 48; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 8; +static constexpr uint16_t LABEL_X = 101; +static constexpr uint16_t LABEL_Y = 22; +static constexpr uint16_t LABEL_W = 150; +static constexpr uint16_t LABEL_H = 53; +static constexpr uint16_t LABEL_FONT = 32; + +PhoneMenuMainItemView::PhoneMenuMainItemView() +{ + bg_.SetPosition(BG_GROUP_X, BG_GROUP_Y, BG_GROUP_W, BG_GROUP_H); + bg_.SetStyle(STYLE_BACKGROUND_OPA, BG_BACKGROUND_OPA); + bg_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + bg_.SetStyle(STYLE_BORDER_RADIUS, BG_BORDER_RADIUS); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + + Add(&bg_); + Add(&icon_); + Add(&label_); +} + +PhoneMenuMainItemView::~PhoneMenuMainItemView() +{ + Remove(&icon_); + Remove(&label_); + Remove(&bg_); +} + +void PhoneMenuMainItemView::SetItemInfo(const PhoneMenuItem &itemInfo) +{ + label_.SetText(itemInfo.label); + LOADIMG::LoadImageViewImg(&icon_, PHONEMENU_IMAGE, itemInfo.iconResId); + SetViewId(itemInfo.viewId); +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainPage.cpp new file mode 100644 index 000000000..445025794 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuMainPage.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuMainPage + * Create: 2025-07-12 + */ +#include "SlicePageFactory.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuMainPage.h" + +namespace OHOS { +static constexpr uint16_t LABEL_POS_X = 97; +static constexpr uint16_t LABEL_POS_Y = 41; +static constexpr uint16_t LABEL_WIDTH = 260; +static constexpr uint16_t LABEL_HEIGHT = 53; +static constexpr uint16_t LABEL_FONT_SIZE = 40; +static constexpr uint16_t LIST_POS_X = 14; +static constexpr uint16_t LIST_POS_Y = 116; +static constexpr uint16_t LIST_WIDTH = 426; +static constexpr uint16_t LIST_HEIGHT = 330; +static constexpr uint16_t LIST_ITEM_W = 426; +static constexpr uint16_t LIST_ITEM_H = 110; +static constexpr uint16_t CONTAINER_TOP_BLANK_SIZE = 40; +static constexpr uint16_t CONTAINER_BOTTOM_BLANK_SIZE = 100; + +REGIST_SLICE_PAGE(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_MAIN_PAGE, PhoneMenuMainPage, true); + +static PhoneMenuMainPage *g_PhoneMenuMainPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + PhoneMenuMainItemView *item = new PhoneMenuMainItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_PhoneMenuMainPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + PhoneMenuMainItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + PhoneMenuItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +void PhoneMenuMainPage::OnStart(void *data) +{ + container_ = new UIScrollView(); + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuMainPage container_ new fail"); + return; + } + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetOnDragListener(this); + container_->SetScrollBlankSize(CONTAINER_TOP_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + container_->SetScrollBlankSize(CONTAINER_BOTTOM_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuMainPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABEL_POS_X, LABEL_POS_Y, LABEL_WIDTH, LABEL_HEIGHT); + titleLabel_->SetText("电话"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + container_->Add(titleLabel_); + + phoneMenuList_ = new UISimpleList(); + if (phoneMenuList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMenuMainPage phoneMenuList_ new fail"); + return; + } + phoneMenuList_->SetPosition(LIST_POS_X, LIST_POS_Y, LIST_WIDTH, LIST_HEIGHT); + phoneMenuList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + phoneMenuList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + phoneMenuList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < PHOEN_MENU_ITEM_NUM; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&phoneMenu_[i]); + phoneMenuList_->AddContent(content); + } + phoneMenuList_->RefreshList(); + container_->Add(phoneMenuList_); + + AddViewToPageContainer(container_); +} + +PhoneMenuMainPage::PhoneMenuMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuMainPage::PhoneMenuMainPage"); + g_PhoneMenuMainPageInstance = this; +} + +PhoneMenuMainPage::~PhoneMenuMainPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (phoneMenuList_ != nullptr) { + delete phoneMenuList_; + phoneMenuList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuMainPage::~PhoneMenuMainPage"); +} + +bool PhoneMenuMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} + +bool PhoneMenuMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), PHONE_MENU_ITEM_CONTACTS_BOOKS) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CONTACTS_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), PHONE_MENU_ITEM_RECENT_CALL) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLER_LOG_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), PHONE_MENU_ITEM_DIAL) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_DIAL_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuPresenter.cpp new file mode 100644 index 000000000..fd166ed01 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuPresenter + * Create: 2025-07-12 + */ + +#include "NativeRegisterManager.h" +#include "phonemenu/PhoneMenuView.h" +#include "phonemenu/PhoneMenuPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_PHONE_MENU, PhoneMenuView, PhoneMenuPresenter, PHONEMENU_ICON, PHONEMENU_ICON, "通话菜单"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuSync.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuSync.cpp new file mode 100644 index 000000000..4f1e68438 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phonemenu/src/PhoneMenuSync.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneMenuSync + * Create: 2025-07-12 + */ + +#include "cJSON.h" +#include "wearable_log.h" +#include "phonemenu/PhoneMenuSync.h" + +namespace OHOS { +std::list PhoneMenuSync::list_; +uint32_t PhoneMenuSync::WriteFileContact(const std::string &filePath, std::string &content) +{ + std::ofstream output(filePath); + if (!output.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no file"); + return JSON_FILE_OPEN_FAIL; + } + output << content; + output.close(); + return OK; +} + +uint32_t PhoneMenuSync::ReadFileContact(const std::string &filePath) +{ + std::ifstream input(filePath.c_str()); + if (!input.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no file"); + return JSON_FILE_OPEN_FAIL; + } + std::stringstream buffer; + buffer << input.rdbuf(); + std::string content = buffer.str(); + int intsize = sizeof(content); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMenuSync::PhoneMenuSync [%s]", content.c_str()); + ParseContactsMsg(content); + PrintContacts(); + return OK; +} + +uint32_t PhoneMenuSync::ParseContactsMsg(std::string &msgContent) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseContactsMsg %s\r\n", msgContent.c_str()); + cJSON *root = cJSON_Parse(msgContent.c_str()); + if (root == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "parse_contacts_msg cJSON_Parse, fail = %p\r\n", root); + return JSON_PARSE_FAIL; + } + if (!cJSON_IsArray(root)) { + cJSON_Delete(root); + return JSON_TYPE_FAIL; + } + list_.clear(); + int arraySize = cJSON_GetArraySize(root); + for (int i = 0; i < arraySize; ++i) { + cJSON *item = cJSON_GetArrayItem(root, i); + if (cJSON_IsObject(item)) { + cJSON *cidJson = cJSON_GetObjectItem(item, "cid"); + cJSON *nameJson = cJSON_GetObjectItem(item, "name"); + cJSON *phoneJson = cJSON_GetObjectItem(item, "phone"); + if (cidJson == nullptr || nameJson == nullptr || phoneJson == nullptr) { + return JSON_KEY_FAIL; + } + Contacts contacts; + contacts.cid_ = cidJson->valuestring; + contacts.name_ = nameJson->valuestring; + contacts.phone_ = phoneJson->valuestring; + list_.push_back(contacts); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "cid [%s], name [%s], phone [%s]", contacts.cid_.c_str(), + contacts.name_.c_str(), contacts.phone_.c_str()); + } + } + cJSON_Delete(root); + return OK; +} + +std::list &PhoneMenuSync::GetContacts() +{ + return list_; +} + +uint32_t PhoneMenuSync::PrintContacts() +{ + for (auto &x : list_) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "cid[%s] name[%s] phone[%s]", x.cid_.c_str(), x.name_.c_str(), + x.phone_.c_str()); + } + return OK; +} + +uint32_t PhoneMenuSync::LookContacts(std::string &contacts) +{ + cJSON *contactsArrayObj = cJSON_CreateArray(); + if (!contactsArrayObj) { + return JSON_CREATE_FAIL; + } + for (auto &contacts : list_) { + cJSON *contactsObj = cJSON_CreateObject(); + if (!contactsObj) { + cJSON_Delete(contactsArrayObj); + return JSON_CREATE_FAIL; + } + cJSON_AddItemToObject(contactsObj, "cid", cJSON_CreateString(contacts.cid_.c_str())); + cJSON_AddItemToObject(contactsObj, "name", cJSON_CreateString(contacts.name_.c_str())); + cJSON_AddItemToObject(contactsObj, "phone", cJSON_CreateString(contacts.phone_.c_str())); + cJSON_AddItemToArray(contactsArrayObj, contactsObj); + } + char *jsonStr = cJSON_Print(contactsArrayObj); + if (!jsonStr) { + cJSON_Delete(contactsArrayObj); + return JSON_TO_STRING_FAIL; + } + contacts = jsonStr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_lookup_contacts [%s]", jsonStr); + cJSON_Delete(contactsArrayObj); + free(jsonStr); + jsonStr = nullptr; + return OK; +} + +uint32_t PhoneMenuSync::CleanFileContacts(const std::string &filePath) +{ + std::ofstream output(filePath); + if (!output.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no file"); + return JSON_FILE_OPEN_FAIL; + } + output.close(); + list_.clear(); + return OK; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/phoneservice/src/PhoneService.cpp index 66b889773..2c4184e77 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/phoneservice/src/PhoneService.cpp @@ -641,8 +641,10 @@ static void ScoStateChanged(const bd_addr_t &bdAddr, hfp_sco_connect_state_t sta if (g_scoFlag != HFP_SCO_STATE_CONNECTED) { g_scoFlag = HFP_SCO_STATE_CONNECTED; CopyBdAddr(bdAddr); - ScoConnectPro(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoStateChanged] SCO connecting!"); + GraphicService::GetInstance()->PostGraphicEvent([]() { + ScoConnectPro(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoStateChanged] SCO connecting!"); + }); } break; case HFP_SCO_STATE_CONNECTED: @@ -881,7 +883,7 @@ int GetCallLog(CallLogInfo **info, int *num) { FILE *fp = fopen(CALL_LOG_PATH, "rb"); if (fp == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen %s failed!", CALL_LOG_PATH); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fopen %s failed!", CALL_LOG_PATH); return OHOS_FAILURE; } @@ -1335,19 +1337,19 @@ static void CallStateChanged(const bd_addr_t &bdAddr, const PhoneHfpCallInfo &ca break; case HFP_HF_CALL_STATE_DIALING: // 呼出,正在拨号 PhoneServiceScreenCtr(1); - CallChangeDialPro(call); + GraphicService::GetInstance()->PostGraphicEvent([call]() { CallChangeDialPro(call); }); break; - case HFP_HF_CALL_STATE_ALERTING: // 呼出,对方响铃 + case HFP_HF_CALL_STATE_ALERTING: // 呼出,对方响铃 PhoneServiceScreenCtr(1); - CallChangeAlertPro(call); + GraphicService::GetInstance()->PostGraphicEvent([call]() { CallChangeAlertPro(call); }); break; - case HFP_HF_CALL_STATE_INCOMING: // 呼入 + case HFP_HF_CALL_STATE_INCOMING: // 呼入 PhoneServiceScreenCtr(1); - CallChangeIncomePro(call); + GraphicService::GetInstance()->PostGraphicEvent([call]() { CallChangeIncomePro(call); }); break; - case HFP_HF_CALL_STATE_WAITING: // 呼入等待 + case HFP_HF_CALL_STATE_WAITING: // 呼入等待 PhoneServiceScreenCtr(1); - CallChangeIncomePro(call); + GraphicService::GetInstance()->PostGraphicEvent([call]() { CallChangeIncomePro(call); }); break; case HFP_HF_CALL_STATE_FINISHED: // 拒接/结束电话 CallChangeFinishPro(call); @@ -1365,10 +1367,6 @@ static void CallStateChanged(const bd_addr_t &bdAddr, const PhoneHfpCallInfo &ca } else { g_currCallState = call.state; } - - if (g_currCallNum == 0) { - g_completeCallFlag = false; - } } static void CallStateChangedCb(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t *call) @@ -1637,7 +1635,7 @@ int RejectIncomingCall(void) } if (phoneCall == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] no incoming"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] no incoming"); return OHOS_SUCCESS; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersModel.cpp index 410d07351..c939183ff 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersModel.cpp @@ -1,745 +1,745 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Player view - * Author: - * Create: 2021-07-26 - */ - -#include "player/PlayersModel.h" -#include "thread_adapter.h" -#include "UiConfig.h" -#include "bts_avrcp_controller.h" -#include "bts_avrcp_target.h" -#include "bts_a2dp_source.h" -#include "bluetooth/BluetoothModel.h" - -namespace OHOS { - -static constexpr int VOLUME_MAXIMUM = 100; -static constexpr int VOLUME_MINIMUM = 0; -static constexpr int VOLUME_PER_CHANGE = 10; - -#define BUFFER_SIZE 15 -static MutexId g_mutex; -PlayersModel::PlayersModel() -{ - g_mutex = MUTEX_InitValue(); -} - -PlayersModel::~PlayersModel() -{ - listPlayers.Clear(); -} - -bool PlayersModel::FetchedPlayersCallBack(PlayersMsg *playersMsg) -{ - if (listPlayers.IsEmpty()) { - return false; - } else { - MUTEX_Lock(g_mutex); - *playersMsg = listPlayers.Front(); - listPlayers.PopFront(); - MUTEX_Unlock(g_mutex); - } - return true; -} - -void PlayersModel::PushPlayersData(PlayersMsg playersMsg) -{ - MUTEX_Lock(g_mutex); - listPlayers.PushBack(playersMsg); - MUTEX_Unlock(g_mutex); -} - -PlayersModel *PlayersModel::GetInstance() -{ - static PlayersModel instance; - return &instance; -} - -std::string PlayersModel::GetPlayerUri(void) -{ - return uri; -} - -void PlayersModel::SetPlayerUri(std::string src) -{ - uri = src; -} - -void PlayersModel::SetPlayButtonState(bool value) -{ - playButtonState = value; -} - -int PlayersModel::PlayerStat() -{ - int32_t ret; - - // 设置回调函数 - playerCtr->SetPlayerCallback(playerCallback); - // 申请资源 - source = std::make_shared(uri, header); - if (source.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "source new fail"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Player uri %s.", uri.c_str()); - playerCtr->SetSource(*source); - playerCtr->Prepare(); - ret = playerCtr->GetDuration(duration_); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%s,%d] GetDuration:%lld, ret:%d", __func__, __LINE__, duration_, ret); - if (!isActivateAudioInterrupt) { - // 申请焦点 - AudioManager& amIntance = AudioManager::GetInstance(); - sessionId = amIntance.MakeSessionId(); - if (sessionId == AUDIO_SESSION_ID_NONE) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "session invalid"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MakeSessionId %d", sessionId); - playerInterruptListener = std::make_shared(); - if (playerInterruptListener.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerInterruptListener new fail"); - return OHOS_FAILURE; - } - playerInterruptListener->SetOwner(playerCtr); - interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; - // 激活音频中断 5s超时 - if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); - return OHOS_FAILURE; - } - isActivateAudioInterrupt = true; - } - playerCtr->SetAudioSessionId(sessionId); - // 播放 - ret = playerCtr->Play(); - if (ret != 0) { - playerCtr->Stop(); // 暂停 - playerCtr->Reset(); // 初始化 - PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); - if (playersPresenter != nullptr) { - playersPresenter->PlayerbackReset(); - SetCircleProgress(100); // 100:进度100% - playersPresenter->SetPlaybackProgress(circleProgress); - } else { - SetPlayButtonState(false); - SetCircleProgress(100); // 100:进度100% - } - AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); - isActivateAudioInterrupt = false; - } - return OHOS_SUCCESS; -} - -bool PlayersModel::GetAudioInitStatus(void) -{ - return audioInitStatus; -} - -void PlayersModel::AudioInit(void) -{ - if (audioInitStatus) { - return; - } - AudioManager& amIntance = AudioManager::GetInstance(); - audioInitStatus = amIntance.Initialize(); - playerCtr = std::make_shared(); - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr new fail"); - return; - } - playerCallback = std::make_shared(); - if (playerCallback.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCallback new fail"); - return; - } -} - -void PlayersModel::SetCircleProgress(int64_t value) -{ - circleProgress = value; -} - -int16_t PlayersModel::GetCurrentIndex(void) -{ - return currentIndex; -} - -void PlayersModel::SetCurrentIndex(int16_t value) -{ - currentIndex = value; -} - -int16_t PlayersModel::GetPlayerModel(void) -{ - return playerModel; -} - -void PlayersModel::SetPlayerModel(int16_t value) -{ - playerModel = value; -} - -void PlayersModel::SetPlayerModelAddOne(void) -{ - playerModel++; -} - -void PlayersModel::PlaySwitching(void) -{ - PlayersMsg playersMsg1; - playersMsg1.playerModel = GetPlayerModel(); - PushPlayersData(playersMsg1); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlaySwitching playerModel1 %d!!!", GetPlayerModel()); - int32_t ret; - PlayersMsg playersMsg; - if (FetchedPlayersCallBack(&playersMsg)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FetchedPlayersCallBack true"); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop to play"); - switch (playersMsg.playerModel) { - case PlayerModelState::LOOP: - // 循环 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoopingPlayout!!!"); - LoopingPlayout(); - break; - case PlayerModelState::SEQUENCE: - // 顺序 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SequencePlayout!!!"); - SequencePlayout(); - break; - case PlayerModelState::REPEATS: - // 重复 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RepeatsPlayout!!!"); - ret = PlayersModel::GetInstance()->playerCtr->Stop(); // 停止 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop, ret:%d", ret); - ret = PlayersModel::GetInstance()->playerCtr->Reset(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); - PlayersModel::GetInstance()->PlayerStat(); // 播放 - break; - case PlayerModelState::RANDOM: - // 随机 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RandomPlayout!!!"); - RandomPlayout(); - break; - default: - break; - } - } -} - -int PlayersModel::PlayerInit(void) -{ - sliceId = PlayersListGroup::GetInstance()->GetCase(currentIndex); - if (sliceId == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCase %d sliceId err !!!", currentIndex); - char strFile[BUFFER_SIZE] = "No music files"; - sliceId = strFile; - } - std::string strSongName = sliceId; - std::string pureName = strSongName.substr(0, strSongName.rfind(".")); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerInit, url: %s ", sliceId); - std::string strSrcMusic(APP_MUSIC_PATH); - std::string tempStr("/"); - std::string strName = sliceId; - uri = strSrcMusic + tempStr + strName; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerInit end!"); - PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); - if (playersPresenter == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerInit playersPresenter GetInstance fail"); - return OHOS_FAILURE; - } - playersPresenter->SetTitleSetText(pureName.c_str()); - playersPresenter->SetPlaybackProgress(circleProgress); - playersPresenter->SetPlayerState(playButtonState); - return 0; -} - -void PlayersModel::NextSong(int16_t index) -{ - SetCurrentIndex(index); - // 播放 - sliceId = PlayersListGroup::GetInstance()->GetCase(index); - if (sliceId == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCase %d sliceId err!!!", index); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCase sliceId %s.", sliceId); - std::string strSrcMusic(APP_MUSIC_PATH); - std::string tempStr("/"); - std::string strName = sliceId; - SetPlayerUri(strSrcMusic + tempStr + strName); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", GetPlayerUri().c_str()); - std::string strSongName = sliceId; - std::string pureName = strSongName.substr(0, strSongName.rfind(".")); - PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); - if (playersPresenter != nullptr) { - playersPresenter->SetTitleSetText(pureName.c_str()); - playersPresenter->SetPlaybackProgress(0); // 0:进度0% - } - int32_t ret; - int32_t playerState; - playerCtr->GetPlayerState(playerState); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerState Value %d.", playerState); - if ((playerState == PlayerStates::PLAYER_STARTED) || (playerState == PlayerStates::PLAYER_PLAYBACK_COMPLETE)) { - /* start play */ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "start play, 160."); - ret = playerCtr->Stop(); // 停止 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop, ret:%d", ret); - ret = playerCtr->Reset(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); - ret = PlayerStat(); // 播放 - if (ret != 0) { - /* stop and exit */ - ret = playerCtr->Stop(); // 停止 - ret = playerCtr->Reset(); - } - } else if (playerState == PlayerStates::PLAYER_PAUSED || (playerState == PlayerStates::PLAYER_IDLE)) { - ret = playerCtr->Reset(); - AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); - ClearActivateAudioInterrupt(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); - } -} - -void PlayersModel::LoopingPlayout() -{ - int16_t index; - List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); - index = GetCurrentIndex(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoopingPlayout, index %d.", index); - if ((index > playersCaseList.Size() - 1) || (index < 0)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); - SetCurrentIndex(0); - return; - } - if (GetPlayerModel() == PlayerModelState::RANDOM) { - RandomPlayout(); - return; - } else { - index++; // 下一曲 - } - if (index > playersCaseList.Size() - 1) { - index = 0; - } - NextSong(index); - SetCircleProgress(0); // 0:进度0% -} - -void PlayersModel::SequencePlayout() -{ - int16_t index; - List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); - index = GetCurrentIndex(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SequencePlayout, index %d.", index); - if ((index > playersCaseList.Size() - 1) || (index < 0)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); - SetCurrentIndex(0); - return; - } - index++; // 下一曲 - if (index > playersCaseList.Size() - 1) { - playerCtr->Stop(); // 暂停 - playerCtr->Reset(); // 初始化 - PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); - if (playersPresenter != nullptr) { - playersPresenter->PlayerbackReset(); - } else { - SetPlayButtonState(false); - } - SetCircleProgress(100); // 100:进度100% - index = playersCaseList.Size() - 1; - } - NextSong(index); -} - -void PlayersModel::RandomPlayout() -{ - int16_t random; - int16_t indexMax; - srand((unsigned)time(nullptr)); - List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); - indexMax = playersCaseList.Size() - 1; - random = (rand() % (indexMax + 1)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RANDOM %d.", random); - if ((random > playersCaseList.Size() - 1) || (random < 0)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "random err"); - SetCurrentIndex(0); - return; - } - if (GetCurrentIndex() == random) { - random++; - if (random > playersCaseList.Size() - 1) { - random = 0; - } - } - NextSong(random); - SetCircleProgress(0); // 0:进度0% -} - -void PlayersModel::PreviousPlayout() -{ - int16_t index; - List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); - index = GetCurrentIndex(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PreviousPlayout, index %d.", index); - if ((index > playersCaseList.Size() - 1) || (index < 0)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); - SetCurrentIndex(0); - return; - } - index--; // 上一曲 - if (index < 0) { - index = playersCaseList.Size() - 1; - } - NextSong(index); - SetCircleProgress(0); // 0:进度0% -} - -std::shared_ptr PlayersModel::GetPlayerCtr() -{ - return playerCtr; -} - -std::shared_ptr PlayersModel::GetPlayerIntrptListener(void) -{ - return playerInterruptListener; -} - -int PlayersModel::GetPlayerState(void) -{ - int state; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] GetPlayerState"); - - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); - return ERR_RET; - } - playerCtr->GetPlayerState(state); - return state; -} - -bool PlayersModel::HasPlayerPlayed(void) -{ - int state = GetPlayerState(); - if (state == ERR_RET) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get Player State failed!!"); - return false; - } - if (state != PlayerStates::PLAYER_STARTED && state != PlayerStates::PLAYER_PAUSED && - state != PlayerStates::PLAYER_STOPPED && state != PlayerStates::PLAYER_PLAYBACK_COMPLETE) { - if (!isStopAndReset) { - return false; - } - } - return true; -} - -/* 蓝牙连接的音频控制,对按钮属性进行设置 */ -void PlayersModel::ConncetBtResetButton() -{ - int32_t connCtState = avrcp_ct_get_device_connect_state(BluetoothModel::GetInstance()->GetLastConnedAddr()); - int32_t connTgState = avrcp_tg_get_device_connect_state(BluetoothModel::GetInstance()->GetLastConnedAddr()); - if (connCtState == PROFILE_STATE_CONNECTED || connTgState == PROFILE_STATE_CONNECTED) { - if (PlayersPresenter::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::GetInstance() == nullptr"); - return; - } - PlayersPresenter::GetInstance()->PlayerHeadsetReset(); - } -} - -int PlayersModel::PlayerPlay(void) -{ - int state; - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerPlay"); - - state = GetPlayerState(); - if (state == ERR_RET) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); - return EXECUTE_FUNC_FAILED; - } - - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); - return EXECUTE_FUNC_FAILED; - } - if (state == PlayerStates::PLAYER_PAUSED || state == PlayerStates::PLAYER_STOPPED) { // 暂停状态则直接开始 - ret = playerCtr->Play(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Play err, ret:%d", ret); - return EXECUTE_FUNC_FAILED; - } - PlayersModel::GetInstance()->SetPlayButtonState(true); // 播放控件图形同步 - ConncetBtResetButton(); // 蓝牙连接的音频控制,对按钮属性进行设置 - return NORMAL; - } else if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { // 已经在播放状态则不做操作 - return SONG_ALREADY_PLAY; - } else { // 其它情况的处理 - ret = PlayersModel::GetInstance()->PlayerStat(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); - return EXECUTE_FUNC_FAILED; - } - PlayersModel::GetInstance()->SetPlayButtonState(true); // 播放控件图形同步 - ConncetBtResetButton(); - return NORMAL; - } -} - -int PlayersModel::PlayerPause(void) -{ - int state; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerPause"); - - state = GetPlayerState(); - if (state == ERR_RET) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); - return EXECUTE_FUNC_FAILED; - } - - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); - return EXECUTE_FUNC_FAILED; - } - if (state == PlayerStates::PLAYER_PAUSED) { // 暂停状态则不操作 - return SONG_ALREADY_PAUSE; - } else if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { - int ret = playerCtr->Pause(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Pause err, ret:%d!!", ret); - return EXECUTE_FUNC_FAILED; - } else { - PlayersModel::GetInstance()->SetPlayButtonState(false); - ConncetBtResetButton(); - return NORMAL; - } - } else if (state == PlayerStates::PLAYER_STOPPED) { - return SONG_ALREADY_STOP; - } - return NORMAL; -} - -int PlayersModel::PlayerStop(void) -{ - int state; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerStop"); - state = GetPlayerState(); - if (state == ERR_RET) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); - return EXECUTE_FUNC_FAILED; - } - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); - return EXECUTE_FUNC_FAILED; - } - if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { - int ret = playerCtr->Stop(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Stop err, ret:%d", ret); - return EXECUTE_FUNC_FAILED; - } - ret = playerCtr->Reset(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Reset err, ret:%d", ret); - return EXECUTE_FUNC_FAILED; - } else { - isStopAndReset = true; - PlayersModel::GetInstance()->SetPlayButtonState(false); - PlayersModel::GetInstance()->SetCircleProgress(0); - ConncetBtResetButton(); - } - AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); - return NORMAL; - } else if (state == PlayerStates::PLAYER_PAUSED) { - int ret = playerCtr->Reset(); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Reset err, ret:%d", ret); - return EXECUTE_FUNC_FAILED; - } else { - PlayersModel::GetInstance()->SetPlayButtonState(false); - PlayersModel::GetInstance()->SetCircleProgress(0); - ConncetBtResetButton(); - } - AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); - return NORMAL; - } else if (state == PlayerStates::PLAYER_STOPPED) { - return SONG_ALREADY_STOP; - } - return NORMAL; -} - -int PlayersModel::PreSongOperate(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PreSongOperate"); - - PlayersModel::GetInstance()->PreviousPlayout(); - PlayersModel::GetInstance()->SetPlayButtonState(true); - return NORMAL; -} - -int PlayersModel::NextSongOperate(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] NextSongOperate"); - - PlayersModel::GetInstance()->LoopingPlayout(); - PlayersModel::GetInstance()->SetPlayButtonState(true); - return NORMAL; -} - -int PlayersModel::IncreaseVolume(void) // 不带界面增加音量 -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] IncreaseVolume"); - - int curSound = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Presound is %d", curSound); - if (curSound > VOLUME_MAXIMUM - VOLUME_PER_CHANGE) { - curSound = VOLUME_MAXIMUM; - } else { - curSound += VOLUME_PER_CHANGE; - } - AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, curSound); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Now music sound is %d", curSound); - return NORMAL; -} - -int PlayersModel::DecreaseVolume(void) // 不带界面减小音量 -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] DecreaseVolume"); - - int curSound = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Presound is %d", curSound); - if (curSound < VOLUME_MINIMUM + VOLUME_PER_CHANGE) { - curSound = VOLUME_MINIMUM; - } else { - curSound -= VOLUME_PER_CHANGE; - } - AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, curSound); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Now music sound is %d", curSound); - return NORMAL; -} - -int32_t PlayersModel::GetPlayerstatus() -{ - int32_t playerState; - if (playerCtr.get() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersModel::GetPlayerstatus playerCtr is nullptr"); - return EXECUTE_FUNC_FAILED; - } - playerCtr->GetPlayerState(playerState); - - switch (playerState) { - case PLAYER_STARTED: - playerState = AVRCP_PLAY_STATUS_PLAYING; - break; - case PLAYER_PAUSED: - playerState = AVRCP_PLAY_STATUS_PAUSED; - break; - case PLAYER_STOPPED: - playerState = AVRCP_PLAY_STATUS_STOPPED; - break; - default: - playerState = AVRCP_PLAY_STATUS_STOPPED; - break; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::GetPlayerstatus]status = [%d]", playerState); - return playerState; -} - -void PlayersModel::SetBTMusicPlay(avrcp_key_operation_t notification) -{ - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] SetBTMusicPlay"); - if (BluetoothModel::GetInstance()->GetLastConnedAddr() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] GetLastConnedAddr is nullptr"); - return; - } - if (notification == AVRCP_KEY_PLAY) { - ret = a2dp_src_start_playing(BluetoothModel::GetInstance()->GetLastConnedAddr()); // 设置耳机的状态为播放 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] A2dpSrcStartPlaying ret:%d", ret); - avrcp_tg_notify_playback_status_changed(PlayersModel::GetInstance()->GetPlayerstatus()); - } else if (notification == AVRCP_KEY_PAUSE) { - ret = a2dp_src_suspend_playing(BluetoothModel::GetInstance()->GetLastConnedAddr()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] A2dpSrcSuspendPlaying ret:%d", ret); // 设置耳机的状态暂停 - avrcp_tg_notify_playback_status_changed(PlayersModel::GetInstance()->GetPlayerstatus()); - } -} -// 蓝牙连接和本地的音乐播放 -int32_t PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState) -{ - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPlay connCtState = %d connTgState = %d", connCtState, connTgState); - avrcp_key_operation_t playNotification = AVRCP_KEY_PLAY; - if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPlay] BT GetPlayerCtr is nullptr "); - return -1; - } - if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { - if (playerState == PlayerStates::PLAYER_PAUSED) { - if (playerInterruptListener->IsInterruptedPaused()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); - return -1; - } - ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); // 暂停后的播放 - PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); - } else { - ret = PlayersModel::GetInstance()->PlayerStat(); // 蓝牙连接播放 - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnBtAndLocalPlay] BTPlayerStat err, ret:%d", ret); - } - PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); - } - } else { - if (playerState == PlayerStates::PLAYER_PAUSED) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PLAYER_PAUSED play, 122."); - if (playerInterruptListener->IsInterruptedPaused()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); - return -1; - } - ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); - } else { - ret = PlayersModel::GetInstance()->PlayerStat(); // 本地播放 - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); - } - } - } - return ret; -} - -// 蓝牙连接和本地音乐的暂停 -int32_t PlayersModel::ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState) -{ - int32_t ret = 0; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPause"); - avrcp_key_operation_t playNotification = AVRCP_KEY_PAUSE; - if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == BTUNSELECTED, 105."); - if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPause] BT GetPlayerCtr is nullptr"); - return -1; - } - ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 蓝牙连接暂停 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BT Music Pause, ret:%d", ret); - PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == UNSELECTED, 105."); - ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 本地暂停 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pause, ret:%d", ret); - } - return ret; -} - -void PlayersModel::ClearActivateAudioInterrupt() -{ - isActivateAudioInterrupt = false; -} - -void PlayersModel::GetDuration(int64_t &duration) -{ - duration = duration_; -} - +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersModel + * Create: 2025-03-23 + */ + +#include "thread_adapter.h" +#include "UiConfig.h" +#include "player/PlayersModel.h" + +namespace OHOS { + +static constexpr int VOLUME_MAXIMUM = 100; +static constexpr int VOLUME_MINIMUM = 0; +static constexpr int VOLUME_PER_CHANGE = 10; + +#define BUFFER_SIZE 15 +static MutexId g_mutex; +PlayersModel::PlayersModel() +{ + g_mutex = MUTEX_InitValue(); +} + +PlayersModel::~PlayersModel() +{ + listPlayers.Clear(); +} + +bool PlayersModel::FetchedPlayersCallBack(PlayersMsg *playersMsg) +{ + if (listPlayers.IsEmpty()) { + return false; + } else { + MUTEX_Lock(g_mutex); + *playersMsg = listPlayers.Front(); + listPlayers.PopFront(); + MUTEX_Unlock(g_mutex); + } + return true; +} + +void PlayersModel::PushPlayersData(PlayersMsg playersMsg) +{ + MUTEX_Lock(g_mutex); + listPlayers.PushBack(playersMsg); + MUTEX_Unlock(g_mutex); +} + +PlayersModel *PlayersModel::GetInstance() +{ + static PlayersModel instance; + return &instance; +} + +std::string PlayersModel::GetPlayerUri(void) +{ + return uri; +} + +void PlayersModel::SetPlayerUri(std::string src) +{ + uri = src; +} + +void PlayersModel::SetPlayButtonState(bool value) +{ + playButtonState = value; +} + +int PlayersModel::PlayerStat() +{ + int32_t ret; + + // 设置回调函数 + playerCtr->SetPlayerCallback(playerCallback); + // 申请资源 + source = std::make_shared(uri, header); + if (source.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "source new fail"); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Player uri %s.", uri.c_str()); + playerCtr->SetSource(*source); + playerCtr->Prepare(); + ret = playerCtr->GetDuration(duration_); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%s,%d] GetDuration:%lld, ret:%d", __func__, __LINE__, duration_, ret); + if (!isActivateAudioInterrupt) { + // 申请焦点 + AudioManager& amIntance = AudioManager::GetInstance(); + sessionId = amIntance.MakeSessionId(); + if (sessionId == AUDIO_SESSION_ID_NONE) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "session invalid"); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MakeSessionId %d", sessionId); + playerInterruptListener = std::make_shared(); + if (playerInterruptListener.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerInterruptListener new fail"); + return OHOS_FAILURE; + } + playerInterruptListener->SetOwner(playerCtr); + interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; + // 激活音频中断 5s超时 + if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); + return OHOS_FAILURE; + } + isActivateAudioInterrupt = true; + } + playerCtr->SetAudioSessionId(sessionId); + // 播放 + ret = playerCtr->Play(); + if (ret != 0) { + playerCtr->Stop(); // 暂停 + playerCtr->Reset(); // 初始化 + + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView != nullptr) { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + SetCircleProgress(100); // 100:进度100% + playersView->SetPlaybackProgress(circleProgress); + } else { + SetPlayButtonState(false); + SetCircleProgress(100); // 100:进度100% + } + AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); + isActivateAudioInterrupt = false; + } + return OHOS_SUCCESS; +} + +bool PlayersModel::GetAudioInitStatus(void) +{ + return audioInitStatus; +} + +void PlayersModel::AudioInit(void) +{ + if (audioInitStatus) { + return; + } + AudioManager& amIntance = AudioManager::GetInstance(); + audioInitStatus = amIntance.Initialize(); + playerCtr = std::make_shared(); + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr new fail"); + return; + } + playerCallback = std::make_shared(); + if (playerCallback.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCallback new fail"); + return; + } +} + +void PlayersModel::SetCircleProgress(int64_t value) +{ + circleProgress = value; +} + +int16_t PlayersModel::GetCurrentIndex(void) +{ + return currentIndex; +} + +void PlayersModel::SetCurrentIndex(int16_t value) +{ + currentIndex = value; +} + +int16_t PlayersModel::GetPlayerModel(void) +{ + return playerModel; +} + +void PlayersModel::SetPlayerModel(int16_t value) +{ + playerModel = value; +} + +void PlayersModel::SetPlayerModelAddOne(void) +{ + playerModel++; +} + +void PlayersModel::PlaySwitching(void) +{ + PlayersMsg playersMsg1; + playersMsg1.playerModel = GetPlayerModel(); + PushPlayersData(playersMsg1); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlaySwitching playerModel1 %d!!!", GetPlayerModel()); + int32_t ret; + PlayersMsg playersMsg; + if (FetchedPlayersCallBack(&playersMsg)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FetchedPlayersCallBack true"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop to play"); + switch (playersMsg.playerModel) { + case PlayerModelState::LOOP: + // 循环 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoopingPlayout!!!"); + LoopingPlayout(); + break; + case PlayerModelState::SEQUENCE: + // 顺序 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SequencePlayout!!!"); + SequencePlayout(); + break; + case PlayerModelState::REPEATS: + // 重复 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RepeatsPlayout!!!"); + ret = PlayersModel::GetInstance()->playerCtr->Stop(); // 停止 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop, ret:%d", ret); + ret = PlayersModel::GetInstance()->playerCtr->Reset(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + PlayersModel::GetInstance()->PlayerStat(); // 播放 + break; + case PlayerModelState::RANDOM: + // 随机 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RandomPlayout!!!"); + RandomPlayout(); + break; + default: + break; + } + } +} + +int PlayersModel::PlayerInit(void) +{ + sliceId = PlayersListGroup::GetInstance()->GetCase(currentIndex); + if (sliceId == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCase %d sliceId err !!!", currentIndex); + char strFile[BUFFER_SIZE] = "No music files"; + sliceId = strFile; + } + std::string strSongName = sliceId; + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerInit, url: %s ", sliceId); + std::string strSrcMusic(APP_MUSIC_PATH); + std::string tempStr("/"); + std::string strName = sliceId; + uri = strSrcMusic + tempStr + strName; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerInit end!"); + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerInit playersView GetInstance fail"); + return OHOS_FAILURE; + } + playersView->TitleSetText(pureName.c_str()); + playersView->SetPlaybackProgress(circleProgress); + playersView->SetPlayerState(playButtonState); + return 0; +} + +void PlayersModel::NextSong(int16_t index) +{ + SetCurrentIndex(index); + // 播放 + sliceId = PlayersListGroup::GetInstance()->GetCase(index); + if (sliceId == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCase %d sliceId err!!!", index); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCase sliceId %s.", sliceId); + std::string strSrcMusic(APP_MUSIC_PATH); + std::string tempStr("/"); + std::string strName = sliceId; + SetPlayerUri(strSrcMusic + tempStr + strName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", GetPlayerUri().c_str()); + std::string strSongName = sliceId; + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView != nullptr) { + playersView->TitleSetText(pureName.c_str()); + playersView->SetPlaybackProgress(0); // 0:进度0% + } + int32_t ret; + int32_t playerState; + playerCtr->GetPlayerState(playerState); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerState Value %d.", playerState); + if ((playerState == PlayerStates::PLAYER_STARTED) || (playerState == PlayerStates::PLAYER_PLAYBACK_COMPLETE)) { + /* start play */ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "start play, 160."); + ret = playerCtr->Stop(); // 停止 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop, ret:%d", ret); + ret = playerCtr->Reset(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + ret = PlayerStat(); // 播放 + if (ret != 0) { + /* stop and exit */ + ret = playerCtr->Stop(); // 停止 + ret = playerCtr->Reset(); + } + } else if (playerState == PlayerStates::PLAYER_PAUSED || (playerState == PlayerStates::PLAYER_IDLE)) { + ret = playerCtr->Reset(); + AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); + ClearActivateAudioInterrupt(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + } +} + +void PlayersModel::LoopingPlayout() +{ + int16_t index; + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + index = GetCurrentIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoopingPlayout, index %d.", index); + if ((index > playersCaseList.Size() - 1) || (index < 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); + SetCurrentIndex(0); + return; + } + if (GetPlayerModel() == PlayerModelState::RANDOM) { + RandomPlayout(); + return; + } else { + index++; // 下一曲 + } + if (index > playersCaseList.Size() - 1) { + index = 0; + } + NextSong(index); + SetCircleProgress(0); // 0:进度0% +} + +void PlayersModel::SequencePlayout() +{ + int16_t index; + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + index = GetCurrentIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SequencePlayout, index %d.", index); + if ((index > playersCaseList.Size() - 1) || (index < 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); + SetCurrentIndex(0); + return; + } + index++; // 下一曲 + if (index > playersCaseList.Size() - 1) { + playerCtr->Stop(); // 暂停 + playerCtr->Reset(); // 初始化 + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView != nullptr) { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + } else { + SetPlayButtonState(false); + } + SetCircleProgress(100); // 100:进度100% + index = playersCaseList.Size() - 1; + } + NextSong(index); +} + +void PlayersModel::RandomPlayout() +{ + int16_t random; + int16_t indexMax; + srand((unsigned)time(nullptr)); + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + indexMax = playersCaseList.Size() - 1; + random = (rand() % (indexMax + 1)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RANDOM %d.", random); + if ((random > playersCaseList.Size() - 1) || (random < 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "random err"); + SetCurrentIndex(0); + return; + } + if (GetCurrentIndex() == random) { + random++; + if (random > playersCaseList.Size() - 1) { + random = 0; + } + } + NextSong(random); + SetCircleProgress(0); // 0:进度0% +} + +void PlayersModel::PreviousPlayout() +{ + int16_t index; + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + index = GetCurrentIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PreviousPlayout, index %d.", index); + if ((index > playersCaseList.Size() - 1) || (index < 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentIndex err"); + SetCurrentIndex(0); + return; + } + index--; // 上一曲 + if (index < 0) { + index = playersCaseList.Size() - 1; + } + NextSong(index); + SetCircleProgress(0); // 0:进度0% +} + +std::shared_ptr PlayersModel::GetPlayerCtr() +{ + return playerCtr; +} + +std::shared_ptr PlayersModel::GetPlayerIntrptListener(void) +{ + return playerInterruptListener; +} + +int PlayersModel::GetPlayerState(void) +{ + int state; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] GetPlayerState"); + + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); + return ERR_RET; + } + playerCtr->GetPlayerState(state); + return state; +} + +bool PlayersModel::HasPlayerPlayed(void) +{ + int state = GetPlayerState(); + if (state == ERR_RET) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get Player State failed!!"); + return false; + } + if (state != PlayerStates::PLAYER_STARTED && state != PlayerStates::PLAYER_PAUSED && + state != PlayerStates::PLAYER_STOPPED && state != PlayerStates::PLAYER_PLAYBACK_COMPLETE) { + if (!isStopAndReset) { + return false; + } + } + return true; +} + +/* 蓝牙连接的音频控制,对按钮属性进行设置 */ +void PlayersModel::ConncetBtResetButton() +{ + int32_t connCtState = avrcp_ct_get_device_connect_state(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); + int32_t connTgState = avrcp_tg_get_device_connect_state(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); + if (connCtState == PROFILE_STATE_CONNECTED || connTgState == PROFILE_STATE_CONNECTED) { + if (PlayersView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::GetInstance() == nullptr"); + return; + } + PlayersView::GetInstance()->PlayerHeadsetReset(); + } +} + +int PlayersModel::PlayerPlay(void) +{ + int state; + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerPlay"); + + state = GetPlayerState(); + if (state == ERR_RET) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); + return EXECUTE_FUNC_FAILED; + } + + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); + return EXECUTE_FUNC_FAILED; + } + if (state == PlayerStates::PLAYER_PAUSED || state == PlayerStates::PLAYER_STOPPED) { // 暂停状态则直接开始 + if (playerInterruptListener->IsInterruptedPaused()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); + return EXECUTE_FUNC_FAILED; + } + ret = playerCtr->Play(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Play err, ret:%d", ret); + return EXECUTE_FUNC_FAILED; + } + PlayersModel::GetInstance()->SetPlayButtonState(true); // 播放控件图形同步 + ConncetBtResetButton(); // 蓝牙连接的音频控制,对按钮属性进行设置 + return NORMAL; + } else if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { // 已经在播放状态则不做操作 + return SONG_ALREADY_PLAY; + } else { // 其它情况的处理 + ret = PlayersModel::GetInstance()->PlayerStat(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); + return EXECUTE_FUNC_FAILED; + } + PlayersModel::GetInstance()->SetPlayButtonState(true); // 播放控件图形同步 + ConncetBtResetButton(); + return NORMAL; + } +} + +int PlayersModel::PlayerPause(void) +{ + int state; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerPause"); + + state = GetPlayerState(); + if (state == ERR_RET) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); + return EXECUTE_FUNC_FAILED; + } + + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); + return EXECUTE_FUNC_FAILED; + } + if (state == PlayerStates::PLAYER_PAUSED) { // 暂停状态则不操作 + return SONG_ALREADY_PAUSE; + } else if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { + int ret = playerCtr->Pause(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Pause err, ret:%d!!", ret); + return EXECUTE_FUNC_FAILED; + } else { + PlayersModel::GetInstance()->SetPlayButtonState(false); + ConncetBtResetButton(); + return NORMAL; + } + } else if (state == PlayerStates::PLAYER_STOPPED) { + return SONG_ALREADY_STOP; + } + return NORMAL; +} + +int PlayersModel::PlayerStop(void) +{ + int state; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PlayerStop"); + state = GetPlayerState(); + if (state == ERR_RET) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get state of player failed!!"); + return EXECUTE_FUNC_FAILED; + } + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr.get() is nullptr!!"); + return EXECUTE_FUNC_FAILED; + } + if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PLAYBACK_COMPLETE) { + int ret = playerCtr->Stop(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Stop err, ret:%d", ret); + return EXECUTE_FUNC_FAILED; + } + ret = playerCtr->Reset(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Reset err, ret:%d", ret); + return EXECUTE_FUNC_FAILED; + } else { + isStopAndReset = true; + PlayersModel::GetInstance()->SetPlayButtonState(false); + PlayersModel::GetInstance()->SetCircleProgress(0); + ConncetBtResetButton(); + } + AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); + return NORMAL; + } else if (state == PlayerStates::PLAYER_PAUSED) { + int ret = playerCtr->Reset(); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Reset err, ret:%d", ret); + return EXECUTE_FUNC_FAILED; + } else { + PlayersModel::GetInstance()->SetPlayButtonState(false); + PlayersModel::GetInstance()->SetCircleProgress(0); + ConncetBtResetButton(); + } + AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); + return NORMAL; + } else if (state == PlayerStates::PLAYER_STOPPED) { + return SONG_ALREADY_STOP; + } + return NORMAL; +} + +int PlayersModel::PreSongOperate(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] PreSongOperate"); + + PlayersModel::GetInstance()->PreviousPlayout(); + PlayersModel::GetInstance()->SetPlayButtonState(true); + return NORMAL; +} + +int PlayersModel::NextSongOperate(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] NextSongOperate"); + + PlayersModel::GetInstance()->LoopingPlayout(); + PlayersModel::GetInstance()->SetPlayButtonState(true); + return NORMAL; +} + +int PlayersModel::IncreaseVolume(void) // 不带界面增加音量 +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] IncreaseVolume"); + + int curSound = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Presound is %d", curSound); + if (curSound > VOLUME_MAXIMUM - VOLUME_PER_CHANGE) { + curSound = VOLUME_MAXIMUM; + } else { + curSound += VOLUME_PER_CHANGE; + } + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, curSound); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Now music sound is %d", curSound); + return NORMAL; +} + +int PlayersModel::DecreaseVolume(void) // 不带界面减小音量 +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayersModel] DecreaseVolume"); + + int curSound = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Presound is %d", curSound); + if (curSound < VOLUME_MINIMUM + VOLUME_PER_CHANGE) { + curSound = VOLUME_MINIMUM; + } else { + curSound -= VOLUME_PER_CHANGE; + } + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, curSound); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Now music sound is %d", curSound); + return NORMAL; +} + +int32_t PlayersModel::GetPlayerstatus() +{ + int32_t playerState; + if (playerCtr.get() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersModel::GetPlayerstatus playerCtr is nullptr"); + return EXECUTE_FUNC_FAILED; + } + playerCtr->GetPlayerState(playerState); + + switch (playerState) { + case PLAYER_STARTED: + playerState = AVRCP_PLAY_STATUS_PLAYING; + break; + case PLAYER_PAUSED: + playerState = AVRCP_PLAY_STATUS_PAUSED; + break; + case PLAYER_STOPPED: + playerState = AVRCP_PLAY_STATUS_STOPPED; + break; + default: + playerState = AVRCP_PLAY_STATUS_STOPPED; + break; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::GetPlayerstatus]status = [%d]", playerState); + return playerState; +} + +void PlayersModel::SetBTMusicPlay(avrcp_key_operation_t notification) +{ + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] SetBTMusicPlay"); + if (SettingBluetoothModel::GetInstance()->GetLastConnedAddr() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] GetLastConnedAddr is nullptr"); + return; + } + if (notification == AVRCP_KEY_PLAY) { + ret = a2dp_src_start_playing(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); // 设置耳机的状态为播放 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] A2dpSrcStartPlaying ret:%d", ret); + avrcp_tg_notify_playback_status_changed(PlayersModel::GetInstance()->GetPlayerstatus()); + } else if (notification == AVRCP_KEY_PAUSE) { + ret = a2dp_src_suspend_playing(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel::SetBTMusicPlay] A2dpSrcSuspendPlaying ret:%d", ret); // 设置耳机的状态暂停 + avrcp_tg_notify_playback_status_changed(PlayersModel::GetInstance()->GetPlayerstatus()); + } +} +// 蓝牙连接和本地的音乐播放 +int32_t PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState) +{ + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPlay connCtState = %d connTgState = %d", connCtState, connTgState); + avrcp_key_operation_t playNotification = AVRCP_KEY_PLAY; + if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPlay] BT GetPlayerCtr is nullptr "); + return -1; + } + if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { + if (playerState == PlayerStates::PLAYER_PAUSED) { + if (playerInterruptListener->IsInterruptedPaused()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); + return -1; + } + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); // 暂停后的播放 + PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); + } else { + ret = PlayersModel::GetInstance()->PlayerStat(); // 蓝牙连接播放 + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnBtAndLocalPlay] BTPlayerStat err, ret:%d", ret); + } + PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); + } + } else { + if (playerState == PlayerStates::PLAYER_PAUSED) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PLAYER_PAUSED play, 122."); + if (playerInterruptListener->IsInterruptedPaused()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); + return -1; + } + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); + } else { + ret = PlayersModel::GetInstance()->PlayerStat(); // 本地播放 + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); + } + } + } + return ret; +} + +// 蓝牙连接和本地音乐的暂停 +int32_t PlayersModel::ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState) +{ + int32_t ret = 0; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPause"); + avrcp_key_operation_t playNotification = AVRCP_KEY_PAUSE; + if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == BTUNSELECTED, 105."); + if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPause] BT GetPlayerCtr is nullptr"); + return -1; + } + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 蓝牙连接暂停 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BT Music Pause, ret:%d", ret); + PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == UNSELECTED, 105."); + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 本地暂停 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pause, ret:%d", ret); + } + return ret; +} + +void PlayersModel::ClearActivateAudioInterrupt() +{ + isActivateAudioInterrupt = false; +} + +void PlayersModel::GetDuration(int64_t &duration) +{ + duration = duration_; +} + } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicItemView.cpp new file mode 100644 index 000000000..8d0f74218 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicItemView.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersMusicItemView + * Create: 2025-03-23 + */ + +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "wearable_log.h" +#include "player/PlayersMusicItemView.h" + +namespace OHOS { +constexpr uint16_t STYLE_BORDER_WIDTH_VALUE = 4; +constexpr uint16_t STYLE_BORDER_RADIUS_VALUE = 12; +constexpr uint16_t LABEL_BUTTON_HEIGHT = 64; +static constexpr uint32 BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333; +PlayersMusicItemView::PlayersMusicItemView() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "PlayersMusicItemView"); + labelButton_.SetPosition(0, 0); + labelButton_.Resize(HORIZONTAL_RESOLUTION, LABEL_BUTTON_HEIGHT); + labelButton_.SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::RELEASED); + labelButton_.SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::PRESSED); + labelButton_.SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::INACTIVE); + labelButton_.SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::RELEASED); + labelButton_.SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::PRESSED); + labelButton_.SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::INACTIVE); + labelButton_.SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); + labelButton_.SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); + labelButton_.SetStyleForState(STYLE_BORDER_RADIUS, STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); + labelButton_.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED); + labelButton_.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED); + labelButton_.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE); + labelButton_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: means font size + labelButton_.SetAlign(TEXT_ALIGNMENT_CENTER); + labelButton_.SetLabelPosition(24, 0); // 24: lable x-coordinate + Add(&labelButton_); +} + +PlayersMusicItemView::~PlayersMusicItemView() +{ + Remove(&labelButton_); +} + +void PlayersMusicItemView::SetItemInfo(const PlayerCaseInfo itemInfo) +{ + itemInfo_ = itemInfo; + std::string strSongName = itemInfo.sliceId; + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + labelButton_.SetText(pureName.c_str()); + labelButton_.SetViewIndex(itemInfo.index); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "pureName.c_str(%s)", pureName.c_str()); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "pureName.index(%d)", itemInfo.index); +} + +PlayerCaseInfo PlayersMusicItemView::GetItem() +{ + return itemInfo_; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicListGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicListGroup.cpp new file mode 100644 index 000000000..413f75a8f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersMusicListGroup.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersMusicListGroup + * Created: 2025-06 + */ + +#include +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_image.h" +#include "graphic_service.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" +#include "main/VolumeSettingView.h" +#include "settings/common/SettingCommon.h" +#include "player/PlayersPresenter.h" +#include "player/PlayersModel.h" +#include "player/PlayersMusicListGroup.h" +#include "bts_avrcp_controller.h" +#include "bts_avrcp_target.h" +#include "player/PlayersMusicItemView.h" +#include "player/PlayersMusicListGroup.h" + +namespace OHOS { +constexpr uint16_t ITEM_HEIGHT = 64; +static PlayersMusicListGroup* g_pPlayersMusicListGroup = nullptr; + +PlayersMusicListGroup::PlayersMusicListGroup() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersMusicListGroup::PlayersMusicListGroup"); + g_pPlayersMusicListGroup = this; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetDraggable(true); + SetTouchable(true); + SetOnClickListener(this); + SetOnDragListener(this); + musicList_ = new UISimpleList(); + if (musicList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); + return; + } + musicList_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + musicList_->SetDraggable(true); + musicList_->SetTouchable(true); + musicList_->SetThrowDrag(true); + musicList_->SetOnDragListener(this); + musicList_->SetOnClickListener(this); + musicList_->SetStartIndex(0); + RefreshMusicList(); + musicList_->Invalidate(); + Add(musicList_); +} + +PlayersMusicListGroup* PlayersMusicListGroup::GetInstance(void) +{ + return g_pPlayersMusicListGroup; +} + +static UIView* CreateViewCb(uint8_t type) +{ + PlayersMusicItemView* item = new PlayersMusicItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0); + item->Resize(HORIZONTAL_RESOLUTION, ITEM_HEIGHT); + item->SetTouchable(true); + item->SetOnClickListener(g_pPlayersMusicListGroup); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + PlayersMusicItemView* item = dynamic_cast(view); + if (view == nullptr || data == nullptr || item == nullptr) { + return; + } + PlayerCaseInfo* content = static_cast(data); + item->SetItemInfo(*content); +} + +void PlayersMusicListGroup::RefreshMusicList() +{ + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + int size = playersCaseList.Size(); + + musicList_->ClearAll(); + musicList_->ScrollTo(0); + ListNode *node = playersCaseList.Head(); + while (node != playersCaseList.End()) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + PlayerCaseInfo &itemData = node->data_; + content.data = reinterpret_cast(&itemData); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "PlayerCaseInfo.itemData(%s)", itemData.sliceId); + musicList_->AddContent(content); + node = node->next_; + } + musicList_->RefreshList(); +} + +PlayersMusicListGroup::~PlayersMusicListGroup() +{ + RemoveAll(); + if (musicList_ != nullptr) { + musicList_->ClearAll(); + delete musicList_; + musicList_ = nullptr; + } + g_pPlayersMusicListGroup = nullptr; + ImageCacheManager::GetInstance().UnloadAllInMultiRes(PLAYER_IAMGES); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersMusicListGroup::~PlayersMusicListGroup"); +} + +void PlayersMusicListGroup::BtnOnListData(UIView& view) +{ + index_ = view.GetViewIndex(); + List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); + ListNode* node = playersCaseList.Begin(); + for (uint16_t i = 0; i < index_; i++) { + node = node->next_; + } + sliceId_ = node->data_.sliceId; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "pureName.index_(%d)", index_); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "pureName.sliceId(%s)", sliceId_); +} + +bool PlayersMusicListGroup::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + int ret; + int32_t playerState; + uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + PlayersView *playersView = PlayersView::GetInstance(); + if (playersView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView null!"); + return false; + } + BtnOnListData(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtnOnClickListListener sliceId_: %s.", sliceId_); + // 标记当前播放歌曲index_ + PlayersModel::GetInstance()->SetCurrentIndex(index_); + // 本地播放文件路径和状态 + std::string strSrcMusic(APP_MUSIC_PATH); + std::string tempStr("/"); + std::string strName = sliceId_; + PlayersModel::GetInstance()->SetPlayerUri(strSrcMusic + tempStr + strName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", PlayersModel::GetInstance()->GetPlayerUri().c_str()); + std::string strSongName = sliceId_; + std::string pureName = strSongName.substr(0, strSongName.rfind(".")); + playersView->TitleSetText(pureName.c_str()); + SetVisible(false); + // 刷新UI + RootView::GetInstance()->Invalidate(); + + state = playersView->GetPlayerButtonState(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state %d", state); + if (state == UICheckBox::UICheckBoxState::UNSELECTED) { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + /* start play */ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "play"); + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + if (playerState == PlayerStates::PLAYER_PAUSED) { + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Reset(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + } + PlayersModel::GetInstance()->PlayerStat(); // 播放 + } else if (state == UICheckBox::UICheckBoxState::SELECTED) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "List to play"); + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + if (playerState == PlayerStates::PLAYER_STARTED) { + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Stop(); // 停止 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stop, ret:%d", ret); + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Reset(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + } + PlayersModel::GetInstance()->PlayerStat(); + } + return true; +} + +bool PlayersMusicListGroup::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + SetVisible(false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersOptionGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersOptionGroup.cpp new file mode 100644 index 000000000..7df910f26 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersOptionGroup.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersOptionGroup + * Created: 2025-06 + */ + +#include +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_image.h" +#include "graphic_service.h" +#include "phoneservice/PhoneService.h" +#include "phonemenu/PhoneMenuView.h" +#include "main/VolumeSettingView.h" +#include "settings/common/SettingCommon.h" +#include "player/PlayersPresenter.h" +#include "player/PlayersModel.h" +#include "bts_avrcp_controller.h" +#include "bts_avrcp_target.h" +#include "player/PlayersOptionGroup.h" + +namespace OHOS { +static constexpr int16_t BUTTON_X = 320; +static constexpr int16_t BUTTON_X2 = 313; +static constexpr int16_t WATCH_BUTTON_Y = 104; +static constexpr int16_t PHONE_BUTTON_Y = 194; +static constexpr int16_t BLUETOOTH_BUTTON_Y = 278; +static constexpr int16_t BUTTON_SIZE = 55; +static constexpr int16_t LABEL_WIDTH = 155; +static constexpr int16_t LABEL_HEIGHT = 40; +static constexpr int16_t LABEL_X = 155; +static constexpr int16_t WATCH_LABEL_Y = 108; +static constexpr int16_t PHONE_LABEL_Y = 199; +static constexpr int16_t BLUETOOTH_LABEL_Y = 290; +static constexpr int16_t IMAGE_X = 50; +static constexpr int16_t WATCH_IMAGE_Y = 98; +static constexpr int16_t PHONE_IMAGE_Y = 187; +static constexpr int16_t BLUETOOTH_IMAGE_Y = 278; +static constexpr int16_t IMAGE_SIZE = 75; +static constexpr char* BLUETOOTH_BUTTON = "BLUETOOTH_BUTTON"; +static PlayersOptionGroup* g_pPlayersOptionGroup = nullptr; + +PlayersOptionGroup::PlayersOptionGroup() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersOptionGroup::PlayersOptionGroup"); + g_pPlayersOptionGroup = this; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetDraggable(true); + SetTouchable(true); + SetOnClickListener(this); + SetOnDragListener(this); + InitImage(); + InitButton(); + InitLabel(); +} + +PlayersOptionGroup::~PlayersOptionGroup() +{ + RemoveAll(); + if (watchLabel_ != nullptr) { + delete watchLabel_; + watchLabel_ = nullptr; + } + if (phoneLabel_ != nullptr) { + delete phoneLabel_; + phoneLabel_ = nullptr; + } + if (bluetoothLabel_ != nullptr) { + delete bluetoothLabel_; + bluetoothLabel_ = nullptr; + } + if (watchImage_ != nullptr) { + delete watchImage_; + watchImage_ = nullptr; + } + if (phoneImage_ != nullptr) { + delete phoneImage_; + phoneImage_ = nullptr; + } + if (bluetoothImage_ != nullptr) { + delete bluetoothImage_; + bluetoothImage_ = nullptr; + } + if (watchButton_ != nullptr) { + delete watchButton_; + watchButton_ = nullptr; + } + if (phoneButton_ != nullptr) { + delete phoneButton_; + phoneButton_ = nullptr; + } + if (bluetoothButton_ != nullptr) { + delete bluetoothButton_; + bluetoothButton_ = nullptr; + } + if (deleteButton != nullptr) { + delete deleteButton; + deleteButton = nullptr; + } + g_pPlayersOptionGroup = nullptr; + ImageCacheManager::GetInstance().UnloadAllInMultiRes(PLAYER_IAMGES); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersOptionGroup::~PlayersOptionGroup"); +} + +void PlayersOptionGroup::InitButton() +{ + if (watchButton_ == nullptr) { + watchButton_ = new UIRadioButton("MusicCategory"); + if (watchButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchButton UIRadio new fail"); + return; + } + } + + watchButton_->SetPosition(BUTTON_X, WATCH_BUTTON_Y, BUTTON_SIZE, BUTTON_SIZE); + watchButton_->SetOnClickListener(this); + watchButton_->SetTouchable(false); + + if (phoneButton_ == nullptr) { + phoneButton_ = new UIRadioButton("MusicCategory"); + if (phoneButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneButton UIRadio new fail"); + return; + } + } + phoneButton_->SetPosition(BUTTON_X, PHONE_BUTTON_Y, BUTTON_SIZE, BUTTON_SIZE); + phoneButton_->SetOnClickListener(this); + phoneButton_->SetTouchable(false); + + if (bluetoothButton_ == nullptr) { + bluetoothButton_ = new UIButton(); + if (bluetoothButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "settingButton UIButton new fail"); + return; + } + } + bluetoothButton_->SetPosition(BUTTON_X2, BLUETOOTH_BUTTON_Y, BUTTON_SIZE, BUTTON_SIZE); + bluetoothButton_->SetOnClickListener(this); + bluetoothButton_->SetImageSrc(PNG_SETTTING_BUTTON_IMAGE, PNG_SETTTING_BUTTON_IMAGE); + bluetoothButton_->SetViewId(BLUETOOTH_BUTTON); + Add(watchButton_); + Add(phoneButton_); + Add(bluetoothButton_); +} + +void PlayersOptionGroup::InitLabel() +{ + if (watchLabel_ == nullptr) { + watchLabel_ = new UILabel(); + if (watchLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchLabel new fail"); + return ; + } + } + + watchLabel_->SetPosition(LABEL_X, WATCH_LABEL_Y, LABEL_WIDTH, LABEL_HEIGHT); + watchLabel_->SetText("手表音乐"); + watchLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); + if (phoneLabel_ == nullptr) { + phoneLabel_ = new UILabel(); + if (phoneLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneLabel new fail"); + return ; + } + } + phoneLabel_->SetPosition(LABEL_X, PHONE_LABEL_Y, LABEL_WIDTH, LABEL_HEIGHT); + phoneLabel_->SetText("手机音乐"); + phoneLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); + if (bluetoothLabel_ == nullptr) { + bluetoothLabel_ = new UILabel(); + if (bluetoothLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothLabel new fail"); + return ; + } + } + bluetoothLabel_->SetPosition(LABEL_X, BLUETOOTH_LABEL_Y, LABEL_WIDTH, LABEL_HEIGHT); + bluetoothLabel_->SetText("蓝牙音乐"); + bluetoothLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); + Add(watchLabel_); + Add(phoneLabel_); + Add(bluetoothLabel_); +} + +void PlayersOptionGroup::InitImage() +{ + watchImage_ = new UIImageView(); + if (watchImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchImage new fail"); + return ; + } + watchImage_->SetPosition(IMAGE_X, WATCH_IMAGE_Y, IMAGE_SIZE, IMAGE_SIZE); + watchImage_->SetSrc(PNG_WATCH_IMAGE); + + phoneImage_ = new UIImageView(); + if (phoneImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage new fail"); + return ; + } + phoneImage_->SetPosition(IMAGE_X, PHONE_IMAGE_Y, IMAGE_SIZE, IMAGE_SIZE); + phoneImage_->SetSrc(PNG_PHONE_IMAGE); + + bluetoothImage_ = new UIImageView(); + if (bluetoothImage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothImage new fail"); + return ; + } + bluetoothImage_->SetPosition(IMAGE_X, BLUETOOTH_IMAGE_Y, IMAGE_SIZE, IMAGE_SIZE); + bluetoothImage_->SetSrc(PNG_BLUETOOTH_IMAGE); + Add(watchImage_); + Add(phoneImage_); + Add(bluetoothImage_); +} + +bool PlayersOptionGroup::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), BLUETOOTH_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchSlice(VIEW_SETTING, SettingPageId::BLUETOOTH_PAGE); + } + return true; +} + +bool PlayersOptionGroup::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + SetVisible(false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersPresenter.cpp index 8571cc9d3..65ca98243 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -1,32 +1,27 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Player view - * Author: - * Create: 2021-07-26 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlayersPresenter + * Created: 2025-06-05 */ #include #include #include #include #include -#include "player/PlayersPresenter.h" #include "wearable_log.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" -#include "player/PlayersView.h" #include "player/PlayersModel.h" -#include "bluetooth/BluetoothPresenter.h" #include "graphic_service.h" #include "phoneservice/PhoneService.h" #include "main/MainViewSample.h" - +#include "phonemenu/PhoneMenuView.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" +#include "player/PlayersPresenter.h" namespace OHOS { -static PlayerOnDragListener *g_pPlayerOnDragListener = nullptr; -static JumpView *g_pJumpView = nullptr; static PlayersPresenter *g_pPlayersPresenter = nullptr; PlayersPresenter *PlayersPresenter::GetInstance(void) @@ -42,351 +37,8 @@ PlayersPresenter::PlayersPresenter() PlayersPresenter::~PlayersPresenter() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~PlayersPresenter"); g_pPlayersPresenter = nullptr; -} - -JumpView *JumpView::GetInstance(void) -{ - return g_pJumpView; -} - -JumpView::JumpView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "JumpView::JumpView"); - g_pJumpView = this; - preProcessView[BLUETOOTHEARPHONEVIEW] = &JumpView::ChangeBluetoothEarPhoneView; - preProcessView[BLUETOOTHEARLISTVIEW] = &JumpView::ChangeBluetoothEarListView; - preProcessView[BLUETOOTHDEVICELISTVIEW] = &JumpView::ChangeBluetoothDeviceListView; - preProcessView[BLUETOOTHEOPTIONSVIEW] = &JumpView::ChangeBluetoothOptionsView; - preProcessView[BLUETOOTHRECONNECTVIEW] = &JumpView::ChangeBluetoothReconnectView; - preProcessView[TIPSSUCCMESSAGEVIEW] = &JumpView::ChangeTipsSuccMessageView; - preProcessView[TIPSCONNFAILMESSAGEVIEW] = &JumpView::ChangeTipsConnFailMessageView; - preProcessView[TIPSFAILMESSAGEVIEW] = &JumpView::ChangeTipsFailMessageView; - preProcessView[BLUETOOTHEVIEW] = &JumpView::ChangeBluetoothView; -} - -JumpView::~JumpView() -{ - delete bluetoothEarPhoneView; - bluetoothEarPhoneView = nullptr; - delete bluetoothOptionsView; - bluetoothOptionsView = nullptr; - delete bluetoothEarListView; - bluetoothEarListView = nullptr; - delete bluetoothReconnectView; - bluetoothReconnectView = nullptr; - delete bluetoothDeviceListView; - bluetoothDeviceListView = nullptr; - delete tipsSuccMessageView; - tipsSuccMessageView = nullptr; - delete tipsConnFailMessageView; - tipsConnFailMessageView = nullptr; - delete tipsFailMessageView; - tipsFailMessageView = nullptr; - delete bluetoothView; - bluetoothView = nullptr; - int i; - for (i = BLUETOOTHEARPHONEVIEW; i <= BLUETOOTHEJUMP_MAX; i++) { - container[i] = nullptr; - } - g_pJumpView = nullptr; -} - -bool JumpView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarPhoneView"); - bluetoothEarPhoneView = new BluetoothEarPhoneView(); - if (bluetoothEarPhoneView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView new fail"); - return false; - } - UIViewGroup *group = bluetoothEarPhoneView->InitShowUpView(); // init view - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - // 动画开始 - bluetoothEarPhoneView->BtAnimatorStart(); - // 蓝牙扫描&清空列表 - bluetoothEarPhoneView->BtEnable(); - return true; -} - -bool JumpView::ChangeBluetoothEarListView(int16_t hideView, int16_t thisView) -{ - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarListView"); - bluetoothEarListView = new BluetoothEarListView(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView new fail"); - return false; - } - UIViewGroup *group = bluetoothEarListView->InitShowUpView(); // init view - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } else { - // 刷新列表 - UIList *scanList = bluetoothEarListView->GetScanUIList(); - if (scanList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick scanList nullptr"); - return false; - } - scanList->RefreshList(); - } - ResetEarListView(hideView); - return true; -} - -bool JumpView::ChangeBluetoothView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothView"); - bluetoothView = new BluetoothView(); - if (bluetoothView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothView new fail"); - return false; - } - // init view - UIViewGroup *group = bluetoothView->LoadBluetoothView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "JumpView::ChangeBluetoothView"); - BluetoothModel::GetInstance()->SetTagConnectView(false); - return true; -} - -bool JumpView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothOptionsView"); - bluetoothOptionsView = new BluetoothOptionsView(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView new fail"); - return false; - } - // init view - UIViewGroup *group = bluetoothOptionsView->InitShowUpView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - return true; -} - -bool JumpView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothDeviceListView"); - bluetoothDeviceListView = new BluetoothDeviceListView(); - if (bluetoothDeviceListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDeviceListView new fail"); - return false; - } - // init view - UIViewGroup *group = bluetoothDeviceListView->InitShowUpView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } else { - // 刷新列表 - UIList *deviceList = bluetoothDeviceListView->GetDeviceUIList(); - if (deviceList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick deviceList nullptr"); - return false; - } - deviceList->RefreshList(); - } - if (bluetoothDeviceListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick bluetoothDeviceListView new fail"); - return false; - } - bluetoothDeviceListView->RefreshText(); - - return true; -} - -bool JumpView::ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothReconnectView"); - bluetoothReconnectView = new BluetoothReconnectView(); - if (bluetoothReconnectView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothReconnectView new fail"); - return false; - } - // init view - UIViewGroup *group = bluetoothReconnectView->InitShowUpView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - BluetoothModel::GetInstance()->SetTagDisconnectView(true); - bluetoothReconnectView->RefreshBluetoothNameLabel(); - bluetoothReconnectView->BtReconnectStart(); - return true; -} - -void JumpView::ResetEarListView(int16_t hideView) -{ - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ResetEarListView bluetoothEarListView == nullptr"); - return; - } - bluetoothEarListView->SetCancelConnedRequestButtonRemove(); - if (hideView == BLUETOOTHEARPHONEVIEW) { - bluetoothEarListView->SetTitleLabel("正在扫描"); - bluetoothEarListView->SetNewEquipmentButtonRemove(); - } else if (hideView == TIPSCONNFAILMESSAGEVIEW) { - bluetoothEarListView->SetTitleLabel("扫描完成"); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); - } -} - -bool JumpView::ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsSuccMessageView"); - tipsSuccMessageView = new TipsSuccMessageView(); - if (tipsSuccMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsSuccMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsSuccMessageView->ShowUpViewInit(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - return true; -} - -bool JumpView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView"); - tipsConnFailMessageView = new TipsConnFailMessageView(); - if (tipsConnFailMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsConnFailMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsConnFailMessageView->ShowUpViewInit(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - if (bluetoothReconnectView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback bluetoothReconnectView == nullptr"); - } else { - container[BLUETOOTHRECONNECTVIEW]->SetVisible(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView SetVisible(false)"); - } - return true; -} - -bool JumpView::ChangeTipsFailMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsFailMessageView"); - tipsFailMessageView = new TipsFailMessageView(); - if (tipsFailMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsFailMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsFailMessageView->ShowUpViewInit(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - MainViewSample::GetInstance()->GetRootContainer()->Add(container[thisView]); - } - return true; -} - -bool JumpView::CheckViewParam(int16_t hideView, int16_t showView) -{ - if (showView < 0 || showView >= BLUETOOTHEJUMP_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JumpView::CheckViewParam showView err."); - return false; - } - - if (hideView < 0 || hideView > BLUETOOTHEJUMP_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JumpView::CheckViewParam showView err."); - return false; - } - - if (hideView != BLUETOOTHEJUMP_MAX) { - if (container[hideView] == nullptr) { - return false; - } - container[hideView]->SetVisible(false); - } - - if (hideView == BLUETOOTHEARLISTVIEW || showView == BLUETOOTHEARLISTVIEW) { - BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - } - - return true; -} - -void JumpView::ChangeView(int16_t hideView, int16_t showView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "JumpView:: ChangeView %d", hideView); - if (!CheckViewParam(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JumpView::ChangeView check param err %d %d.", hideView, showView); - return; - } - - PreprosssChangeView tmpPreProcessView = preProcessView[showView]; - - if (!(this->*tmpPreProcessView)(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JumpView::ChangeView %d %d failed", showView, hideView); - return; - } - container[showView]->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "JumpView:: ChangeView end!!!%d", showView); - RootView::GetInstance()->Invalidate(); - BluetoothModel::GetInstance()->SetCurView(showView); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~PlayersPresenter"); } PlayersListGroup::~PlayersListGroup() @@ -425,6 +77,7 @@ void PlayersListGroup::SetUpListCase() List& PlayersListGroup::GetCase() { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "playersCaseList_.Size(%d)", playersCaseList_->Size()); return *playersCaseList_; } @@ -477,174 +130,6 @@ int PlayersListGroup::GetAllFiles(List *playersCaseList) return OHOS_SUCCESS; } -ButtonOnClickListener::~ButtonOnClickListener() -{ - delete volumeSettingView; - volumeSettingView = nullptr; -} - -// Button OnClick -void ButtonOnClickListener::PlayerButtonOnClick() -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView GetInstance fail"); - return; - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerButton OnClick"); - uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - int32_t playerState; - int32_t connCtState = avrcp_ct_get_device_connect_state(BluetoothModel::GetInstance()->GetLastConnedAddr()); - int32_t connTgState = avrcp_tg_get_device_connect_state(BluetoothModel::GetInstance()->GetLastConnedAddr()); - - state = playersView->GetPlayerButtonState(); - if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersModel::GetInstance()->GetPlayerCtr() nullptr"); - return; - } - PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonState = %d playerState = %d", state, playerState); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "connCtState = %d connTgState = %d", connCtState, connTgState); - - if (GetCurrCallNum() != 0 && GetScoConnectState() == HFP_SCO_STATE_CONNECTED) { - if (state == UICheckBox::UICheckBoxState::SELECTED) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } else { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerButtonOnClick] calling phone"); - return; - } - if (state == UICheckBox::UICheckBoxState::SELECTED) { - /* start play */ - PlayersModel::GetInstance()->ConnectBtAndLocalPlay(connCtState, connTgState, playerState); - } else if (state == UICheckBox::UICheckBoxState::UNSELECTED) { - PlayersModel::GetInstance()->ConnectBtAndLocalPause(connCtState, connTgState); - } -} - -void ButtonOnClickListener::SoundButtonOnClick() -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundButtonOnClick playersView nullptr err"); - return; - } - if (volumeSettingView == nullptr) { - volumeSettingView = new VolumeSettingView(); - if (volumeSettingView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volumeSetting nullptr err"); - return; - } - if (!volumeSettingView->SetUpVolume()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volumeSetting SetUpVolume fail"); - return; - } - MainViewSample::GetInstance()->GetRootContainer()->Add(volumeSettingView); - } - int32_t volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "current volume = %d", volume); - volumeSettingView->GetProgress()->SetValue(volume); - if (volume == 0) { - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); - volumeSettingView->GetDecreaseButton()->SetImageSrc(image, image); - } - VolumeSliderEventListener *volumeSliderEventListener = volumeSettingView->GetVolumeEventListener(); - if (volumeSliderEventListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundButtonOnClick volumeSliderEventListener nullptr err"); - return; - } - volumeSliderEventListener->SetPlayerCoefficients(VOLUMEPLAYERS); // 进度条系数 - playersView->SetVisible(false); - volumeSettingView->SetVisible(true); - // 刷新UI - RootView::GetInstance()->Invalidate(); -} - -void ButtonOnClickListener::OptionsButtonOnClick() -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OptionsButtonOnClick playersView nullptr err"); - return; - } - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - playersView->SetVisible(false); - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEJUMP_MAX, - JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW); -} - -void ButtonOnClickListener::PlayerModelButtonOnClick() -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerModelButtonOnClick playersView nullptr err"); - return; - } - switch (PlayersModel::GetInstance()->GetPlayerModel()) { - case LOOP: - playersView->PlayerModelButtonSetSrc(PLAYER_PLAYERSMODEL_LOOP); // 循环 - break; - case SEQUENCE: - playersView->PlayerModelButtonSetSrc(PLAYER_PLAYERSMODEL_SEQUENCE); // 顺序 - break; - case REPEATS: - playersView->PlayerModelButtonSetSrc(PLAYER_PLAYERSMODEL_REPEATS); // 重复 - break; - case RANDOM: - playersView->PlayerModelButtonSetSrc(PLAYER_PLAYERSMODEL_RANDOM); // 随机 - break; - default: - break; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerModel %d", PlayersModel::GetInstance()->GetPlayerModel()); -} - -bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event) -{ - UNUSED(view); - UNUSED(event); - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::GetInstance"); - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ButtonOnClickListener OnClick"); - if (view_ == (UIView *)playersView->GetPlayerButton()) { - PlayerButtonOnClick(); - } else if (view_ == (UIView *)playersView->GetNextButton()) { - if (playersView->GetPlaybackProgress() != nullptr) { - playersView->GetPlaybackProgress()->SetValue(0); // 0:进度0% - playersView->GetPlaybackProgress()->Invalidate(); - } - PlayersModel::GetInstance()->LoopingPlayout(); - } else if (view_ == (UIView *)playersView->GetPreButton()) { - if (playersView->GetPlaybackProgress() != nullptr) { - playersView->GetPlaybackProgress()->SetValue(0); // 0:进度0% - playersView->GetPlaybackProgress()->Invalidate(); - } - PlayersModel::GetInstance()->PreviousPlayout(); - } else if (view_ == (UIView *)playersView->GetPlayerModelButton()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerModelButton OnClick"); - PlayersModel::GetInstance()->SetPlayerModelAddOne(); - if (PlayersModel::GetInstance()->GetPlayerModel() > RANDOM) { - PlayersModel::GetInstance()->SetPlayerModel(LOOP); - } - PlayerModelButtonOnClick(); - } else if (view_ == (UIView *)playersView->GetSoundButton()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "soundButton OnClick"); - SoundButtonOnClick(); - } else if (view_ == (UIView *)playersView->GetOptionsButton()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "optionsButton OnClick"); - OptionsButtonOnClick(); - } - return true; -} // 播放器回调 PlayerCallbackImpl::PlayerCallbackImpl() @@ -662,13 +147,11 @@ void PlayerCallbackImpl::OnPlaybackComplete() GraphicService::GetInstance()->PostGraphicEvent([] { PlayersView *playersView = PlayersView::GetInstance(); if (playersView != nullptr) { - if (playersView->GetPlaybackProgress() != nullptr) { - playersView->GetPlaybackProgress()->SetValue(100); // 100:进度100% - playersView->GetPlaybackProgress()->Invalidate(); - } + playersView->SetPlaybackProgress(100); // 100:进度100% } }); - usleep(20000); + int sleepTime = 20000; + usleep(sleepTime); GraphicService::GetInstance()->PostGraphicEvent(std::bind(&PlayersModel::PlaySwitching, PlayersModel::GetInstance())); } @@ -781,17 +264,10 @@ static void Pause(void) return; } - PlayersView *playersView = PlayersView::GetInstance(); - player->GetPlayerState(state); if (state == PLAYER_STARTED) { ret = player->Pause(); if (ret == 0) { - if (playersView == nullptr) { - PlayersModel::GetInstance()->SetPlayButtonState(false); - } else { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } PlayerIntrptListener->RestFlag(); PlayerIntrptListener->SetPaused(true); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::PausePlayer]"); @@ -822,17 +298,10 @@ static void Resume(void) return; } - PlayersView *playersView = PlayersView::GetInstance(); - player->GetPlayerState(state); if (state == PLAYER_PAUSED && PlayerIntrptListener->IsPaused()) { ret = player->Play(); if (ret == 0) { - if (playersView == nullptr) { - PlayersModel::GetInstance()->SetPlayButtonState(true); - } else { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } PlayerIntrptListener->RestFlag(); PlayerIntrptListener->SetResumed(true); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::ResumePlayer]"); @@ -843,8 +312,10 @@ static void Resume(void) void PlayerInterruptListener::ResumePlayer(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::ResumePlayer] start"); - usleep(500000); // 确保界面切换完成 - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAEKPHONE_SAMPLE || + int sleepTime = 500000; + usleep(sleepTime); // 确保界面切换完成 + if (NativeAbility::GetInstance().GetCurTargetId() == + (VIEW_PHONE_MENU | static_cast(PhoneMenuPages::PHONE_MENU_CALLING_PAGE) << PAGE_OFFSET) || (GetCurrCallState() != HFP_HF_CALL_STATE_FINISHED && GetScoConnectState() == HFP_SCO_STATE_CONNECTED)) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::ResumePlayer] this is in calling"); return; // 通话界面,禁止音乐恢复播放 @@ -888,512 +359,4 @@ void PlayerInterruptListener::OnInterrupt(int32_t type, int32_t hint) } } } - -PlayerOnDragListener::PlayerOnDragListener() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerOnDragListener"); - g_pPlayerOnDragListener = this; -} - -PlayerOnDragListener::~PlayerOnDragListener() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~PlayerOnDragListener"); - g_pPlayerOnDragListener = nullptr; -} - -PlayerOnDragListener *PlayerOnDragListener::GetInstance(void) -{ - return g_pPlayerOnDragListener; -} - -void PlayerOnDragListener::OnDragChangView(const DragEvent& event, int16_t hideView, int16_t showView, bool isStopScan) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDragChangeView=%d showView=%d", hideView, showView); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - if (isStopScan) { - BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); - if (bluetoothEarPhoneView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView GetInstance fail"); - return; - } - bluetoothEarPhoneView->BtAnimatorStop(); - bluetoothEarPhoneView->StopBtDiscovery(); - } - // 跳转设置页面 - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(hideView, showView); - } -} - -void PlayerOnDragListener::OnDragChangBluetoothView(const DragEvent& event) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDragChangBluetoothView"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DIRECTION_LEFT_TO_RIGHT"); - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView GetInstance fail"); - return; - } - BluetoothView *bluetoothView = BluetoothView::GetInstance(); - if (bluetoothView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothView GetInstance fail"); - return; - } - bluetoothView->group->SetVisible(false); - playersView->SetVisible(true); - // 刷新UI - RootView::GetInstance()->Invalidate(); - } -} - -void PlayerOnDragListener::DropEarPhoneView(const DragEvent& event) -{ - bool ret = BluetoothModel::GetInstance()->IsTagReturnToDeviceListView(); - if (ret) { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, true); - } else { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW, true); - } -} - -void PlayerOnDragListener::DropEarListView(const DragEvent& event) -{ - bool ret = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); - if (ret) { - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerOnDragListener::DropEarListView Addr: %02x%02x%02x%02x%02x%02x", - caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ - caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerOnDragListener::DropEarListView gap_disconnect_remote_device retVal = %d", retVal); - } - BluetoothItemView *pbItermView = BluetoothModel::GetInstance()->GetConnectionView(); - if (pbItermView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnDragEnd The GetConnectionView nullptr."); - } else { - pbItermView->ConnectAnimatorStop(); - BluetoothModel::GetInstance()->SetConnectionView(nullptr); - } - OnDragChangView(event, JumpView::BluetoothJumpViewNum::BLUETOOTHEARLISTVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW, true); -} - -bool PlayerOnDragListener::OnDragEnd(UIView& view, const DragEvent& event) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayerOnDragListener::OnDragEnd- %s", view.GetViewId()); - if (view.GetViewId() == nullptr) { - return true; - } - if (strcmp(view.GetViewId(), BLUETOOTH_EAR_PHONE_VIEW) == 0) { - DropEarPhoneView(event); - } else if (strcmp(view.GetViewId(), TIPS_SUCC_MESSAGE_VIEW) == 0) { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::TIPSSUCCMESSAGEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, false); - } else if (strcmp(view.GetViewId(), TIPS_FAIL_MESSAGE_VIEW) == 0) { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::TIPSFAILMESSAGEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, false); - } else if (strcmp(view.GetViewId(), TIPS_CONN_FAIL_MESSAGE_VIEW) == 0) { - CorrespondingJump(event, JumpView::BluetoothJumpViewNum::TIPSCONNFAILMESSAGEVIEW); - } else if (strcmp(view.GetViewId(), BLUETOOTH_EARLIST_VIEW) == 0) { - DropEarListView(event); - } else if (strcmp(view.GetViewId(), BLUETOOTH_RECONNECT_VIEW) == 0) { - BluetoothModel::GetInstance()->SetTagDisconnectView(false); - CorrespondingJump(event, JumpView::BluetoothJumpViewNum::BLUETOOTHRECONNECTVIEW); - BluetoothReconnectView *bluetoothReconnectView = BluetoothReconnectView::GetInstance(); - if (bluetoothReconnectView != nullptr) { - bluetoothReconnectView->BtReconnectStop(); - } - } else if (strcmp(view.GetViewId(), BLUETOOTH_OPTIONS_VIEW) == 0) { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, false); - } else if (strcmp(view.GetViewId(), BLUETOOTH_VIEW) == 0) { - OnDragChangBluetoothView(event); - } else if (strcmp(view.GetViewId(), BLUETOOTH_DEVICE_LIST_VIEW) == 0) { - OnDragChangView(event, JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW, false); - } - return true; -} - - -void PlayerOnDragListener::CorrespondingJump(const DragEvent& event, int16_t hideView) -{ - BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); - if (bluetoothModel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothModel == nullptr"); - return; - } - if (bluetoothModel->GetTagReconnectJump()) { - OnDragChangView(event, hideView, - JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW, false); - } else { - std::list &bluetoothScanList = BluetoothModel::GetInstance()->GetCase(); - bool ret = bluetoothScanList.empty(); - if (!ret) { - OnDragChangView(event, hideView, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARLISTVIEW, false); - } else { - OnDragChangView(event, hideView, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, false); - } - } - return; -} - -bool PlayerOnDragListener::OnDrag(UIView& view, const DragEvent& event) -{ - UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerbackReset playersView GetInstance fail"); - return false; - } - playersView->SetPlayerListGroupStatus(false); - RootView::GetInstance()->Invalidate(); - } - return false; -} - -void PlayersPresenter::OnClickRescanButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RescanButtonOnClickListener OnClick"); - // 跳转正在搜索界面 - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEARLISTVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW); - return; -} -void PlayersPresenter::OnClickNewEquipmentButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NewEquipmentButtonOnClickListener OnClick"); - BluetoothModel::GetInstance()->SetTagReturnToDeviceListView(true); - // 跳转正在搜索界面 - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW); - return; -} - -void PlayersPresenter::OnClickCancelConnedRequestButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelConnedRequestButton OnClick"); - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton Addr: %02x%02x%02x%02x%02x%02x", - caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ - caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClickCancelConnedRequestButton DisconnectRemoteDevice retVal = %d", retVal); - - BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - // 刷新列表 - BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton bluetoothEarListView nullptr"); - return; - } - if (bluetoothEarListView->GetScanUIList() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton GetScanUIList nullptr"); - return; - } - bluetoothEarListView->GetScanUIList()->RefreshList(); - bluetoothEarListView->SetCancelConnedRequestButtonRemove(); - bluetoothEarListView->SetTitleLabel("扫描完成"); - - BluetoothItemView *pbItermView = BluetoothModel::GetInstance()->GetConnectionView(); - if (pbItermView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleBeforeChangeView The GetConnectionView get failed."); - return; - } - pbItermView->ConnectAnimatorStop(); - BluetoothModel::GetInstance()->SetConnectionView(nullptr); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); - return; -} - -void PlayersPresenter::OnClickButtonUnpair(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_UNPAIR_BUTTON"); - BluetoothModel::GetInstance()->SetTagConnectNew(false); - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); - return; - } - bluetoothOptionsView->SetUnpair(); // 取消配对 - // 删除对应设备列表节点 - bd_addr_t bdAddr = bluetoothOptionsView->GetCurrentAddr(); - List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - ListNode *node = bluetoothCaseList.Begin(); - if (node == nullptr) { - return; - } - while (node != bluetoothCaseList.End()) { - if ((bdAddr.addr[0] == node->data_.addr[0]) && (bdAddr.addr[1] == node->data_.addr[1]) - && (bdAddr.addr[2] == node->data_.addr[2]) && (bdAddr.addr[3] == node->data_.addr[3]) - && (bdAddr.addr[4] == node->data_.addr[4]) && (bdAddr.addr[5] == node->data_.addr[5])) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bdAddr true"); - bluetoothCaseList.Remove(node); - } - node = node->next_; - } - - // 跳转并刷新列表 - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW); -} - -void PlayersPresenter::OnClickButtonOptionOne(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON"); - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); - return; - } - BluetoothModel::GetInstance()->SetBtStatus(); - if (BluetoothModel::GetInstance()->GetAclConnected()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClickButtonOptionOne GetAclConnected()"); - BluetoothModel::GetInstance()->SetTagConnectNew(false); - bluetoothOptionsView->SetBtDisconnect(); - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW); - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClickButtonOptionOne GetAclConnected() fail"); - BluetoothModel::GetInstance()->SetTagReconnectJump(true); - // 重连动画 - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHRECONNECTVIEW); - // 判断是否正在连接 - bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::ClickOptionsOneButton lastAddr: %02x%02x%02x%02x%02x%02x", - lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ - lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ - if (bt_is_acl_connected(lastAddr)) { - BluetoothModel::GetInstance()->SetTagConnectNew(true); - bluetoothOptionsView->SetBtDisconnect(); - } else { - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickOptionsOneButton ConnectRemoteDevice retVal = %d", retVal); - } - } -} - - -void PlayersPresenter::OnClickSetting(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_SETTING_BUTTON"); - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); - if (bluetoothModel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClickSetting BluetoothModel GetInstance fail"); - return; - } - bluetoothModel->SetTagConnectView(true); - bluetoothModel->SetBluetoothCalleridStatus(CALLERPLAYERS); - BluetoothModel::GetInstance()->SetTagReturnToDeviceListView(false); - // 设备列表 - List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - bool ret = bluetoothCaseList.IsEmpty(); - if (!ret) { - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW); - } else { - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW); - } -} - -void PlayersPresenter::OnClickDelete(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_DELETE_BUTTON"); -} - -void PlayersPresenter::OnClickSuccBack(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_SUCC_BACK_BUTTON"); - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::TIPSSUCCMESSAGEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW); -} - -void PlayersPresenter::OnClickConnFailBack(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_CONN_FAIL_BACK_BUTTON"); - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::TIPSCONNFAILMESSAGEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHRECONNECTVIEW); - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClickConnFailBack ConnectRemoteDevice retVal = %d", retVal); -} - -void PlayersPresenter::OnClickFailBack(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick BLUETOOTH_FAIL_BACK_BUTTON"); - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - return; - } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::TIPSFAILMESSAGEVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW); -} - -struct PlayersOnClickMapper { - const char *id; - void (PlayersPresenter::*func)(void); -}; - -static const PlayersOnClickMapper OnClickMapper[] = { - {BLUETOOTH_RESCAN_BUTTON, &PlayersPresenter::OnClickRescanButton}, - {BLUETOOTH_NEWEQUIPMENT_BUTTON, &PlayersPresenter::OnClickNewEquipmentButton}, - {BLUETOOTH_CANCELCONNEDREQUEST_BUTTON, &PlayersPresenter::OnClickCancelConnedRequestButton}, - {BLUETOOTH_UNPAIR_BUTTON, &PlayersPresenter::OnClickButtonUnpair}, - {BLUETOOTH_OPTIONONE_BUTTON, &PlayersPresenter::OnClickButtonOptionOne}, - {BLUETOOTH_SETTING_BUTTON, &PlayersPresenter::OnClickSetting}, - {BLUETOOTH_DELETE_BUTTON, &PlayersPresenter::OnClickDelete}, - {BLUETOOTH_SUCC_BACK_BUTTON, &PlayersPresenter::OnClickSuccBack}, - {BLUETOOTH_CONN_FAIL_BACK_BUTTON, &PlayersPresenter::OnClickConnFailBack}, - {BLUETOOTH_FAIL_BACK_BUTTON, &PlayersPresenter::OnClickFailBack} -}; - -bool PlayersPresenter::OnClick(UIView &view, const ClickEvent &event) -{ - uint16_t i; - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick %s", view.GetViewId()); - for (i = 0; i < sizeof(OnClickMapper) / sizeof(OnClickMapper[0]); i++) { - if (strcmp(view.GetViewId(), OnClickMapper[i].id) == 0) { - (this->*(OnClickMapper[i].func))(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersPresenter::OnClick i %d", i); - return true; - } - } - return false; -} - -void PlayersPresenter::SetTitleSetText(const char *text) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetTitleSetText playersView GetInstance fail"); - return; - } - if (playersView->GetTitleLabel() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetTitleSetText titleLabel nullptr"); - return; - } - playersView->TitleSetText(text); -} - -void PlayersPresenter::SetPlaybackProgress(int64_t value) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPlaybackProgress playersView GetInstance fail"); - return; - } - UICircleProgress *playbackProgress = playersView->GetPlaybackProgress(); - if (playbackProgress == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playbackProgress nullptr err"); - return; - } - playbackProgress->SetValue(value); - playbackProgress->Invalidate(); -} - -void PlayersPresenter::SetPlayerState(bool value) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPlayerState playersView GetInstance fail"); - return; - } - if (value) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - PlayersModel::GetInstance()->SetPlayButtonState(false); - } -} - -void PlayersPresenter::PlayerbackReset(void) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerbackReset playersView GetInstance fail"); - return; - } - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); -} - -// 播放器按钮复位 -void PlayersPresenter::PlayerHeadsetReset(void) -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerbackReset playersView GetInstance fail"); - return; - } - - if (playersView->GetPlayerButtonState() == UICheckBox::UICheckBoxState::UNSELECTED) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } else { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } - -} - -void PlayersPresenter::ShowPlayerListGroup() -{ - PlayersView *playersView = PlayersView::GetInstance(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerbackReset playersView GetInstance fail"); - return; - } - // 添加list - playersView->SetPlayerListGroupStatus(true); - // 刷新UI - RootView::GetInstance()->Invalidate(); - return; -} - } // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersView.cpp index 3c10323bf..668ce3906 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/player/src/PlayersView.cpp @@ -7,25 +7,58 @@ #include #include #include "common/image_cache_manager.h" +#include "phoneservice/PhoneService.h" +#include "main/LoadImg.h" #include "ui_resource_image.h" -#include "player/PlayersView.h" #include "UiConfig.h" #include "player/PlayersModel.h" -#include "player/PlayersCaseListAdapter.h" +#include "player/PlayersMusicItemView.h" +#include "bts_avrcp_target.h" +#include "bts_avrcp_controller.h" #include "main/MainViewSample.h" +#include "player/PlayersView.h" namespace OHOS { static PlayersView* g_pPlayersView = nullptr; - -#define STEP_LABEL_X 166 -#define STEP_LABEL_Y 30 -#define TEXT_WIDTH 120 -#define TEXT_HEIGHT 30 +static constexpr uint16_t PROGRESS_PERCENTAGE = 100; +static constexpr uint16_t PLAYER_PERIOD = 500; + +static constexpr int16_t NEXT_BUTTON_POSITION_X = 331; +static constexpr int16_t PRE_BUTTON_POSITION_X = 31; +static constexpr int16_t BUTTON_POSITION_Y_ONE = 168; +static constexpr int16_t PLAY_MODE_BUTTON_POSITION_X = 87; +static constexpr int16_t SOUND_BUTTON_POSITION_X = 176; +static constexpr int16_t OPTION_BUTTON_POSITION_X = 284; +static constexpr int16_t BUTTON_POSITION_Y_TWO = 316; +static constexpr int16_t PULL_BUTTON_POSITION_X = 178; +static constexpr int16_t PULL_BUTTON_POSITION_Y = 394; +static constexpr int16_t PLAY_OR_PAUSE_BUTTON_POSITION_X = 140; +static constexpr int16_t PLAY_OR_PAUSE_BUTTON_POSITION_Y = 139; +static constexpr int16_t PLAY_OR_PAUSE_BUTTON_SIZE = 172; +static constexpr int16_t MUSIC_NAME_LABEL_POSITION_X = 72; +static constexpr int16_t MUSIC_NAME_LABEL_POSITION_Y = 35; +static constexpr int16_t MUSIC_NAME_LABEL_WIDTH = 300; +static constexpr int16_t MUSIC_NAME_LABEL_HEIGHT = 53; +static constexpr int16_t MUSIC_AUTHOR_LABEL_POSITIO0N_X = 77; +static constexpr int16_t MUSIC_AUTHOR_LABEL_POSITION_Y = 92; +static constexpr int16_t MUSIC_AUTHOR_LABEL_WIDTH = 300; +static constexpr int16_t MUSIC_AUTHOR_LABEL_HEIGHT = 38; +static constexpr char* NEXT_SONG_BUTTON = "NEXT_SONG_BUTTON"; +static constexpr char* PRE_SONG_BUTTON = "PRE_SONG_BUTTON"; +static constexpr char* PLAY_OR_PAUSE_BUTTON = "PLAY_OR_PAUSE_BUTTON"; +static constexpr char* PLAYMODE_CHANGE_BUTTON = "PLAYMODE_CHANGE_BUTTON"; +static constexpr char* VOICE_ADJUST_BUTTON = "VOICE_ADJUST_BUTTON"; +static constexpr char* OPTIONS_BUTTON = "OPTIONS_BUTTON"; +static constexpr char* PULL_BUTTON = "PULL_BUTTON"; PlayersView::PlayersView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::PlayersView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetDraggable(true); + SetTouchable(true); + SetOnClickListener(this); + SetOnDragListener(this); g_pPlayersView = this; } @@ -38,54 +71,85 @@ PlayersView::~PlayersView() PlayersModel::GetInstance()->SetPlayButtonState(true); } RemoveAll(); - listGroup->RemoveAll(); - delete list; - list = nullptr; - delete playerlistener; - playerlistener = nullptr; - delete playerButton; - playerButton = nullptr; - delete soundlistener; - soundlistener = nullptr; - delete nextButton; - nextButton = nullptr; - delete nextlistener; - nextlistener = nullptr; - delete preButton; - preButton = nullptr; - TearDownView(); - delete adapterText; - adapterText = nullptr; - delete backGround; - delete titleLabel; - delete subTitleLabel; - backGround = nullptr; - titleLabel = nullptr; - subTitleLabel = nullptr; - delete playbackProgress; - playbackProgress = nullptr; - delete jumpView; - jumpView = nullptr; - delete playersPresenter; - playersPresenter = nullptr; - delete playerOnDragListener; - playerOnDragListener = nullptr; + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + if (musicNameLabel_ != nullptr) { + delete musicNameLabel_; + musicNameLabel_ = nullptr; + } + if (musicAuthorLabel_ != nullptr) { + delete musicAuthorLabel_; + musicAuthorLabel_ = nullptr; + } + if (optionsButton_ != nullptr) { + delete optionsButton_; + optionsButton_ = nullptr; + } + if (preButton_ != nullptr) { + delete preButton_; + preButton_ = nullptr; + } + if (nextButton_ != nullptr) { + delete nextButton_; + nextButton_ = nullptr; + } + if (soundButton_ != nullptr) { + delete soundButton_; + soundButton_ = nullptr; + } + if (playModelChangeButton_ != nullptr) { + delete playModelChangeButton_; + playModelChangeButton_ = nullptr; + } + if (pullButton_ != nullptr) { + delete pullButton_; + pullButton_ = nullptr; + } + if (playerOrPauseButton_ != nullptr) { + delete playerOrPauseButton_; + playerOrPauseButton_ = nullptr; + } + if (playbackProgress_ != nullptr) { + delete playbackProgress_; + playbackProgress_ = nullptr; + } + if (volumeSettingView_ != nullptr) { + delete volumeSettingView_; + volumeSettingView_ = nullptr; + } + if (playerOptionGroup_ != nullptr) { + delete playerOptionGroup_; + playerOptionGroup_ = nullptr; + } + if (playersMusicListGroup != nullptr) { + delete playersMusicListGroup; + playersMusicListGroup = nullptr; + } } g_pPlayersView = nullptr; } void PlayersView::TitleSetText(const char *text) { - titleLabel->SetText(text); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + if (musicNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::TitleSetText musicNameLabel_ is null"); + return; + } + + if (text && *text) { + musicNameLabel_->SetText(text); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::TitleSetText text nullptr"); + musicNameLabel_->SetText("Music Name"); + } } void PlayersView::PlayerModelButtonSetSrc(uint32_t playMode) { ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(playMode, PLAYER_IAMGES); - playerModelButton->SetSrc(image); + playModelChangeButton_->SetSrc(image); } int16_t PlayersView::GetVolumeRank(void) @@ -103,81 +167,36 @@ void PlayersView::SetVolumeAddOne(void) volumeSet++; } -UIButton *PlayersView::GetPullButton(void) -{ - return pullButton; -} - -UIButton *PlayersView::GetOptionsButton(void) -{ - return optionsButton; -} - -UIButton *PlayersView::GetPreButton(void) -{ - return preButton; -} - -UIButton *PlayersView::GetNextButton(void) -{ - return nextButton; -} - -UILabel *PlayersView::GetTitleLabel(void) -{ - return titleLabel; -} - -UICheckBox *PlayersView::GetPlayerButton(void) -{ - return playerButton; -} - -UIImageView *PlayersView::GetSoundButton(void) -{ - return soundButton; -} - -UICircleProgress *PlayersView::GetPlaybackProgress(void) -{ - return playbackProgress; -} - -UIImageView *PlayersView::GetPlayerModelButton(void) +UICheckBox::UICheckBoxState PlayersView::GetPlayerButtonState(void) { - return playerModelButton; + return playerOrPauseButton_->GetState(); } -UICheckBox::UICheckBoxState PlayersView::GetPlayerButtonState(void) +void PlayersView::SetPlayerState(bool value) { - return playerButton->GetState(); + if (value) { + SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + PlayersModel::GetInstance()->SetPlayButtonState(false); + } } void PlayersView::SetPlayerButtonState(UICheckBox::UICheckBoxState state) { - if (playerButton == nullptr) { + if (playerOrPauseButton_ == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetPlayerButtonState playerButton nullptr"); return; } - return playerButton->SetState(state); -} - -UIList *PlayersView::GetPlayerList(void) -{ - return list; + return playerOrPauseButton_->SetState(state); } -void PlayersView::SetPlayerListGroupStatus(bool status) +void PlayersView::SetPlaybackProgress(int8_t value) { - if (listGroup == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView listGroup is nullptr"); + if (playbackProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::playbackProgress_ nullptr"); return; } - UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); - if (vew != nullptr) { - vew->SetVisible(!status); - } - listGroup->SetVisible(status); + playbackProgress_->SetValue(value); + playbackProgress_->Invalidate(); return; } @@ -186,429 +205,379 @@ void PlayersView::SetPlayerCtrVolume(float leftVolume, float rightVolume) PlayersModel::GetInstance()->GetPlayerCtr()->SetVolume(leftVolume, rightVolume); } -void PlayersView::TearDownView() +PlayersView* PlayersView::GetInstance(void) { - delete prelistener; - prelistener = nullptr; - delete playerModelButton; - playerModelButton = nullptr; - delete modellistener; - modellistener = nullptr; - delete soundButton; - soundButton = nullptr; - delete optionslistener; - optionslistener = nullptr; - delete optionsButton; - optionsButton = nullptr; - delete pullButton; - pullButton = nullptr; - delete listGroup; - listGroup = nullptr; + return g_pPlayersView; } -PlayersView* PlayersView::GetInstance(void) +bool PlayersView::InitView(void) { - return g_pPlayersView; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView InitView"); + InitImage(); + InitButton(); + InitLabel(); + InitCircleProgress(); + InitSoundAdjust(); + InitOption(); + InitListView(); + Invalidate(); + return true; } -// list -void PlayersView::ShowUpListView() +void PlayersView::InitButton() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView"); - listGroup = new UIViewGroup(); - if (listGroup == nullptr) { + if (nextButton_ == nullptr) { + nextButton_ = new UIImageView(); + } + if (preButton_ == nullptr) { + preButton_ = new UIImageView(); + } + if (playerOrPauseButton_ == nullptr) { + playerOrPauseButton_ = new UICheckBox(); + } + if (playModelChangeButton_ == nullptr) { + playModelChangeButton_ = new UIImageView(); + } + if (soundButton_ == nullptr) { + soundButton_ = new UIImageView(); + } + if (optionsButton_ == nullptr) { + optionsButton_ = new UIImageView(); + } + if (pullButton_ == nullptr) { + pullButton_ = new UIImageView(); + } + if ((nextButton_ == nullptr) || (preButton_ == nullptr) || (optionsButton_ == nullptr) + || (soundButton_ == nullptr) || (playModelChangeButton_ == nullptr) || (pullButton_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIButton new fail"); + return; + } + if ((playerOrPauseButton_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerOrPauseButton_ new fail"); return; } - listGroup->SetPosition(0, 0); - listGroup->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - // list type - if (adapterText == nullptr) { - adapterText = new PlayersCaseListAdapter(); - if (adapterText == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "adapterText new fail"); - return; - } + nextButton_->SetPosition(NEXT_BUTTON_POSITION_X, BUTTON_POSITION_Y_ONE); + nextButton_->SetViewId(NEXT_SONG_BUTTON); + LOADIMG::LoadImageViewImg(nextButton_, PLAYER_IAMGES, PLAYER_NEXT_BUTTON); + nextButton_->SetTouchable(true); + nextButton_->SetOnClickListener(this); + + preButton_->SetPosition(PRE_BUTTON_POSITION_X, BUTTON_POSITION_Y_ONE); + preButton_->SetViewId(PRE_SONG_BUTTON); + LOADIMG::LoadImageViewImg(preButton_, PLAYER_IAMGES, PLAYER_PRE_BUTTOW); + preButton_->SetTouchable(true); + preButton_->SetOnClickListener(this); + + ImageInfo *image; + ImageInfo *hlImage; + playerOrPauseButton_->SetPosition(PLAY_OR_PAUSE_BUTTON_POSITION_X, PLAY_OR_PAUSE_BUTTON_POSITION_Y, + PLAY_OR_PAUSE_BUTTON_SIZE, PLAY_OR_PAUSE_BUTTON_SIZE); + playerOrPauseButton_->SetViewId(PLAY_OR_PAUSE_BUTTON); + playerOrPauseButton_->SetOnClickListener(this); + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAYER, PLAYER_IAMGES); + hlImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAYERHIGHLIGHT, PLAYER_IAMGES); + playerOrPauseButton_->SetImages(hlImage, image); + + playModelChangeButton_->SetPosition(PLAY_MODE_BUTTON_POSITION_X, BUTTON_POSITION_Y_TWO); + playModelChangeButton_->SetViewId(PLAYMODE_CHANGE_BUTTON); + SetUpPlayerMode(); + playModelChangeButton_->SetTouchable(true); + playModelChangeButton_->SetOnClickListener(this); + + soundButton_->SetPosition(SOUND_BUTTON_POSITION_X, BUTTON_POSITION_Y_TWO); + soundButton_->SetViewId(VOICE_ADJUST_BUTTON); + LOADIMG::LoadImageViewImg(soundButton_, PLAYER_IAMGES, PLAYER_SOUND_IMAGE); + soundButton_->SetTouchable(true); + soundButton_->SetOnClickListener(this); + + optionsButton_->SetPosition(OPTION_BUTTON_POSITION_X, BUTTON_POSITION_Y_TWO); + optionsButton_->SetViewId(OPTIONS_BUTTON); + LOADIMG::LoadImageViewImg(optionsButton_, PLAYER_IAMGES, PLAYER_OPTIONS_IMAGE); + optionsButton_->SetTouchable(true); + optionsButton_->SetOnClickListener(this); + + pullButton_->SetPosition(PULL_BUTTON_POSITION_X, PULL_BUTTON_POSITION_Y); + pullButton_->SetViewId(PULL_BUTTON); + pullButton_->SetSrc(PNG_PULLUP_BUTTON); + pullButton_->SetTouchable(true); + pullButton_->SetOnClickListener(this); + + Add(nextButton_); + Add(preButton_); + Add(optionsButton_); + Add(soundButton_); + Add(playModelChangeButton_); + Add(playerOrPauseButton_); + Add(pullButton_); +} + +void PlayersView::InitLabel() +{ + musicNameLabel_ = new UILabel(); + if (musicNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "musicNameLabel_ new fail"); + return; } - if (list == nullptr) { - list = new UIList(UIList::VERTICAL); - if (list == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); - return; - } - list->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - list->SetStartIndex(0); // 0 : list start index - list->SetAdapter(adapterText); - } - listGroup->Add(list); - MainViewSample::GetInstance()->GetRootContainer()->Add(listGroup); - UIView::OnDragListener *dragListener = (UIView::OnDragListener*)OHOS::PlayerOnDragListener::GetInstance(); - if (dragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::OnDragListener fail"); + musicNameLabel_->SetPosition(MUSIC_NAME_LABEL_POSITION_X, MUSIC_NAME_LABEL_POSITION_Y, + MUSIC_NAME_LABEL_WIDTH, MUSIC_NAME_LABEL_HEIGHT); + musicNameLabel_->SetText("Music Name"); + musicNameLabel_->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + musicNameLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + musicNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); + Add(musicNameLabel_); + + musicAuthorLabel_ = new UILabel(); + if (musicAuthorLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "musicAuthorLabel_ new fail"); return; } - listGroup->SetDraggable(true); - listGroup->SetTouchable(true); - listGroup->SetOnDragListener(dragListener); - listGroup->SetVisible(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView end"); + musicAuthorLabel_->SetPosition(MUSIC_AUTHOR_LABEL_POSITIO0N_X, MUSIC_AUTHOR_LABEL_POSITION_Y, + MUSIC_AUTHOR_LABEL_WIDTH, MUSIC_AUTHOR_LABEL_HEIGHT); + musicAuthorLabel_->SetText("Musical Authors"); + musicAuthorLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); // 30:font data + musicAuthorLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + Add(musicAuthorLabel_); } -void PlayersView::SetUpButton(UIButton *btn, const Point& point, - int16_t width, int16_t height, UIView::OnClickListener *listener) +void PlayersView::InitImage() { - if (btn == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetUpButton nullptr"); + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ new fail"); return; } - Add(btn); - btn->SetPosition(point.x, point.y, width, height); - btn->SetOnClickListener(listener); + bgImg_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(bgImg_, PLAYER_IAMGES, PLAYER_BACK_GROUND); + Add(bgImg_); } -int PlayersView::ShowUpCheckBoxButton() +void PlayersView::InitCircleProgress() { - ImageInfo *image; - ImageInfo *hlImage; - if (playerButton == nullptr) { - playerButton = new UICheckBox(); + playbackProgress_ = new UICircleProgress(); + if (playbackProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playbackProgress_ new fail"); + return; } - if (soundButton == nullptr) { - soundButton = new UIImageView(); + playbackProgress_->SetPosition(140, 139, 172, 172); // 140:x 139:y 172:width 172:height + playbackProgress_->SetCenterPosition(86, 86); // 86:x 86:y + playbackProgress_->SetRange(PLAY_PROGRESS_MAX, PLAY_PROGRESS_MIN); + playbackProgress_->SetRadius(86); // 86:radius + playbackProgress_->SetStartAngle(0); + playbackProgress_->SetEndAngle(360); // 360: end angle + playbackProgress_->SetValue(0); + playbackProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, Color::Gray().full); + playbackProgress_->SetForegroundStyle(STYLE_LINE_COLOR, Color::Red().full); + playbackProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, 3); // 3:width + playbackProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, 3); // 3:width + Add(playbackProgress_); +} + +void PlayersView::InitSoundAdjust() +{ + volumeSettingView_ = new VolumeSettingView(); + if (volumeSettingView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volumeSetting nullptr err"); + return; } - if ((playerButton == nullptr) || (soundButton == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new fail"); - return OHOS_FAILURE; + if (!volumeSettingView_->SetUpVolume()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volumeSetting SetUpVolume fail"); + return; } - playerlistener = new ButtonOnClickListener(reinterpret_cast(playerButton)); - if (playerlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerlistener new fail"); - return OHOS_FAILURE; + int32_t volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "current volume = %d", volume); + volumeSettingView_->GetProgress()->SetValue(volume); + if (volume == 0) { + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); + volumeSettingView_->GetDecreaseButton()->SetImageSrc(image, image); } - playerButton->SetPosition(140, 139, 172, 172); // 140:x 139:y 172:width 172:height - playerButton->SetOnClickListener(playerlistener); - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAYER, PLAYER_IAMGES); - hlImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAYERHIGHLIGHT, PLAYER_IAMGES); - playerButton->SetImages(hlImage, image); - Add(playerButton); - - soundlistener = new ButtonOnClickListener(reinterpret_cast(soundButton)); - if (soundlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soundlistener new fail"); - return OHOS_FAILURE; + volumeSliderEventListener_ = volumeSettingView_->GetVolumeEventListener(); + if (volumeSliderEventListener_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundButtonOnClick volumeSliderEventListener_ nullptr err"); + return; } - soundButton->SetTouchable(true); - soundButton->SetPosition(178, 316, 95, 76); // 178:x 316:y 95:width 76:height - soundButton->SetOnClickListener(soundlistener); - if (!LoadPlayerImage(soundButton, PLAYER_SOUND_IMAGE)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerModelButton LoadPlayerImage fail"); - return false; + volumeSettingView_->SetVisible(false); + Add(volumeSettingView_); +} + +void PlayersView::InitOption() +{ + playerOptionGroup_ = new PlayersOptionGroup(); // 打开BluetoothView对应的group + if (playerOptionGroup_ == nullptr) { + return; } - Add(soundButton); - return OHOS_SUCCESS; + playerOptionGroup_->SetVisible(false); + Add(playerOptionGroup_); } -int PlayersView::ShowUpButton() +void PlayersView::InitListView() { - struct Point pointBtn; - ImageInfo *image; - pointBtn.x = 331; // 331:x - pointBtn.y = 168; // 168:y - nextlistener = new ButtonOnClickListener(reinterpret_cast(nextButton)); - if (nextlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextlistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(nextButton, pointBtn, 93, 116, nextlistener); // 93:width 116:height - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_NEXT_BUTTON, PLAYER_IAMGES); - nextButton->SetImageSrc(image, image); - pointBtn.x = 31; // 31:x - pointBtn.y = 168; // 168:y - prelistener = new ButtonOnClickListener(reinterpret_cast(preButton)); - if (prelistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "prelistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(preButton, pointBtn, 86, 116, prelistener); // 86:width 116:height - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PRE_BUTTOW, PLAYER_IAMGES); - preButton->SetImageSrc(image, image); - - pointBtn.x = 87; // 87:x - pointBtn.y = 316; // 316:y - modellistener = new ButtonOnClickListener(reinterpret_cast(playerModelButton)); - if (modellistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "modellistener new fail"); - return OHOS_FAILURE; - } - playerModelButton->SetTouchable(true); - playerModelButton->SetPosition(pointBtn.x, pointBtn.y, 95, 76); // 95:width 76:height - playerModelButton->SetOnClickListener(modellistener); - if (!ShowUpPlayerMode()) { - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerModel %d", PlayersModel::GetInstance()->GetPlayerModel()); - Add(playerModelButton); - - return OHOS_SUCCESS; -} - -bool PlayersView::ShowUpPlayerMode() + // 遍历文件名到list链表 + PlayersListGroup::GetInstance()->SetUpListCase(); + PlayersModel::GetInstance()->PlayerInit(); + playersMusicListGroup = new PlayersMusicListGroup(); // 打开BluetoothView对应的group + if (playersMusicListGroup == nullptr) { + return; + } + playersMusicListGroup->SetVisible(false); + Add(playersMusicListGroup); +} + +void PlayersView::SetUpPlayerMode() { if (PlayersModel::GetInstance()->GetPlayerModel() == LOOP) { - if (!LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_LOOP)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYER_PLAYERSMODEL_LOOP fail"); - return false; - } + LOADIMG::LoadImageViewImg(playModelChangeButton_, PLAYER_IAMGES, PLAYER_PLAYERSMODEL_LOOP); } else if (PlayersModel::GetInstance()->GetPlayerModel() == SEQUENCE) { - if (!LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_SEQUENCE)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_SEQUENCE fail"); - return false; - } + LOADIMG::LoadImageViewImg(playModelChangeButton_, PLAYER_IAMGES, PLAYER_PLAYERSMODEL_SEQUENCE); } else if (PlayersModel::GetInstance()->GetPlayerModel() == REPEATS) { - if (!LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_REPEATS)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_REPEATS fail"); - return false; - } + LOADIMG::LoadImageViewImg(playModelChangeButton_, PLAYER_IAMGES, PLAYER_PLAYERSMODEL_REPEATS); } else if (PlayersModel::GetInstance()->GetPlayerModel() == RANDOM) { - if (!LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_RANDOM)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_RANDOM fail"); - return false; - } + LOADIMG::LoadImageViewImg(playModelChangeButton_, PLAYER_IAMGES, PLAYER_PLAYERSMODEL_RANDOM); } - return true; } -int PlayersView::ShowUpButtonView() +void PlayersView::PlayerHeadsetReset() { - int32_t ret = ShowUpCheckBoxButton(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - if (nextButton == nullptr) { - nextButton = new UIButton(); - } - if (preButton == nullptr) { - preButton = new UIButton(); - } - if (optionsButton == nullptr) { - optionsButton = new UIButton(); - } - if (pullButton == nullptr) { - pullButton = new UIButton(); - } - if (playerModelButton == nullptr) { - playerModelButton = new UIImageView(); - } - if ((nextButton == nullptr) || (preButton == nullptr) || (playerModelButton == nullptr) || (optionsButton == nullptr) || - (pullButton == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIButton new fail"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpButtonView"); - - ret = ShowUpButton(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - ret = ShowUpButtonOptions(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - ret = ShowUpCircleProgress(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; + if (playerOrPauseButton_->GetState() == UICheckBox::UICheckBoxState::UNSELECTED) { + SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + } else { + SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); } - return OHOS_SUCCESS; } -int PlayersView::ShowUpButtonOptions() -{ - struct Point pointBtn; - pointBtn.x = 284; // 284 : x - pointBtn.y = 316; // 316 : y - optionslistener = new ButtonOnClickListener(reinterpret_cast(optionsButton)); - if (optionslistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "optionslistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(optionsButton, pointBtn, 75, 76, optionslistener); // 75:width 76:height - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_OPTIONS_IMAGE, PLAYER_IAMGES); - optionsButton->SetImageSrc(image, image); - - pointBtn.x = 178; // 178:x - pointBtn.y = 394; // 394:y - SetUpButton(pullButton, pointBtn, 95, 48, nullptr); // 95:width 48:height - pullButton->SetImageSrc(PNG_PULLBUTTON_FACE_IMAGE, PNG_PULLBUTTON_FACE_IMAGE); - return OHOS_SUCCESS; -} - -int PlayersView::ShowUpCircleProgress() -{ - if (playbackProgress == nullptr) { - playbackProgress = new UICircleProgress(); - if (playbackProgress == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playbackProgress new fail"); - return OHOS_FAILURE; - } - } - playbackProgress->SetPosition(140, 139, 172, 172); // 140:x 139:y 172:width 172:height - playbackProgress->SetCenterPosition(86, 86); // 86:x 86:y - playbackProgress->SetRange(PLAY_PROGRESS_MAX, PLAY_PROGRESS_MIN); - playbackProgress->SetRadius(86); // 86:radius - playbackProgress->SetStartAngle(0); - playbackProgress->SetEndAngle(360); // 360: end angle - playbackProgress->SetValue(0); - playbackProgress->SetBackgroundStyle(STYLE_LINE_COLOR, Color::Gray().full); - playbackProgress->SetForegroundStyle(STYLE_LINE_COLOR, Color::Red().full); - playbackProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, 3); // 3:width - playbackProgress->SetForegroundStyle(STYLE_LINE_WIDTH, 3); // 3:width - Add(playbackProgress); - return OHOS_SUCCESS; -} - -void PlayersView::CreateJumpView(void) +void PlayersView::PreLoad(void) { - if (jumpView == nullptr) { - jumpView = new JumpView(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView new fail"); - return; + if (!viewiInitStatus) { + if (InitView()) { + viewiInitStatus = true; } } } -void PlayersView::CreatePlayersPresenter(void) +void PlayersView::UnLoad(void) { - if (playersPresenter == nullptr) { - playersPresenter = new PlayersPresenter(); - if (playersPresenter == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersPresenter new fail"); - return; - } - } + // Players's usage scenes is complicated, so we do not release it's resources inner slice. } -void PlayersView::CreatePlayerOnDragListener(void) +void PlayersView::OnInactive(void) { - if (playerOnDragListener == nullptr) { - playerOnDragListener = new PlayerOnDragListener(); - if (playerOnDragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerOnDragListener new fail"); - return; - } - } + volumeSettingView_->SetVisible(false); + playersMusicListGroup->SetVisible(false); + SetVisible(true); } -bool PlayersView::InitBackGround(void) + +bool PlayersView::OnClick(UIView &view, const ClickEvent &event) { - if (backGround == nullptr) { - backGround = new UIImageView(); - if (backGround == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround new fail"); - return false; + UNUSED(event); + if (strcmp(view.GetViewId(), NEXT_SONG_BUTTON) == 0) { + playbackProgress_->SetValue(0); // 0:进度0% + playbackProgress_->Invalidate(); + PlayersModel::GetInstance()->LoopingPlayout(); + } else if (strcmp(view.GetViewId(), PRE_SONG_BUTTON) == 0) { + playbackProgress_->SetValue(0); // 0:进度0% + playbackProgress_->Invalidate(); + PlayersModel::GetInstance()->PreviousPlayout(); + } else if (strcmp(view.GetViewId(), PLAY_OR_PAUSE_BUTTON) == 0) { + PlayOrPauseButtonOnClick(); + } else if (strcmp(view.GetViewId(), PLAYMODE_CHANGE_BUTTON) == 0) { + PlayersModel::GetInstance()->SetPlayerModelAddOne(); + if (PlayersModel::GetInstance()->GetPlayerModel() > RANDOM) { + PlayersModel::GetInstance()->SetPlayerModel(LOOP); } - } - backGround->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - if (!LoadPlayerImage(backGround, PLAYER_BACK_GROUND)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround LoadPlayerImage fail"); - return false; - } - Add(backGround); + SetUpPlayerMode(); + } else if (strcmp(view.GetViewId(), VOICE_ADJUST_BUTTON) == 0) { + volumeSliderEventListener_->SetPlayerCoefficients(VOLUMEPLAYERS); // 进度条系数 + volumeSettingView_->SetVisible(true); + } else if (strcmp(view.GetViewId(), OPTIONS_BUTTON) == 0) { + playerOptionGroup_->SetVisible(true); + } else if (strcmp(view.GetViewId(), PULL_BUTTON) == 0) { + // 无对应的逻辑代码,预留接口 + } + Invalidate(); return true; } -void PlayersView::CreatePlayerMusicName() +void PlayersView::PlayOrPauseButtonOnClick() { - if (titleLabel == nullptr) { - titleLabel = new UILabel(); - if (titleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); - return; - } + uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + int32_t playerState; + int32_t connCtState = avrcp_ct_get_device_connect_state(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); + int32_t connTgState = avrcp_tg_get_device_connect_state(SettingBluetoothModel::GetInstance()->GetLastConnedAddr()); + + state = playerOrPauseButton_->GetState(); + if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersModel::GetInstance()->GetPlayerCtr() nullptr"); + return; } - titleLabel->SetPosition(127, 35, 200, 53); // 127:x 35:y 200:width 53:height - titleLabel->SetText("Music Name"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); - Add(titleLabel); + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonState = %d playerState = %d", state, playerState); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "connCtState = %d connTgState = %d", connCtState, connTgState); - if (subTitleLabel == nullptr) { - subTitleLabel = new UILabel(); - if (subTitleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "subTitleLabel new fail"); - return; + if (GetCurrCallNum() != 0 && GetScoConnectState() == HFP_SCO_STATE_CONNECTED) { + if (state == UICheckBox::UICheckBoxState::SELECTED) { + playerOrPauseButton_->SetState(UICheckBox::UICheckBoxState::UNSELECTED); + } else { + playerOrPauseButton_->SetState(UICheckBox::UICheckBoxState::SELECTED); } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerButtonOnClick] calling phone"); + return; + } + if (state == UICheckBox::UICheckBoxState::SELECTED) { + /* start play */ + PlayersModel::GetInstance()->ConnectBtAndLocalPlay(connCtState, connTgState, playerState); + } else if (state == UICheckBox::UICheckBoxState::UNSELECTED) { + PlayersModel::GetInstance()->ConnectBtAndLocalPause(connCtState, connTgState); } - subTitleLabel->SetPosition(77, 92, 300, 38); // 77:x 92:y 300:width 38:height - subTitleLabel->SetText("Musical Authors"); - subTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data - subTitleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - Add(subTitleLabel); - return; } bool PlayersView::OnDragEvent(const DragEvent& event) { - /* 300: y limit of drag start point */ - if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) { - PlayersPresenter::GetInstance()->ShowPlayerListGroup(); - return true; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView OnDrage"); + int yMoveDistance = 300; + if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && + (event.GetStartPoint().y > yMoveDistance)) { + PlayersMusicListGroup::GetInstance()->RefreshMusicList(); + playersMusicListGroup->SetVisible(true); + return true; } - + Invalidate(); return false; } -bool PlayersView::InitView(void) +void PlayersView::Update(void) { - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " PlayersView InitView"); - - if (!InitBackGround()) { - return false; + if (playbackProgress_ == nullptr) { + return; } + int32_t playerState = 0; + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); - CreatePlayerMusicName(); - // changeView - CreateJumpView(); - // OnClick - CreatePlayersPresenter(); - // OnDrag - CreatePlayerOnDragListener(); - // 按键设置 - ret = ShowUpButtonView(); - if (ret == OHOS_FAILURE) { - return false; + if (playerState == PLAYER_STARTED) { + SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + } else { + SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); } - // 遍历文件名到list链表 - PlayersListGroup::GetInstance()->SetUpListCase(); - PlayersModel::GetInstance()->PlayerInit(); - ShowUpListView(); - SetTouchable(true); - SetDraggable(true); - return true; -} -void PlayersView::PreLoad(void) -{ - if (!viewiInitStatus) { - if (InitView()) { - viewiInitStatus = true; + if (playerState == PLAYER_STARTED) { + PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); + PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); + if (playerMusicDuration_ != 0) { + playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); + } else { + playerProgressValue_ = 100; // 100: max progress value } + PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_); + playbackProgress_->SetValue(playerProgressValue_); + playbackProgress_->Invalidate(); } } -void PlayersView::UnLoad(void) +uint32_t PlayersView::GetPeriod(void) { - // Players's usage scenes is complicated, so we do not release it's resources inner slice. + return PLAYER_PERIOD; } -bool PlayersView::LoadPlayerImage(UIImageView *view, uint32_t resId) -{ - std::string file = PLAYER_IAMGES; - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::LoadPlayerImage %x fail", resId); - return false; - } - view->SetSrc(image); - return true; -} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/quickaccess/FloatAccessView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/quickaccess/FloatAccessView.cpp new file mode 100644 index 000000000..84411d2a0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/quickaccess/FloatAccessView.cpp @@ -0,0 +1,326 @@ + /* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: FloatAccessView + * Author: Hisi Graphic Team + * Created: 2025-09 + */ + +#include +#include +#include "NativeRegisterManager.h" +#include "wearable_log.h" +#include "components/root_view.h" +#include "common/screen.h" +#include "common/image_cache_manager.h" +#include "TransitionType.h" +#include "NativeAbility.h" +#include "kv_store.h" +#include "easing_equation.h" +#include "quickaccess/FloatAccessView.h" + +namespace OHOS { +constexpr uint16_t ITEM_SIZE = 60; +constexpr uint16_t ITEM_PADDING = 10; +constexpr uint16_t VIEW_ID_VALUE_LEN = 4; +constexpr uint16_t EXT_OFFSET = 50; +constexpr uint16_t MAX_FILE_NAME_LENGTH = 7; + +inline bool ItemIsNotNull(AppItem item) +{ + return item.id != VIEW_INVALID; +} + +FloatAccessView* FloatAccessView::GetInstance(void) +{ + static FloatAccessView instance; + return &instance; +} + +void FloatAccessView::AddItem(AppItem item, uint8_t index) +{ + if (index >= MAX_ITEM_SIZE) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index value must smaller than 3"); + return; + } + items_[index] = item; + SaveAppItemsData(); +} + +void FloatAccessView::DeleteItem(const char* label) +{ + if (label == nullptr) { + return; + } + for (int i = 0; i < MAX_ITEM_SIZE; ++i) { + if (strcmp(items_[i].label, label) == 0) { + items_[i] = {}; + SaveAppItemsData(); + return; + } + } +} + +AppItem FloatAccessView::GetItem(uint8_t index) +{ + if (index >= MAX_ITEM_SIZE) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index value must smaller than 3"); + return {}; + } + return items_[index]; +} + +void FloatAccessView::OnItemClick(const std::string& name) +{ + uint32_t targetId = NativeAbility::GetInstance().GetCurTargetId(); + uint16_t curSlice = static_cast(targetId & SLICE_MASK); + + for (int i = 0; i < MAX_ITEM_SIZE; ++i) { + if (strcmp(items_[i].label, name.c_str()) == 0 && curSlice != items_[i].id) { + // 添加点击应用标记 (进入应用时,退出悬浮框,并且不显示退出动画) + isClickItem_ = true; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FloatAccessView::OnClick viewid = %d", items_[i].id); + NativeAbility::GetInstance().ChangeSlice(items_[i].id, TransitionType::TRANSITION_ZOOM); + return; + } + } +} + +bool FloatAccessView::OnClick(UIView& view, const ClickEvent& event) +{ + ExitView(); + return false; +} + +void FloatAccessView::EnterApp() +{ + uint32_t targetId = NativeAbility::GetInstance().GetCurTargetId(); + uint16_t curSlice = static_cast(targetId & SLICE_MASK); + + for (int i = 0; i < MAX_ITEM_SIZE; ++i) { + // 快捷应用存在且不为当前应用,则进入应用页 + if (curSlice != (items_[i].id)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FloatAccessView::OnClick viewid = %d", items_[i].id); + NativeAbility::GetInstance().ChangeSlice(items_[i].id, TransitionType::TRANSITION_ZOOM); + return; + } + } +} + +void FloatAccessView::InitView() +{ + if (!isInitView_) { + LoadAppItemsData(); + if (GetItemSize() == 0) { + return; + } else if (GetItemSize() == 1) { + EnterApp(); + } else { + Resize(Screen::GetInstance().GetWidth() + EXT_OFFSET, Screen::GetInstance().GetHeight() + EXT_OFFSET); + SetStyle(STYLE_BACKGROUND_OPA, 100); // opa 100 + SetDraggable(false); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + floatBoxView_ = new UIFloatBoxView(); + enterCallback_ = new FloatAnimatorCallback(floatBoxView_); + if (floatBoxView_ == nullptr || enterCallback_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FloatAccessView::InitView failed, can't alloc memory"); + return; + } + floatBoxView_->SetOnItemClickListener(this); + floatBoxView_->SetOnClickListener(this); + floatBoxView_->SetPosition(EXT_OFFSET, EXT_OFFSET, + Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + floatBoxView_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + floatBoxView_->SetItemSize(ITEM_SIZE); + floatBoxView_->SetItemSpacing(ITEM_PADDING); + floatBoxView_->SetDragFactor(0.4f); // 0.4 : factor + floatBoxView_->SetAccFactor(0.5f); // 0.5 : factor + floatBoxView_->SetAlignAvgSpeed(5.0f); // 5.0 : factor + AddAppItemsData(); + Add(floatBoxView_); + isInitView_ = true; + } + } +} + +void FloatAccessView::ShowView() +{ + if (!isInitView_) { + InitView(); + } + if (enterCallback_ == nullptr || enterCallback_->GetState() == Animator::START) { + return; + } + isShowView_ = true; + RootView::GetInstance()->AddSystemView(this); + Invalidate(); + enterCallback_->DoEnter(); +} + +void FloatAccessView::ExitView() +{ + if (!isInitView_ || !isShowView_ || enterCallback_ == nullptr || enterCallback_->GetState() == Animator::START) { + return; + } + if (isClickItem_) { + CleanView(); + return; + } + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + enterCallback_->DoExit(); +} + +void FloatAccessView::CleanView() +{ + RootView::GetInstance()->RemoveSystemView(this); + RemoveAll(); + if (floatBoxView_ != nullptr) { + delete floatBoxView_; + floatBoxView_ = nullptr; + } + if (enterCallback_ != nullptr) { + delete enterCallback_; + enterCallback_ = nullptr; + } + isInitView_ = false; + isShowView_ = false; + isClickItem_ = false; +} + +bool FloatAccessView::IsShowView() +{ + return isShowView_; +} + +uint8_t FloatAccessView::GetItemSize() +{ + uint8_t count = 0; + for (int i = 0; i< MAX_ITEM_SIZE; i++) { + if (ItemIsNotNull(items_[i])) { + ++count; + } + } + return count; +} + +void FloatAccessView::LoadAppItemsData() +{ + // 只加载一次 + if (isLoadData_) { + return; + } + char quick[MAX_ITEM_SIZE][VIEW_ID_VALUE_LEN] = {0, 0, 0}; + // 从文件中读取快捷应用的viewId + (void)UtilsGetValue("quick1", quick[0], VIEW_ID_VALUE_LEN); // 0: index + (void)UtilsGetValue("quick2", quick[1], VIEW_ID_VALUE_LEN); // 1: index + (void)UtilsGetValue("quick3", quick[2], VIEW_ID_VALUE_LEN); // 2: index + + List& nativeAppLists = NativeRegisterManager::GetInstance().GetNativeAppLists(); + uint8_t registerNativeAppNum = nativeAppLists.Size(); + ListNode* appNode = nativeAppLists.Head(); + for (int32_t index = 0; index < registerNativeAppNum; index++) { + const char* viewIdStr = std::to_string(appNode->data_.id).c_str(); + // 根据id设置应用的信息 + for (int k = 0; k < MAX_ITEM_SIZE; k++) { + if (strcmp(viewIdStr, quick[k]) == 0) { + items_[k] = appNode->data_; + break; + } + } + appNode = appNode->next_; + } + isLoadData_ = true; +} + +void FloatAccessView::AddAppItemsData() +{ + if (floatBoxView_ == nullptr) { + return; + } + FloatItem items[MAX_ITEM_SIZE]; + int cnt = 0; + for (int i = 0; i < MAX_ITEM_SIZE; i++) { + if (ItemIsNotNull(items_[i])) { + std::string s(items_[i].label); + ImageInfo* image = ImageCacheManager::GetInstance().LoadSingleRes(items_[i].iconSmall); + items[cnt++] = {s, image}; + } + } + floatBoxView_->AddItems(items, cnt); +} + +void FloatAccessView::SaveAppItemsData() +{ + char dest[MAX_FILE_NAME_LENGTH] = "quick"; // quick1,quick2,quick3 + dest[MAX_FILE_NAME_LENGTH - 1] = '\0'; + for (int i = 0; i= duration) return distance; + + double x = t / duration; + double peakPosition = distance * (1 + overshot); + + // 使用三次贝塞尔曲线控制点确保连续性 + if (x < peakTime) { + // 三次曲线: 曲速到峰值 + double p = x / peakTime; + return distance * (3 * p * p - 2 * p * p * p) + (peakPosition - distance) * p * p; // 3,2: 阶数 + } else { + // 平滑回弹曲线: 从峰值回弹 + double r = (x - peakTime) / (1 - peakTime); + return peakPosition - (peakPosition - distance) * (3 * r * r - 2 * r * r * r); // 3,2: 阶数 + } +} + +void FloatAnimatorCallback::Callback(UIView *view) +{ + UIFloatBoxView* floatBoxView_ = dynamic_cast(view); + int16_t pos; + if (isExit_) { + pos = EasingEquation::QuadEaseOut(startPos_, endPos_, animator_->GetRunTime(), animator_->GetTime()); + } else { + // 进入时使用反弹动画 + int16_t totalTime = 100; // 100: 表示总时间为100份 + int16_t curTime = EasingEquation::LinearEaseNone(0, totalTime, animator_->GetRunTime(), animator_->GetTime()); + int distance = endPos_ - startPos_; + pos = startPos_ + ReboundFunc(distance, curTime, totalTime); + } + floatBoxView_->SetPosition(pos, pos); + floatBoxView_->Invalidate(); +} + +void FloatAnimatorCallback::DoEnter() +{ + isExit_ = false; + startPos_ = EXT_OFFSET; + endPos_ = -10; // -10 end pos + animator_->Start(); +} + +void FloatAnimatorCallback::DoExit() +{ + isExit_ = true; + startPos_ = 0; + endPos_ = EXT_OFFSET; + animator_->Start(); +} + +void FloatAnimatorCallback::OnStop(UIView& view) +{ + if (isExit_) { + FloatAccessView::GetInstance()->CleanView(); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/LoadingFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/LoadingFragment.cpp new file mode 100644 index 000000000..85e45db43 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/LoadingFragment.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: LoadingFragment.cpp + * Author: + * Create: 2025-07-17 + */ + +#include "recent_app/LoadingFragment.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint8_t DEFAULT_TEXT_SIZE = 30; + +void LoadingFragment::OnCreateView(void* data) +{ + loadingLabel_ = new UILabel(); + if (loadingLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UILabel fail"); + return; + } + fragmentView_.Add(loadingLabel_); + loadingLabel_->SetText("Loading..."); + loadingLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); + loadingLabel_->Resize(300, 100); // 300, 100: size + loadingLabel_->LayoutCenterOfParent(); + loadingLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); +} + +void LoadingFragment::OnDestroyView() +{ + if (loadingLabel_ != nullptr) { + delete loadingLabel_; + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp index 63b9a668f..7926144f5 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp @@ -23,68 +23,10 @@ namespace OHOS { REGIST_SLICE(VIEW_RECENT_APP, RecentAppView, RecentAppPresenter); - RecentAppPresenter::RecentAppPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppPresenter::RecentAppPresenter()"); - } - - RecentAppPresenter::~RecentAppPresenter() {} - - void RecentAppPresenter::OnResume() - { - if (view_ != nullptr) { - view_->LoadContent(); - } - } - - bool RecentAppPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UIRollerView* roller = view_->GetRollerView(); - if (roller == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "roller is nullptr!"); - return false; - } - - UIViewGroup* currentItemGroup = roller->GetCurrentItem(); - if (currentItemGroup == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentItemGroup is nullptr!"); - return false; - } - - std::string itemName = roller->GetCurrentItemName(); - std::string prefix(itemName.begin(), itemName.begin() + RECENT_ITEM_PREFIX_LEN); - std::string name(itemName.begin() + RECENT_ITEM_PREFIX_LEN, itemName.end()); - - uint32_t sliceId = 0; - bool isNativeSlice = true; - if (prefix == RECENT_ITEM_NATIVE_PREFIX) { - sliceId = static_cast(std::stoul(name)); - } else { - isNativeSlice = false; - } - - const char* viewId = view.GetViewId(); - if (viewId != nullptr && strcmp(viewId, RECENT_APP_DELETE_BTN_ID) == 0) { - if (isNativeSlice) { - RecentManager::GetInstance()->RemoveRecentApp(sliceId); - } else { - RecentManager::GetInstance()->RemoveRecentApp(name.c_str()); - } - roller->RemoveItem(itemName); - return true; - } - - Point clickPoint = event.GetCurrentPos(); - Rect rect = currentItemGroup->GetChildrenHead()->GetRect(); - if (rect.IsContains(clickPoint)) { - if (isNativeSlice) { - NativeAbility::GetInstance().ChangeSlice(sliceId); - } else { -#ifdef JS_ENABLE - StartJsApp(const_cast(name.c_str())); -#endif - } - } - return true; +void RecentAppPresenter::OnResume() +{ + if (view_ != nullptr) { + view_->OnResume(); } } +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppView.cpp index 792432059..42bf4d4f3 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RecentAppView.cpp @@ -14,6 +14,7 @@ */ #include "recent_app/RecentAppView.h" +#include "recent_app/RollerRecentAppFragment.h" #include "wearable_log.h" #include "common/image_cache_manager.h" #include "common/screen.h" @@ -21,17 +22,18 @@ #include "RecentManager.h" namespace OHOS { -static constexpr uint8_t DEFAULT_TEXT_SIZE = 30; -RecentAppView::RecentAppView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppView::RecentAppView"); - loadingAnimCb_.SetRecentAppView(this); -} RecentAppView::~RecentAppView() { - if (roller_ != nullptr) { - delete roller_; + if (loadingFragment_ != nullptr) { + loadingFragment_->DestroyView(); + delete loadingFragment_; + loadingFragment_ = nullptr; + } + if (rencentAppFragment_ != nullptr) { + rencentAppFragment_->DestroyView(); + delete rencentAppFragment_; + rencentAppFragment_ = nullptr; } if (loadingAnim_ != nullptr) { if (loadingAnim_->GetState() != Animator::STOP) { @@ -39,166 +41,66 @@ RecentAppView::~RecentAppView() } delete loadingAnim_; } - if (loadingLabel_ != nullptr) { - delete loadingLabel_; - } - if (noRecentAppLabel_ != nullptr) { - delete noRecentAppLabel_; - } - if (delBtn_ != nullptr) { - delete delBtn_; - } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppView::~RecentAppView"); } void RecentAppView::OnStart(void) { - UIViewGroup* container = GetRootContainer(); + loadingAnimCb_.SetRecentAppView(this); - loadingLabel_ = new UILabel(); - if (loadingLabel_ == nullptr) { - return; + if (loadingFragment_ == nullptr) { + loadingFragment_ = new LoadingFragment(); } - container->Add(loadingLabel_); - loadingLabel_->SetText("Loading..."); - loadingLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); - loadingLabel_->Resize(300, 100); // 300, 100: size - loadingLabel_->LayoutCenterOfParent(); - loadingLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + loadingFragment_->GetFragmentView()->SetPosition(0, 0, GetRootContainer()->GetWidth(), + GetRootContainer()->GetHeight()); + loadingFragment_->CreateView(); + AddViewToRootContainer(loadingFragment_->GetFragmentView()); } -void RecentAppView::LoadContent() +void RecentAppView::OnResume() { if (viewiInitStatus_) { return; } - UIViewGroup* rootContainer = GetRootContainer(); if (!RecentManager::GetInstance()->IsUpdateCompleted()) { - loadingAnim_ = new Animator(&loadingAnimCb_, roller_, 0, true); + loadingAnim_ = new Animator(&loadingAnimCb_, nullptr, 0, true); if (loadingAnim_ == nullptr) { return; } loadingAnim_->Start(); } else { - LoadRecentAppContent(); + LoadContent(); } viewiInitStatus_ = true; } -void RecentAppView::LoadingAnimCb::Callback(UIView* view) -{ - if (RecentManager::GetInstance()->IsUpdateCompleted()) { - recentAppView_->LoadRecentAppContent(); - } -} - -void RecentAppView::AddRecentAppToRoller() +void RecentAppView::LoadContent() { - const List& recent = RecentManager::GetInstance()->GetRecentApps(); - ListNode* node = recent.Begin(); - std::string alignItemName = ""; - while (node != recent.End()) { - RecentAppInfo* appInfo = node->data_; - ImageInfo* imgInfo = appInfo->snapshot; - std::string name; - if (appInfo->isNativeSlice) { - name = RECENT_ITEM_NATIVE_PREFIX + std::to_string(appInfo->targetId & SLICE_MASK); - } else { - name = RECENT_ITEM_JS_PREFIX + appInfo->bundleName; - } - if (imgInfo->data != nullptr) { - roller_->AddItem(name, imgInfo); - } else { - std::string path(appInfo->snapshot->file, appInfo->snapshot->fileLen); - if (appInfo->snapshot->resId == 0) { - imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(path); - } else { - imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(appInfo->snapshot->resId, path); - } - - if (imgInfo == nullptr) { - GRAPHIC_LOGE("Load res failed: %s", path.c_str()); - node = node->next_; - continue; - } - roller_->AddItem(name, imgInfo); - } - node = node->next_; - if (alignItemName == "") { - alignItemName = name; - } + if (loadingAnim_ != nullptr) { + loadingAnim_->Stop(); } - roller_->SetCurrentItem(alignItemName); -} -void RecentAppView::InitRecentApps() -{ - if (delBtn_ == nullptr) { - delBtn_ = new UILabelButton(); - } - if (delBtn_ == nullptr) { - GRAPHIC_LOGE("new delBtn_ failed!"); - return; + if (loadingFragment_ != nullptr) { + loadingFragment_->GetFragmentView()->SetVisible(false); } - - if (roller_ == nullptr) { - roller_ = new UIRollerView(false); + if (rencentAppFragment_ == nullptr) { + rencentAppFragment_ = new RollerRecentAppFragment(); } - if (roller_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIRollerView fail"); - return; + if (rencentAppFragment_ != nullptr) { + rencentAppFragment_->GetFragmentView()->SetPosition(0, 0, GetRootContainer()->GetWidth(), + GetRootContainer()->GetHeight()); + rencentAppFragment_->CreateView(); + AddViewToRootContainer(rencentAppFragment_->GetFragmentView()); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new RollerRecentAppFragment failed!"); } - - UIView::OnClickListener* onClickListener = dynamic_cast(presenter_); - - GetRootContainer()->Add(roller_); - roller_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - roller_->SetItemSize(250, 250); // 250: item size - roller_->SetThrowDrag(true); - roller_->SetItemPadding(80); // 80: item padding - roller_->SetCamDistance(380); // 380: Camera distance - roller_->SetCamY(48); // 48: camY - roller_->SetOnClickListener(onClickListener); - - GetRootContainer()->Add(delBtn_); - delBtn_->Resize(120, 50); // 120,50: width and height - delBtn_->LayoutCenterOfParent(0, 180); // 180: y offset - delBtn_->SetText("delete"); - delBtn_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); - delBtn_->SetViewId(RECENT_APP_DELETE_BTN_ID); - delBtn_->SetOnClickListener(onClickListener); - - AddRecentAppToRoller(); } -void RecentAppView::LoadRecentAppContent() +void RecentAppView::LoadingAnimCb::Callback(UIView* view) { - if (loadingAnim_ != nullptr) { - loadingAnim_->Stop(); - } - - if (loadingLabel_ != nullptr) { - loadingLabel_->SetVisible(false); - } - - uint32_t size = RecentManager::GetInstance()->GetCurrentSize(); - if (size == 0) { - if (noRecentAppLabel_ == nullptr) { - noRecentAppLabel_ = new UILabel(); - } - if (noRecentAppLabel_ != nullptr) { - GetRootContainer()->Add(noRecentAppLabel_); - noRecentAppLabel_->SetText("No Recent App."); - noRecentAppLabel_->Resize(300, 100); // 300, 100: size - noRecentAppLabel_->LayoutCenterOfParent(); - noRecentAppLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - } - return; + if (RecentManager::GetInstance()->IsUpdateCompleted()) { + recentAppView_->LoadContent(); } - - InitRecentApps(); } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RollerRecentAppFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RollerRecentAppFragment.cpp new file mode 100644 index 000000000..86420b15e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/RollerRecentAppFragment.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: RollerRecentAppFragment.cpp + * Author: + * Create: 2025-07-17 + */ + +#include "recent_app/RollerRecentAppFragment.h" +#include "wearable_log.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "Slice.h" +#include "RecentManager.h" +#include "NativeAbility.h" +#include "msg_center_customer.h" + +namespace OHOS { +static constexpr uint8_t DEFAULT_TEXT_SIZE = 30; + +void RollerRecentAppFragment::OnCreateView(void* data) +{ + LoadRecentAppContent(); +} + +void RollerRecentAppFragment::OnDestroyView() +{ + if (rollerContainer_ != nullptr) { + delete rollerContainer_; + } + if (noRecentAppLabel_ != nullptr) { + delete noRecentAppLabel_; + } + if (delBtn_ != nullptr) { + delete delBtn_; + } +} + +void RollerRecentAppFragment::LoadRecentAppContent() +{ + uint32_t size = RecentManager::GetInstance()->GetCurrentSize(); + if (size == 0) { + if (noRecentAppLabel_ == nullptr) { + noRecentAppLabel_ = new UILabel(); + } + if (noRecentAppLabel_ != nullptr) { + fragmentView_.Add(noRecentAppLabel_); + noRecentAppLabel_->SetText("No Recent App."); + noRecentAppLabel_->Resize(300, 100); // 300, 100: size + noRecentAppLabel_->LayoutCenterOfParent(); + noRecentAppLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } + return; + } + + InitRecentApps(); +} + +void RollerRecentAppFragment::InitRecentApps() +{ + if (delBtn_ == nullptr) { + delBtn_ = new UILabelButton(); + } + if (delBtn_ == nullptr) { + GRAPHIC_LOGE("new UILabelButton failed!"); + return; + } + + if (rollerContainer_ == nullptr) { + rollerContainer_ = new UIRollerView(false); + } + if (rollerContainer_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIRollerView fail"); + return; + } + + fragmentView_.Add(rollerContainer_); + rollerContainer_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + rollerContainer_->SetItemSize(250, 250); // 250: item size + rollerContainer_->SetThrowDrag(true); + rollerContainer_->SetItemPadding(80); // 80: item padding + rollerContainer_->SetCamDistance(380); // 380: Camera distance + rollerContainer_->SetCamY(48); // 48: camY + rollerContainer_->SetOnClickListener(this); + + fragmentView_.Add(delBtn_); + delBtn_->Resize(120, 50); // 120,50: width and height + delBtn_->LayoutCenterOfParent(0, 180); // 180: y offset + delBtn_->SetText("delete"); + delBtn_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); + delBtn_->SetViewId(RECENT_APP_DELETE_BTN_ID); + delBtn_->SetOnClickListener(this); + + AddRecentAppToRoller(); +} + +void RollerRecentAppFragment::AddRecentAppToRoller() +{ + const List& recent = RecentManager::GetInstance()->GetRecentApps(); + ListNode* node = recent.Begin(); + std::string alignItemName = ""; + while (node != recent.End()) { + RecentAppInfo* appInfo = node->data_; + ImageInfo* imgInfo = appInfo->snapshot; + std::string name; + if (appInfo->isNativeSlice) { + name = RECENT_ITEM_NATIVE_PREFIX + std::to_string(appInfo->targetId & SLICE_MASK); + } else { + name = RECENT_ITEM_JS_PREFIX + appInfo->bundleName; + } + if (imgInfo->data != nullptr) { + rollerContainer_->AddItem(name, imgInfo); + } else { + std::string path(appInfo->snapshot->file, appInfo->snapshot->fileLen); + if (appInfo->snapshot->resId == 0) { + imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(path); + } else { + imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(appInfo->snapshot->resId, path); + } + + if (imgInfo == nullptr) { + GRAPHIC_LOGE("Load res failed: %s", path.c_str()); + node = node->next_; + continue; + } + rollerContainer_->AddItem(name, imgInfo); + } + node = node->next_; + if (alignItemName == "") { + alignItemName = name; + } + } + rollerContainer_->SetCurrentItem(alignItemName); +} + +bool RollerRecentAppFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UIViewGroup* currentItemGroup = rollerContainer_->GetCurrentItem(); + if (currentItemGroup == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentItemGroup is nullptr!"); + return false; + } + + std::string itemName = rollerContainer_->GetCurrentItemName(); + std::string prefix(itemName.begin(), itemName.begin() + RECENT_ITEM_PREFIX_LEN); + std::string name(itemName.begin() + RECENT_ITEM_PREFIX_LEN, itemName.end()); + + uint32_t sliceId = 0; + bool isNativeSlice = true; + if (prefix == RECENT_ITEM_NATIVE_PREFIX) { + sliceId = static_cast(std::stoul(name)); + } else { + isNativeSlice = false; + } + + const char* viewId = view.GetViewId(); + if (viewId != nullptr && strcmp(viewId, RECENT_APP_DELETE_BTN_ID) == 0) { + if (isNativeSlice) { + RecentManager::GetInstance()->RemoveRecentApp(sliceId); + } else { + RecentManager::GetInstance()->RemoveRecentApp(name.c_str()); + } + rollerContainer_->RemoveItem(itemName); + return true; + } + + Point clickPoint = event.GetCurrentPos(); + Rect rect = currentItemGroup->GetChildrenHead()->GetRect(); + if (rect.IsContains(clickPoint)) { + if (isNativeSlice) { + NativeAbility::GetInstance().ChangeSlice(sliceId); + } else { +#ifdef JS_ENABLE + StartJsApp(const_cast(name.c_str())); +#endif + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/SlipFlowRecentAppFragment.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/SlipFlowRecentAppFragment.cpp new file mode 100644 index 000000000..48b71b1dc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/recent_app/src/SlipFlowRecentAppFragment.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: SlipFlowRecentAppFragment.cpp + * Author: + * Create: 2025-07-17 + */ + +#include "recent_app/SlipFlowRecentAppFragment.h" +#include "wearable_log.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "Slice.h" +#include "RecentManager.h" +#include "NativeAbility.h" +#include "msg_center_customer.h" + +namespace OHOS { +void SlipFlowRecentAppFragment::OnCreateView(void* data) +{ + LoadRecentAppContent(); +} + +void SlipFlowRecentAppFragment::OnDestroyView() +{ + if (slipFlowContainer_ != nullptr) { + UIViewGroup* child = dynamic_cast(slipFlowContainer_->GetChildrenHead()); + while (child != nullptr) { + UIView* node = child->GetChildrenHead(); + child = dynamic_cast(child->GetNextSibling()); + delete node; + } + delete slipFlowContainer_; + } + if (noRecentAppLabel_ != nullptr) { + delete noRecentAppLabel_; + } + if (slipUpNoticeLabel_ != nullptr) { + delete slipUpNoticeLabel_; + } +} + +void SlipFlowRecentAppFragment::LoadRecentAppContent() +{ + uint32_t size = RecentManager::GetInstance()->GetCurrentSize(); + if (size == 0) { + if (noRecentAppLabel_ == nullptr) { + noRecentAppLabel_ = new UILabel(); + } + if (noRecentAppLabel_ != nullptr) { + fragmentView_.Add(noRecentAppLabel_); + noRecentAppLabel_->SetText("No Recent App."); + noRecentAppLabel_->Resize(300, 100); // 300, 100: size + noRecentAppLabel_->LayoutCenterOfParent(); + noRecentAppLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } + return; + } + + InitRecentApps(); +} + +void SlipFlowRecentAppFragment::InitRecentApps() +{ + if (slipFlowContainer_ == nullptr) { + slipFlowContainer_ = new UISlipflowView(); + } + if (slipFlowContainer_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UISlipflowView fail"); + return; + } + if (slipUpNoticeLabel_ == nullptr) { + slipUpNoticeLabel_ = new UILabel(); + } + if (slipUpNoticeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UILabel fail"); + return; + } + + fragmentView_.Add(slipFlowContainer_); + slipFlowContainer_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + slipFlowContainer_->SetThrowDrag(true); + slipFlowContainer_->SetOnClickListener(this); + slipFlowContainer_->SetOnSlipflowListener(this); + AddRecentAppToSlipFlow(); + + slipUpNoticeLabel_->SetPosition(127, 400, 200, 50); // 127 400 200 50: label position + slipUpNoticeLabel_->SetTextColor(Color::White()); + slipUpNoticeLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + slipUpNoticeLabel_->SetText("继续上滑删除"); + slipUpNoticeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30 : font size + slipUpNoticeLabel_->SetVisible(false); + fragmentView_.Add(slipUpNoticeLabel_); +} + +void SlipFlowRecentAppFragment::AddImageToSlipFlow(int index) +{ + UIImageView* image = new UIImageView(); + image->SetViewId(appNames_[index].c_str()); + image->SetSrc(appImgInfos_[index]); + image->Resize(250, 250); // 250: page size + image->SetResizeMode(UIImageView::ImageResizeMode::FILL); + image->SetAutoEnable(false); + slipFlowContainer_->Add(image); + image->LayoutCenterOfParent(); +} + +void SlipFlowRecentAppFragment::AddRecentAppToSlipFlow() +{ + const List& recent = RecentManager::GetInstance()->GetRecentApps(); + ListNode* node = recent.Begin(); + while (node != recent.End()) { + RecentAppInfo* appInfo = node->data_; + ImageInfo* imgInfo = appInfo->snapshot; + std::string name; + if (appInfo->isNativeSlice) { + name = RECENT_ITEM_NATIVE_PREFIX + std::to_string(appInfo->targetId & SLICE_MASK); + } else { + name = RECENT_ITEM_JS_PREFIX + appInfo->bundleName; + } + if (imgInfo->data == nullptr) { + std::string path(appInfo->snapshot->file, appInfo->snapshot->fileLen); + if (appInfo->snapshot->resId == 0) { + imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(path); + } else { + imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(appInfo->snapshot->resId, path); + } + + if (imgInfo == nullptr) { + GRAPHIC_LOGE("Load res failed: %s", path.c_str()); + node = node->next_; + continue; + } + } + appNames_.PushBack(name); + appImgInfos_.PushBack(imgInfo); + node = node->next_; + } + int index = appNames_.Size() - 1; + while (index >= 0) { + AddImageToSlipFlow(index); + index--; + } +} + +bool SlipFlowRecentAppFragment::OnClick(UIView &view, const ClickEvent &event) +{ + std::string itemName(slipFlowContainer_->GetCurrentView()->GetViewId()); + std::string prefix(itemName.begin(), itemName.begin() + RECENT_ITEM_PREFIX_LEN); + std::string name(itemName.begin() + RECENT_ITEM_PREFIX_LEN, itemName.end()); + UIViewGroup* currentItemGroup = dynamic_cast(slipFlowContainer_->GetCurrentView()); + if (currentItemGroup == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentItemGroup is nullptr!"); + return false; + } + uint32_t sliceId = 0; + bool isNativeSlice = true; + if (prefix == RECENT_ITEM_NATIVE_PREFIX) { + sliceId = static_cast(std::stoul(name)); + } else { + isNativeSlice = false; + } + Point clickPoint = event.GetCurrentPos(); + Rect rect = currentItemGroup->GetChildrenHead()->GetRect(); + if (rect.IsContains(clickPoint)) { + if (isNativeSlice) { + NativeAbility::GetInstance().ChangeSlice(sliceId); + } else { +#ifdef JS_ENABLE + StartJsApp(const_cast(name.c_str())); +#endif + } + } + return true; +} + +void SlipFlowRecentAppFragment::OnScrollUpStart() +{ + slipUpNoticeLabel_->SetVisible(true); +} + +void SlipFlowRecentAppFragment::OnScrollUpEnd() +{ + slipUpNoticeLabel_->SetVisible(false); +} + +bool SlipFlowRecentAppFragment::OnRemove(UIView* view) +{ + if (view == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Remove view is nullptr!"); + return false; + } + std::string itemName(view->GetViewId()); + std::string prefix(itemName.begin(), itemName.begin() + RECENT_ITEM_PREFIX_LEN); + std::string name(itemName.begin() + RECENT_ITEM_PREFIX_LEN, itemName.end()); + uint32_t sliceId = 0; + bool isNativeSlice = true; + if (prefix == RECENT_ITEM_NATIVE_PREFIX) { + sliceId = static_cast(std::stoul(name)); + } else { + isNativeSlice = false; + } + if (view->GetViewId() != nullptr) { + if (isNativeSlice) { + RecentManager::GetInstance()->RemoveRecentApp(sliceId); + } else { + RecentManager::GetInstance()->RemoveRecentApp(name.c_str()); + } + } + delete view; + view = nullptr; + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp index 47a30ab48..2365d3417 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp @@ -6,7 +6,6 @@ #include "restoredefaults/RestoreDefaultsPresenter.h" #include "restoredefaults/RestoreDefaultsView.h" -#include "bluetooth/BluetoothModel.h" #include "bts_br_gap.h" #include "drag_event.h" #include "cmsis_os.h" @@ -119,7 +118,6 @@ void RestoreDefaultsPresenter::ConfirmOnClick() bundleInfos = nullptr; } } - StopwatchModel::GetInstance().ClearData(); uapi_system_reboot(SYSTEM_SOFT_REBOOT); return; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp index 991ee5938..b95865960 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp @@ -75,10 +75,11 @@ static void EnterAod() ElementName *elementName = AbilityMsClient::GetInstance().GetTopAbility(); if (elementName != nullptr) { g_pre_bundle_name = elementName->bundleName; + FreeElement(elementName); } g_is_native = false; } - NativeAbility::GetInstance().ChangeSlice(VIEW_AOD); + NativeAbility::GetInstance().EnterAod(); } static void ExitAod() @@ -89,11 +90,15 @@ static void ExitAod() uint16_t sliceId = NativeAbility::GetInstance().GetPreTargetId() & SLICE_MASK; for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) { if (ignore_slice_ids[i] == sliceId) { - NativeAbility::GetInstance().ChangeSlice(sliceId); + NativeAbility::GetInstance().ExitAod(sliceId); return; } } - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + if (OHOS::MainViewSample::GetInstance() != nullptr && !OHOS::MainViewSample::GetInstance()->IsMainClockPage()) { + // 当前页面为主表盘的其他页面时,切换回主表盘页面 + OHOS::MainViewSample::GetInstance()->SwitchToClockPage(); + } + NativeAbility::GetInstance().ExitAod(VIEW_MAIN_SAMPLE); } else { if (!g_is_native) { Want *want = new Want(); @@ -109,7 +114,7 @@ static void ExitAod() return; } uint32_t preId = NativeAbility::GetInstance().GetPreTargetId(); - NativeAbility::GetInstance().SwitchSlice(preId & SLICE_MASK, preId >> PAGE_OFFSET); + NativeAbility::GetInstance().ExitAod(preId); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/screensetting/src/ScreenModels.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/screensetting/src/ScreenModels.cpp index 6be2328bd..c94c4c9d0 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/screensetting/src/ScreenModels.cpp @@ -45,7 +45,6 @@ void ScreenModels::InitKvStorage(void) int ret = UtilsSetEnv("../bin"); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UtilsSetEnv ../user ret = %d", ret); #endif - } void ScreenModels::LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId) @@ -77,6 +76,5 @@ void ScreenModels::PreLoadAppimages(void) LoadAppMultiImages(CLOCK_IAMGES, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); LoadAppMultiImages(COMPASS_IAMGES, COMPASS_ROTATE_CENTER_IMAGE, COMPASS_COMPASS); LoadAppMultiImages(DROPDOWN_IAMGES, DROPDOWN_DROPDOWN_BLUETOOTH, DROPDOWN_DROPDOWN_BRI_SCREEN_B); - LoadAppMultiImages(HEART_IAMGES, HEART_HEARTRATECOOR, HEART_HEARTRATE_TOP); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/SettingPresenter.cpp index fbf508ee9..b50403cdf 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/SettingPresenter.cpp @@ -1,14 +1,18 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.cpp - * Author: - * Create: 2021-11-23 - */ - -#include "settings/SettingView.h" -#include "settings/SettingPresenter.h" -#include "NativeRegisterManager.h" - -namespace OHOS { -REGIST_MENU(VIEW_SETTING, SettingView, SettingPresenter, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_DEFAULT_IMG, "设置"); -} +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPresenter + * Create: 2025-06-01 + */ +#include "NativeRegisterManager.h" +#include "settings/common/SettingCommon.h" +#include "settings/SettingView.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_SETTING, SettingView, SettingPresenter, SETTING_ICON, SETTING_ICON, "设置"); + +SettingPresenter::~SettingPresenter() +{ + ImageCacheManager::GetInstance().UnloadAllInMultiRes(SETTING_IMAGE); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingBluetoothItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingBluetoothItemGroup.cpp new file mode 100644 index 000000000..103d5f13f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingBluetoothItemGroup.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBluetoothItemView + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "ui_resource_settings.h" +#include "common/image_cache_manager.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/common/SettingBluetoothItemGroup.h" + +namespace OHOS { +static constexpr int16_t BLUETOOTH_ITEM_X = 14; +static constexpr int16_t BLUETOOTH_ITEM_WIDTH = 426; +static constexpr int16_t BLUETOOTH_ITEM_HEIGHT = 129; +static constexpr int16_t BLUETOOTH_ITEM_ICON1_X = 30; +static constexpr int16_t BLUETOOTH_ITEM_ICON1_Y = 35; +static constexpr int16_t BLUETOOTH_ITEM_ICON2_X = 378; +static constexpr int16_t BLUETOOTH_ITEM_ICON2_Y = 46; +static constexpr int16_t BLUETOOTH_ITEM_LABEL1_X = 110; +static constexpr int16_t BLUETOOTH_ITEM_LABEL1_Y = 15; +static constexpr int16_t BLUETOOTH_ITEM_LABEL1_STATUS_EXIST_Y = 33; +static constexpr int16_t BLUETOOTH_ITEM_LABEL2_Y = 57; +static constexpr int16_t BLUETOOTH_ITEM_CHARTLINE_X = 20; +static constexpr int16_t BLUETOOTH_ITEM_CHARTLINE_Y = 78; +static constexpr int16_t BLUETOOTH_ITEM_CHARTLINE_WIDTH = 450; +static constexpr int16_t BLUETOOTH_ITEM_CHARTLINE_HEIGHT = 2; +static constexpr int16_t BLUETOOTH_ITEM_ITEM_BUTTON_WIDTH = 390; +static constexpr int16_t BLUETOOTH_ITEM_ITEM_BUTTON_HEIGHT = 83; +static constexpr int16_t BLUETOOTH_ITEM_ITEM_LABEL_WIDTH = 240; +static constexpr int16_t BLUETOOTH_ITEM_ITEM_LABEL_HEIGHT = 40; +static constexpr int16_t BLUETOOTH_ITEM_ITEM_FONT_SIZE = 32; +static constexpr int16_t BLUETOOTH_ITEM_IMAGE_SIZE = 300; +static constexpr int16_t BLUETOOTH_ITEM_CONNSTATE_SIZE = 30; + +SettingBluetoothItemGroup::SettingBluetoothItemGroup() +{ + SetPosition(BLUETOOTH_ITEM_X, 0, BLUETOOTH_ITEM_WIDTH, BLUETOOTH_ITEM_HEIGHT); + + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + SetTouchable(true); + SetUpChild(); + ImageInfo* image = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_BG, SETTING_IMAGE); + background_.SetSrc(image); + background_.SetPosition(0, 0); + + Add(&background_); + Add(&icon_); + Add(&deviceName_); + Add(&connectStatus_); + Add(&conn_); +} + +SettingBluetoothItemGroup::~SettingBluetoothItemGroup() +{ + Remove(&background_); + Remove(&icon_); + Remove(&deviceName_); + Remove(&connectStatus_); + Remove(&conn_); +} + +void SettingBluetoothItemGroup::SetItemInfo(const BtCaseInfo* itemInfo) +{ + if (memcpy_s(itemInfo_.deviceName, BD_NAME_LEN, itemInfo->deviceName, BD_NAME_LEN) != 0) { + return; + } + if (memcpy_s(itemInfo_.addr, BD_ADDR_LEN, itemInfo->addr, BD_ADDR_LEN) != 0) { + return; + } + itemInfo_.connect_status = itemInfo->connect_status; + itemInfo_.rssi = itemInfo->rssi; + deviceName_.SetText((const char*)itemInfo_.deviceName); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBluetoothItemGroup::SetItemInfo %s", itemInfo_.deviceName); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBluetoothItemGroup::connect_status %s", itemInfo_.connect_status.c_str()); + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_BLUETOOTH, SETTING_IMAGE); + icon_.SetSrc(image); + connectStatus_.SetText(itemInfo_.connect_status.c_str()); + if (itemInfo_.connect_status == "已连接") { + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONNECT, SETTING_IMAGE); + conn_.SetSrc(image); + conn_.SetVisible(true); + } else { + conn_.SetVisible(false); + } + if (itemInfo_.connect_status == "") { + deviceName_.SetPosition(BLUETOOTH_ITEM_LABEL1_X, BLUETOOTH_ITEM_LABEL1_STATUS_EXIST_Y); + deviceName_.SetVisible(true); + connectStatus_.SetVisible(false); + } else { + deviceName_.SetPosition(BLUETOOTH_ITEM_LABEL1_X, BLUETOOTH_ITEM_LABEL1_Y); + deviceName_.SetVisible(true); + connectStatus_.SetVisible(true); + } +} + +BtCaseInfo& SettingBluetoothItemGroup::GetItem() +{ + return itemInfo_; +} + +void SettingBluetoothItemGroup::SetUpChild() +{ + icon_.SetPosition(BLUETOOTH_ITEM_ICON1_X, BLUETOOTH_ITEM_ICON1_Y); + icon_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + conn_.SetPosition(BLUETOOTH_ITEM_ICON2_X, BLUETOOTH_ITEM_ICON2_Y); + conn_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + deviceName_.Resize(BLUETOOTH_ITEM_ITEM_LABEL_WIDTH, BLUETOOTH_ITEM_ITEM_LABEL_HEIGHT); + deviceName_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLUETOOTH_ITEM_ITEM_FONT_SIZE); + deviceName_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + deviceName_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + deviceName_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + deviceName_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + deviceName_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + + connectStatus_.SetPosition(BLUETOOTH_ITEM_LABEL1_X, BLUETOOTH_ITEM_LABEL2_Y); + connectStatus_.Resize(BLUETOOTH_ITEM_ITEM_LABEL_WIDTH, BLUETOOTH_ITEM_ITEM_LABEL_HEIGHT); + connectStatus_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLUETOOTH_ITEM_CONNSTATE_SIZE); + connectStatus_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + connectStatus_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + connectStatus_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + connectStatus_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardAddItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardAddItemGroup.cpp new file mode 100644 index 000000000..b62e2f708 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardAddItemGroup.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardAddItemGroup + * Create: 2025-06-01 + */ +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingCardAddItemGroup.h" + +namespace OHOS { +static constexpr int16_t SETTING_CARD_ADD_ITEM_WIDTH = 157; +static constexpr int16_t SETTING_CARD_ADD_ITEM_HEIGHT = 397; +static constexpr int16_t SETTING_CARD_ADD_ITEM_MARGIN = 15; +static constexpr int16_t SETTING_CARD_ADD_ITEM_IMAGE_WIDTH = 157; +static constexpr int16_t SETTING_CARD_ADD_ITEM_IMAGE_HEIGHT = 157; +static constexpr int16_t SETTING_CARD_ITEM_BUTTON_X = 4; +static constexpr int16_t SETTING_CARD_ITEM_BUTTON_Y = 202; +static constexpr int16_t SETTING_CARD_ITEM_BUTTON_WIDTH = 150; +static constexpr int16_t SETTING_CARD_ITEM_BUTTON_HEIGHT = 70; + +SettingCardAddItemGroup::SettingCardAddItemGroup() +{ + SetPosition(0, 0, SETTING_CARD_ADD_ITEM_WIDTH, SETTING_CARD_ADD_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetStyle(STYLE_MARGIN_LEFT, SETTING_CARD_ADD_ITEM_MARGIN); + SetStyle(STYLE_MARGIN_RIGHT, SETTING_CARD_ADD_ITEM_MARGIN); + + image_.SetAutoEnable(false); + image_.SetPosition(0, 0, SETTING_CARD_ADD_ITEM_IMAGE_WIDTH, SETTING_CARD_ADD_ITEM_IMAGE_HEIGHT); + image_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + image_.SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + image_.SetResizeMode(UIImageView::CONTAIN); + + button_.SetPosition(SETTING_CARD_ITEM_BUTTON_X, SETTING_CARD_ITEM_BUTTON_Y); + button_.Resize(SETTING_CARD_ITEM_BUTTON_WIDTH, SETTING_CARD_ITEM_BUTTON_HEIGHT); + button_.SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button_.SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + button_.SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + button_.SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + button_.SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + button_.SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + + Add(&image_); + Add(&button_); +} + +SettingCardAddItemGroup::~SettingCardAddItemGroup() +{ + if (imageData_ != nullptr && imageSrc_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(imageSrc_); + imageData_ = nullptr; + imageSrc_ = nullptr; + } +} + +void SettingCardAddItemGroup::UpdateItemGroup(SettingCardItemData* itemData) +{ + if (imageData_ != nullptr && imageSrc_ != nullptr) { + // 通过LoadSingleRes加载的图片不会自动释放 + ImageCacheManager::GetInstance().UnloadSingleRes(imageSrc_); + imageData_ = nullptr; + imageSrc_ = nullptr; + } + + imageSrc_ = itemData->image; + imageData_ = ImageCacheManager::GetInstance().LoadSingleRes(imageSrc_); + image_.SetSrc(imageData_); + if (itemData->isSelect) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CARD_ADD_ADDED, SETTING_IMAGE); + button_.SetImageSrc(image, image); + button_.SetTouchable(false); + } else { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CARD_ADD_ADD, SETTING_IMAGE); + button_.SetImageSrc(image, image); + button_.SetTouchable(true); + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardEffectItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardEffectItemGroup.cpp new file mode 100644 index 000000000..79e2f809a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardEffectItemGroup.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffectItemGroup + * Create: 2025-04 + */ +#include "common/image_cache_manager.h" +#include "gfx_utils/graphic_log.h" +#include "UiConfig.h" +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingCardEffectSample.h" +#include "settings/common/SettingCardEffectItemGroup.h" + +namespace OHOS { +static constexpr int16_t NUMS_2 = 2; +static constexpr int16_t SCREEN_MIDDLE = HORIZONTAL_RESOLUTION / NUMS_2; +static constexpr int16_t ANIMATOR_SICON_SIZE = 148; +static constexpr int16_t ANIMATOR_SICON_POINT_X = (SCREEN_MIDDLE - ANIMATOR_SICON_SIZE) / NUMS_2; +static constexpr int16_t ANIMATOR_SICON_POINT_Y = 150; +static constexpr int16_t BIND_IMAGE_DELAY = 180; +static constexpr int16_t PAUSE_TIME = 800; +static constexpr int16_t ITEM_LABEL_X = 0; +static constexpr int16_t ITEM_LABEL_Y = 320; +static constexpr int16_t ITEM_LABEL_WIDTH = SCREEN_MIDDLE; +static constexpr int16_t ITEM_LABEL_HEIGHT = 40; +static constexpr int16_t SETTING_ITEM_FONT_SIZE = 30; +static constexpr int16_t BACKDROP_ICON_X = ANIMATOR_SICON_POINT_X - 21; +static constexpr int16_t BACKDROP_ICON_Y = ANIMATOR_SICON_POINT_Y - 21; +static constexpr int16_t BACKDROP_ICON_SIZE = 190; + +SettingCardEffectItemGroup::SettingCardEffectItemGroup() +{ + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + SetUpChild(); + Add(&leftSelectIcon_); + Add(&leftPreviewIcon_); + Add(&leftAnimator_); + Add(&leftLabel_); + Add(&rightSelectIcon_); + Add(&rightPreviewIcon_); + Add(&rightAnimator_); + Add(&rightLabel_); +} + +SettingCardEffectItemGroup::~SettingCardEffectItemGroup() +{ + Remove(&leftAnimator_); + Remove(&leftLabel_); + Remove(&leftSelectIcon_); + Remove(&leftPreviewIcon_); + Remove(&rightSelectIcon_); + Remove(&rightPreviewIcon_); + Remove(&rightAnimator_); + Remove(&rightLabel_); +} + +void SettingCardEffectItemGroup::SetItemInfo(const SettingCardEffectSample& leftItemInfo, + const SettingCardEffectSample& rightItemInfo) +{ + leftItemInfo_ = leftItemInfo; + rightItemInfo_ = rightItemInfo; + + leftLabel_.SetText(leftItemInfo_.label); + leftSelectIcon_.SetVisible(leftItemInfo_.selected); + + if (!LoadMultiImages(leftItemInfo_, false)) { + GRAPHIC_LOGE("leftItemInfo_ cannot open file: %s", leftItemInfo_.resourceImage); + return; + } + + rightLabel_.SetText(rightItemInfo_.label); + rightSelectIcon_.SetVisible(rightItemInfo_.selected); + + if (!LoadMultiImages(rightItemInfo_, true)) { + GRAPHIC_LOGE("rightItemInfo_ cannot open file: %s", rightItemInfo_.resourceImage); + return; + } +} + +bool SettingCardEffectItemGroup::LoadMultiImages(SettingCardEffectSample& itemInfo, bool right) +{ + UIImageView* previewIcon = &leftPreviewIcon_; + UIImageView* selectIcon = &leftSelectIcon_; + UIImageAnimatorView* animator = &leftAnimator_; + uint16_t animatorSiconX = ANIMATOR_SICON_POINT_X; + if (right) { + previewIcon = &rightPreviewIcon_; + selectIcon = &rightSelectIcon_; + animator = &rightAnimator_; + animatorSiconX = ANIMATOR_SICON_POINT_X + SCREEN_MIDDLE; + } + + if (itemInfo.viewId == CardEffectID::UI_INVALIDE) { // -1: UI_INVALIDE + previewIcon->SetVisible(false); + selectIcon->SetVisible(false); + animator->SetVisible(false); + GRAPHIC_LOGE("itemInfo.viewId is UI_INVALIDE"); + return false; + } + + FILE* fp = fopen(itemInfo.resourceImage, "rb"); + if (fp == nullptr) { + GRAPHIC_LOGE("cannot open file: %s", itemInfo.resourceImage); + return false; + } + + previewIcon->SetSrc(ImageCacheManager::GetInstance(). + LoadOneInMultiRes(itemInfo.resIds[0], itemInfo.resourceImage, fp)); + selectIcon->SetSrc(ImageCacheManager::GetInstance(). + LoadOneInMultiRes(itemInfo.backgroundImageId, itemInfo.resourceImage, fp)); + + uint8_t imageNum = itemInfo.resIds.size(); + std::vector searchImageInfo(imageNum); + for (uint8_t i = 0; i < imageNum; i++) { + searchImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes( + itemInfo.resIds[i], itemInfo.resourceImage, fp); + searchImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo[i].pos.x = animatorSiconX; + searchImageInfo[i].pos.y = ANIMATOR_SICON_POINT_Y; + searchImageInfo[i].width = ANIMATOR_SICON_SIZE; + searchImageInfo[i].height = ANIMATOR_SICON_SIZE; + } + animator->SetImageAnimatorSrc(searchImageInfo.data(), imageNum, BIND_IMAGE_DELAY); + fclose(fp); + return true; +} + +void SettingCardEffectItemGroup::SetUpChild() +{ + InitializeAnimator(leftAnimator_, ANIMATOR_SICON_POINT_X, ANIMATOR_SICON_POINT_Y, ANIMATOR_SICON_SIZE); + + InitializeIcon(leftPreviewIcon_, ANIMATOR_SICON_POINT_X, ANIMATOR_SICON_POINT_Y, ANIMATOR_SICON_SIZE); + + InitializeLabel(leftLabel_, ITEM_LABEL_X, ITEM_LABEL_Y, ITEM_LABEL_WIDTH, ITEM_LABEL_HEIGHT); + + InitializeIcon(leftSelectIcon_, BACKDROP_ICON_X, BACKDROP_ICON_Y, BACKDROP_ICON_SIZE); + + int rightItemX = SCREEN_MIDDLE + ANIMATOR_SICON_POINT_X; + InitializeAnimator(rightAnimator_, rightItemX, ANIMATOR_SICON_POINT_Y, ANIMATOR_SICON_SIZE); + + InitializeIcon(rightPreviewIcon_, rightItemX, ANIMATOR_SICON_POINT_Y, ANIMATOR_SICON_SIZE); + + rightItemX = SCREEN_MIDDLE + ITEM_LABEL_X; + InitializeLabel(rightLabel_, rightItemX, ITEM_LABEL_Y, ITEM_LABEL_WIDTH, ITEM_LABEL_HEIGHT); + + rightItemX = SCREEN_MIDDLE + BACKDROP_ICON_X; + InitializeIcon(rightSelectIcon_, rightItemX, BACKDROP_ICON_Y, BACKDROP_ICON_SIZE); +} + +void SettingCardEffectItemGroup::InitializeAnimator(UIImageAnimatorView& animator, int x, int y, int size) +{ + animator.SetPosition(x, y); + animator.Resize(size, size); + animator.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + animator.SetRepeat(true); + animator.SetTimeOfPause(PAUSE_TIME); +} + +void SettingCardEffectItemGroup::InitializeIcon(UIImageView& icon, int x, int y, int size) +{ + icon.SetPosition(x, y); + icon.Resize(size, size); + icon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + icon.SetVisible(true); +} + +void SettingCardEffectItemGroup::InitializeLabel(UILabel& label, int x, int y, int width, int height) +{ + label.SetPosition(x, y); + label.Resize(width, height); + label.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); + label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + label.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + label.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + label.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); +} + +CardEffectID SettingCardEffectItemGroup::GetViewId(const ClickEvent& event) +{ + int16_t clickY = event.GetCurrentPos().y; + int16_t minItemY = BACKDROP_ICON_Y; + int16_t maxItemY = BACKDROP_ICON_Y + BACKDROP_ICON_SIZE + ITEM_LABEL_HEIGHT; + + // Check if the click position is within the valid Y-axis range + if (clickY < minItemY || clickY > maxItemY) { + // -1 indicates an invalid UI element + return CardEffectID::UI_INVALIDE; + } + + int16_t clickX = event.GetCurrentPos().x; + int16_t leftItemX = BACKDROP_ICON_X; + int16_t rightItemX = SCREEN_MIDDLE + BACKDROP_ICON_X; + int16_t itemWidth = BACKDROP_ICON_SIZE; + // Check if the click position is within the left item's X-axis range + if (clickX > leftItemX && clickX < (leftItemX + itemWidth)) { + return leftItemInfo_.viewId; + } + + // Check if the click position is within the right item's X-axis range + if (clickX > rightItemX && clickX < rightItemX + itemWidth) { + return rightItemInfo_.viewId; + } + + // -1 indicates an invalid UI element + return CardEffectID::UI_INVALIDE; +} + +void SettingCardEffectItemGroup::SelectedChange() +{ + leftAnimator_.SetVisible(true); + leftAnimator_.Start(); + leftPreviewIcon_.SetVisible(false); + + rightAnimator_.SetVisible(true); + rightAnimator_.Start(); + rightPreviewIcon_.SetVisible(false); +} + +void SettingCardEffectItemGroup::Reset() +{ + leftAnimator_.SetVisible(false); + leftAnimator_.Stop(); + leftPreviewIcon_.SetVisible(true); + + rightAnimator_.SetVisible(false); + rightAnimator_.Stop(); + rightPreviewIcon_.SetVisible(true); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardMgrItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardMgrItemGroup.cpp new file mode 100644 index 000000000..13ec15ff4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingCardMgrItemGroup.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardMgrItemGroup + * Create: 2025-06-01 + */ +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingCardMgrItemGroup.h" + +namespace OHOS { +static constexpr int16_t SETTING_CARD_MGR_ITEM_WIDTH = 454; +static constexpr int16_t SETTING_CARD_MGR_ITEM_HEIGHT = 245; + +SettingCardMgrItemGroup::SettingCardMgrItemGroup() +{ + SetPosition(0, 0, SETTING_CARD_MGR_ITEM_WIDTH, SETTING_CARD_MGR_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + + image_.SetAutoEnable(false); + image_.SetPosition(0, 0, SETTING_CARD_MGR_ITEM_WIDTH, SETTING_CARD_MGR_ITEM_HEIGHT); + image_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + image_.SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + image_.SetResizeMode(UIImageView::CONTAIN); + Add(&image_); +} + +SettingCardMgrItemGroup::~SettingCardMgrItemGroup() +{ + if (imageData_ != nullptr && imageSrc_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(imageSrc_); + imageData_ = nullptr; + imageSrc_ = nullptr; + } +} + +void SettingCardMgrItemGroup::UpdateItemGroup(SettingCardItemData* itemData) +{ + if (imageData_ != nullptr && imageSrc_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(imageSrc_); + imageData_ = nullptr; + imageSrc_ = nullptr; + } + imageSrc_ = itemData->image; + imageData_ = ImageCacheManager::GetInstance().LoadSingleRes(imageSrc_); + image_.SetSrc(imageData_); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingDesktopHomeItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingDesktopHomeItemGroup.cpp new file mode 100644 index 000000000..64470b0fb --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingDesktopHomeItemGroup.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopHomeItemGroup + * Create: 2025-06-01 + */ +#include +#include "UiConfig.h" +#include "wearable_log.h" +#include "settings/common/SettingDesktopHomeItemGroup.h" + +namespace OHOS { +static constexpr int16_t SETTING_HOME_ITEM_WIDTH = 153; +static constexpr int16_t SETTING_HOME_ITEM_HEIGHT = 205; +static constexpr int16_t SETTING_HOME_ITEM_MARGIN = 13; + +static constexpr int16_t SETTING_HOME_BUTTON_HEIGHT = 153; +static constexpr int16_t SETTING_HOME_BUTTON_RADIUS = 0; +static constexpr int16_t SETTING_HOME_LABEL_X = 28; +static constexpr int16_t SETTING_HOME_LABEL_Y = 167; +static constexpr int16_t SETTING_HOME_LABEL_WIDTH = 98; +static constexpr int16_t SETTING_HOME_LABEL_HEIGHT = 38; +static constexpr int16_t SETTING_HOME_LABEL_FSIZE = 32; + +SettingDesktopHomeItemGroup::SettingDesktopHomeItemGroup() +{ + SetPosition(0, 0, SETTING_HOME_ITEM_WIDTH, SETTING_HOME_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetStyle(STYLE_MARGIN_LEFT, SETTING_HOME_ITEM_MARGIN); + SetStyle(STYLE_MARGIN_RIGHT, SETTING_HOME_ITEM_MARGIN); + SetTouchable(true); + + button_.SetPosition(0, 0, SETTING_HOME_ITEM_WIDTH, SETTING_HOME_BUTTON_HEIGHT); + button_.SetStyle(STYLE_BORDER_RADIUS, SETTING_HOME_BUTTON_RADIUS); + + label_.SetPosition(SETTING_HOME_LABEL_X, SETTING_HOME_LABEL_Y); + label_.Resize(SETTING_HOME_LABEL_WIDTH, SETTING_HOME_LABEL_HEIGHT); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_HOME_LABEL_FSIZE); + label_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + Add(&button_); + Add(&label_); +} + +SettingDesktopHomeItemGroup::~SettingDesktopHomeItemGroup() +{ + RemoveAll(); +} + +void SettingDesktopHomeItemGroup::UpdateItemGroup(SettingDesktopHomeItemData* itemData) +{ + SetViewId(itemData->label); + label_.SetText(itemData->label); + ImageInfo* select = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemData->selectIcon, SETTING_IMAGE); + ImageInfo* unselect = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemData->unSelectIcon, SETTING_IMAGE); + button_.SetImages(select, unselect); + if (itemData->isSelect) { + button_.SetState(UICheckBox::SELECTED, true); + } else { + button_.SetState(UICheckBox::UNSELECTED, true); + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingToggleButton.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingToggleButton.cpp new file mode 100644 index 000000000..a4b8d26c2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingToggleButton.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingToggleButton + * Create: 2025-06-01 + */ +#include "common/image.h" +#include "imgdecode/cache_manager.h" +#include "engines/gfx/gfx_engine_manager.h" +#include "settings/common/SettingToggleButton.h" + +namespace OHOS { +constexpr uint8_t TOGGLE_BTN_UNSELECTED_OPA = 97; +constexpr uint8_t TOGGLE_HALF_NUM = 2; +#if DEFAULT_ANIMATION +constexpr int16_t DEFAULT_ANIMATOR_TIME = 150; +constexpr float BEZIER_CONTROL_POINT_X_1 = 0.2; +constexpr float BEZIER_CONTROL_POINT_X_2 = 0.2; +#endif + +SettingToggleButton::SettingToggleButton() +{ + backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA; + image_[UNSELECTED].SetSrc(""); + image_[SELECTED].SetSrc(""); +#if DEFAULT_ANIMATION + checkBoxAnimator_.SetTime(DEFAULT_ANIMATOR_TIME); +#endif + Resize(width_, height_); +} + +void SettingToggleButton::SetTrackPadding(int16_t padding) +{ + trackPadding_ = padding; +} + +void SettingToggleButton::CalculateSize() +{ + width_ = GetWidth() - 1; // UIView中保存的矩形宽高会比设置的宽高小1 + height_ = GetHeight() - 1; + + trackCorner_ = height_ / TOGGLE_HALF_NUM; + thumbRadius_ = trackCorner_ - trackPadding_; + + Rect contentRect = GetContentRect(); + leftCenter_ = {static_cast(contentRect.GetX() + trackCorner_), + static_cast(contentRect.GetY() + trackCorner_)}; + rightCenter_ = {static_cast(contentRect.GetX() + width_ - trackCorner_), + static_cast(contentRect.GetY() + trackCorner_)}; +#if DEFAULT_ANIMATION + if (checkBoxAnimator_.GetState() != Animator::START) { + currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White(); + } +#else + currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White(); +#endif + rectMid_.SetRect(contentRect.GetX(), contentRect.GetY(), contentRect.GetX() + width_, + contentRect.GetY() + (trackCorner_ << 1) + 1); +} + +void SettingToggleButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) +{ + if ((image_[SELECTED].GetSrcType() != IMG_SRC_UNKNOWN) && (image_[UNSELECTED].GetSrcType() != IMG_SRC_UNKNOWN)) { + UICheckBox::OnDraw(gfxDstBuffer, invalidatedArea); + } else { + CalculateSize(); + BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, GetRect(), invalidatedArea, *style_, opaScale_); + Rect contentRect = GetContentRect(); + Rect trunc = invalidatedArea; + bool isIntersect = trunc.Intersect(trunc, contentRect); + if (isIntersect == false) { + return; + } + Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); + styleUnSelect.bgColor_ = bgColor_; + styleUnSelect.bgOpa_ = backgroundOpacity_; + styleUnSelect.borderRadius_ = trackCorner_; + BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rectMid_, trunc, styleUnSelect, opaScale_); + ArcInfo arcInfoLeft = {currentCenter_, {0}, thumbRadius_, 0, CIRCLE_IN_DEGREE, nullptr}; + styleUnSelect.lineColor_ = Color::White(); + styleUnSelect.lineWidth_ = thumbRadius_; + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoLeft, trunc, styleUnSelect, OPA_OPAQUE, + CapType::CAP_NONE); + } +} + +#if DEFAULT_ANIMATION +void SettingToggleButton::Callback(UIView* view) +{ + runTime_ = checkBoxAnimator_.GetRunTime(); + float x = static_cast(runTime_) / checkBoxAnimator_.GetTime(); + float coefficient = Interpolation::GetBezierY(x, BEZIER_CONTROL_POINT_X_1, 0, BEZIER_CONTROL_POINT_X_2, 1); + if (state_ == SELECTED) { + currentCenter_.y = rightCenter_.y; + currentCenter_.x = (rightCenter_.x - leftCenter_.x) * coefficient + leftCenter_.x; + backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA + (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient; + bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * coefficient); + } else { + currentCenter_.y = leftCenter_.y; + currentCenter_.x = rightCenter_.x - (rightCenter_.x - leftCenter_.x) * coefficient; + backgroundOpacity_ = OPA_OPAQUE - (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient; + bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * (1 - coefficient)); + } + Invalidate(); +} + +void SettingToggleButton::OnStop(UIView& view) +{ + if (state_ == SELECTED) { + bgColor_ = selectedStateColor_; + } else { + bgColor_ = Color::White(); + } + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + Invalidate(); +} +#endif +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingUnionItemGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingUnionItemGroup.cpp new file mode 100644 index 000000000..205d5095d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/common/SettingUnionItemGroup.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingUnionItemGroup + * Create: 2025-06-01 + */ +#include +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "settings/common/SettingUnionItemGroup.h" + +namespace OHOS { +static constexpr int16_t SETTING_PAGE_ITEM_WIDTH = 426; +static constexpr int16_t SETTING_PAGE_ITEM_HEIGHT = 96; +static constexpr int16_t SETTING_PAGE_ITEM_RADIUS = 48; +static constexpr int16_t SETTING_PAGE_ITEM_MARGIN_BOTTON = 15; +static constexpr int8_t SETTING_PAGE_ITEM_ICON_X = 6; +static constexpr int8_t SETTING_PAGE_ITEM_ICON_Y = 6; +static constexpr int8_t SETTING_PAGE_ITEM_ICON_WIDTH = 84; +static constexpr int8_t SETTING_PAGE_ITEM_ICON_HEIGHT = 84; +static constexpr int16_t SETTING_PAGE_ITEM_LABEL_FSIZE = 32; + +static constexpr int16_t SETTING_PAGE_STATIC_LABEL_WIDTH = 260; +static constexpr int16_t SETTING_PAGE_STATIC_LABEL_HEIGHT = 53; +static constexpr int16_t SETTING_PAGE_STATIC_LABEL_X = 83; +static constexpr int16_t SETTING_PAGE_STATIC_LABEL_Y = 25; +static constexpr int16_t SETTING_PAGE_STATIC_LABEL_FSIZE = 38; + +static constexpr int16_t SETTING_PAGE_TOGGLE_X = 312; +static constexpr int16_t SETTING_PAGE_TOGGLE_Y = 24; +static constexpr int16_t SETTING_PAGE_TOGGLE_WIDTH = 84; +static constexpr int16_t SETTING_PAGE_TOGGLE_HEIGHT = 48; +static constexpr int16_t SETTING_PAGE_TOGGLE_TRACK_PADDING = 4; + +static constexpr int16_t SETTING_PAGE_INPAGE_TLABEL_X = 101; +static constexpr int16_t SETTING_PAGE_INPAGE_LABEL_Y = 29; +static constexpr int16_t SETTING_PAGE_INPAGE_LABEL_WIDTH = 38; +static constexpr int16_t SETTING_PAGE_INPAGE_DLABEL_X_OFFSET = 13; // TextLabel后偏移13个像素是DataLabel的起点 +static constexpr int16_t SETTING_PAGE_INPAGE_DLABEL_OPA = 127; +static constexpr int16_t SETTING_PAGE_INPAGE_IMAGE_X = 380; +static constexpr int16_t SETTING_PAGE_INPAGE_IMAGE_Y = 33; +static constexpr int16_t SETTING_PAGE_INPAGE_IMAGE_WIDTH = 18; +static constexpr int16_t SETTING_PAGE_INPAGE_IMAGE_HEIGHT = 31; + +SettingUnionItemType SettingUnionItemData::GetUnionItemType() +{ + return type_; +} + +void* SettingUnionItemData::GetUnionItemData() +{ + return &unionItemData_; +} + +SettingUnionItemData::SettingUnionItemData(const PlainTextItemData& itemData) { + type_ = PLAIN_TEXT; + unionItemData_.plainTextItemData = itemData; +} + +SettingUnionItemData::SettingUnionItemData(const IconTextToggleItemData& itemData) { + type_ = ICON_TEXT_TOGGLE; + unionItemData_.iconTextToggleItemData = itemData; +} + +SettingUnionItemData::SettingUnionItemData(const IconTextNavigationItemData& itemData) { + type_ = ICON_TEXT_NAVIGATION; + unionItemData_.iconTextNavigationItemData = itemData; +} + +PlainTextItemView::PlainTextItemView() +{ + SetPosition(0, 0, SETTING_PAGE_ITEM_WIDTH, SETTING_PAGE_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(false); + + label_.SetPosition(SETTING_PAGE_STATIC_LABEL_X, SETTING_PAGE_STATIC_LABEL_Y); + label_.Resize(SETTING_PAGE_STATIC_LABEL_WIDTH, SETTING_PAGE_STATIC_LABEL_HEIGHT); + label_.SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_PAGE_STATIC_LABEL_FSIZE); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + label_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + label_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + Add(&label_); +} + +PlainTextItemView::~PlainTextItemView() +{ + Remove(&label_); +} + +void PlainTextItemView::UpdateViewData(PlainTextItemData* data) +{ + if (data != nullptr) { + label_.SetText(data->textContent); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + } +} + +IconTextToggleItemView::IconTextToggleItemView() +{ + SetPosition(0, 0, SETTING_PAGE_ITEM_WIDTH, SETTING_PAGE_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetStyle(STYLE_BORDER_RADIUS, SETTING_PAGE_ITEM_RADIUS); + SetStyle(STYLE_MARGIN_BOTTOM, SETTING_PAGE_ITEM_MARGIN_BOTTON); + SetTouchable(true); + + icon_.SetPosition(SETTING_PAGE_ITEM_ICON_X, SETTING_PAGE_ITEM_ICON_Y); + icon_.Resize(SETTING_PAGE_ITEM_ICON_WIDTH, SETTING_PAGE_ITEM_ICON_HEIGHT); + icon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + icon_.SetAutoEnable(false); + icon_.SetResizeMode(UIImageView::SCALE_DOWN); + + label_.SetPosition(SETTING_PAGE_INPAGE_TLABEL_X, SETTING_PAGE_INPAGE_LABEL_Y); + label_.Resize(0, SETTING_PAGE_INPAGE_LABEL_WIDTH); + label_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_PAGE_ITEM_LABEL_FSIZE); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + label_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + toggleButton_.SetPosition(SETTING_PAGE_TOGGLE_X, SETTING_PAGE_TOGGLE_Y); + toggleButton_.Resize(SETTING_PAGE_TOGGLE_WIDTH, SETTING_PAGE_TOGGLE_HEIGHT); + toggleButton_.SetTrackPadding(SETTING_PAGE_TOGGLE_TRACK_PADDING); + toggleButton_.SetTouchable(false); + + Add(&icon_); + Add(&label_); + Add(&toggleButton_); +} + +IconTextToggleItemView::~IconTextToggleItemView() +{ + Remove(&icon_); + Remove(&label_); + Remove(&toggleButton_); +} + +void IconTextToggleItemView::UpdateViewData(IconTextToggleItemData* data) +{ + if (data != nullptr) { + SetStyle(STYLE_BACKGROUND_COLOR, data->bgColor.full); + SetStyle(STYLE_BACKGROUND_OPA, data->bgOpa); + icon_.SetSrc(CacheImage(data->icon)); + label_.SetText(data->textContent); + toggleButton_.SetState(data->selected); + } +} + +IconTextNavigationItemView::IconTextNavigationItemView() +{ + SetPosition(0, 0, SETTING_PAGE_ITEM_WIDTH, SETTING_PAGE_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetStyle(STYLE_BORDER_RADIUS, SETTING_PAGE_ITEM_RADIUS); + SetStyle(STYLE_MARGIN_BOTTOM, SETTING_PAGE_ITEM_MARGIN_BOTTON); + SetTouchable(true); + + icon_.SetPosition(SETTING_PAGE_ITEM_ICON_X, SETTING_PAGE_ITEM_ICON_Y); + icon_.Resize(SETTING_PAGE_ITEM_ICON_WIDTH, SETTING_PAGE_ITEM_ICON_HEIGHT); + icon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + icon_.SetAutoEnable(false); + icon_.SetResizeMode(UIImageView::SCALE_DOWN); + + textLabel_.SetPosition(SETTING_PAGE_INPAGE_TLABEL_X, SETTING_PAGE_INPAGE_LABEL_Y); + textLabel_.Resize(0, SETTING_PAGE_INPAGE_LABEL_WIDTH); + textLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + textLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + textLabel_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + textLabel_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + textLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_PAGE_ITEM_LABEL_FSIZE); + + dataLabel_.Resize(0, SETTING_PAGE_INPAGE_LABEL_WIDTH); + dataLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + dataLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + dataLabel_.SetStyle(STYLE_TEXT_OPA, SETTING_PAGE_INPAGE_DLABEL_OPA); + dataLabel_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + dataLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_PAGE_ITEM_LABEL_FSIZE); + + nextImage_.SetPosition(SETTING_PAGE_INPAGE_IMAGE_X, SETTING_PAGE_INPAGE_IMAGE_Y); + nextImage_.Resize(SETTING_PAGE_INPAGE_IMAGE_WIDTH, SETTING_PAGE_INPAGE_IMAGE_HEIGHT); + LOADIMG::LoadImageViewImg(&nextImage_, SETTING_IMAGE, IMAGE_MAIN_LIST_ARROW); + nextImage_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + nextImage_.SetAutoEnable(false); + nextImage_.SetResizeMode(UIImageView::SCALE_DOWN); + + Add(&icon_); + Add(&textLabel_); + Add(&dataLabel_); + Add(&nextImage_); +} + +IconTextNavigationItemView::~IconTextNavigationItemView() +{ + Remove(&icon_); + Remove(&textLabel_); + Remove(&dataLabel_); + Remove(&nextImage_); +} + +void IconTextNavigationItemView::UpdateViewData(IconTextNavigationItemData* data) +{ + if (data != nullptr) { + SetStyle(STYLE_BACKGROUND_COLOR, data->bgColor.full); + SetStyle(STYLE_BACKGROUND_OPA, data->bgOpa); + icon_.SetSrc(CacheImage(data->icon)); + textLabel_.SetText(data->textContent); + dataLabel_.SetVisible(false); + if (data->dataContent != nullptr) { + dataLabel_.SetPosition( + SETTING_PAGE_INPAGE_TLABEL_X + textLabel_.GetTextWidth() + SETTING_PAGE_INPAGE_DLABEL_X_OFFSET, + SETTING_PAGE_INPAGE_LABEL_Y); + dataLabel_.SetText(data->dataContent); + dataLabel_.SetVisible(true); + } + nextImage_.SetVisible(data->hasSecondMenu); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingAboutModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingAboutModel.cpp new file mode 100644 index 000000000..e2d871e24 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingAboutModel.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingAboutModel + * Create: 2025-06-01 + */ +#include "bts_br_gap.h" +#if !defined(_WIN32) +#include "nv.h" +#endif +#include "nv_config/include/common.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingAboutModel.h" + +namespace OHOS { +constexpr static uint8_t SYS_NAME_LEN = 32; + +std::string SettingAboutModel::GetSystemName() +{ +#if !defined(_WIN32) + unsigned char sysName[SYS_NAME_LEN] = ""; + unsigned char sysNameLen = SYS_NAME_LEN; + if (bluetooth_get_local_name(sysName, &sysNameLen) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutModel::GetSystemName error"); + return ""; + } + return std::string((const char*)sysName); +#else + return std::string("WATCH 2 0322"); +#endif +} + +std::string SettingAboutModel::GetSystemType() +{ +#if !defined(_WIN32) + sys_product_info_t info = {0}; + uint16_t nvsize = 0; + errcode_t ret = uapi_nv_read(NV_ID_SYS_PRODUCT_INFO, sizeof(sys_product_info_t), &nvsize, (uint8_t *)&info); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutModel::GetSystemType error, ret=%u", ret); + return ""; + } + if (nvsize < sizeof(sys_product_info_t) || info.size == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "invalid system type: nvsize=%u, info.size=%u", nvsize, info.size); + return ""; + } + return std::string((const char*)info.name); +#else + return std::string("WATCH-BX9"); +#endif +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothHeadsetEvent.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothHeadsetEvent.cpp new file mode 100644 index 000000000..e9070b6eb --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothHeadsetEvent.cpp @@ -0,0 +1,479 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBluetoothHeadsetEvent + * Create: 2022-3-22 + */ + +#include "settings/model/SettingBluetoothHeadsetEvent.h" +#include "bts_avrcp_target.h" +#include "bts_avrcp_controller.h" +#include "player/PlayersModel.h" +#include "graphic_service.h" + +using namespace OHOS; + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRCP_CT_AUTO_REG_TYPE 1 +uint8_t g_avrcp_tg_local_media_vol = AVRCP_ABSOLUTE_VOLUME_INVALID; +#define BT_A2DP_MEDIA_VOL_LEVEL 100 + +bt_avrcp_tg_bts_cbk g_avrcp_tg_audio_cb; +avrcp_ct_callbacks_t g_avrcp_ct_cb; +avrcp_tg_callbacks_t g_avrcp_tg_cb; +SettingBtAvrcpTgInf g_avrcp_srv_inf; + +void SettingBtAvrcpVolumeChangedSyncMedia(uint8_t a2dp_volume) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[SettingBtAvrcpVolumeChangedSyncMedia]::a2dp_volume = 0x%x\r\n", a2dp_volume); + int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_A2DP_MUSIC, audio_volume); /* 设置增益音量 */ + g_avrcp_tg_local_media_vol = a2dp_volume; + avrcp_tg_notify_volume_changed(a2dp_volume); +} + +/* tg通知媒体状态 */ +static void SettingBtAvrcpTgNotifyMeidaStatus(bt_avrcp_tg_evt_status_param *notifyEventStatusParam) +{ + if (notifyEventStatusParam == nullptr || notifyEventStatusParam->event_id >= AVRCP_NOTIFY_EVENT_RESERVED) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SettingBtAvrcpTgNotifyMeidaStatus] param is error"); + return; + } + switch (notifyEventStatusParam->event_id) { + case AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED: + avrcp_tg_notify_playback_status_changed(*(td_u8 *)notifyEventStatusParam->event_status); + break; + case AVRCP_NOTIFY_EVENT_TRACK_CHANGED: + avrcp_tg_notify_track_changed(*(unsigned long long *)notifyEventStatusParam->event_status); + break; + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_END: + avrcp_tg_notify_track_reached_end(); + break; + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_START: + avrcp_tg_notify_track_reached_start(); + break; + case AVRCP_NOTIFY_EVENT_PLAYBACK_POS_CHANGED: + avrcp_tg_notify_playback_pos_changed(*(td_u32 *)notifyEventStatusParam->event_status); + break; + case AVRCP_NOTIFY_EVENT_BATT_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_SYSTEM_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_NOW_PLAYING_CONTENT_CHANGED: + avrcp_tg_notify_now_playing_content_changed(); + break; + case AVRCP_NOTIFY_EVENT_AVAILABLE_PLAYERS_CHANGED: + avrcp_tg_notify_available_players_changed(); + break; + case AVRCP_NOTIFY_EVENT_ADDRESSED_PLAYER_CHANGED: + avrcp_tg_notify_addressed_players_changed(*(td_u16 *)notifyEventStatusParam->event_status, + *(td_u16 *)(notifyEventStatusParam->event_status + sizeof(td_u16))); + break; + case AVRCP_NOTIFY_EVENT_UIDS_CHANGED: + avrcp_tg_notify_uid_changed(*(td_u16 *)notifyEventStatusParam->event_status); + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: + SettingBtAvrcpVolumeChangedSyncMedia(notifyEventStatusParam->event_status[0]); + break; + case AVRCP_NOTIFY_EVENT_RESERVED: + break; + default: + break; + } +} + +void SettingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SettingPressButtonStatusCallback]::keyValue = 0x%x keyOperation = 0x%x", + keyValue, keyOperation); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(SettingUsingPressButtonStatusCallback, keyOperation, keyValue)); +} + +void SettingBtAvrcpTgNotifyVolumeChangedProc(uint8_t a2dp_volume) +{ + int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "NotifyVolume = %d", audio_volume); + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, audio_volume); // 耳机连接手表场景调节手表音量 +} + +void SettingUsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) +{ + bt_avrcp_tg_evt_status_param event; + switch (keyOperation) { + case AVRCP_KEY_VOLUME_UP: // 耳机控制手表加减音量不走key_operation事件 + case AVRCP_KEY_VOLUME_DOWN: // 减小音量 + break; + case AVRCP_KEY_MUTE: // 静音 + event.event_status[0] = AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_0; + event.event_id = AVRCP_NOTIFY_EVENT_VOLUME_CHANGED; + break; + case AVRCP_KEY_PLAY: // 播放 + (void)PlayersModel::GetInstance()->PlayerPlay(); + event.event_status[0] = AVRCP_PLAY_STATUS_PLAYING; + event.event_id = AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED; + break; + case AVRCP_KEY_STOP: // 停止 + (void)PlayersModel::GetInstance()->PlayerStop(); + event.event_status[0] = AVRCP_PLAY_STATUS_STOPPED; + event.event_id = AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED; + break; + case AVRCP_KEY_PAUSE: // 暂停 + (void)PlayersModel::GetInstance()->PlayerPause(); + event.event_status[0] = AVRCP_PLAY_STATUS_PAUSED; + event.event_id = AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED; + break; + case AVRCP_KEY_FORWARD: // 下一曲 + PlayersModel::GetInstance()->LoopingPlayout(); + event.event_status[0] = AVRCP_PLAY_STATUS_FWD_SEEK; + event.event_id = AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED; + break; + case AVRCP_KEY_BACKWARD: // 上一曲 + PlayersModel::GetInstance()->PreviousPlayout(); + event.event_status[0] = AVRCP_PLAY_STATUS_REV_SEEK; + event.event_id = AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED; + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: + /* 手机连接手表场景,控制手表喇叭声音 */ + event.event_status[0] = keyValue; + event.event_id = AVRCP_NOTIFY_EVENT_VOLUME_CHANGED; + SettingBtAvrcpTgNotifyVolumeChangedProc((uint8_t)keyValue); + default: + break; + } + + SettingBtAvrcpTgNotifyMeidaStatus(&event); +} + +uint8_t SettingBtAvrcpTgGetLocMediaVolume(void) +{ + if (g_avrcp_tg_local_media_vol == AVRCP_ABSOLUTE_VOLUME_INVALID) { + int32_t audio_volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_A2DP_MUSIC); + uint8_t a2dp_volume = (uint8_t)(audio_volume * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / BT_A2DP_MEDIA_VOL_LEVEL); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audio_volume 0x%x, a2dp_volume 0x%x\n", audio_volume, a2dp_volume); + g_avrcp_tg_local_media_vol = a2dp_volume; + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get local media volume, a2dp_volume = 0x%x", g_avrcp_tg_local_media_vol); + return g_avrcp_tg_local_media_vol; +} + +void SettingMediaStatusCallback(bt_avrcp_tg_evt_status_param *eventStatusParam) +{ + if (eventStatusParam == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "eventStatusParam is nullptr"); + return; + } + + int32_t playerStatus = PlayersModel::GetInstance()->GetPlayerstatus(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerStatus = %d", playerStatus); + + switch (eventStatusParam->event_id) { + case AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED: + eventStatusParam->event_status[0] = playerStatus; + break; + case AVRCP_NOTIFY_EVENT_TRACK_CHANGED: + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_END: + break; + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_START: + break; + case AVRCP_NOTIFY_EVENT_PLAYBACK_POS_CHANGED: + eventStatusParam->event_status[0] = 0xFF; + break; + case AVRCP_NOTIFY_EVENT_BATT_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_SYSTEM_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_NOW_PLAYING_CONTENT_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_AVAILABLE_PLAYERS_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_ADDRESSED_PLAYER_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_UIDS_CHANGED: + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: + eventStatusParam->event_status[0] = SettingBtAvrcpTgGetLocMediaVolume(); + break; + case AVRCP_NOTIFY_EVENT_RESERVED: + break; + default : + break; + } +} + +void SettingConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct update conn stat:%u", state); + if (bdAddr == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bdaddr nullptr"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingConnCtStateChangedCallback addr: %02x%02x%02x%02x%02x%02x ", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* 2 1 0 idx */ + (void)memcpy_s(g_avrcp_srv_inf.bd_addr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + g_avrcp_srv_inf.avrcp_srv_conn_stat = state; +} + +static bd_addr_t *SettingBtAvrcpSrvGetActiveAddr(void) +{ + return &g_avrcp_srv_inf.bd_addr; +} + +void SettingConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp tg update conn stat:%u", state); + if (bdAddr == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bdaddr nullptr"); + return; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingConnCtStateChangedCallback addr: %02x%02x%02x%02x%02x%02x ", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* 2 1 0 idx */ + (void)memcpy_s(g_avrcp_srv_inf.bd_addr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + g_avrcp_srv_inf.avrcp_srv_conn_stat = state; + + /* 手表耳机链接场景时,耳机控制音量是一个事件而非key_operation,故需要在手表侧向耳机注册音量变更事件 */ + if (state == PROFILE_STATE_CONNECTED) { + (void)avrcp_ct_get_supported_events(SettingBtAvrcpSrvGetActiveAddr()); + } +} + +static void SettingBtAvrcpCtPressButtonRspCallback(const bd_addr_t *bd_addr, int32_t key_operation) +{ + if (bd_addr == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + if (g_avrcp_srv_inf.avrcp_button_flag == SETTING_AVRCP_SRV_RELEASED_VALUE) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct press button button_flag change:%u->%u\n", + g_avrcp_srv_inf.avrcp_button_flag, SETTING_AVRCP_SRV_PRESS_VALUE); + g_avrcp_srv_inf.avrcp_button_flag = SETTING_AVRCP_SRV_PRESS_VALUE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct press button cbk key:%d button_flag:%u\n", + key_operation, g_avrcp_srv_inf.avrcp_button_flag); +} + +static void SettingBtAvrcpPressReleaseButtonLog(uint32_t key_operation) +{ + switch (key_operation) { + case AVRCP_KEY_VOLUME_UP: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_VOLUME_UP\n"); + break; + case AVRCP_KEY_VOLUME_DOWN: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_VOLUME_DOWN\n"); + break; + case AVRCP_KEY_MUTE: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_VOLUME_MUTE\n"); + break; + case AVRCP_KEY_PLAY: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_PLAY\n"); + break; + case AVRCP_KEY_STOP: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_STOP\n"); + break; + case AVRCP_KEY_PAUSE: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_PAUSE\n"); + break; + case AVRCP_KEY_FORWARD: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_FORWARD\n"); + break; + case AVRCP_KEY_BACKWARD: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_KEY_BACKWARD\n"); + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AVRCP_EVENT_VOLUME_CHANGED\n"); + break; + default: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "invalid\n"); + break; + } +} + +static void SettingBtAvrcpCtReleaseButtonRspCallback(const bd_addr_t *bd_addr, int32_t key_operation) +{ + UNUSED(bd_addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct release button cbk key:%d\n", key_operation); + if (g_avrcp_srv_inf.avrcp_button_flag == SETTING_AVRCP_SRV_PRESS_VALUE) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct released button button_flag change:%u->%u\n", + g_avrcp_srv_inf.avrcp_button_flag, SETTING_AVRCP_SRV_RELEASED_VALUE); + g_avrcp_srv_inf.avrcp_button_flag = SETTING_AVRCP_SRV_RELEASED_VALUE; + } + SettingBtAvrcpPressReleaseButtonLog((uint32_t)key_operation); +} + +static void SettingBtAvrcpCtSupportCompanyCallback(const bd_addr_t *bd_addr, avrcp_ct_support_company_para_t *company) +{ + if (bd_addr == nullptr || company == nullptr || company->company_id == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "get company list:"); + for (uint8_t i = 0; i < company->company_num; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " 0x%x ", *company->company_id); + } +} + +static void SettingBtAvrcpCtSupportEventCallback(const bd_addr_t *bd_addr, avrcp_ct_support_event_para_t *event) +{ + if (bd_addr == nullptr || event == nullptr || event->event_id == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + + for (uint8_t i = 0; i < event->event_num; i++) { + if (event->event_id[i] == AVRCP_NOTIFY_EVENT_VOLUME_CHANGED) { + int ret = avrcp_ct_register_notification(bd_addr, event->event_id[i], 0); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); + } + } + + for (uint8_t i = 0; i < event->event_num; i++) { + if (event->event_id[i] != AVRCP_NOTIFY_EVENT_VOLUME_CHANGED) { + int ret = avrcp_ct_register_notification(bd_addr, event->event_id[i], 0); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); + } + } +} + +static void SettingBtAvrcpCtGetElementAttriCallback(const bd_addr_t *bd_addr, avrcp_ct_element_attr_para_cb_t *attr_cb_para) +{ + if (bd_addr == nullptr || attr_cb_para == nullptr || attr_cb_para->attr_value == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + + for (uint8_t i = 0; i < attr_cb_para->attr_num; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "attrId-charaId-valLen: 0x%x-0x%x-%u \n", + attr_cb_para->attr_value[i].attr_id, + attr_cb_para->attr_value[i].character_set_id, + attr_cb_para->attr_value[i].value_len); + switch (attr_cb_para->attr_value[i].attr_id) { + case AVRCP_CT_ELEMENT_ATTR_TITLE: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Title:"); + break; + case AVRCP_CT_ELEMENT_ATTR_ARTIST_NAME: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Name:"); + break; + case AVRCP_CT_ELEMENT_ATTR_ALBUM_NAME: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Album:"); + break; + case AVRCP_CT_ELEMENT_ATTR_TRACK_NUMBER: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Track Number:"); + break; + case AVRCP_CT_ELEMENT_ATTR_TOTAL_NUMBER_OF_TRACKS: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Total Number Of Track:"); + break; + case AVRCP_CT_ELEMENT_ATTR_TRACK_GENRE: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Track GENRE:"); + break; + case AVRCP_CT_ELEMENT_ATTR_TRACK_PLAYING_TIME: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attr Track Playing Time_ms:"); + break; + default: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Other:"); + break; + } + + uint8_t *value = (uint8_t *)(void *)malloc(attr_cb_para->attr_value[i].value_len + 1); + if (attr_cb_para->attr_value[i].value_len > 0 && attr_cb_para->attr_value[i].value != nullptr) { + if (memcpy_s(value, attr_cb_para->attr_value[i].value_len, + attr_cb_para->attr_value[i].value, attr_cb_para->attr_value[i].value_len) != EOK) { + free(value); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s fail."); + return; + } + } + value[attr_cb_para->attr_value[i].value_len] = '\0'; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " %s \n", value); + free(value); + } +} + +static void SettingBtAvrcpCtGetPlayStatusCallback(const bd_addr_t *bd_addr, avrcp_ct_play_status_cb_t *status) +{ + if (bd_addr == nullptr || status == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "test get play status songlen:%u, songpos:%u, playstatus:%u:", + status->song_length, status->song_position, status->play_status); +} + +static void SettingBtAvrcpCtHdlNotifyVolumeRspCbk(avrcp_ct_notification_value_cb_t *notification) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Set local volume: 0x%x\n", notification->volume); /* 注册事件后通知的音量 */ + SettingBtAvrcpTgNotifyVolumeChangedProc((uint8_t)notification->volume); +} + +static void SettingBtAvrcpCtNotificationCallback( + const bd_addr_t *bd_addr, avrcp_notify_event_t event_id, avrcp_ct_notification_value_cb_t *notification) +{ + if (bd_addr == nullptr || notification == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); + return; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ct notification cbk event_id:0x%x\n", event_id); + bool notify_flag = true; + switch (event_id) { + case AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "tg notify ct playback status changed :%u\n", + notification->play_status); + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: + SettingBtAvrcpCtHdlNotifyVolumeRspCbk(notification); + break; + case AVRCP_NOTIFY_EVENT_NOW_PLAYING_CONTENT_CHANGED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "play conent changed event_id:0x%x\n", event_id); + break; + case AVRCP_NOTIFY_EVENT_TRACK_CHANGED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "track changed event_id:0x%x\n", event_id); + break; + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_END: + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_START: + case AVRCP_NOTIFY_EVENT_PLAYBACK_POS_CHANGED: + case AVRCP_NOTIFY_EVENT_BATT_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_SYSTEM_STATUS_CHANGED: + case AVRCP_NOTIFY_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: + case AVRCP_NOTIFY_EVENT_AVAILABLE_PLAYERS_CHANGED: + case AVRCP_NOTIFY_EVENT_ADDRESSED_PLAYER_CHANGED: + case AVRCP_NOTIFY_EVENT_UIDS_CHANGED: + case AVRCP_NOTIFY_EVENT_RESERVED: + default: + notify_flag = false; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "invalid event id event_id:0x%x\n", event_id); + break; + } + if (notify_flag) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "notify reg event_id: 0x%x\n", event_id); + avrcp_ct_register_notification(bd_addr, event_id, 0); /* TG通知变化后CT重新注册事件 */ + } +} + +void SettingInitBtHeadsetEvent() +{ + g_avrcp_tg_audio_cb.notify_pass_through_status_cbk = SettingPressButtonStatusCallback; + g_avrcp_tg_audio_cb.get_media_status_cbk = SettingMediaStatusCallback; + + g_avrcp_tg_cb.conn_state_changed_cb = SettingConnectTgStateChangedCallback; + + g_avrcp_ct_cb.conn_state_changed_cb = SettingConnCtStateChangedCallback; + g_avrcp_ct_cb.press_button_cb = SettingBtAvrcpCtPressButtonRspCallback; + g_avrcp_ct_cb.release_button_cb = SettingBtAvrcpCtReleaseButtonRspCallback; + g_avrcp_ct_cb.supported_companies_cb = SettingBtAvrcpCtSupportCompanyCallback; + g_avrcp_ct_cb.supported_event_cb = SettingBtAvrcpCtSupportEventCallback; + g_avrcp_ct_cb.element_attr_cb = SettingBtAvrcpCtGetElementAttriCallback; + g_avrcp_ct_cb.play_status_cb = SettingBtAvrcpCtGetPlayStatusCallback; + g_avrcp_ct_cb.notification_cb = SettingBtAvrcpCtNotificationCallback; + + avrcp_tg_register_callbacks(&g_avrcp_tg_cb); + avrcp_ct_register_callbacks(&g_avrcp_ct_cb); + bt_avrcp_tg_register_audio_cbk(&g_avrcp_tg_audio_cb); +} +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothModel.cpp new file mode 100644 index 000000000..f5232433d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingBluetoothModel.cpp @@ -0,0 +1,1438 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSettingBluetoothModel + * Created: 2025-06-05 + */ + +#include +#include "bluetooth/BluetoothWrapper.h" +#include "player/PlayersModel.h" +#include "phoneservice/PhoneAudio.h" +#include "graphic_service.h" +#include "msg_center.h" +#include "bts_def.h" +#include "bts_gatt_stru.h" +#include "bts_a2dp_source.h" +#include "bts_gatt_server.h" +#include "bts_le_gap.h" +#include "bts_spp.h" +#include "osal_task.h" +#ifdef SUPPORT_ALIPAY_SEC +#include "alipay_feature.h" +#endif +#include "bts_a2dp_sink.h" +#include "bts_feature.h" +#include "bt_audio_hal_interface.h" +#include "audio_manager_c_wrapper.h" +#include "bts_avrcp_target.h" +#include "msg_center_msg.h" +#include "client/msg_center_client.h" +#include "msg_center_protocol.h" +#include "dfx_channel.h" +#include "tcxo.h" +#include "uiservice/ui_service.h" +#include "network/network_listener.h" +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) +#include "lwip_driver_adapter.h" +#endif +#include "main/PullUpDownView.h" +#include "settings/common/SettingCommon.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingConnectionOpen.h" +#include "findphone/FindPhoneMainPage.h" +#include "bluetooth/BluetoothChangeBle.h" +#include "settings/model/SettingBluetoothModel.h" + +namespace OHOS { +constexpr uint16_t SETTING_BLUETOOTH_CONN_HANDLE = 64; +constexpr uint16_t SETTING_BLUETOOTH_INTERVAL_TOMAX_MIN = 12; +constexpr uint16_t SETTING_BLUETOOTH_INTERVAL_TOMAX_MAX = 12; +constexpr uint16_t SETTING_BLUETOOTH_INTERVAL_TODEFAULT_MIN = 24; +constexpr uint16_t SETTING_BLUETOOTH_INTERVAL_TODEFAULT_MAX = 48; +constexpr uint16_t SETTING_BLUETOOTH_LATENCY = 0; +constexpr uint16_t SETTING_BLUETOOTH_TIMEOUT_MUTIPLIER = 500; +#define BT_SPP_TASK_STACK_SIZE 2048 +#define BT_SPP_TASK_PRI 20 +#define TEN 10 + +static constexpr uint16_t BLUETOOTH_MAX_NUM = 20; +static constexpr int16_t SETTING_ADDR2 = 2; +static constexpr int16_t SETTING_ADDR3 = 3; +static constexpr int16_t SETTING_ADDR4 = 4; +static constexpr int16_t SETTING_ADDR5 = 5; +static constexpr int16_t BLUETOOTH_ADDR_SET = 8; +static constexpr int16_t WRITECB_PARA_LEGNTH_TWO = 2; +static constexpr int16_t WRITECB_PARA_LEGNTH_NINE = 9; +static constexpr int16_t WRITECB_PARA_LEGNTH_TEN = 10; +static constexpr int16_t WAIT_TIME = 50; +#define MEDIA_A2DP_SNK_INTERFACE 1 +#define A2DP_STREAM_ACCEPT_TIMER_PERIOD 500 +osal_timer g_setting_a2dp_stream_accept_timer = {nullptr, nullptr, 0, 0}; +AudioFormatConfig g_setting_audio_format_config = {AUDIO_DEFAULT, 0, 0}; +static uint16_t g_sample_svr_handle = 0; +static uint16_t g_sample_characteristic_handle = 0; +static uint16_t g_diag_characteristic_handle = 0; +static uint16_t g_diag_desc_handle = 0; +constexpr uint16_t g_sample_adv_id = 2; +static bd_addr_t g_bd_addr = { 0 }; + +SettingBluetoothModel::SettingBluetoothModel() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel::SettingBluetoothModel"); +} + +SettingBluetoothModel *SettingBluetoothModel::GetInstance(void) +{ + static SettingBluetoothModel instance; + return &instance; +} + +char* SettingBluetoothModel::GetWatchName(void) +{ + return watchName_; +} + +// 扫描设备 btEarPhoneList存在数据 设置为1 否则设置为0 +void SettingBluetoothModel::SetEarPhoneListHasData(bool status) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel EarPhoneListHasData_ = %d", status); + EarPhoneListHasData_ = status; +} + +uint32_t SettingBluetoothModel::GetEarPhoneListHasData() +{ + return EarPhoneListHasData_; +} + +void SettingBluetoothModel::SetDeviceName(std::string deviceName) +{ + deviceName_ = deviceName; +} + +std::string SettingBluetoothModel::GetDeviceName() +{ + return deviceName_; +} + +void SettingBluetoothModel::SetBlueToothConnectStatus(bool status) +{ + btConnectStatus_ = status; +} + +bool SettingBluetoothModel::GetBlueToothConnectStatus(void) +{ + return btConnectStatus_; +} + +void SettingBluetoothModel::SetConnectFragmentStatus(bool status) +{ + connectFragmentStatus_ = status; +} + +bool SettingBluetoothModel::GetConnectFragmentStatus(void) +{ + return connectFragmentStatus_; +} + +void SettingBluetoothModel::MoveMatchingDeviceToFront() +{ + std::list matchedItems; + std::list otherItems; + if(btScansDevicesList_.size() == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MoveMatchingDeviceToFront btScansDevicesList_ size = 0"); + return; + } + bd_addr_t bdAddr = *(GetLastConnedAddr()); + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); ++it) { + if ((bdAddr.addr[0] == it->addr[0]) && (bdAddr.addr[1] == it->addr[1]) + && (bdAddr.addr[SETTING_ADDR2] == it->addr[SETTING_ADDR2]) + && (bdAddr.addr[SETTING_ADDR3] == it->addr[SETTING_ADDR3]) + && (bdAddr.addr[SETTING_ADDR4] == it->addr[SETTING_ADDR4]) + && (bdAddr.addr[SETTING_ADDR5] == it->addr[SETTING_ADDR5])) { + matchedItems.push_back(*it); + } else { + otherItems.push_back(*it); + } + } + + btScansDevicesList_.clear(); + btScansDevicesList_.insert(btScansDevicesList_.begin(), matchedItems.begin(), matchedItems.end()); + btScansDevicesList_.insert(btScansDevicesList_.end(), otherItems.begin(), otherItems.end()); +} + +void SettingBluetoothModel::UpdateConnectStatusForDevice() +{ + for (auto& item : btScansDevicesList_) { + if (std::strcmp(reinterpret_cast(item.deviceName), deviceName_.c_str()) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateConnectStatusForDevice deviceName:%s", item.deviceName); + item.connect_status = "连接中..."; + } + } +} + +void SettingBluetoothModel::UpdateDisconnectStatusForDevice(const bd_addr_t &bdAddr) +{ + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); ++it) { + if ((bdAddr.addr[0] == it->addr[0]) && (bdAddr.addr[1] == it->addr[1]) + && (bdAddr.addr[SETTING_ADDR2] == it->addr[SETTING_ADDR2]) + && (bdAddr.addr[SETTING_ADDR3] == it->addr[SETTING_ADDR3]) + && (bdAddr.addr[SETTING_ADDR4] == it->addr[SETTING_ADDR4]) + && (bdAddr.addr[SETTING_ADDR5] == it->addr[SETTING_ADDR5])) { + it->connect_status = "连接已经断开"; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UpdateDisconnectStatusForDevice addr: %02x%02x%02x%02x%02x%02x", + it->addr[SETTING_ADDR5], it->addr[SETTING_ADDR4], it->addr[SETTING_ADDR3], + it->addr[SETTING_ADDR2], it->addr[1], it->addr[0]); + } + } +} + +void SettingBluetoothModel::UpdateConnectedStatusForDevice(const bd_addr_t &bdAddr) +{ + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); ++it) { + if ((bdAddr.addr[0] == it->addr[0]) && (bdAddr.addr[1] == it->addr[1]) + && (bdAddr.addr[SETTING_ADDR2] == it->addr[SETTING_ADDR2]) + && (bdAddr.addr[SETTING_ADDR3] == it->addr[SETTING_ADDR3]) + && (bdAddr.addr[SETTING_ADDR4] == it->addr[SETTING_ADDR4]) + && (bdAddr.addr[SETTING_ADDR5] == it->addr[SETTING_ADDR5])) { + it->connect_status = "已连接"; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UpdateConnectedStatusForDevice addr: %02x%02x%02x%02x%02x%02x", + it->addr[SETTING_ADDR5], it->addr[SETTING_ADDR4], it->addr[SETTING_ADDR3], + it->addr[SETTING_ADDR2], it->addr[1], it->addr[0]); + } + } +} + +bool SettingBluetoothModel::GetConnectResultPage() +{ + return redirct_; +} + +void SettingBluetoothModel::HandleUnpairRequest(void) +{ + bool ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingSettingBluetoothModel::HandleUnpairRequest lastConnedAddr_: %02x%02x%02x%02x%02x%02x", + selectedDeviceInfo_.addr[SETTING_ADDR5], selectedDeviceInfo_.addr[SETTING_ADDR4], selectedDeviceInfo_.addr[SETTING_ADDR3], + selectedDeviceInfo_.addr[SETTING_ADDR2], selectedDeviceInfo_.addr[1], selectedDeviceInfo_.addr[0]); + ret = gap_remove_pair((const bd_addr_t*)&selectedDeviceInfo_.addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingSettingBluetoothModel::HandleUnpairRequest gap_remove_pair %d", ret); +} + +// 是否需要显示连接成功/失败的页面 在连接新耳机或者断开耳机连接时改变为true +void SettingBluetoothModel::SetConnectResultPage(bool redirct) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBuletoothModel::SetRedirect :%d", redirct); + redirct_ = redirct; +} + +void SettingBluetoothModel::InitBluetoothInfo(void) +{ + errcode_t ret; + unsigned char nameLen = BD_NAME_LEN; + memset_s(watchName_, sizeof(watchName_), 0, sizeof(watchName_)); + ret = bluetooth_get_local_name((unsigned char *)watchName_, &nameLen); + // 为了实验室测试需要,客户需要自己修改 + if ((nameLen == strlen("WatchDemo") + 1) && (strcmp("WatchDemo", watchName_) == 0)) { + uint32_t currentUs = uapi_tcxo_get_us(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "currentUs 0x%x", currentUs); + // 设置蓝牙名称 + (void)sprintf_s(watchName_, sizeof(watchName_), "Watch%x", (currentUs & 0xFFFF)); + ret = bluetooth_set_local_name((unsigned char*)watchName_, strlen((char*)watchName_) + 1); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_set_local_name %s ret = %u", watchName_, ret); + + // 设置蓝牙地址 + bd_addr_t addr = {{0x1C, 0x1D, 0x2B, 0x0, 0x0, 0x0} ,0}; + addr.addr[3] = currentUs & 0xFF; + addr.addr[4] = (currentUs & 0XFF00) >> 8; + addr.addr[5] = currentUs & 0xFF; + ret = bluetooth_set_local_addr(addr.addr, BD_ADDR_LEN); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_set_local_addr [0x%x:0x%x] ret = %u", addr.addr[0], addr.addr[1], ret); + } else { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "watchName_: %s", watchName_); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "nameLen: %u", nameLen); + } +} + +void SettingBluetoothModel::Init() +{ +#ifndef SUPPORT_AUTO_OTA + errcode_t ret; + + // 设置自动回连,ios一键双连依赖此配置 + bts_feature_t bts_feature = { 0 }; + bts_feature.bt_auto_reconnect_closed = 0; + ret = bts_set_features(&bts_feature); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = %u", ret); + + ret = enable_bt_stack(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %u", ret); + + // 设置安全连接 + gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 1, GAP_BLE_GAP_SECURITY_MODE1_LEVEL3 }; + ret = gap_ble_set_sec_param(&sec_param); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_ble_set_sec_param ret = %u", ret); + + InitBluetoothInfo(); + SettingBtInitCallBacks(); + wrapper_ble_register(); +#ifdef SUPPORT_ALIPAY_SEC + svr_alipay_bluetooth_init(); +#endif + SettingBtInitCallBacksEx(); + SettingBtInitGatts(); + SettingBtInitSpp(); + + /* 实验室测试需要,开机开广播 */ + BleSettingAdvStart(); + + ClearScansDevicesList(); + SetUpPairedDevicesList(); +#endif +} + +void SettingBluetoothModel::ClearScansDevicesList() +{ + btScansDevicesList_.clear(); +} + +bool SettingBluetoothModel::CheckExistScanList(BtCaseInfo caseInfo) +{ + std::list::iterator node = btScansDevicesList_.begin(); + if (btScansDevicesList_.empty()) { + return false; + } + while (node != btScansDevicesList_.end()) { + if ((caseInfo.addr[0] == node->addr[0]) && (caseInfo.addr[1] == node->addr[1]) + && (caseInfo.addr[2] == node->addr[2]) && (caseInfo.addr[3] == node->addr[3]) + && (caseInfo.addr[4] == node->addr[4]) && (caseInfo.addr[5] == node->addr[5])) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "true"); + return true; + } + node++; + } + return false; +} + +std::list& SettingBluetoothModel::GetScansDevicesList() +{ + return btScansDevicesList_; +} + +void SettingBluetoothModel::ScansDevicesListAddCase(BtCaseInfo caseInfo) +{ + SetEarPhoneListHasData(true); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ScansDevicesListAddCase::caseInfo addr: %02x%02x%02x%02x%02x%02x", + caseInfo.addr[5], caseInfo.addr[4], caseInfo.addr[3], /* mac下标 0 1 2 3 4 5 */ + caseInfo.addr[2], caseInfo.addr[1], caseInfo.addr[0]); + if (btScansDevicesList_.size() >= BLUETOOTH_MAX_NUM) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "btScansDevicesList_.size is BLUETOOTH_MAX_NUM"); + return; + } else { + btScansDevicesList_.push_back(caseInfo); + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel::ScansDevicesListAddCase after size: %d", btScansDevicesList_.size()); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel::ScansDevicesListAddCase %s", caseInfo.deviceName); +} + +void SettingBluetoothModel::SetScansCaseRssi(const bd_addr_t *bdAddr, int rssi) +{ + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); it++) { + if ((it->addr[0] == bdAddr->addr[0]) && (it->addr[1] == bdAddr->addr[1]) + && (it->addr[2] == bdAddr->addr[2]) && (it->addr[3] == bdAddr->addr[3]) + && (it->addr[4] == bdAddr->addr[4]) && (it->addr[5] == bdAddr->addr[5])) { + it->rssi = rssi; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "btScansDevicesList_ rssi:%d deviceName:%s", it->rssi, it->deviceName); + } + } +} + + +bool CompBuletoothInfo(const BtCaseInfo& a, const BtCaseInfo& b) +{ + if (a.rssi > b.rssi) { + return true; + } + return false; +} + +void SettingBluetoothModel::SortScansCaseRssi() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel::SortScansCaseRssi"); + btScansDevicesList_.sort(CompBuletoothInfo); +} + +void SettingBluetoothModel::ResetScanDevicesCase(const BtCaseInfo& caseInfo) +{ + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); it++) { + if ((it->addr[0] == caseInfo.addr[0]) && (it->addr[1] == caseInfo.addr[1]) + && (it->addr[2] == caseInfo.addr[2]) && (it->addr[3] == caseInfo.addr[3]) + && (it->addr[4] == caseInfo.addr[4]) && (it->addr[5] == caseInfo.addr[5])) { + (void)memcpy_s(it->deviceName, BD_NAME_LEN, + caseInfo.deviceName, BD_NAME_LEN); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResetConnedDevicesCase deviceName:%s", it->deviceName); + } + } +} + +/* 已配对设备队列 */ +void SettingBluetoothModel::SetPairedDevicesListClear() +{ + btPairedDevicesList_->Clear(); +} + +void SettingBluetoothModel::SetUpPairedDevicesList() +{ + if (btPairedDevicesList_ == nullptr) { + btPairedDevicesList_ = new List(); + if (btPairedDevicesList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothModel btPairedDevicesList_ new fail"); + return; + } + SetPairedDevicesListClear(); + unsigned int connedDevicesNum = 0; + bool ret = gap_get_paired_devices_num(&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setup GetPariedDevicesNum ret = %d, num = %d", ret, connedDevicesNum); + + gap_paired_device_info_t *devInfo = (gap_paired_device_info_t*)malloc(sizeof(gap_paired_device_info_t) *connedDevicesNum); + if (devInfo == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DevInfo malloc failed %u", sizeof(gap_paired_device_info_t) *connedDevicesNum); + return; + } + ret = gap_get_paired_devices_list(devInfo, (int *)&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpPairedDevicesList gap_get_paired_devices_list ret = %d", ret); + + BtCaseInfo caseInfo{}; + for (int i = 0; i < static_cast(connedDevicesNum); ++i) { + if ((gap_get_device_class((const bd_addr_t *)devInfo[i].addr.addr) & 0x200) != 0) { + continue; + } + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, devInfo[i].addr.addr, BD_ADDR_LEN); + (void)memcpy_s(caseInfo.deviceName, BD_NAME_LEN, devInfo[i].device_name, BD_NAME_LEN); + caseInfo.connect_status = "连接已经断开"; + AddPairedDevicesCase(caseInfo); + btScansDevicesList_.push_back(caseInfo); + } + free(devInfo); + } +} + +void SettingBluetoothModel::AddPairedDevicesCase(BtCaseInfo caseInfo) +{ + if (btPairedDevicesList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btPairedDevicesList_ nullptr"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddPairedDevicesCase::caseInfo addr: %02x%02x%02x%02x%02x%02x", + caseInfo.addr[5], caseInfo.addr[4], caseInfo.addr[3], /* mac下标 0 1 2 3 4 5 */ + caseInfo.addr[2], caseInfo.addr[1], caseInfo.addr[0]); + if (btPairedDevicesList_->Size() >= BLUETOOTH_MAX_NUM) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "btPairedDevicesList_->Size is BLUETOOTH_MAX_NUM"); + return; + } else { + btPairedDevicesList_->PushBack(caseInfo); + } +} + +List& SettingBluetoothModel::GetPairedDevicesCase() +{ + return *btPairedDevicesList_; +} + +bool SettingBluetoothModel::GetAclConnected(void) +{ + return aclConnected_; +} + +void SettingBluetoothModel::SetAclConnected(bool tag) +{ + aclConnected_ = tag; +} + +void SettingBluetoothModel::UpdateAclConnectStatus(bool status) +{ + aclConnected_ = status; + if (PullUpDownView::GetInstance() != nullptr) { + PullUpDownView::GetInstance()->UpdateBlueToothStatus(status); + } +} + +void SettingBluetoothModel::SetSelectedDeviceInfo(BtCaseInfo *caseInfo) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetSelectedDeviceInfo: %02x%02x%02x%02x%02x%02x", + caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac챐 0 1 2 3 4 5 */ + caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac챐 0 1 2 3 4 5 */ + (void)memcpy_s(selectedDeviceInfo_.addr, BD_ADDR_LEN, + caseInfo->addr, BD_ADDR_LEN); + (void)memcpy_s(selectedDeviceInfo_.deviceName, BD_NAME_LEN, + caseInfo->deviceName, BD_NAME_LEN); +} + +BtCaseInfo *SettingBluetoothModel::GetSelectedDeviceInfo(void) +{ + return &selectedDeviceInfo_; +} + +void SettingBluetoothModel::SetLastConnedAddr(const bd_addr_t *addr) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetLastConnedAddr: %02x%02x%02x%02x%02x%02x", + addr->addr[5], addr->addr[4], addr->addr[3], /* mac챐 0 1 2 3 4 5 */ + addr->addr[2], addr->addr[1], addr->addr[0]); /* mac챐 0 1 2 3 4 5 */ + (void)memcpy_s(lastConnedAddr_.addr, BD_ADDR_LEN, addr->addr, BD_ADDR_LEN); +} + +bd_addr_t *SettingBluetoothModel::GetLastConnedAddr(void) +{ + return &lastConnedAddr_; +} + +bool SettingBluetoothModel::CheckExistPairedList(BtCaseInfo caseInfo) +{ + ListNode *node = btPairedDevicesList_ ->Begin(); + if (node == nullptr) { + return false; + } else if ((caseInfo.addr[0] == 0) && (caseInfo.addr[1] == 0) + && (caseInfo.addr[2] == 0) && (caseInfo.addr[3] == 0) + && (caseInfo.addr[4] == 0) && (caseInfo.addr[5] == 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckExistPairedList false addr: 000000000000"); + return true; + } + while (node != btPairedDevicesList_ ->End()) { + if ((caseInfo.addr[0] == node->data_.addr[0]) && (caseInfo.addr[1] == node->data_.addr[1]) + && (caseInfo.addr[2] == node->data_.addr[2]) && (caseInfo.addr[3] == node->data_.addr[3]) + && (caseInfo.addr[4] == node->data_.addr[4]) && (caseInfo.addr[5] == node->data_.addr[5])) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckExistPairedList true"); + return true; + } + node = node->next_; + } + return false; +} + +void SettingBluetoothModel::AddNodeFromPairListToScanList(const bd_addr_t &bdAddr) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddNodeFromPairListToScanList"); + // 检查扫描设备列表 + for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); ++it) { + if (memcmp(it->addr, bdAddr.addr, sizeof(bdAddr.addr)) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddNodeFromPairListToScanList btScansDevicesList_ true"); + return; + } + } + + // 检查已配对设备列表 + ListNode *node = btPairedDevicesList_->Begin(); + bool found = false; + while (node != btPairedDevicesList_->End()) { + if (memcmp(node->data_.addr, bdAddr.addr, sizeof(bdAddr.addr)) == 0) { + found = true; + break; + } + node = node->next_; + } + + if (found) { + btScansDevicesList_.push_back(node->data_); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btScansDevicesList_ error"); + } +} + +bool SettingBluetoothModel::GetAdvStartState(void) +{ + return advStartState_; +} +void SettingBluetoothModel::SetAdvStartState(bool state) +{ + advStartState_ = state; +} + +int SettingBluetoothModel::ConnectRemoteDevice(const bd_addr_t *addr) +{ + /* 恢厂后耳机连接要开启BT广播否则会导致AVRCP无法音量控制 */ + bool ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE, 60); + if (!ret) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice gap_br_set_bt_scan_mode ret = 0x%x", ret); + } + errcode_t retVal = gap_connect_remote_device(addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice gap_connect_remote_device ret = 0x%x", retVal); + (void)memcpy_s(&remoteConnectAddr_, sizeof(bd_addr_t), addr, sizeof(bd_addr_t)); + return retVal; +} + +bool SettingBluetoothModel::ConnectRemoteCheck(const bd_addr_t *addr) +{ + bool ret; + if ((remoteConnectAddr_.addr[0] == addr->addr[0]) && (remoteConnectAddr_.addr[1] == addr->addr[1]) && + (remoteConnectAddr_.addr[2] == addr->addr[2]) && (remoteConnectAddr_.addr[3] == addr->addr[3]) && + (remoteConnectAddr_.addr[4] == addr->addr[4]) && (remoteConnectAddr_.addr[5] == addr->addr[5])) { + ret = true; + (void)memset_s(&remoteConnectAddr_, sizeof(bd_addr_t), 0, sizeof(bd_addr_t)); + } else { + ret = false; + } + return ret; +} + +#ifdef __cplusplus +extern "C" { +#endif + +// 回调: gap_read_remote_rssi_value 接口的数据上报 +void SettingBtGapReadRemoteRssiEventCallback(const bd_addr_t *bdAddr, int rssi, int status) +{ + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGapReadRemoteRssiEventCallback addr: %02x%02x%02x%02x%02x%02x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + SettingBluetoothModel::GetInstance()->SetScansCaseRssi(bdAddr, rssi); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt SettingBtGapReadRemoteRssiEventCallback SetSortCaseRssi: %d status: %d", rssi, status); +} + +// 回调:发现状态变化上报/扫描结束 +void SettingBtGapDiscoveryStateChangedCallback(int status) +{ + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt SettingBtGapDiscoveryStateChangedCallback %d", status); +} + +static void LoadScanResult() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadScanResult"); + SettingBluetoothPage* bluetoothPage = SettingBluetoothPage::GetInstance(); + if (bluetoothPage == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bluetoothPage nullptr"); + return; + } + bluetoothPage->SetScanStatus(false); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadScanResult::LoadFindDeviceList"); + bluetoothPage->LoadFindDeviceList(); +} + +void SettingBluetoothModel::SettingBtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr) +{ + BtCaseInfo caseInfo{}; + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr.addr, BD_ADDR_LEN); + + unsigned char nameLen = BD_NAME_LEN; + bool getNameRet = gap_get_device_name(&bdAddr, caseInfo.deviceName, &nameLen); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_discovery_result_callback getNameRet(bool): %d nameLen: %d name:%s", + getNameRet, nameLen, caseInfo.deviceName); + + if (nameLen == 0) { // 过滤未扫描到名字的设备 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nameLen == 0 return"); + return; + } + // 去重操作 + bool tag = SettingBluetoothModel::GetInstance()->CheckExistScanList(caseInfo); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckExistScanList ret = %d", tag); + if (!tag) { + SettingBluetoothModel::GetInstance()->ScansDevicesListAddCase(caseInfo); // 增加扫描设备信息 + LoadScanResult(); + bool ret = gap_read_remote_rssi_value(&bdAddr); // 获取rssi + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_read_remote_rssi_value ret = %d", ret); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt SettingBtGapDiscoveryResultCallback end"); +} + +void SettingBtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", + bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], status); /* addr下标 0 1 2 3 */ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GAP_PAIR_PAIRED %d", GAP_PAIR_PAIRED); + if (status == GAP_PAIR_PAIRED) { + if (SettingBluetoothModel::GetInstance()->GetConnectFragmentStatus()) { + SettingBluetoothModel::GetInstance()->SetConnectFragmentStatus(false); + NativeAbility::GetInstance().SwitchPageInSlice(SettingPageId::MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + } +} + +void SettingBtGapPairRequestedCallback(const bd_addr_t *bdAddr) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGapPairRequestedCallback addr: ****%02x%02x%02x%02x\n", + bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* addr下标 0 1 2 3 */ +} + +void SettingBtGapPairConfirmedCallback(const bd_addr_t *bdAddr, int req_type, int number) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGapPairConfirmedCallback addr: ****%02x%02x%02x%02x req_type: %d number: %d\n", + bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], /* addr下标 0 1 2 3 */ + req_type, number); +} + +// 回调:扫描结果处理/发现结果上报 +void SettingBtGapDiscoveryResultCallback(const bd_addr_t *bdAddr) +{ + if ((gap_get_device_class(bdAddr) & DEVICE_MAJOR_CLASS_PHONE) != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGapDiscoveryResultCallback: Mobile Phone Device"); + return; + } + + if (bdAddr == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr nullptr"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_discovery_result_callback addr: %02x%02x%02x%02x%02x%02x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&SettingBluetoothModel::SettingBtGapDiscoveryResultCallbakHandle, + SettingBluetoothModel::GetInstance(), *bdAddr)); +} + +static void ACLConnectionSuss(const bd_addr_t &bdAddr) +{ + // 成功提示 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ACLConnectionSuss conn success"); + SettingBluetoothModel::GetInstance()->SetLastConnedAddr(&bdAddr); + SettingBluetoothModel::GetInstance()->SetBlueToothConnectStatus(true); + SettingBluetoothModel::GetInstance()->UpdateConnectedStatusForDevice(bdAddr); + if (SettingBluetoothPage::GetInstance() != nullptr) { + SettingBluetoothPage::GetInstance()->LoadFindDeviceList(); + } + if ((SettingBluetoothModel::GetInstance()->GetConnectResultPage() == true) && + (SettingBluetoothPage::GetInstance() != nullptr)) { + SettingBluetoothPage::GetInstance()->ShowResultGroup(CONNECT_BLUETOOTH_SUCCESS_FRAGMENT); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetConnectResultPage is false or GetInstance is nullptr"); + } + SettingBluetoothModel::GetInstance()->SetConnectResultPage(false); +} + +static void ACLConnectionFail(const bd_addr_t &bdAddr) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail conn fail"); + SettingBluetoothModel::GetInstance()->SetBlueToothConnectStatus(false); + SettingBluetoothModel::GetInstance()->UpdateDisconnectStatusForDevice(bdAddr); + if (SettingBluetoothPage::GetInstance() != nullptr) { + SettingBluetoothPage::GetInstance()->LoadFindDeviceList(); + } + if ((SettingBluetoothModel::GetInstance()->GetConnectResultPage()) == true && + (SettingBluetoothPage::GetInstance() != nullptr)) { + SettingBluetoothPage::GetInstance()->ShowResultGroup(CONNECT_BLUETOOTH_FAIL_FRAGMENT); + } + // 失败提示页 + SettingBluetoothModel::GetInstance()->SetConnectResultPage(false); +} + +void SettingBluetoothModel::SettingBtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr) +{ + if ((reason == 0x13) || (reason == 0x14) || (reason == 0x15) || (reason == 0x3D) || (reason == 0x08)) { // 连接断开 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "The peer end is disconnected."); + } else if (reason == 0x16) { // 主动断开连接 + BtCaseInfo *onClickBtCaseInfo = SettingBluetoothModel::GetInstance()->GetSelectedDeviceInfo(); + } else if ((reason == 0xb) || (reason > 0x45)) { // 0xb:重复点击连接按钮 0x45:acl状态最大参数 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reason is false."); + } + + if ((state == GAP_ACL_STATE_CONNECTED) || (state == GAP_ACL_STATE_LE_CONNECTED)) { + // 将数据存入设备列表 + BtCaseInfo *info = GetSelectedDeviceInfo(); + bool tag = CheckExistPairedList(*info); + if ((!tag) && (memcmp(info->addr, bdAddr.addr, BD_ADDR_LEN) == 0)) { + AddPairedDevicesCase(*info); + } + // 从配对的列表里面取出数据 ,将该数据填充进入到ScanList + SettingBluetoothModel::GetInstance()->SetLastConnedAddr(&bdAddr); + SettingBluetoothModel::GetInstance()->AddNodeFromPairListToScanList(bdAddr); + if (SettingBluetoothModel::GetInstance()->ConnectRemoteCheck(&bdAddr)) { + int32_t retA2dp = a2dp_src_connect(&bdAddr); + if (retA2dp) { + ACLConnectionFail(bdAddr); + } else { + SetLastConnedAddr(&bdAddr); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connect result 0x%x", retA2dp); + } + } else { + ACLConnectionFail(bdAddr); + } +} + +void ChangeBleConnectToMax() +{ + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + gap_conn_param_update_t conn_param = { 0 }; + conn_param.conn_handle = SETTING_BLUETOOTH_CONN_HANDLE; + conn_param.interval_min = SETTING_BLUETOOTH_INTERVAL_TOMAX_MIN; + conn_param.interval_max = SETTING_BLUETOOTH_INTERVAL_TOMAX_MAX; + conn_param.slave_latency = SETTING_BLUETOOTH_LATENCY; + conn_param.timeout_multiplier = SETTING_BLUETOOTH_TIMEOUT_MUTIPLIER; + errcode_t ret = gap_ble_connect_param_update(&conn_param); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleConnectCallback change to max interval ret:%d : latency-min:%u latency-max:%u\n", + ret, conn_param.interval_min, conn_param.interval_max); + } +} + +void ChangeBleConnectToDefault() +{ + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + gap_conn_param_update_t conn_param = { 0 }; + conn_param.conn_handle = SETTING_BLUETOOTH_CONN_HANDLE; + conn_param.interval_min = SETTING_BLUETOOTH_INTERVAL_TODEFAULT_MIN; + conn_param.interval_max = SETTING_BLUETOOTH_INTERVAL_TODEFAULT_MAX; + conn_param.slave_latency = SETTING_BLUETOOTH_LATENCY; + conn_param.timeout_multiplier = SETTING_BLUETOOTH_TIMEOUT_MUTIPLIER; + errcode_t ret = gap_ble_connect_param_update(&conn_param); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleConnectCallback change to default interval ret:%d : latency-min:%u latency-max:%u\n", + ret, conn_param.interval_min, conn_param.interval_max); + } +} + +// 回调:ACL连接状态上报 +void SettingBtGapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt SettingGapAclStateChangedCallback state %d, reason %x succ or err", state, reason); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + static bd_addr_t gapAclConnectAddr{0}; /* 连接后保存手机地址,手表清除手机配对后查询不到class比较手机地址 */ + if ((gap_get_device_class(bdAddr) & 0x200) != 0 || memcmp(gapAclConnectAddr.addr, bdAddr->addr, BD_ADDR_LEN) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingGapAclStateChangedCallback: Mobile Phone Device"); + if (state == GAP_ACL_STATE_DISCONNECTED) { + /* 通知msg_center,ble状态仍用bt状态,此处不区分 */ + MsgCenterSendMsg(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + // send to ace network + SettingBluetoothModel::GetInstance()->SetAclConnected(false); + net_connect_status_change(NETWORK_TYPE_BLUETOOTH, CONNECTION_STATUS_DISCONNECTED); + // 断开蓝牙连接时,若存在查找手机页面,刷新页面为断开页面 + if (FindPhoneMainPage::GetInstance() != nullptr) { + FindPhoneMainPage::GetInstance()->ChangeToDisConnect(); + } +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) + lwip_close_bt_pan(); +#endif + } else if (state == GAP_ACL_STATE_CONNECTED) { + (void)memcpy_s(gapAclConnectAddr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + MsgCenterSendMsg(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); + SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); + // send to ace network + SettingBluetoothModel::GetInstance()->SetAclConnected(true); +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) + lwip_open_bt_pan(); +#endif + net_connect_status_change(NETWORK_TYPE_BLUETOOTH, CONNECTION_STATUS_CONNECTED); + } + return; + } + + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&SettingBluetoothModel::SettingBtGapAclStateChangedHandle, SettingBluetoothModel::GetInstance(), state, reason, *bdAddr)); +} + +// 回调:远端设备名称变化 +void SettingBtRemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *deviceName, unsigned char length) +{ + if ((gap_get_device_class(bdAddr) & 0x200) != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtRemoteNameChangedCallback: Mobile Phone Device"); + return; + } + BtCaseInfo caseInfo{}; + if (bdAddr == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBtRemoteNameChangedCallback addr nullptr"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtRemoteNameChangedCallback addr: %02x%02x%02x%02x%02x%02x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + int ret = memcpy_s(caseInfo.deviceName, BD_NAME_LEN, deviceName, length); + if (ret != EOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBtRemoteNameChangedCallback memcpy fail!"); + return; + } + SettingBluetoothModel::GetInstance()->ResetScanDevicesCase(caseInfo); +} + +void SettingBtIsAcceptConnOnSafeModeCallback(const bd_addr_t *bdAddr, bool *res) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtIsAcceptConnOnSafeModeCallback addr: %02x%02x%02x%02x%02x%02x set *res true", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* addr下标 3 4 5 */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* addr下标 0 1 2 */ + *res = true; +} + +static void A2dpSettingSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectStateChangedCallback addr: %02x%02x%02x%02x%02x%02x connState: %x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], connState); /* 2 1 0 idx */ + if ((gap_get_device_class(bdAddr) & 0x200) != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectstateChangedCb: Mobile Phone Device"); + return; + } + if (connState == PROFILE_STATE_CONNECTED) { + uint32_t ret = avrcp_ct_connect(bdAddr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp_ct_connect ret = 0x%x", ret); + PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_CONNECTED); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionSuss, *bdAddr)); + } + + if (connState == PROFILE_STATE_DISCONNECTED) { + PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_DISCONNECTED); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionFail, *bdAddr)); + /* 实验室测试耳机回连场景,用户根据需要调整策略 */ + bool ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 60); // start scan + if (!ret) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "a2dp disc: gap_br_set_bt_scan_mode ret = 0x%x", ret); + } + } +} + +static void A2dpSettingSrcPlayingStateChanged(bd_addr_t *bdAddr, int playState) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "A2dpSettingSrcPlayingStateChangedCallback addr: %02x%02x%02x%02x%02x%02x playState: %x", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], playState); /* 2 1 0 idx */ +} + +static void A2dpSettingSrcConfigureChanged(bd_addr_t *bdAddr, a2dp_codec_info_t *info) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "A2dpSettingSrcConfigurationChangedCallback addr: %02x%02x%02x%02x%02x%02x ", + bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ + bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* 2 1 0 idx */ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "codec_priority: %04x codec_type: %04x sample_rate: %02x bits_per_sample: %02x channel_mode: %02x ", + info->codec_priority, info->codec_type, info->sample_rate, info->bits_per_sample, info->channel_mode); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "codec_specific1: %04x codec_specific2: %04x codec_specific3: %04x codec_specific4: %04x", + info->codec_specific1, info->codec_specific2, info->codec_specific3, info->codec_specific4); +} + +static void SettingBleConnStateChangeCallback(unsigned short connId, bd_addr_t *addr, gap_ble_conn_state_t connState, + gap_ble_pair_state_t pairState, gap_ble_disc_reason_t discReason) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleConnStateChangeCallback connId 0x%x, connState 0x%x, pairState 0x%x", + connId, connState, pairState); + if (GAP_BLE_STATE_DISCONNECTED == connState) { // restart ble adv when disconnected + /* 通知msg_center,ble状态仍用bt状态,此处不区分 */ + MsgCenterSendMsg(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + msg_center_set_ble_conn_state(GAP_BLE_STATE_DISCONNECTED); + // send to ace network + net_connect_status_change(NETWORK_TYPE_BLUETOOTH_LE, CONNECTION_STATUS_DISCONNECTED); + // 断开蓝牙连接时,若存在查找手机页面,刷新页面为断开页面 + if (FindPhoneMainPage::GetInstance() != nullptr) { + FindPhoneMainPage::GetInstance()->ChangeToDisConnect(); + } + } else { + MsgCenterSendMsg(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); + msg_center_set_ble_conn_state(GAP_BLE_STATE_CONNECTED); + (void)memcpy_s(&g_bd_addr, sizeof(bd_addr_t), addr, sizeof(bd_addr_t)); + // send to ace network + net_connect_status_change(NETWORK_TYPE_BLUETOOTH_LE, CONNECTION_STATUS_CONNECTED); + } + // send to ace network +} + +static void SettingBleAdvStartStateCallback(uint8_t advId, adv_status_t status) +{ + if (g_sample_adv_id == advId) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleAdvStartStateCallback advId: %d, status:%d\n", advId, status); + SettingBluetoothModel::GetInstance()->SetAdvStartState(true); + } +} + +static void SettingBleAdvStopCallback(uint8_t advId, adv_status_t status) +{ + if (g_sample_adv_id == advId) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleAdvStopCallback advId: %d, status:%d\n", advId, status); + SettingBluetoothModel::GetInstance()->SetAdvStartState(false); + } +} + +static void SettingBleAdvTerminateCallback(uint8_t advId, adv_status_t status) +{ + if (g_sample_adv_id == advId) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleAdvTerminateCallback advId: %d, status:%d\n", advId, status); + SettingBluetoothModel::GetInstance()->SetAdvStartState(false); + // 此处开广播是为了实验室测试需要,客户需要自己修改 + BleSettingAdvStart(); + } +} + +static void SettingBtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_t srvcHandle, errcode_t status) +{ + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF01F)) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsServiceAddCallback 0x%x 0x%x 0x%x", + status, serverId, srvcHandle); + uint16_t sample_id = 0xF11F; + uint16_t diag_id = 0xF21F; + gatts_add_chara_info_t character; + uint16_t value = 0; + + memset_s(&character, sizeof(gatts_add_chara_info_t), 0, sizeof(gatts_add_chara_info_t)); + character.chara_uuid.uuid_len = sizeof(sample_id); + memcpy_s(character.chara_uuid.uuid, sizeof(character.chara_uuid.uuid), (char *)&sample_id, sizeof(sample_id)); + character.permissions = GATT_ATTRIBUTE_PERMISSION_WRITE; + character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP; + character.value_len = (uint16_t)sizeof(value); + character.value = (uint8_t *)(&value); + int ret = gatts_add_characteristic(serverId, srvcHandle, &character); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_characteristic sample ret 0x%x", ret); + + memset_s(&character, sizeof(gatts_add_chara_info_t), 0, sizeof(gatts_add_chara_info_t)); + character.chara_uuid.uuid_len = sizeof(diag_id); + memcpy_s(character.chara_uuid.uuid, sizeof(character.chara_uuid.uuid), (char *)&diag_id, sizeof(diag_id)); + character.permissions = GATT_ATTRIBUTE_PERMISSION_WRITE | GATT_ATTRIBUTE_PERMISSION_READ; + character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP | GATT_CHARACTER_PROPERTY_BIT_READ | GATT_CHARACTER_PROPERTY_BIT_NOTIFY; + character.value_len = (uint16_t)sizeof(value); + character.value = (uint8_t *)(&value); + + ret = gatts_add_characteristic(serverId, srvcHandle, &character); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_characteristic diag ret 0x%x", ret); + + g_sample_svr_handle = srvcHandle; + } +} + +static void SettingBtGattsCharacteristicAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_t srvcHandle, gatts_add_character_result_t *result, errcode_t status) +{ + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF11F)) { + g_sample_characteristic_handle = result->value_handle; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsCharacteristicAddCallback 0x%x 0x%x 0x%x 0x%x", + status, serverId, srvcHandle, g_sample_characteristic_handle); + } + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF21F)) { + g_diag_characteristic_handle = result->value_handle; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsCharacteristicAddCallback 0x%x 0x%x 0x%x 0x%x", + status, serverId, srvcHandle, g_diag_characteristic_handle); + + uint8_t ccc_val[] = { 0x01, 0x00 }; + uint16_t diag_desc = 0x0229; + gatts_add_desc_info_t descriptor; + memset_s(&descriptor, sizeof(gatts_add_desc_info_t), 0, sizeof(gatts_add_desc_info_t)); + descriptor.desc_uuid.uuid_len = sizeof(diag_desc); + memcpy_s(descriptor.desc_uuid.uuid, sizeof(descriptor.desc_uuid.uuid), (char *)&diag_desc, sizeof(diag_desc)); + descriptor.permissions = GATT_ATTRIBUTE_PERMISSION_READ | GATT_ATTRIBUTE_PERMISSION_WRITE; + descriptor.value_len = (uint16_t)sizeof(ccc_val); + descriptor.value = ccc_val; + int ret = gatts_add_descriptor(serverId, srvcHandle, &descriptor); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_descriptor diag_desc ret 0x%x", ret); + } + + if (g_sample_characteristic_handle != 0 && g_diag_characteristic_handle !=0 && g_diag_desc_handle != 0) { + int ret = gatts_start_service(serverId, srvcHandle); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_start_service ret 0x%x", ret); + } +} + +static void SettingBtGattsDescriptorAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_t srvcHandle, uint16_t descriptorHandle, errcode_t status) +{ + if (g_sample_svr_handle == srvcHandle) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsDescriptorAddCallback 0x%x 0x%x 0x%x 0x%x", + status, serverId, srvcHandle, descriptorHandle); + g_diag_desc_handle = descriptorHandle; + } + + if (g_sample_characteristic_handle != 0 && g_diag_characteristic_handle !=0 && g_diag_desc_handle != 0) { + int ret = gatts_start_service(serverId, srvcHandle); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_start_service ret 0x%x", ret); + } +} + +static void SettingBtGattsServiceStartCallback(uint8_t serverId, uint16_t srvcHandle, errcode_t status) +{ + if (g_sample_svr_handle == srvcHandle) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsServiceStartCallback 0x%x 0x%x 0x%x", status, serverId, srvcHandle); + } +} + +static void SettingBtGattsServiceStopCallback(uint8_t serverId, uint16_t srvcHandle, errcode_t status) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsServiceStopCallback 0x%x 0x%x 0x%x", status, serverId, srvcHandle); +} + +static void SettingBtGattsServiceDeleteCallback(uint8_t serverId, errcode_t status) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsServiceDeleteCallback 0x%x 0x%x", status, serverId); +} + +static void SettingBtGattsRequestReadCallback(uint8_t serverId, uint16_t connId, gatts_req_read_cb_t *readCbPara, errcode_t status) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGattsRequestReadCallback handle = %u", readCbPara->handle); +} + +static void SettingBtGattsRequestWriteCallback(uint8_t serverId, uint16_t connId, gatts_req_write_cb_t *writeCbPara, errcode_t status) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGattsRequestWriteCallback handle = %u", writeCbPara->handle); + if (g_sample_characteristic_handle == writeCbPara->handle) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBtGattsRequestWriteCallback handle = %u", writeCbPara->handle); + if (writeCbPara->length == 9) { + if (memcmp("open ctkd", writeCbPara->value, writeCbPara->length) == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "enable ctkd"); + // 一键双连使能(依赖安全连接参数配置) + errcode_t ret = gap_ble_set_ctkd_enable(true); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_enable ret = %u", ret); + + // 发起ble配对 + ret = gap_ble_pair_remote_device(&g_bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gap_ble_pair_remote_device ret = %u ", ret); + } + } else if (writeCbPara->length == 10) { + if (memcmp("close ctkd", writeCbPara->value, writeCbPara->length) == 0) { + // 一键双连去使能 + errcode_t ret = gap_ble_set_ctkd_enable(false); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_disable ret = %u", ret); + } + } + } else if (g_diag_characteristic_handle == writeCbPara->handle) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "diag_gatt_write_req_cbk handle = %u", writeCbPara->handle); + diag_gatt_write_req_cbk(serverId, connId, writeCbPara, status); + } else if (g_diag_desc_handle == writeCbPara->handle) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "diag_gatt_set_handle handle = %u", writeCbPara->handle); + if ((writeCbPara->length == 2) && (*(char*)(writeCbPara->value) == 1)) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "open gatt channel"); + diag_gatt_set_handle(serverId, connId, g_diag_characteristic_handle); + msg_center_set_trans_channel(DIAG_FRAME_FID_BT); + } else if ((writeCbPara->length == 2) && (*(char*)(writeCbPara->value) == 0)) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "close gatt channel"); + diag_gatt_set_handle(0, 0, 0); + msg_center_set_trans_channel(DIAG_FRAME_FID_PHONE); + } + } +} + +static void SettingBtGattsMtuChangedCallback(uint8_t serverId, uint16_t connId, uint16_t mtuSize, errcode_t status) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBtGattsMtuChangedCallback connId = %u mtuSize = %u", connId, mtuSize); +} + +static void SettingBtA2dpSnkAcceptTimerStop(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "stop timer\n"); + if (g_setting_a2dp_stream_accept_timer.timer != nullptr) { + (void)osal_timer_stop(&g_setting_a2dp_stream_accept_timer); + (void)osal_timer_destroy(&g_setting_a2dp_stream_accept_timer); + g_setting_a2dp_stream_accept_timer.timer = nullptr; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "stop timer success!\n"); +} + +static void SettingBtA2dpSnStartAcceptHandler(unsigned long data) +{ + UNUSED(data); + bd_addr_t active_bd_addr = a2dp_snk_get_active_device(); + a2dp_snk_start_accept(&active_bd_addr); + SettingBtA2dpSnkAcceptTimerStop(); +} + +static errcode_t SettingBtA2dpSnkStartAcceptTimer(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "start timer\n"); + if (g_setting_a2dp_stream_accept_timer.timer != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timer is running"); + return ERRCODE_SUCC; + } + + g_setting_a2dp_stream_accept_timer.handler = SettingBtA2dpSnStartAcceptHandler; + g_setting_a2dp_stream_accept_timer.interval = A2DP_STREAM_ACCEPT_TIMER_PERIOD; + + int32_t timer_ret = osal_timer_init(&g_setting_a2dp_stream_accept_timer); + if (timer_ret != EOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "create timer error! ret: %x\n", timer_ret); + SettingBtA2dpSnkAcceptTimerStop(); + return ERRCODE_FAIL; + } + timer_ret = osal_timer_start(&g_setting_a2dp_stream_accept_timer); + if (timer_ret != EOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "start timer error! ret: %x\n", timer_ret); + SettingBtA2dpSnkAcceptTimerStop(); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static int32_t SettingBtA2dpSnkAudioCreate() +{ +#if MEDIA_A2DP_SNK_INTERFACE + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", + g_setting_audio_format_config.audioFormat, g_setting_audio_format_config.channelCount, g_setting_audio_format_config.sampleRate); + + int32_t ret = AudioManagerA2dpSinkSetParam(g_setting_audio_format_config); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkSetParam ret %x\n", ret); + ret = AudioManagerA2dpSinkCreate(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); +#endif + /* 起定时器接受音乐开始请求 */ + (void)SettingBtA2dpSnkStartAcceptTimer(); + return 0; +} + +static int32_t SettingBtA2dpSnkAudioDestroy() +{ +#if MEDIA_A2DP_SNK_INTERFACE + int32_t ret = AudioManagerA2dpSinkDestroy(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkDestroy ret %x\n", ret); +#endif + return 0; +} + +static void SettingBtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ +} + +static void SettingBtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x \n", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* 3 2 1 0 idx */ + SettingBtA2dpSnkAudioCreate(); +} + +static void SettingBtA2dpSnkPlayingStateChangedCb(bd_addr_t *bd_addr, int playing_state) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x playing_state: %x\n", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], playing_state); /* 3 2 1 0 idx */ + if (playing_state == A2DP_NOT_PLAYING) { + SettingBtA2dpSnkAudioDestroy(); + } +} + +static void SettingBtA2dpSnkConfigChangedCb(bd_addr_t *bd_addr, a2dp_snk_codec_info_t *info) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x ", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* 3 2 1 0 idx */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, + "codec_priority: %04x codec_type: %04x sample_rate: %02x bits_per_sample: %02x channel_mode: %02x", + info->codec_priority, info->codec_type, info->sample_rate, info->bits_per_sample, info->channel_mode); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, + "codec_specific1: %04x codec_specific2: %04x codec_specific3: %04x codec_specific4: %04x\n", + (unsigned int)info->codec_specific1, + (unsigned int)info->codec_specific2, + (unsigned int)info->codec_specific3, + (unsigned int)info->codec_specific4); +#if MEDIA_A2DP_SNK_INTERFACE + if (info->codec_type == A2DP_SNK_CODEC_TYPE_AAC) { + g_setting_audio_format_config.audioFormat = AAC_LC; + } else { + g_setting_audio_format_config.audioFormat = SBC; + } + /* channel count 1 or 2 */ + g_setting_audio_format_config.channelCount = (info->channel_mode == A2DP_SNK_CODEC_CHANNEL_MODE_NONE ? 1 : 2); + + switch (info->sample_rate) { + case A2DP_SNK_CODEC_SAMPLE_RATE_48000: + g_setting_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE48000; + break; + case A2DP_SNK_CODEC_SAMPLE_RATE_88200: + g_setting_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE88200; + break; + case A2DP_SNK_CODEC_SAMPLE_RATE_96000: + g_setting_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE96000; + break; + default: + g_setting_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE44100; + break; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", + g_setting_audio_format_config.audioFormat, g_setting_audio_format_config.channelCount, g_setting_audio_format_config.sampleRate); +#endif +} + +// 注册回调函数 +static gap_call_backs_t g_settingBtGapCallBacks{}; +static a2dp_src_callbacks_t g_settingA2dprcCallbacks{}; +static gap_ble_callbacks_t g_settingGapBleCallbacks{}; +static gatts_callbacks_t g_settingBtGattsCallbacks{}; +static a2dp_snk_callbacks_t g_settingA2dpSnkCallbacks = {}; + + +static void SettingBleConnectCallback(uint16_t conn_id, errcode_t status, const gap_ble_conn_param_update_t *param) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBleConnectCallback conn_id:%u, interval-1:%u latency:%u timeout:%u\n",conn_id, param->interval, param->latency, param->timeout); +} + +void SettingBtInitCallBacks() +{ + g_settingBtGapCallBacks.discovery_result_callback = SettingBtGapDiscoveryResultCallback; + g_settingBtGapCallBacks.discovery_state_changed_callback = SettingBtGapDiscoveryStateChangedCallback; + g_settingBtGapCallBacks.acl_state_changed_callbak = SettingBtGapAclStateChangedCallback; + g_settingBtGapCallBacks.read_remote_rssi_event_callback = SettingBtGapReadRemoteRssiEventCallback; + g_settingBtGapCallBacks.remote_name_changed_callback = SettingBtRemoteNameChangedCallback; + g_settingBtGapCallBacks.is_accept_conn_on_safe_mode_callback = SettingBtIsAcceptConnOnSafeModeCallback; + g_settingBtGapCallBacks.pair_status_changed_callback = SettingBtGapPairStatusChangedCallback; + g_settingBtGapCallBacks.pair_requested_callback = SettingBtGapPairRequestedCallback; + g_settingBtGapCallBacks.pair_confiremed_callback = SettingBtGapPairConfirmedCallback; + gap_register_callbacks(&g_settingBtGapCallBacks); + + g_settingA2dprcCallbacks.connectstate_changed_cb = A2dpSettingSrcConnectstateChanged; + g_settingA2dprcCallbacks.configuration_changed_cb = A2dpSettingSrcConfigureChanged; + g_settingA2dprcCallbacks.playing_state_changed_cb = A2dpSettingSrcPlayingStateChanged; + a2dp_src_register_callbacks(&g_settingA2dprcCallbacks); + + /* a2dp sink */ + g_settingA2dpSnkCallbacks.connectstate_changed_cb = SettingBtA2dpSnkConnectStateChangedCb; + g_settingA2dpSnkCallbacks.start_stream_request_cb = SettingBtA2dpSnkStartStreamReqCb; + g_settingA2dpSnkCallbacks.playing_state_changed_cb = SettingBtA2dpSnkPlayingStateChangedCb; + g_settingA2dpSnkCallbacks.configuration_changed_cb = SettingBtA2dpSnkConfigChangedCb; + a2dp_snk_register_callbacks(&g_settingA2dpSnkCallbacks); +} + +void SettingBtInitCallBacksEx() +{ + g_settingGapBleCallbacks.conn_state_change_cb = SettingBleConnStateChangeCallback; + g_settingGapBleCallbacks.start_adv_cb = SettingBleAdvStartStateCallback; + g_settingGapBleCallbacks.stop_adv_cb = SettingBleAdvStopCallback; + g_settingGapBleCallbacks.terminate_adv_cb = SettingBleAdvTerminateCallback; + g_settingGapBleCallbacks.conn_param_update_cb = SettingBleConnectCallback; + wrapper_gap_ble_register_callbacks(&g_settingGapBleCallbacks); + + g_settingBtGattsCallbacks.add_service_cb = SettingBtGattsServiceAddCallback; + g_settingBtGattsCallbacks.add_characteristic_cb = SettingBtGattsCharacteristicAddCallback; + g_settingBtGattsCallbacks.add_descriptor_cb = SettingBtGattsDescriptorAddCallback; + g_settingBtGattsCallbacks.start_service_cb = SettingBtGattsServiceStartCallback; + g_settingBtGattsCallbacks.stop_service_cb = SettingBtGattsServiceStopCallback; + g_settingBtGattsCallbacks.delete_service_cb = SettingBtGattsServiceDeleteCallback; + g_settingBtGattsCallbacks.read_request_cb = SettingBtGattsRequestReadCallback; + g_settingBtGattsCallbacks.write_request_cb = SettingBtGattsRequestWriteCallback; + g_settingBtGattsCallbacks.mtu_changed_cb = SettingBtGattsMtuChangedCallback; + wrapper_gatts_register_callbacks(&g_settingBtGattsCallbacks); +} + +void SettingBtInitGatts(void) +{ + uint16_t id = 0xF01F; + uint16_t ser_id = 0xFF1F; + uint8_t serverId = 0; + bt_uuid_t uuid; + int ret; + + uuid.uuid_len = sizeof(ser_id); + memcpy_s(uuid.uuid, sizeof(uuid.uuid), (char *)&ser_id, sizeof(ser_id)); + ret = wrapper_gatts_register_server(&uuid, &serverId); /* 注册gatt server */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_register_server ret: 0x%x serverId = 0x%x", ret, serverId); + + uuid.uuid_len = sizeof(id); + memcpy_s(uuid.uuid, sizeof(uuid.uuid), (char *)&id, sizeof(id)); + ret = wrapper_gatts_add_service(serverId, &uuid, true); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_service ret: 0x%x", ret); + + wrapper_gatts_service_start(); +} + +static uint8_t Char2Num(int8_t c) +{ + if (c >= '0' && c <= '9') { + return (uint8_t)(c - '0'); + } else if (c >= 'A' && c <= 'F') { + return (uint8_t)(c - 'A' + TEN); + } else if (c >= 'a' && c <= 'f') { + return (uint8_t)(c - 'a' + TEN); + } else { + return 0xFF; + } +} + +static uint32_t GenerateUuidFromString(const char *str, uint8_t len, bt_uuid_t *uuid_out) +{ + int slen = (int)strnlen(str, len); + bool new_uuid = false; + if (uuid_out == nullptr) { + return ERRCODE_INVALID_PARAM; + } + + uuid_out->uuid_len = (uint8_t)slen / 2; /* 2: 2个字符组成一个字节,因此只取偶数个字符 */ + for (int i = 0; i + 1 < slen; i += 2) { /* 2: 同上 */ + uint8_t num1 = Char2Num(str[i]); + uint8_t num2 = Char2Num(str[i + 1]); + if (num1 == UINT8_MAX || num2 == UINT8_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "invalid input %c%c\n", str[i], str[i + 1]); + return ERRCODE_INVALID_PARAM; + } + + uuid_out->uuid[i / 2] = (uint8_t)((num1 << BIT4) | num2); /* 2: 同上 */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "%02x ", (uint8_t)(uuid_out->uuid[i / 2])); /* 2: 同上 */ + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "\n"); + return ERRCODE_SUCC; +} + +void SettingBtSppServerCreate(const char *spp_uuid, const char *name, uint8_t name_len) +{ + spp_create_socket_para_t param; + if (GenerateUuidFromString((const char *)spp_uuid, (uint8_t)strlen(spp_uuid), ¶m.uuid) != ERRCODE_SUCC) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get uuid fail\n"); + return; + } + + param.socket_type = SPP_SOCKET_RFCOMM; + param.is_encrypt = true; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "uuid: %s uuid_len: %u\n", spp_uuid, param.uuid.uuid_len); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "socket_type: %x is_encrypt: %d name: %s nameLen: %u\n", param.socket_type, + param.is_encrypt, name, name_len); + + int ret = spp_server_create(¶m, name, name_len); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "spp_server_create ret: %x\n", ret); +} + +static int BtSppServerAcceptTaskBody(void *data) +{ + int server_id = (int)(intptr_t)data; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "server_id: %x\n", server_id); + + int ret = spp_server_accept(server_id); + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "spp_server_accept ret: %x\n", ret); + + return OSAL_SUCCESS; +} + +/* 等待client连接 */ +void SettingBtSppServerAccept(uint8_t server_id) +{ + osal_task *task = osal_kthread_create(BtSppServerAcceptTaskBody, (void *)(uintptr_t)server_id, + "spp_server_accept_task", BT_SPP_TASK_STACK_SIZE); + if (task == nullptr) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "create task fail\n"); + return; + } + + int ret = osal_kthread_set_priority(task, BT_SPP_TASK_PRI); + if (ret != OSAL_SUCCESS) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "set pri error: %08x\n", ret); + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "create task success.\n"); +} + +void SettingBtInitSpp(void) +{ + char uuid[] = "1101"; + char name[] = "COM1"; + uint8_t name_len = strlen(name) + 1; + uint8_t server_id = 0; + + /* 创建spp */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "create spp server uuid=%s name=%s name_len=%d\n", uuid, name, name_len); + SettingBtSppServerCreate(uuid, name, name_len); + SettingBtSppServerAccept(server_id); +} + +void BleSettingAdvStart(void) +{ + int advId = g_sample_adv_id; + if (SettingBluetoothModel::GetInstance()->GetAdvStartState()) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleSettingAdvStart already started"); + gap_ble_stop_adv(advId); + osDelay(50); + } + gap_ble_adv_params_t adv_para; + memset_s(&adv_para, sizeof(gap_ble_adv_params_t), 0, sizeof(gap_ble_adv_params_t)); + adv_para.min_interval = 0x30; + adv_para.max_interval = 0x60; + adv_para.adv_type = GAP_BLE_ADV_CONN_SCAN_UNDIR; + adv_para.channel_map = 0x7; + adv_para.duration = 0; + gap_ble_set_adv_param(advId, &adv_para); + gap_ble_set_local_appearance(GAP_BLE_APPEARANCE_TYPE_GENERIC_WATCH); + errcode_t ret = gap_ble_start_adv(advId); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleSettingAdvStart bt gap_ble_start_adv ret = 0x%x", ret); +} + +#ifdef __cplusplus +} +#endif +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingCardModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingCardModel.cpp new file mode 100644 index 000000000..b434cf5f6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingCardModel.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardModel + * Create: 2025-06-01 + */ +#include +#include +#include "dfx_reboot.h" +#include "kv_store.h" +#include "UiConfig.h" +#include "main/MainModel.h" +#include "settings/common/SettingCardEffectResourceImage.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingCardModel.h" + +namespace OHOS { +static const int STYLE_VALUE_LEN = 128; +static const char* SWIPE_EFFECT = "swipe_effect"; + +static const std::map>> g_effectMap = { + {CardEffectID::UI_CUBE, std::make_pair("3D折叠", UI_3D_FOLD_RESIDS)}, + {CardEffectID::UI_CARD_FLIP, std::make_pair("十字平滑", UI_CARD_FLIP_RESIDS)}, + {CardEffectID::UI_PUSH_PRESS, std::make_pair("推压", UI_PUSH_PRESS_RESIDS)}, + {CardEffectID::UI_TURN_PAGE, std::make_pair("翻页", UI_TURN_PAGE_RESIDS)}, + {CardEffectID::UI_WINDMILL, std::make_pair("风车", UI_WINDMILL_RESIDS)}, + {CardEffectID::UI_ZOOM, std::make_pair("缩放", UI_ZOOM_RESIDS)}, +}; + +SettingCardModel::SettingCardModel() +{ + std::vector tempUnionData = {{ + PlainTextItemData{"卡片"}, + IconTextNavigationItemData{SettingPageId::CARD_EFFECT_PAGE, IMAGE_CARD_LIST_CARDANIMATOR, "卡片动效", + nullptr,true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::CARD_MGR_PAGE, IMAGE_CARD_LIST_CARDMANAGER, "卡片管理", + nullptr,true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + }}; + cardUnionData_.swap(tempUnionData); + + selectStyle_ = CardEffectID::UI_INVALIDE; + int backgroundImageId = IMAGE_DESKTOP_BG; + const char* resourceImage = SETTING_IMAGE; + for (auto it = g_effectMap.begin(); it != g_effectMap.end(); ++it) { + effects_[it->first] = SettingCardEffectSample(it->first, + it->second.second, it->second.first, + backgroundImageId, resourceImage, false); + } +} + +std::vector& SettingCardModel::GetCardUnionData() +{ + return cardUnionData_; +} + +std::vector& SettingCardModel::GetCardData() +{ + RefreshCardData(); + return cardData_; +} + +void SettingCardModel::RefreshCardData() +{ + MainModel::GetInstance().InitCardSettings(); + uint8_t selectedCardCount = MainModel::GetInstance().GetCardSettingCount(); + CardId *selectedCardSettings = MainModel::GetInstance().GetCardSettings(); + + if (cardData_.size() != (MAX_CARD - 1)) { + cardData_.resize(MAX_CARD - 1); // 系统中的card总个数是固定的, WATCH_FACE不属于card范畴 + } + for (uint8_t i = 0; i < cardData_.size(); i++) { + CardId cardId = (CardId)(i+1); // CardId是定义的枚举, WATCH_FACE=0, COMPASS=1; + uint8_t cardIndex = i; // CardIndex是cardInfoMap中的index, cardInfoMap[0]=COMPASS + + const CardInfo *info = MainModel::GetInstance().GetCardInfo(cardId); + if (info == nullptr) { + continue; + } + + SettingCardItemData& data = cardData_[cardIndex]; + data.index = cardIndex; + data.id = info->id; + data.image = info->cardImg; + data.isSelect = false; + for (uint8_t j = 0; j < selectedCardCount; j++) { + if (selectedCardSettings[j] == cardId) { + data.isSelect = true; + break; + } + } + } +} + +void SettingCardModel::AddCard(uint8_t index) +{ + MainModel::GetInstance().AddCardSetting(index); +} + +void SettingCardModel::DeleteCard(uint8_t index) +{ + MainModel::GetInstance().DeleteCardSetting(index); +} + +void SettingCardModel::SetSelectedCard(uint8_t cardId) +{ + selectedCardId_ = cardId; +} + +uint8_t SettingCardModel::GetSelectedCard(void) +{ + return selectedCardId_; +} + +void SettingCardModel::InitEffectItem(void) +{ + for (auto& pair : effects_) { + pair.second.selected = false; + } + CardEffectID selectStyle = this->GetSwipeEffectStyle(); + effects_[selectStyle].selected = true; +} + +std::map& SettingCardModel::GetEffectListItems(void) +{ + return effects_; +} + +CardEffectID SettingCardModel::GetSwipeEffectStyle(void) +{ + if (selectStyle_ != CardEffectID::UI_INVALIDE) { + return selectStyle_; + } + selectStyle_ = CardEffectID::UI_ZOOM; + char temp[STYLE_VALUE_LEN] = { 0 }; + (void)UtilsGetValue(SWIPE_EFFECT, temp, STYLE_VALUE_LEN); + auto it = std::find_if(effects_.begin(), effects_.end(), + [temp](const std::pair& pair) { + return strcmp(temp, pair.second.label) == 0; + }); + if (it != effects_.end()) { + selectStyle_ = it->first; + } + return selectStyle_; +} + +void SettingCardModel::SetSwipeEffectStyle(CardEffectID swipeId) +{ + if (swipeId == CardEffectID::UI_INVALIDE) { + // If the corresponding style is not found, set the default value to UI_ZOOM. + swipeId = CardEffectID::UI_ZOOM; + } + (void)UtilsSetValue(SWIPE_EFFECT, effects_[swipeId].label); + selectStyle_ = swipeId; +} +} // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDesktopModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDesktopModel.cpp new file mode 100644 index 000000000..d22e7ec2e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDesktopModel.cpp @@ -0,0 +1,371 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopModel + * Create: 2025-06-01 + */ +#include +#include "dirent.h" +#include "UiConfig.h" +#include "kv_store.h" +#include "common/image_cache_manager.h" +#include "wearable_log.h" +#include "main/DialBinParser.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingDesktopModel.h" + +namespace OHOS { +static constexpr uint32_t STYLE_VALUE_LEN = 32; +static constexpr uint8_t SETTING_DIAL_STYLE_ROLLER_IDX = 1; +static constexpr uint8_t SETTING_DIAL_STYLE_COVERFLOW_IDX = 2; +static constexpr uint8_t SETTING_DIAL_STYLE_AOD_IDX = 3; + +SettingDesktopModel::SettingDesktopModel() +{ + std::vector tempDesktopUnionData = {{ + PlainTextItemData{"表盘与桌面"}, + IconTextNavigationItemData{SettingPageId::DESKTOP_DIAL_PAGE, IMAGE_DESKTOP_LIST_DIAL, "表盘", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DESKTOP_HOME_PAGE, IMAGE_DESKTOP_LIST_HOME, "桌面风格", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DESKTOP_DIAL_STYLE_PAGE, IMAGE_DESKTOP_LIST_DIAL_STYLE, "表盘风格", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + }}; + desktopUnionData_.swap(tempDesktopUnionData); + + std::vector tempDesktopHomeData = {{ + {APPLIST_STYLE, IMAGE_DESKTOP_HOME_SELECTED_APPLIST, IMAGE_DESKTOP_HOME_UNSELECT_APPLIST, "列表", false}, + {HEXAGONS_STYLE, IMAGE_DESKTOP_HOME_SELECTED_HEXAGONS, IMAGE_DESKTOP_HOME_UNSELECT_HEXAGONS, "蜂窝", false}, + {FOOTBALL_STYLE, IMAGE_DESKTOP_HOME_SELECTED_FOOTBALL, IMAGE_DESKTOP_HOME_UNSELECT_FOOTBALL, "足球", false}, + {WATERFALL_STYLE, IMAGE_DESKTOP_HOME_SELECTED_WATERFALL, IMAGE_DESKTOP_HOME_UNSELECT_WATERFALL, "瀑布", false}, + {PLANET_STYLE, IMAGE_DESKTOP_HOME_SELECTED_PLANET, IMAGE_DESKTOP_HOME_UNSELECT_PLANET, "星球", false}, + }}; + desktopHomeData_.swap(tempDesktopHomeData); + + std::vector tempDialStyleUnionData = {{ + PlainTextItemData{"表盘风格"}, + IconTextToggleItemData{IMAGE_DESKTOP_DIALSTYLE_COVERFLOW, "coverflow", false, + SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextToggleItemData{IMAGE_DESKTOP_DIALSTYLE_ROLLER, "roller", false, + SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextToggleItemData{IMAGE_DESKTOP_DIALSTYLE_AOD, "息屏显示", false, + SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + }}; + dialStyleUnionData_.swap(tempDialStyleUnionData); +} + +std::vector& SettingDesktopModel::GetDesktopUnionData() +{ + return desktopUnionData_; +} + +std::vector& SettingDesktopModel::GetDesktopHomeData() +{ + DesktopStyle style = GetDesktopStyle(); + for (auto& it : desktopHomeData_) { + it.isSelect = (it.style == style); + } + return desktopHomeData_; +} + +std::vector& SettingDesktopModel::GetDialStyleUnionData() +{ + RefreshDialStyleUnionDataForStyle(); + RefreshDialStyleUnionDataForAod(); + return dialStyleUnionData_; +} + +void SettingDesktopModel::RefreshDialStyleUnionDataForStyle() +{ + DialStyle style = GetDialStyle(); + auto coverflowItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_COVERFLOW_IDX].GetUnionItemData()); + auto rollerItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_ROLLER_IDX].GetUnionItemData()); + coverflowItemData->selected = (style == DialStyle::COVERFLOW); + rollerItemData->selected = (style == DialStyle::ROLLER); +} + +void SettingDesktopModel::RefreshDialStyleUnionDataForAod() +{ + auto aodItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_AOD_IDX].GetUnionItemData()); + aodItemData->selected = MainModel::GetInstance().IsAodEnabled(); +} + +DesktopStyle SettingDesktopModel::GetDesktopStyle(void) +{ + DesktopStyle style; + char temp[STYLE_VALUE_LEN] = { 0 }; + (void)UtilsGetValue("applist_style", temp, STYLE_VALUE_LEN); + if (strcmp(temp, "hexagons") == 0) { + style = HEXAGONS_STYLE; + } else if (strcmp(temp, "football") == 0) { + style = FOOTBALL_STYLE; + } else if (strcmp(temp, "waterfall") == 0) { + style = WATERFALL_STYLE; + } else if (strcmp(temp, "planet") == 0) + style = PLANET_STYLE; + else { + style = APPLIST_STYLE; + } + return style; +} + +void SettingDesktopModel::SetDesktopStyle(DesktopStyle style) +{ + if (style == APPLIST_STYLE) { + (void)UtilsSetValue("applist_style", "list"); + } else if (style == HEXAGONS_STYLE) { + (void)UtilsSetValue("applist_style", "hexagons"); + } else if (style == FOOTBALL_STYLE) { + (void)UtilsSetValue("applist_style", "football"); + } else if (style == WATERFALL_STYLE) { + (void)UtilsSetValue("applist_style", "waterfall"); + } else if (style == PLANET_STYLE) { + (void)UtilsSetValue("applist_style", "planet"); + } +} + +uint8_t SettingDesktopModel::GetDesktopHomeDataSelect() +{ + DesktopStyle style = GetDesktopStyle(); + for (size_t i = 0; i < desktopHomeData_.size(); i++) { + if (desktopHomeData_[i].style == style) { + return i; + } + } + return 0; +} + +void SettingDesktopModel::SetDesktopHomeDataSelect(DesktopStyle style) +{ + for (auto& it : desktopHomeData_) { + it.isSelect = (it.style == style); + } + SetDesktopStyle(style); +} + +DialStyle SettingDesktopModel::GetDialStyle() +{ + DialStyle style; + char temp[STYLE_VALUE_LEN] = { 0 }; + (void)UtilsGetValue("set_dial_style", temp, STYLE_VALUE_LEN); + if (strcmp(temp, "DialStyle::ROLLER") == 0) { + style = DialStyle::ROLLER; + } else { // "DialStyle::COVERFLOW" or "" + style = DialStyle::COVERFLOW; + } + return style; +} + +void SettingDesktopModel::SetDialStyle(DialStyle style) +{ + if (style == DialStyle::COVERFLOW) { + (void)UtilsSetValue("set_dial_style", "DialStyle::COVERFLOW"); + } else if (style == DialStyle::ROLLER) { + (void)UtilsSetValue("set_dial_style", "DialStyle::ROLLER"); + } +} + +void SettingDesktopModel::SetDialStyleDataSelect(const char* DialStyleName) +{ + auto coverflowItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_COVERFLOW_IDX].GetUnionItemData()); + auto rollerItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_ROLLER_IDX].GetUnionItemData()); + auto aodItemData = static_cast( + dialStyleUnionData_[SETTING_DIAL_STYLE_AOD_IDX].GetUnionItemData()); + + if (strcmp(DialStyleName, aodItemData->textContent) == 0) { + aodItemData->selected = !aodItemData->selected; + MainModel::GetInstance().EnableAod(aodItemData->selected); + } else { + DialStyle style; + rollerItemData->selected = !rollerItemData->selected; + coverflowItemData->selected = !coverflowItemData->selected; + style = rollerItemData->selected ? DialStyle::ROLLER : DialStyle::COVERFLOW; + SetDialStyle(style); + } +} + +void SettingDesktopModel::LoadAllDial(void) +{ + LoadAllDialFromRam(); // 导入在线表盘 + size_t dialSize = dialInfos_.size(); + size_t aodSize = aodDialInfos_.size(); + LoadAllDialFromFs(); // 导入离线表盘 + /* 只排序离线表盘 */ + std::sort(dialInfos_.begin() + dialSize, dialInfos_.end(), [](const SetDialInfo& f, const SetDialInfo& n) { + return f.dialName < n.dialName; + }); + std::sort(aodDialInfos_.begin() + aodSize, + aodDialInfos_.end(), + [](const SetDialInfo &f, const SetDialInfo &n) { return f.dialName < n.dialName; }); +} + +std::vector& SettingDesktopModel::GetDialInfo(void) +{ + return dialInfos_; +} + +std::vector& SettingDesktopModel::GetAmbientDialInfo(void) +{ + return aodDialInfos_; +} + +void SettingDesktopModel::SaveDialSetting(uint8_t pageIndex) +{ + if (pageIndex >= dialInfos_.size()) { + return; + } + DialSetting diagSetting; + SetDialInfo &info = dialInfos_[pageIndex]; + diagSetting.dialFlag = info.dialFlag; + diagSetting.dialId = info.id; + diagSetting.dialFullName = info.dialFullName; + MainModel::GetInstance().AddDialSetting(diagSetting); +} + +void SettingDesktopModel::SetSpecifyDialSetting(const DialSetting &setting) +{ + hasSpecificDial_ = true; + specificDialSetting_ = setting; +} + +void SettingDesktopModel::ClearDialInfo(void) +{ + for (auto iter : dialInfos_) { + if (iter.dialFlag) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(iter.resId, iter.dialFullName); + } else { + ImageCacheManager::GetInstance().UnloadSingleRes(iter.imageFullName); + } + } + dialInfos_.clear(); + aodDialInfos_.clear(); + + if (hasSpecificDial_) { + MainModel::GetInstance().GetDialSetting() = specificDialSetting_; + MainModel::GetInstance().AddDialSetting(specificDialSetting_); + } +} + +uint8_t SettingDesktopModel::GetPageIndex(void) +{ + uint8_t index = 0; + DialSetting dialSetting = MainModel::GetInstance().GetDialSetting(); + for (auto& iter : dialInfos_) { + if (dialSetting.dialFlag) { + if (strcmp(iter.dialFullName.c_str(), dialSetting.dialFullName.c_str()) == 0) { + return index; + } + } else { + if ((!iter.dialFlag) && (iter.id == dialSetting.dialId)) { + return index; + } + } + index++; + } + return 0; +} + +void SettingDesktopModel::LoadAllDialFromRam() +{ + for (uint8_t i = 0; i < MainModel::GetInstance().GetDialInfoNum(); i++) { + const DialInfo *info = MainModel::GetInstance().GetDialInfo(i); + if (info == nullptr) { + continue; + } + SetDialInfo dialInfo{0}; + dialInfo.dialFlag = 0; + dialInfo.id = i; + dialInfo.dialName = info->dialName; + dialInfo.imageFullName = info->dialImg; + ImageInfo* imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(info->dialImg, false); + if (info == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", info->dialImg); + continue; + } + dialInfo.preImageInfo = imageInfo; + if (info->capability == DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY) { + dialInfos_.push_back(dialInfo); + } else if (info->capability == DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY) { + aodDialInfos_.push_back(dialInfo); + } else { + dialInfos_.push_back(dialInfo); + aodDialInfos_.push_back(dialInfo); + } + } +} + +void SettingDesktopModel::LoadAllDialFromFs() +{ + struct dirent *direntp; + + // 打开目录 + DIR *dirp = opendir(APP_DIAL_PATH); + // 遍历文件 + if (dirp != nullptr) { + while ((direntp = readdir(dirp)) != nullptr) { + SetDialInfo dialInfo{0}; + if (ParseDialHeader(direntp->d_name, dialInfo) != 0) { + continue; + } + if (dialInfo.capability == DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY) { + dialInfos_.push_back(dialInfo); + } else if (dialInfo.capability == DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY) { + aodDialInfos_.push_back(dialInfo); + } else { + dialInfos_.push_back(dialInfo); + aodDialInfos_.push_back(dialInfo); + } + } + } + // 关闭目录 + closedir(dirp); +} + +int32_t SettingDesktopModel::ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo) +{ + std::string dialFullName = APP_DIAL_PATH; + dialFullName += "/"; + dialFullName += dialFileName; + FILE *fp = fopen(dialFullName.c_str(), "rb"); + if (fp == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader cannot open file: %s", + dialFullName.c_str()); + return -1; + } + DialPreviewInfo preInfo{0}; + bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(dialFullName, fp, &preInfo); + if (!ret) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialPreviewInfo %s fail", dialFullName.c_str()); + fclose(fp); + return -1; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialFullName: %s", dialFullName.c_str()); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialName: %s", preInfo.dialName); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseDialHeader description: %s", preInfo.description); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseDialHeader previewImgId: %u", preInfo.imgId); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ParseDialHeader imageOffset: %u", preInfo.offset); + ImageInfo *info = ImageCacheManager::GetInstance().LoadOneInMultiRes( + preInfo.imgId, dialFullName, fp, false, preInfo.offset); + if (info == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader loadimage fail"); + fclose(fp); + return -1; + } + + dialInfo.dialFlag = 1; + dialInfo.id = 0; + dialInfo.resId = preInfo.imgId; + dialInfo.dialFullName = dialFullName; + dialInfo.dialName = preInfo.dialName; + dialInfo.description = preInfo.description; + dialInfo.preImageInfo = info; + dialInfo.capability = preInfo.capability; + + fclose(fp); + return 0; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDisplayModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDisplayModel.cpp new file mode 100644 index 000000000..3c7f9d644 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingDisplayModel.cpp @@ -0,0 +1,347 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayModel + * Create: 2025-06-01 + */ + +#include "kv_store.h" +#ifndef _WIN32 +#include "screennotify/ui_screennotify.h" +#endif +#include "power_display_service.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "main/HealthModel.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingDisplayModel.h" + +namespace OHOS { +static constexpr uint32_t SETTING_DISPLAY_VALUE_LEN = 32; +static constexpr uint8_t SETTING_DISPLAY_MODLE_BRI_PERCENT_MAX = 100; +static constexpr uint8_t SETTING_DISPLAY_MODEL_BRI_PERCENT_DEFAULT = 50; +static constexpr uint8_t SETTING_DISPLAY_MODLE_BRI_RANGE_MIN = 55; +static constexpr uint8_t SETTING_DISPLAY_MODLE_BRI_RANGE_STEP = 2; +static const char* SETTING_SCREEN_OFF_ALL_STR[] = {"5秒钟", "10秒钟", "15秒钟", "30秒钟", "1分钟", "5分钟"}; +static const char* SETTING_STEADY_ON_ALL_STR[] = {"5分钟", "10分钟", "20分钟", "30分钟", "1小时", "2小时"}; +enum SettingStrIndex {INDEX_0, INDEX_1, INDEX_2, INDEX_3, INDEX_4, INDEX_5, INDEX_6}; + +SettingDisplayModel::SettingDisplayModel() +{ + std::vector tempUnionData = {{ + PlainTextItemData{"显示与亮度"}, + IconTextNavigationItemData{SettingPageId::DISPLAY_BRIGHTNESS_PAGE, IMAGE_DISPLAY_LIST_ADJUST_BRIGHTNESS, + "调节亮度", nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextToggleItemData{IMAGE_DISPLAY_LIST_AUTO_ADJUST, "自动调节", false, + SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DISPLAY_SCREEN_OFF_PAGE, IMAGE_DISPLAY_LIST_SCREEN_OFF_TIME, + "熄屏时间", nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DISPLAY_STEADY_ON_PAGE, IMAGE_DISPLAY_LIST_SCREEN_ON_TIME, + "长亮时刻", nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + }}; + displayUnionData_.swap(tempUnionData); +} + +std::vector& SettingDisplayModel::GetDisplayUnionData() +{ + RefreshDisplayUnionDataForAutoAdjustBrightness(); + RefreshDisPlayUnionDataForScreenOffDataContext(); + RefreshDisplayUnionDataForSteadyOnDataContext(); + return displayUnionData_; +} + +void SettingDisplayModel::RefreshDisplayUnionDataForAutoAdjustBrightness() +{ + auto toggleItemData = static_cast(displayUnionData_[INDEX_2].GetUnionItemData()); + toggleItemData->selected = GetAutoAdjustBrightness(); +} + +void SettingDisplayModel::RefreshDisPlayUnionDataForScreenOffDataContext() +{ + auto screenOffItemData = static_cast(displayUnionData_[INDEX_3].GetUnionItemData()); + screenOffItemData->dataContent = GetScreenOffTimeShortStr(GetScreenOffTime()); +} + +void SettingDisplayModel::RefreshDisplayUnionDataForSteadyOnDataContext() +{ + auto steadyOnItemData = static_cast(displayUnionData_[INDEX_4].GetUnionItemData()); + steadyOnItemData->dataContent = GetSteadyOnTimeShortStr(GetSteadyOnTime()); +} + +void SettingDisplayModel::InitDisplayModel() +{ + const power_display_svr_api_t* svr = power_display_svr_get_api(); + if (svr == nullptr) { + return; + } + // 设置亮度调节模式 + SetAutoAdjustBrightness(GetAutoAdjustBrightness()); + // 设置当前亮度 + SetBrightness(GetBrightness()); + // 设置熄屏时间 + SetScreenOffTime(GetScreenOffTime()); +} + +void SettingDisplayModel::EnableSteadyOn() +{ + const power_display_svr_api_t *srv = power_display_svr_get_api(); + if (srv == nullptr) { + return; + } + if (OHOS::HealthModel::GetInstance()->GetBriScrStatus() == 0) { +#if !defined(_WIN32) + // 设置应用永不返回 + set_back_to_home_interval(0xFFFFFFFF); +#endif + if (srv->get_screen_state() != SCREEN_ON) { + srv->turn_on_screen(); + } + srv->set_screen_set_keepon_timeout((uint32_t)GetSteadyOnTime()); + } +} + +void SettingDisplayModel::DisableSteadyOn() +{ + const power_display_svr_api_t *srv = power_display_svr_get_api(); + if (srv == nullptr) { + return; + } + if (OHOS::HealthModel::GetInstance()->GetBriScrStatus() == 0) { +#if !defined(_WIN32) + // 设置应用的返回时间和灭屏时间相同 + set_back_to_home_interval((uint32_t)GetScreenOffTime()); +#endif + srv->set_screen_auto_off_timeout((uint32_t)GetScreenOffTime()); + srv->set_screen_set_keepon_timeout(0); + } +} + +bool SettingDisplayModel::GetAutoAdjustBrightness() +{ + uint8_t brightness = 0; + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + (void)UtilsGetValue("auto_adjust_brightness", temp, SETTING_DISPLAY_VALUE_LEN); + if (strcmp(temp, "auto") == 0) { + return true; + } else if (strcmp(temp, "manual") == 0) { + return false; + } + // 配置文件读取失败时, 取当前系统的设置 + const power_display_svr_api_t* svr = power_display_svr_get_api(); + if (svr == nullptr) { + return false; + } + return svr->get_brightness_mode() == AUTO; +} + +void SettingDisplayModel::SetAutoAdjustBrightness(bool isAuto) +{ + const power_display_svr_api_t* svr = power_display_svr_get_api(); + if (svr == nullptr) { + return; + } + if (isAuto) { + svr->set_brightness_mode(AUTO); + // 自动调节没有传感器支持, 当前设置为默认亮度 + svr->set_brightness(TransBriPercentToValue(SETTING_DISPLAY_MODEL_BRI_PERCENT_DEFAULT)); + (void)UtilsSetValue("auto_adjust_brightness", "auto"); + } else { // 从自动调节转到非自动调节时, 设置存储的亮度值 + svr->set_brightness_mode(MANUAL); + svr->set_brightness(TransBriPercentToValue(GetBrightness())); + (void)UtilsSetValue("auto_adjust_brightness", "manual"); + } +} + +uint8_t SettingDisplayModel::GetBrightness() +{ + uint32_t brightness = 0; + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + (void)UtilsGetValue("brightness", temp, SETTING_DISPLAY_VALUE_LEN); + if (sscanf_s(temp, "%hhu", &brightness) != 1) { + // 配置文件读取失败时, 取最大亮度的50% + return SETTING_DISPLAY_MODEL_BRI_PERCENT_DEFAULT; + } + if (brightness > SETTING_DISPLAY_MODLE_BRI_PERCENT_MAX) { + brightness = SETTING_DISPLAY_MODLE_BRI_PERCENT_MAX; + } + return brightness; +} + +void SettingDisplayModel::SetBrightness(uint8_t brightness) +{ + if (brightness > SETTING_DISPLAY_MODLE_BRI_PERCENT_MAX) { + brightness = SETTING_DISPLAY_MODLE_BRI_PERCENT_MAX; + } + // 非自动调节时 应用传入亮度值, 否则仅保存亮度值 + if (!GetAutoAdjustBrightness()) { + const power_display_svr_api_t* svr = power_display_svr_get_api(); + if (svr == nullptr) { + return; + } + svr->set_brightness(TransBriPercentToValue(brightness)); + } + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + if (sprintf_s(temp, sizeof(temp), "%u", brightness) > 0) { + (void)UtilsSetValue("brightness", temp); + } +} + +ScreenOffTime SettingDisplayModel::GetScreenOffTime() +{ + ScreenOffTime screenOffTime = ScreenOffTime::SECONDS_5; + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + (void)UtilsGetValue("screen_off_time", temp, SETTING_DISPLAY_VALUE_LEN); + if (sscanf_s(temp, "%u", &screenOffTime) == 0) { + return ScreenOffTime::SECONDS_5; + } + return screenOffTime; +} + +void SettingDisplayModel::SetScreenOffTime(ScreenOffTime screenOffTime) +{ + const power_display_svr_api_t* svr = power_display_svr_get_api(); + if (svr == nullptr) { + return; + } + // 设置灭屏时间 + errcode_t err = svr->set_screen_auto_off_timeout((uint32_t)screenOffTime); +#if !defined(_WIN32) + // 设置应用返回的时间和灭屏时间同步 + set_back_to_home_interval((uint32_t)screenOffTime); +#endif + // 保存灭屏时间到配置 + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + if (sprintf_s(temp, sizeof(temp), "%u", screenOffTime) > 0) { + (void)UtilsSetValue("screen_off_time", temp); + } + return; +} + +SteadyOnTime SettingDisplayModel::GetSteadyOnTime() +{ + SteadyOnTime steadyOnTime = SteadyOnTime::MINUTE_10; + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + (void)UtilsGetValue("steady_on_time", temp, SETTING_DISPLAY_VALUE_LEN); + if (sscanf_s(temp, "%u", &steadyOnTime) == 0) { + return SteadyOnTime::MINUTE_5; + } + return steadyOnTime; +} + +void SettingDisplayModel::SetSteadyOnTime(SteadyOnTime steadyOnTime) +{ + char temp[SETTING_DISPLAY_VALUE_LEN] = ""; + if (sprintf_s(temp, sizeof(temp), "%u", steadyOnTime) > 0) { + (void)UtilsSetValue("steady_on_time", temp); + } +} + +const char** SettingDisplayModel::GetScreenOffTimeAllStr() +{ + return SETTING_SCREEN_OFF_ALL_STR; +} + +const char** SettingDisplayModel::GetSteadyOnTimeAllStr() +{ + return SETTING_STEADY_ON_ALL_STR; +} + +uint8_t SettingDisplayModel::GetScreenOffTimeAllStrSize() +{ + return sizeof(SETTING_SCREEN_OFF_ALL_STR)/sizeof(SETTING_SCREEN_OFF_ALL_STR[0]); +} + +uint8_t SettingDisplayModel::GetSteadyOnTimeAllStrSize() +{ + return sizeof(SETTING_STEADY_ON_ALL_STR)/sizeof(SETTING_SCREEN_OFF_ALL_STR[0]); +} + +uint8_t SettingDisplayModel::GetScreenOffTimeIndex() +{ + ScreenOffTime screenOffTime = GetScreenOffTime(); + switch (screenOffTime) { + case ScreenOffTime::SECONDS_5: return INDEX_0; + case ScreenOffTime::SECONDS_10: return INDEX_1; + case ScreenOffTime::SECONDS_15: return INDEX_2; + case ScreenOffTime::SECONDS_30: return INDEX_3; + case ScreenOffTime::MINUTE_1: return INDEX_4; + case ScreenOffTime::MINUTE_5: return INDEX_5; + } +} + +uint8_t SettingDisplayModel::GetSteadyOnTimeIndex() +{ + SteadyOnTime steadyOnTime = GetSteadyOnTime(); + switch (steadyOnTime) { + case SteadyOnTime::MINUTE_5: return INDEX_0; + case SteadyOnTime::MINUTE_10: return INDEX_1; + case SteadyOnTime::MINUTE_20: return INDEX_2; + case SteadyOnTime::MINUTE_30: return INDEX_3; + case SteadyOnTime::HOUR_1: return INDEX_4; + case SteadyOnTime::HOUR_2: return INDEX_5; + } +} + +void SettingDisplayModel::SetScreenOffTimeIndex(uint8_t index) +{ + ScreenOffTime screenOffTime; + switch (index) { + case INDEX_0: screenOffTime = ScreenOffTime::SECONDS_5; break; + case INDEX_1: screenOffTime = ScreenOffTime::SECONDS_10; break; + case INDEX_2: screenOffTime = ScreenOffTime::SECONDS_15; break; + case INDEX_3: screenOffTime = ScreenOffTime::SECONDS_30; break; + case INDEX_4: screenOffTime = ScreenOffTime::MINUTE_1; break; + case INDEX_5: screenOffTime = ScreenOffTime::MINUTE_5; break; + default: return; + } + SetScreenOffTime(screenOffTime); +} + +void SettingDisplayModel::SetSteadyOnTimeIndex(uint8_t index) +{ + SteadyOnTime steadyOnTime; + switch (index) { + case INDEX_0: steadyOnTime = SteadyOnTime::MINUTE_5; break; + case INDEX_1: steadyOnTime = SteadyOnTime::MINUTE_10; break; + case INDEX_2: steadyOnTime = SteadyOnTime::MINUTE_20; break; + case INDEX_3: steadyOnTime = SteadyOnTime::MINUTE_30; break; + case INDEX_4: steadyOnTime = SteadyOnTime::HOUR_1; break; + case INDEX_5: steadyOnTime = SteadyOnTime::HOUR_2; break; + default: return; + } + SetSteadyOnTime(steadyOnTime); +} + +const char* SettingDisplayModel::GetScreenOffTimeShortStr(ScreenOffTime screenOffTime) +{ + switch (screenOffTime) { + case ScreenOffTime::SECONDS_5: return "5s"; + case ScreenOffTime::SECONDS_10: return "10s"; + case ScreenOffTime::SECONDS_15: return "15s"; + case ScreenOffTime::SECONDS_30: return "30s"; + case ScreenOffTime::MINUTE_1: return "1m"; + case ScreenOffTime::MINUTE_5: return "5m"; + } +} + +const char* SettingDisplayModel::GetSteadyOnTimeShortStr(SteadyOnTime steadyOnTime) +{ + switch (steadyOnTime) { + case SteadyOnTime::MINUTE_5: return "5m"; + case SteadyOnTime::MINUTE_10: return "10m"; + case SteadyOnTime::MINUTE_20: return "20m"; + case SteadyOnTime::MINUTE_30: return "30m"; + case SteadyOnTime::HOUR_1: return "1h"; + case SteadyOnTime::HOUR_2: return "2h"; + } +} + +uint8_t SettingDisplayModel::TransBriValueToPercent(uint8_t value) +{ + return (value - SETTING_DISPLAY_MODLE_BRI_RANGE_MIN) / SETTING_DISPLAY_MODLE_BRI_RANGE_STEP; +} + +uint8_t SettingDisplayModel::TransBriPercentToValue(uint8_t percent) +{ + return percent * SETTING_DISPLAY_MODLE_BRI_RANGE_STEP + SETTING_DISPLAY_MODLE_BRI_RANGE_MIN; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingMainModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingMainModel.cpp new file mode 100644 index 000000000..edf24ab45 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingMainModel.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainModel + * Create: 2025-06-01 + */ +#include "Slice.h" +#include "UiConfig.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingMainModel.h" + +namespace OHOS { +SettingMainModel::SettingMainModel() +{ + std::vector tempUnionData = {{ + PlainTextItemData{"设置"}, + IconTextNavigationItemData{SettingPageId::BLUETOOTH_PAGE, IMAGE_MAIN_LIST_BLUETOOTH, "蓝牙", + nullptr, true, SETTING_LIST_BLUETOOTH_BG_COLOR, SETTING_LIST_BLUETOOTH_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DISPLAY_PAGE, IMAGE_MAIN_LIST_DISPLAY, "显示与亮度", + nullptr, true, SETTING_LIST_DISPLAY_BG_COLOR, SETTING_LIST_DISPLAY_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::DESKTOP_PAGE, IMAGE_MAIN_LIST_DESKTOP, "表盘与桌面", + nullptr, true, SETTING_LIST_DESKTOP_BG_COLOR, SETTING_LIST_DESKTOP_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::POWER_PAGE, IMAGE_MAIN_LIST_POWER, "电量", + nullptr, true, SETTING_LIST_POWER_BG_COLOR, SETTING_LIST_POWER_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::CARD_PAGE, IMAGE_MAIN_LIST_CARD, "卡片", + nullptr, true, SETTING_LIST_CARD_BG_COLOR, SETTING_LIST_CARD_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::SYSTEM_PAGE, IMAGE_MAIN_LIST_SYSTEM, "系统和升级", + nullptr, true, SETTING_LIST_SYSTEM_BG_COLOR, SETTING_LIST_SYSTEM_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::ABOUT_PAGE, IMAGE_MAIN_LIST_ABOUT, "关于", + nullptr, true, SETTING_LIST_ABOUT_BG_COLOR, SETTING_LIST_ABOUT_BG_COLOR_OPA}, + }}; + mainUnionData_.swap(tempUnionData); +} + +std::vector& SettingMainModel::GetMainUnionData() +{ + return mainUnionData_; +} + +UIView* SettingMainModel::OnSimpleListCreate(uint8_t type) +{ + if (type == SettingUnionItemType::PLAIN_TEXT) { + return new PlainTextItemView(); + } else if (type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + return new IconTextToggleItemView(); + } else if (type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + return new IconTextNavigationItemView(); + } + return nullptr; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingPowerModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingPowerModel.cpp new file mode 100644 index 000000000..60f49e2e4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingPowerModel.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPowerModel + * Create: 2025-06-01 + */ +#if !defined(_WIN32) +#include "osal_interrupt.h" +#endif +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingPowerModel.h" + +namespace OHOS { +static constexpr const uint8_t percentage_scale = 100; // 百分比换算基数 +static constexpr const uint8_t percentage_max = 100; +static constexpr const uint8_t percentage_min = 0; + +static constexpr const uint32_t adc_reference_ratio_numerator = 450U; +static constexpr const uint32_t adc_reference_ratio_denominator = 1024U / 2U; +static constexpr const uint32_t millivolt_per_volt = 1000U; + +static constexpr const uint32_t def_samples_to_keep = 10; +static constexpr const uint32_t def_samples_to_discard = 5; +static constexpr const uint32_t def_adc_max_range_mv = 380; +static constexpr const uint32_t def_adc_min_range_mv = 0; + +#if !defined(_WIN32) +SettingPowerModel::SettingPowerModel() +{ + channel_ = ADC_CHANNEL_3; + analog_pin_ = S_AGPIO_L27; + mode_ = PIN_MODE_0; + samples_to_keep_ = def_samples_to_keep; + samples_to_discard_ = def_samples_to_discard; + // 毫伏更容易计算电量百分比 + adc_max_range_mv_ = def_adc_max_range_mv; + adc_min_range_mv_ = def_adc_min_range_mv; +} + +SettingPowerModel::~SettingPowerModel() +{ + adc_context_shutdown(); +} + +uint8_t SettingPowerModel::GetBatteryPowerLevel() +{ + uint32_t voltage = 0; + // 从adc获取电压值 + if (adc_context_startup()) { + voltage = calc_voltage(); + } + adc_context_shutdown(); + // 根据电压值计算电量百分比 + return calc_percentage(voltage); +} + +const char* SettingPowerModel::GetPowerModelNotify() +{ + return "这是相对于新电池而言的电池容量。容量较低可能导致充电后,电池使用时间缩短。内建动态软硬件系统将协助克服随手表化学老化出现的性能影响。"; +} + +bool SettingPowerModel::adc_context_init() +{ + // 初始化pin模块 + uapi_pin_init(); + // 初始化高精度计数器 + errcode_t err = uapi_tcxo_init(); + if (err != ERRCODE_SUCC) { + return false; + } + // 设置pin脚模式 + err = uapi_pin_set_mode(analog_pin_, mode_); + if (err != ERRCODE_SUCC) { + return false; + } + return true; +} + +bool SettingPowerModel::adc_context_startup() +{ + errcode_t err = uapi_adc_init(ADC_CLOCK_500KHZ); // 初始化adc + if (err != ERRCODE_SUCC) { + return false; + } + uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, true); + err = uapi_adc_open_channel(channel_); + if (err != ERRCODE_SUCC) { + return false; + } + return true; +} + +void SettingPowerModel::adc_context_shutdown() +{ + errcode_t err = uapi_adc_close_channel(channel_); + if (err != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_adc_close_channel error %u", err); + } + uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, false); + uapi_adc_deinit(); +} + +uint8_t SettingPowerModel::calc_percentage(uint32_t voltage) +{ + if (voltage >= adc_max_range_mv_) { + return percentage_max; + } + if (voltage <= adc_min_range_mv_) { + return percentage_min; + } + + uint32_t voltage_range = adc_max_range_mv_ - adc_min_range_mv_; + uint32_t rounding_term = voltage_range / 2; + uint32_t voltage_offset = voltage - adc_min_range_mv_; + return static_cast((voltage_offset * percentage_scale + rounding_term) / voltage_range); +} + +uint32_t SettingPowerModel::calc_voltage() +{ + // 丢弃初始帧数据 + for (uint32_t i = 0; i < samples_to_discard_; i++) { + uapi_adc_manual_sample(ADC_CHANNEL_NONE); + uapi_tcxo_delay_ms((uint64_t)3); // 延迟3ms + } + + uint32_t stick = 0; + uint32_t stick_count = 0; + // 采集样本数 + for (uint32_t i = 0; i < samples_to_keep_; i++) { + uint32_t irq_sts = osal_irq_lock(); + uint32_t sample_result = + (uint32_t)uapi_adc_manual_sample(ADC_CHANNEL_NONE); // 每次读取CHANNEL_NONE? testsuit中是这样写的 + if (sample_result != 0) { + stick += sample_result; + stick_count++; + } + osal_irq_restore(irq_sts); + } + if (stick_count == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "calc voltage error, no result"); + return 0; + } + return adc_trans_sytick_to_voltages(stick / stick_count); +} + +uint32_t SettingPowerModel::adc_trans_sytick_to_voltages(uint32_t sytick) +{ + // 整数运算公式:(sytick * numerator + denominator/2) / denominator + return (sytick * adc_reference_ratio_numerator + adc_reference_ratio_denominator) / adc_reference_ratio_denominator; +} +#else +uint8_t SettingPowerModel::GetBatteryPowerLevel() +{ + return percentage_max; +} + +const char* SettingPowerModel::GetPowerModelNotify() +{ + return "这是相对于新电池而言的电池容量。容量较低可能导致充电后,电池使用时间缩短。内建动态软硬件系统将协助克服随手表化学老化出现的性能影响。"; +} +#endif +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingQrcodeConnModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingQrcodeConnModel.cpp new file mode 100644 index 000000000..d832f79de --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingQrcodeConnModel.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingQrcodeConnModel + * Created: 2025-06-05 + */ + +#include "settings/model/SettingQrcodeConnModel.h" + +namespace OHOS { +SettingQrcodeConnModel::SettingQrcodeConnModel() {} + +SettingQrcodeConnModel::~SettingQrcodeConnModel() {} + +SettingQrcodeConnModel &SettingQrcodeConnModel::GetInstance() +{ + static SettingQrcodeConnModel instance; + return instance; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingSystemModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingSystemModel.cpp new file mode 100644 index 000000000..ed4bd4d6f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/model/SettingSystemModel.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemModel + * Create: 2025-06-01 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#if !defined(_WIN32) +#include "tcxo.h" +#include "upg.h" +#include "upg_porting.h" +#include "upg_definitions.h" +#include "upg_common_porting.h" +#endif +#include "dfx_reboot.h" +#include "bundlems_slite_client.h" +#include "abilityms_slite_client.h" +#include "bundle_info.h" +#include "adapter.h" +#ifdef SUPPORT_ALIPAY_SEC +#include "alipay_feature.h" +#endif +#include "UiConfig.h" +#include "wearable_log.h" +#include "sport/SportModel.h" +#include "gfx_utils/list.h" +#include "bts_def.h" +#include "bts_br_gap.h" +#include "flashlight/FlashLightModel.h" +#include "settings/model/SettingSystemModel.h" + + +namespace OHOS { +#define MODLE_THREAD_STACK_SIZE 4096 +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_5 = 5; +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_10 = 10; +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_25 = 25; +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_40 = 40; +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_50 = 50; +static constexpr uint8_t SETTING_SYSTEM_OTA_PERCENT_100 = 100; + +SettingSystemModel::SettingSystemModel() +{ + std::vector tempUnionData = {{ + PlainTextItemData{"系统和升级"}, + IconTextNavigationItemData{SettingPageId::SYSTEM_OPERATION_PAGE, IMAGE_SYSTEM_LIST_POWEROFF, "关机", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::SYSTEM_OPERATION_PAGE, IMAGE_SYSTEM_LIST_RESTART, "重启", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::SYSTEM_OPERATION_PAGE, IMAGE_SYSTEM_LIST_RESUME, "恢复出厂", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + IconTextNavigationItemData{SettingPageId::SYSTEM_OTA_PAGE, IMAGE_SYSTEM_LIST_OTA, "OTA升级", + nullptr, true, SETTING_LIST_DEFAULT_BG_COLOR, SETTING_LIST_DEFAULT_BG_COLOR_OPA}, + }}; + systemUnionData_.swap(tempUnionData); +} + +SettingSystemModel::~SettingSystemModel() +{ +#if !defined(_WIN32) + if (systemOtaTask_ != nullptr) { + osal_kthread_destroy(systemOtaTask_, 0); + } +#endif +} + +std::vector& SettingSystemModel::GetSystemUnionData() +{ + return systemUnionData_; +} + +void SettingSystemModel::SystemOperation(const char* operationName) +{ +#if !defined(_WIN32) + if (strcmp(operationName, "关机") == 0) { + uapi_system_shutdown(0); + } else if (strcmp(operationName, "重启") == 0) { + uapi_system_reboot(SYSTEM_SOFT_REBOOT); + } else if (strcmp(operationName, "恢复出厂") == 0) { + RestoreJSApplication(); + RestoreNativeApplication(); + RestoreKvstore(); + uapi_system_reboot(SYSTEM_SOFT_REBOOT); + } +#endif +} + +void SettingSystemModel::RestoreJSApplication() +{ +#if !defined(_WIN32) + bool res = bluetooth_factory_reset(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_factory_reset res:%u.", (uint32_t)res); +#ifdef SUPPORT_ALIPAY_SEC + (void)uapi_alipay_svr_reset(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "uapi_alipay_svr_reset process."); +#endif + + BundleInfo *bundleInfos = nullptr; + int32_t bundleCount = 0; + uint32_t err = ERRCODE_FAIL; + + err = BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &bundleCount); + if (err != 0) { + bundleCount = 0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Get bundleInfos Failed, errno is %d\n", err); + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "----------------- AppList Start[%d] ------------------", bundleCount); + for (int32_t i = 0; ibundleName, bundleInfos[i].bundleName) == 0)) { + AbilityMsClient::GetInstance().TerminateAbility(0); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "terminate %-20s", bundleInfos[i].bundleName); + } + + InstallParam installParam = {.installLocation = 1, .keepData = false}; + BundleMsClient::GetInstance().Uninstall(bundleInfos[i].bundleName, &installParam, + SettingSystemModel::UninstallCallback); + FreeElement(topAbility); + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "----------------- AppList End[%d] ------------------", bundleCount); + + if (bundleInfos != nullptr && bundleCount != 0) { + for (int32_t i = 0; id_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + std::string full_path = std::string(path) + "/" + entry->d_name; + struct stat statbuf; + if (lstat(full_path.c_str(), &statbuf) == -1) + continue; + if (!S_ISDIR(statbuf.st_mode)) { + unlink(full_path.c_str()); + } + } + closedir(dir); +#endif +#endif +} + +void SettingSystemModel::UninstallCallback(const uint8_t resultCode, const void *resultMessage) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Uninstall %-20s, %u", resultMessage, resultCode); +} + +uint32_t SettingSystemModel::GetOtaPackageSize() +{ +#if !defined(_WIN32) + FILE *fp = fopen(upg_get_pkg_file_path(), "rb"); + if (fp == nullptr) { + return 0; + } + fseek(fp, 0L, SEEK_END); + uint32_t total_size = ftell(fp); + fclose(fp); + + return total_size; +#else + return 0; +#endif +} + +bool SettingSystemModel::GetOtaIsUpgrade() +{ + std::lock_guard lock(otaOSALMtx_); +#ifndef _WIN32 + return systemOtaTask_ != nullptr; +#else + return false; +#endif +} + +uint8_t SettingSystemModel::GetOtaNativeUpgradePercent() +{ + std::lock_guard lock(otaOSALMtx_); + return otaUpgradePrecent_; +} + +std::string SettingSystemModel::GetOtaNativeUpgradeMessage() +{ + std::lock_guard lock(otaOSALMtx_); + return otaUpgradeMessage_; +} + +void SettingSystemModel::SetOtaNativeUpgradePercent(uint8_t percent) +{ + std::lock_guard lock(otaOSALMtx_); + otaUpgradePrecent_ = percent; +} + +void SettingSystemModel::SetOtaNativeUpgradeMessage(std::string message) +{ + std::lock_guard lock(otaOSALMtx_); + otaUpgradeMessage_ = message; +} + +void SettingSystemModel::StartOtaNativeUpgrade() +{ +#if !defined(_WIN32) + systemOtaTask_ = osal_kthread_create(&SettingSystemModel::SystemOta, this, + "sys_ota", MODLE_THREAD_STACK_SIZE); + if (systemOtaTask_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ota osal_wait_init error"); + return; + } +#endif +} + +void SettingSystemModel::StopOtaNativeUpgrade() +{ +#if !defined(_WIN32) + if (systemOtaTask_ != nullptr) { + osal_kthread_destroy(systemOtaTask_, 0); + systemOtaTask_ = nullptr; + } +#endif +} + +int SettingSystemModel::SystemOta(void *data) +{ + SettingSystemModel* model = (SettingSystemModel*)data; + do { +#if !defined(_WIN32) + upg_prepare_info_t info; + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_5); + model->SetOtaNativeUpgradeMessage("检查文件..."); + info.package_len = model->GetOtaPackageSize(); + if (info.package_len == 0) { + model->SetOtaNativeUpgradeMessage("检查文件失败"); + break; + } + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_10); + model->SetOtaNativeUpgradeMessage("准备中..."); + errcode_t ret = uapi_upg_prepare(&info); + if (ret != ERRCODE_SUCC) { + model->SetOtaNativeUpgradeMessage("准备失败"); + break; + } + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_25); + model->SetOtaNativeUpgradeMessage("申请升级..."); + ret = uapi_upg_request_upgrade(false); + if (ret != ERRCODE_SUCC) { + model->SetOtaNativeUpgradeMessage("申请升级失败"); + break; + } + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_40); + model->SetOtaNativeUpgradeMessage("备份系统..."); + ret = upg_image_backups_update(); + if (ret != ERRCODE_SUCC) { + model->SetOtaNativeUpgradeMessage("备份失败"); + break; + } + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_50); + model->SetOtaNativeUpgradeMessage("升级中..."); + ret = uapi_upg_start(); + if (ret != ERRCODE_SUCC) { + model->SetOtaNativeUpgradeMessage("升级失败"); + break; + } + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_100); + model->SetOtaNativeUpgradeMessage("即将重启..."); + uapi_system_reboot(SYSTEM_SOFT_REBOOT); +#else + model->SetOtaNativeUpgradePercent(SETTING_SYSTEM_OTA_PERCENT_100); + model->SetOtaNativeUpgradeMessage("即将重启..."); +#endif + } while (false); + model->StopOtaNativeUpgrade(); // 停止线程 + return 0; +} +} // OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingAboutPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingAboutPage.cpp new file mode 100644 index 000000000..4453ab608 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingAboutPage.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingAboutPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "settings/model/SettingAboutModel.h" +#include "settings/page/SettingAboutPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::ABOUT_PAGE, SettingAboutPage, false); + +static constexpr int16_t SETTING_ABOUT_DEFAULT_X = 78; +static constexpr int16_t SETTING_ABOUT_DEFAULT_WIDTH = 298; +static constexpr int16_t SETTING_ABOUT_DEFAULT_DATA_OPA = 168; // 66% + +static const char* SETTING_ABOUT_TITLE_TEXT = "关于"; +static const char* SETTING_ABOUT_DEVICENAME_TEXT = "设备名称"; +static const char* SETTING_ABOUT_DEVICETYPE_TEXT = "型号"; + +static constexpr int16_t SETTING_ABOUT_TITLE_X = 100; +static constexpr int16_t SETTING_ABOUT_TITLE_Y = 39; +static constexpr int16_t SETTING_ABOUT_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_ABOUT_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_ABOUT_TITLE_FSIZE = 38; + +static constexpr int16_t SETTING_ABOUT_DEVICENAME_Y = 134; +static constexpr int16_t SETTING_ABOUT_DEVICENAME_HEIGHT = 54; +static constexpr int16_t SETTING_ABOUT_DEVICENAME_FSIZE = 38; + +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_Y = 268; +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_HEIGHT = 54; +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_FSIZE = 38; + +static constexpr int16_t SETTING_ABOUT_DEVICENAME_DATA_Y = 192; +static constexpr int16_t SETTING_ABOUT_DEVICENAME_DATA_HEIGHT = 45; +static constexpr int16_t SETTING_ABOUT_DEVICENAME_DATA_FSIZE = 32; + +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_DATA_Y = 322; +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_DATA_HEIGHT = 45; +static constexpr int16_t SETTING_ABOUT_DEVICETYPE_DATA_FSIZE = 32; + +void SettingAboutPage::OnStart(void* data) +{ + InitTitle(); + InitDeviceNameView(); + InitDeviceTypeView(); + AddViewToPageContainer(title_); + AddViewToPageContainer(deviceNameTitle_); + AddViewToPageContainer(deviceTypeTitle_); + AddViewToPageContainer(deviceName_); + AddViewToPageContainer(deviceType_); +} + +void SettingAboutPage::OnResume() +{ + deviceName_->SetText(SettingAboutModel::GetInstance().GetSystemName().c_str()); + deviceType_->SetText(SettingAboutModel::GetInstance().GetSystemType().c_str()); +} + +void SettingAboutPage::OnStop() +{ + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (deviceNameTitle_ != nullptr) { + delete deviceNameTitle_; + deviceNameTitle_ = nullptr; + } + if (deviceTypeTitle_ != nullptr) { + delete deviceTypeTitle_; + deviceTypeTitle_ = nullptr; + } + if (deviceName_ != nullptr) { + delete deviceName_; + deviceName_ = nullptr; + } + if (deviceType_ != nullptr) { + delete deviceType_; + deviceType_ = nullptr; + } +} + +void SettingAboutPage::InitTitle() +{ + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutPage::OnStart title_ new fail"); + return; + } + title_->SetPosition(SETTING_ABOUT_TITLE_X, SETTING_ABOUT_TITLE_Y); + title_->Resize(SETTING_ABOUT_TITLE_WIDTH, SETTING_ABOUT_TITLE_HEIGHT); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_ABOUT_TITLE_FSIZE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetText(SETTING_ABOUT_TITLE_TEXT); +} + +void SettingAboutPage::InitDeviceTypeView() +{ + deviceTypeTitle_ = new UILabel(); + if (deviceTypeTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutPage::OnStart deviceTypeTitle_ new fail"); + return; + } + deviceTypeTitle_->SetPosition(SETTING_ABOUT_DEFAULT_X, SETTING_ABOUT_DEVICETYPE_Y); + deviceTypeTitle_->Resize(SETTING_ABOUT_DEFAULT_WIDTH, SETTING_ABOUT_DEVICETYPE_HEIGHT); + deviceTypeTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deviceTypeTitle_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ABOUT_DEVICETYPE_FSIZE); + deviceTypeTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + deviceTypeTitle_->SetText(SETTING_ABOUT_DEVICETYPE_TEXT); + + deviceType_ = new UILabel(); + if (deviceType_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutPage::OnStart deviceType_ new fail"); + return; + } + deviceType_->SetPosition(SETTING_ABOUT_DEFAULT_X, SETTING_ABOUT_DEVICETYPE_DATA_Y); + deviceType_->Resize(SETTING_ABOUT_DEFAULT_WIDTH, SETTING_ABOUT_DEVICETYPE_DATA_HEIGHT); + deviceType_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deviceType_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ABOUT_DEVICETYPE_DATA_FSIZE); + deviceType_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + deviceType_->SetStyle(STYLE_TEXT_OPA, SETTING_ABOUT_DEFAULT_DATA_OPA); +} + +void SettingAboutPage::InitDeviceNameView() +{ + deviceNameTitle_ = new UILabel(); + if (deviceNameTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutPage::OnStart deviceNameTitle_ new fail"); + return; + } + deviceNameTitle_->SetPosition(SETTING_ABOUT_DEFAULT_X, SETTING_ABOUT_DEVICENAME_Y); + deviceNameTitle_->Resize(SETTING_ABOUT_DEFAULT_WIDTH, SETTING_ABOUT_DEVICENAME_HEIGHT); + deviceNameTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deviceNameTitle_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ABOUT_DEVICENAME_FSIZE); + deviceNameTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + deviceNameTitle_->SetText(SETTING_ABOUT_DEVICENAME_TEXT); + + deviceName_ = new UILabel(); + if (deviceName_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingAboutPage::OnStart deviceName_ new fail"); + return; + } + deviceName_->SetPosition(SETTING_ABOUT_DEFAULT_X, SETTING_ABOUT_DEVICENAME_DATA_Y); + deviceName_->Resize(SETTING_ABOUT_DEFAULT_WIDTH, SETTING_ABOUT_DEVICENAME_DATA_HEIGHT); + deviceName_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deviceName_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ABOUT_DEVICENAME_DATA_FSIZE); + deviceName_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + deviceName_->SetStyle(STYLE_TEXT_OPA, SETTING_ABOUT_DEFAULT_DATA_OPA); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingBluetoothPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingBluetoothPage.cpp new file mode 100644 index 000000000..04503b46c --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingBluetoothPage.cpp @@ -0,0 +1,814 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingBluetoothPage + * Created: 2025-06-05 + */ + +#include "components/ui_simple_list.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "ui_resource_settings.h" +#include "ohos_timer.h" +#include "graphic_service.h" +#include "main/LoadImg.h" +#include "settings/common/SettingCommon.h" +#include "settings/common/SettingBluetoothItemGroup.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::BLUETOOTH_PAGE, SettingBluetoothPage, false); + +static SettingBluetoothPage *g_pSettingBluetoothPage{nullptr}; +GraphicTimer* g_settingStopScanHandle = nullptr; +static constexpr uint32_t SCAN_TIME = 25000; +static constexpr int16_t SETTING_ADDR2 = 2; +static constexpr int16_t SETTING_ADDR3 = 3; +static constexpr int16_t SETTING_ADDR4 = 4; +static constexpr int16_t SETTING_ADDR5 = 5; +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_POSITION_Y = 350; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 50; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 LIST_POS = 20; +static constexpr int16 SNUM_2 = 2; +static constexpr int16_t SETTING_CONTENT_HEIGHT = 160; +static constexpr int16_t SETTING_TITLE_Y = 39; +static constexpr int16_t SETTING_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_TITLE_FONT = 38; +static constexpr int16_t SETTING_AVILABLE_Y = 102; +static constexpr int16_t SETTING_AVILABLE_HEIGHT = 39; +static constexpr int16_t SETTING_AVILABLE_FONT = 32; +static constexpr int16_t SETTING_SEATCHBTN_HEIGHT = 36; +static constexpr int16_t SETTING_SEATCHBTN_FONT = 30; +static constexpr int16_t SETTING_ITEM_HEIGHT_ = 130; +static constexpr int16_t SETTING_NODEVICE_Y = 150; +static constexpr int16_t SETTING_NODEVICE_FONT = 25; +static constexpr int16_t SETTING_RESEARCH_X = 111; +static constexpr int16_t SETTING_RESEARCH_Y = 230; +static constexpr int16_t SETTING_CONYENT_HEIGHT = 40; +static constexpr int16_t SETTING_RESEARCH_WIDTH = 232; +static constexpr int16_t SETTING_RESEARCH_HEIGHT = 76; +static constexpr int16_t SETTING_IMGANI_X = 163; +static constexpr int16_t SETTING_IMGANI_HEIGHT = 126; +static constexpr int16_t SETTING_IMGANI_Y = 150; +static constexpr int16_t SETTING_IMGANI_UPDATE = 120; +static constexpr int16_t SETTING_BTLIST_X = 426; +static constexpr int16_t SETTING_BTLIST_Y = 129; +static constexpr int16_t SETTING_BTLIST_ROUND = 30; +static constexpr int16_t CONTAINER_BLANK_SIZE = 100; +static constexpr int16_t LIST_WIDTH = 416; +static constexpr int16_t SEARCH_BTN_Y = 271; +static constexpr int16_t LIST_CONTENT_HEIGHT = 207; +static constexpr int16_t SETTING_RESET_RESEARCH_OFFSE5T = 50; +static constexpr int16_t SETTING_RESETTESEARCH_OFFSE5T = 80; +static constexpr int16_t SETTING_CONTENT_OFFSE5T_SEARCH = 85; +static constexpr int16_t SETTING_CONTENT_OFFSE5T_NOSEARCH = 200; +static constexpr char *RESEARCH_BUTTON = "researchButton"; +static constexpr char *OPTION_LIST = "optionList"; +static constexpr char *BT_LIST = "btList"; + +std::vector g_bluetoothOptionData = { + {SettingPageId::CONNECT_NEW_PHONE_PAGE, IMAGE_PHONE, "连接新手机", + nullptr, true, SETTING_LIST_ABOUT_BG_COLOR, SETTING_LIST_ABOUT_BG_COLOR_OPA}, + {SettingPageId::QRCODE_CONN_PAGE, IMAGE_QCODE, "二维码连接", + nullptr, true, SETTING_LIST_ABOUT_BG_COLOR, SETTING_LIST_ABOUT_BG_COLOR_OPA}}; + +const int g_imageAnimator[SEARCH_IMAGE_COUNT] = { + IMAGE_Y3_1, + IMAGE_Y3_2, + IMAGE_Y3_3, + IMAGE_Y3_4, + IMAGE_Y3_5, + IMAGE_Y3_6, + IMAGE_Y3_7, + IMAGE_Y3_8, + IMAGE_Y3_9, + IMAGE_Y3_10, + IMAGE_Y3_11, + IMAGE_Y3_12, + IMAGE_Y3_13, + IMAGE_Y3_14, + IMAGE_Y3_15, + IMAGE_Y3_16, + IMAGE_Y3_17, + IMAGE_Y3_18, + IMAGE_Y3_19, + IMAGE_Y3_20, + IMAGE_Y3_21, + IMAGE_Y3_22, + IMAGE_Y3_23, + IMAGE_Y3_24, + IMAGE_Y3_25, + IMAGE_Y3_26, + IMAGE_Y3_27, + IMAGE_Y3_28, + IMAGE_Y3_29, + IMAGE_Y3_30, + IMAGE_Y3_31, +}; + +SettingBluetoothPage::SettingBluetoothPage() +{ + g_pSettingBluetoothPage = this; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::SettingBluetoothPage"); +} + +SettingBluetoothPage::~SettingBluetoothPage() +{ + bool ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); + if (ret) { + bool results = gap_br_cancel_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtScan CancelBtDiscovery results %d", results); + } + BtAnimatorStop(); + DestoryPageView(); + g_pSettingBluetoothPage = nullptr; + SettingBluetoothModel::GetInstance()->SetConnectFragmentStatus(false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::~SettingBluetoothPage"); +} + +void SettingBluetoothPage::InitContentList() +{ + optionList_->ClearAll(); + for (auto& it : g_bluetoothOptionData) { + Contents cont; + cont.createFunc = SettingBluetoothPage::CreateForContent; + cont.updateFunc = SettingBluetoothPage::UpdateForContent; + cont.type = SettingUnionItemType::ICON_TEXT_NAVIGATION; + cont.data = ⁢ + optionList_->AddContent(cont); + } + optionList_->RefreshList(); +} + +SettingBluetoothPage* SettingBluetoothPage::GetInstance() +{ + return g_pSettingBluetoothPage; +} + +void SettingBluetoothPage::SetScanStatus(bool value) +{ + scanStart_ = value; +} + +bool SettingBluetoothPage::GetScanStatus() +{ + return scanStart_; +} + +void SettingBluetoothPage::OnStart(void *data) +{ + InitPageView(); + InitImageAnimator(); + if (SettingBluetoothModel::GetInstance()->GetScansDevicesList().size() != 0) { + SettingBluetoothModel::GetInstance()->MoveMatchingDeviceToFront(); + LoadFindDeviceList(); + } + BtScan(); + InitContentList(); + AddViewToPageContainer(scroll_); + AddViewToPageContainer(connectNewPhoneFragment_->GetFragmentView()); + AddViewToPageContainer(connectOpenFragment_->GetFragmentView()); + AddViewToPageContainer(reconnectionFragment_->GetFragmentView()); + AddViewToPageContainer(secondConfirmFragment_->GetFragmentView()); + AddViewToPageContainer(unPairFragment_->GetFragmentView()); + AddViewToPageContainer(successFragment_->GetFragmentView()); + AddViewToPageContainer(failFragment_->GetFragmentView()); +} + +void SettingBluetoothPage::InitPageView() +{ + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::scroll_ new fail"); + return; + } + scroll_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, HORIZONTAL_RESOLUTION); + scroll_->SetVerticalScrollState(true); + scroll_->SetYScrollBarVisible(true); + scroll_->SetOnDragListener(this); + scroll_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + connectNewPhoneFragment_ = new SettingConnectNewPhone(); + connectNewPhoneFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + connectNewPhoneFragment_->CreateView(); + if (connectNewPhoneFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::successFragment_ new fail"); + return; + } + connectNewPhoneFragment_->GetFragmentView()->SetVisible(false); + + connectOpenFragment_ = new SettingConnectionOpen(); + connectOpenFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + connectOpenFragment_->CreateView(); + if (connectOpenFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::connectOpenFragment_ new fail"); + return; + } + connectOpenFragment_->GetFragmentView()->SetVisible(false); + + reconnectionFragment_ = new SettingReconnection(); + reconnectionFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + reconnectionFragment_->CreateView(); + if (reconnectionFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::reconnectionFragment_ new fail"); + return; + } + reconnectionFragment_->GetFragmentView()->SetVisible(false); + + secondConfirmFragment_ = new SettingReconnectSecondConfirm(); + secondConfirmFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + secondConfirmFragment_->CreateView(); + if (secondConfirmFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::secondConfirmFragment_ new fail"); + return; + } + secondConfirmFragment_->GetFragmentView()->SetVisible(false); + + unPairFragment_ = new UnPairSecondConfirm(); + unPairFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + unPairFragment_->CreateView(); + if (unPairFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::unPairFragment_ new fail"); + return; + } + unPairFragment_->GetFragmentView()->SetVisible(false); + + successFragment_ = new SettingConnectBlueSuccess(); + successFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + successFragment_->CreateView(); + if (successFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::successFragment_ new fail"); + return; + } + successFragment_->GetFragmentView()->SetVisible(false); + + failFragment_ = new SettingConnectBlueFail(); + failFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + failFragment_->CreateView(); + + if (failFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::failFragment_ new fail"); + return; + } + failFragment_->GetFragmentView()->SetVisible(false); + + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(0, SETTING_TITLE_Y, RESOLUTION_WIDTH, SETTING_TITLE_HEIGHT); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_TITLE_FONT); + titleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + titleLabel_->SetText("蓝牙"); + + availableDeviceLabel_ = new UILabel(); + if (availableDeviceLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::availableDeviceLabel_ new fail"); + return; + } + availableDeviceLabel_->SetPosition(0, SETTING_AVILABLE_Y, RESOLUTION_WIDTH, SETTING_AVILABLE_HEIGHT); + availableDeviceLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + availableDeviceLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_AVILABLE_FONT); + availableDeviceLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + availableDeviceLabel_->SetText("可用设备"); + + // 根据list数量下移 + searchBtnTextLabel_ = new UILabel(); + if (searchBtnTextLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::searchBtnTextLabel_ new fail"); + return; + } + searchBtnTextLabel_->SetPosition(0, SEARCH_BTN_Y, RESOLUTION_WIDTH, SETTING_SEATCHBTN_HEIGHT); + searchBtnTextLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + searchBtnTextLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SEATCHBTN_FONT); + searchBtnTextLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + searchBtnTextLabel_->SetText("正在搜索..."); + searchBtnTextLabel_->SetVisible(true); + + noDeviceLabel_ = new UILabel(); + if (noDeviceLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::noDeviceLabel_ new fail"); + return; + } + noDeviceLabel_->SetPosition(0, SETTING_NODEVICE_Y, RESOLUTION_WIDTH, SETTING_SEATCHBTN_HEIGHT); + noDeviceLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + noDeviceLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_NODEVICE_FONT); + noDeviceLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + noDeviceLabel_->SetText("未发现附近有可用设备"); + noDeviceLabel_->SetVisible(false); + + resetResearchButton_ = new UILabelButton(); + if (resetResearchButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::resetResearchButton_ new fail"); + return; + } + resetResearchButton_->SetPosition(SETTING_RESEARCH_X, SETTING_RESEARCH_Y, SETTING_RESEARCH_WIDTH, + SETTING_RESEARCH_HEIGHT); + resetResearchButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + resetResearchButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_AVILABLE_FONT); + resetResearchButton_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + resetResearchButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + resetResearchButton_->SetText("重新搜索"); + resetResearchButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::PRESSED); + resetResearchButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::RELEASED); + resetResearchButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::INACTIVE); + resetResearchButton_->SetViewId(RESEARCH_BUTTON); + resetResearchButton_->SetOnClickListener(this); + resetResearchButton_->SetVisible(false); + + optionList_ = new UISimpleList(); + if (optionList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::optionList_ new fail"); + return; + } + optionList_->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y); + optionList_->Resize(LIST_WIDTH, LIST_CONTENT_HEIGHT); + optionList_->SetDraggable(false); + optionList_->SetScrollBlankSize(0); + optionList_->SetMaxScrollDistance(0); + optionList_->SetViewId(OPTION_LIST); + + btEarPhoneList_ = new UISimpleList(); + if (btEarPhoneList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitPageView::btEarPhoneList_ new fail"); + return; + } + btEarPhoneList_->SetPosition(SETTING_LIST_POSITION_X, SETTING_NODEVICE_Y); + btEarPhoneList_->SetScrollBlankSize(0); + btEarPhoneList_->SetMaxScrollDistance(0); + btEarPhoneList_->SetVisible(true); + btEarPhoneList_->SetViewId(BT_LIST); + + scroll_->Add(titleLabel_); + scroll_->Add(availableDeviceLabel_); + scroll_->Add(searchBtnTextLabel_); + scroll_->Add(optionList_); + scroll_->Add(resetResearchButton_); + scroll_->Add(noDeviceLabel_); + scroll_->Add(btEarPhoneList_); +} + +void SettingBluetoothPage::LoadFindDeviceList() +{ + std::list &bluetoothCaseList = SettingBluetoothModel::GetInstance()->GetScansDevicesList(); + btEarPhoneList_->ClearAll(); + for (auto& it : bluetoothCaseList) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadFindDeviceList addr: %02x%02x%02x%02x%02x%02x", + it.addr[SETTING_ADDR5], it.addr[SETTING_ADDR4], it.addr[SETTING_ADDR3], + it.addr[SETTING_ADDR2], it.addr[1], it.addr[0]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadFindDeviceList connect_status:%s", it.connect_status.c_str()); + Contents cont; + cont.createFunc = SettingBluetoothPage::CreateForBtList; + cont.updateFunc = SettingBluetoothPage::UpdateForBtList; + cont.type = 1; + cont.data = ⁢ + btEarPhoneList_->AddContent(cont); + } + btEarPhoneList_->Resize(SETTING_BTLIST_X, SETTING_BTLIST_Y * bluetoothCaseList.size()); + btEarPhoneList_->SetDraggable(false); + btEarPhoneList_->EnableAutoAlign(true); + btEarPhoneList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + btEarPhoneList_->RefreshList(); + UpdataImageAnimatorAndList(); + scroll_->Invalidate(); +} + +void SettingBluetoothPage::InitImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::InitImageAnimator::imageAnimator_ new fail"); + return; + } + + imageAnimator_->SetPosition(SETTING_IMGANI_X, SETTING_IMGANI_Y, SETTING_IMGANI_HEIGHT, SETTING_IMGANI_HEIGHT); + for (uint8_t i = 0; i < SEARCH_IMAGE_COUNT; i++) { + searchImageInfo_[i].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimator[i], SETTING_IMAGE); + searchImageInfo_[i].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo_[i].pos.x = SETTING_IMGANI_X; + searchImageInfo_[i].pos.y = SETTING_IMGANI_Y; + searchImageInfo_[i].width = SETTING_IMGANI_HEIGHT; + searchImageInfo_[i].height = SETTING_IMGANI_HEIGHT; + } + imageAnimator_->SetImageAnimatorSrc(searchImageInfo_, SEARCH_IMAGE_COUNT, SETTING_IMGANI_UPDATE); + imageAnimator_->SetRepeat(true); + imageAnimator_->SetAutoEnable(false); + imageAnimator_->SetResizeMode(UIImageView::FILL); + imageAnimator_->SetVisible(true); + imageAnimator_->SetSizeFixed(true); + scroll_->Add(imageAnimator_); +} + +void SettingBluetoothPage::UpdataImageAnimatorAndList() +{ + int16_t imageAnimatorPosY = btEarPhoneList_->GetY() + + ((SettingBluetoothModel::GetInstance()->GetScansDevicesList().size()) * SETTING_ITEM_HEIGHT_); + imageAnimator_->SetPosition(SETTING_IMGANI_X, imageAnimatorPosY, SETTING_IMGANI_HEIGHT, SETTING_IMGANI_HEIGHT); + for (uint8_t i = 0; i < SEARCH_IMAGE_COUNT; i++) { + searchImageInfo_[i].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimator[i], SETTING_IMAGE); + searchImageInfo_[i].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo_[i].pos.x = SETTING_IMGANI_X; + searchImageInfo_[i].pos.y = imageAnimatorPosY; + searchImageInfo_[i].width = SETTING_IMGANI_HEIGHT; + searchImageInfo_[i].height = SETTING_IMGANI_HEIGHT; + } + imageAnimator_->SetImageAnimatorSrc(searchImageInfo_, SEARCH_IMAGE_COUNT, SETTING_IMGANI_UPDATE); + imageAnimator_->SetRepeat(true); + imageAnimator_->SetAutoEnable(false); + imageAnimator_->SetResizeMode(UIImageView::FILL); + imageAnimator_->SetSizeFixed(true); + imageAnimator_->Invalidate(); + imageAnimator_->Start(); + searchBtnTextLabel_->SetPosition(0, imageAnimator_->GetY() + SETTING_IMGANI_HEIGHT); + resetResearchButton_->SetPosition(SETTING_RESEARCH_X, imageAnimator_->GetY() + SETTING_RESETTESEARCH_OFFSE5T); + optionList_->SetPosition(SETTING_LIST_POSITION_X, imageAnimator_->GetY() + SETTING_CONTENT_OFFSE5T_NOSEARCH); + scroll_->Invalidate(); +} + +void SettingBluetoothPage::BtAnimatorStart(void) +{ + imageAnimator_->Start(); +} + +void SettingBluetoothPage::BtAnimatorStop(void) +{ + imageAnimator_->Stop(); +} + +void SettingBluetoothPage::NotFindDevice() +{ + BtAnimatorStop(); + searchBtnTextLabel_->SetVisible(false); + imageAnimator_->SetVisible(false); + noDeviceLabel_->SetVisible(true); + resetResearchButton_->SetVisible(true); + scroll_->Invalidate(); +} + +void SettingBluetoothPage::TimerFindDevice() +{ + BtAnimatorStop(); + searchBtnTextLabel_->SetVisible(false); + imageAnimator_->SetVisible(false); + noDeviceLabel_->SetVisible(false); + resetResearchButton_->SetVisible(true); + scroll_->Invalidate(); +} + +void SettingCancelBrScanHandle(void) +{ + if (g_settingStopScanHandle != nullptr) { + g_settingStopScanHandle->Stop(); + delete g_settingStopScanHandle; + g_settingStopScanHandle = nullptr; + } + bool results = gap_br_cancel_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingCancelBrScanHandle CancelBtDiscovery results %d", results); +} + +void SettingEndScanHandle(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "SettingBluetoothModel::GetInstance()->GetScansDevicesList().size() results %d", + SettingBluetoothModel::GetInstance()->GetScansDevicesList().size()); + SettingBluetoothPage* bluetoothPage = SettingBluetoothPage::GetInstance(); + if (bluetoothPage == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bluetoothPage nullptr"); + return; + } + if (SettingBluetoothModel::GetInstance()->GetScansDevicesList().size() > 0) { + bluetoothPage->TimerFindDevice(); + } else { + // 未发现蓝牙耳机 + bluetoothPage->NotFindDevice(); + } +} + +// 定时器回调函数 +static void SettingBluetoothScanTimerCallbackProc(void* data) +{ + (void)data; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bt scan end jumpView"); + SettingCancelBrScanHandle(); + SettingEndScanHandle(); +} + +void SettingBluetoothScanTimerCallback(void* data) +{ + GraphicService::GetInstance()->PostGraphicEvent(std::bind(SettingBluetoothScanTimerCallbackProc, data)); +} + +void SettingBluetoothPage::BtScan() +{ + bool ret; + bool results; + SetScanStatus(true); + BtAnimatorStart(); + ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); + if (ret) { + results = gap_br_cancel_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtScan CancelBtDiscovery results %d", results); + } + + results = gap_br_set_inquiry_paramters(DEVICE_MAJOR_CLASS_AUDIO_VIDEO, 0); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "SettingBluetoothPage gap_br_set_inquiry_paramters results %d", results); + results = gap_br_start_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "SettingBluetoothPage gap_br_start_discovery results %d", results); + if (g_settingStopScanHandle != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtScan g_settingStopScanHandle != nullptr"); + return; + } + uint32_t tick = GetOSTick(SCAN_TIME); + g_settingStopScanHandle = new GraphicTimer(tick, SettingBluetoothScanTimerCallback, nullptr, true); + if (g_settingStopScanHandle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtScan new GraphicTimer failed!!"); + return; + } + bool retTimer = g_settingStopScanHandle->Start(); + if (!retTimer) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtScan Start failed"); + if (g_settingStopScanHandle != nullptr) { + delete g_settingStopScanHandle; + g_settingStopScanHandle = nullptr; + } + return; + } + return; +} + +void SettingBluetoothPage::StopBtScan() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::StopBtScan"); + if (imageAnimator_->GetState() == true) { + SettingCancelBrScanHandle(); + SettingEndScanHandle(); + } +} + +void SettingBluetoothPage::DestoryPageView() +{ + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (connectNewPhoneFragment_ != nullptr) { + connectNewPhoneFragment_->DestroyView(); + delete connectNewPhoneFragment_; + connectNewPhoneFragment_ = nullptr; + } + if (connectOpenFragment_ != nullptr) { + connectOpenFragment_->DestroyView(); + delete connectOpenFragment_; + connectOpenFragment_ = nullptr; + } + if (reconnectionFragment_ != nullptr) { + reconnectionFragment_->DestroyView(); + delete reconnectionFragment_; + reconnectionFragment_ = nullptr; + } + if (secondConfirmFragment_ != nullptr) { + secondConfirmFragment_->DestroyView(); + delete secondConfirmFragment_; + secondConfirmFragment_ = nullptr; + } + if (unPairFragment_ != nullptr) { + unPairFragment_->DestroyView(); + delete unPairFragment_; + unPairFragment_ = nullptr; + } + if (successFragment_ != nullptr) { + successFragment_->DestroyView(); + delete successFragment_; + successFragment_ = nullptr; + } + if (failFragment_ != nullptr) { + failFragment_->DestroyView(); + delete failFragment_; + failFragment_ = nullptr; + } + if (optionList_ != nullptr) { + delete optionList_; + optionList_ = nullptr; + } + if (btEarPhoneList_ != nullptr) { + delete btEarPhoneList_; + btEarPhoneList_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (noDeviceLabel_ != nullptr) { + delete noDeviceLabel_; + noDeviceLabel_ = nullptr; + } + if (searchBtnTextLabel_ != nullptr) { + delete searchBtnTextLabel_; + searchBtnTextLabel_ = nullptr; + } + if (resetResearchButton_ != nullptr) { + delete resetResearchButton_; + resetResearchButton_ = nullptr; + } + if (availableDeviceLabel_ != nullptr) { + delete availableDeviceLabel_; + availableDeviceLabel_ = nullptr; + } + if (imageAnimator_ != nullptr) { + delete imageAnimator_; + imageAnimator_ = nullptr; + } +} + +UIView* SettingBluetoothPage::CreateForContent(uint8_t type) +{ + if (type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView* item = new IconTextNavigationItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetOnClickListener(g_pSettingBluetoothPage); + return item; + } + return nullptr; +} + +void SettingBluetoothPage::UpdateForContent(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + IconTextNavigationItemView* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr || data == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); +} + +UIView* SettingBluetoothPage::CreateForBtList(uint8_t type) +{ + UNUSED(type); + return new SettingBluetoothItemGroup(); +} + +void SettingBluetoothPage::UpdateForBtList(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SettingBluetoothItemGroup* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + BtCaseInfo* caseInfo = static_cast(data); + itemGroup->SetItemInfo(caseInfo); + itemGroup->SetOnClickListener(g_pSettingBluetoothPage); +} + +void SettingBluetoothPage::UpdateBtListContent(int16_t viewIndex) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateBtListContent"); + std::string deviceName = SettingBluetoothModel::GetInstance()->GetDeviceName(); + SettingBluetoothModel::GetInstance()->UpdateConnectStatusForDevice(); + std::list bluetoothCaseList = SettingBluetoothModel::GetInstance()->GetScansDevicesList(); + for (auto& it : bluetoothCaseList) { + if (std::strcmp(reinterpret_cast(it.deviceName), deviceName.c_str()) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateBtListContent addr: %02x%02x%02x%02x%02x%02x", + it.addr[SETTING_ADDR5], it.addr[SETTING_ADDR4], it.addr[SETTING_ADDR3], + it.addr[SETTING_ADDR2], it.addr[1], it.addr[0]); + Contents cont; + cont.createFunc = SettingBluetoothPage::CreateForBtList; + cont.updateFunc = SettingBluetoothPage::UpdateForBtList; + cont.type = 1; + cont.data = ⁢ + btEarPhoneList_->UpdateContent(viewIndex, cont); + break; + } + } + btEarPhoneList_->RefreshList(); +} + +bool SettingBluetoothPage::IsDeviceConnect() +{ + std::list bluetoothCaseList = SettingBluetoothModel::GetInstance()->GetScansDevicesList(); + for (auto& it : bluetoothCaseList) { + if (it.connect_status == "已连接") { + return true; + } + } + return false; +} + +bool SettingBluetoothPage::GetImageAnimatorState() +{ + return imageAnimator_->GetState(); +} + +void SettingBluetoothPage::ChangeView(int16_t value) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeView value: %d", value); + if (value == BT_MAIN_PAGE) { + scroll_->SetVisible(true); + } else if (value == CONNECT_OPEN_FRAGMENT) { + connectOpenFragment_->RefreshFragment(); + SettingBluetoothModel::GetInstance()->SetConnectFragmentStatus(true); + connectOpenFragment_->GetFragmentView()->SetVisible(true); + } else if (value == RECONNECT_SECOND_CONFIRM_FRAGMENT) { + secondConfirmFragment_->RefreshFragment(); + secondConfirmFragment_->GetFragmentView()->SetVisible(true); + } else if (value == UNPAIR_CONFIRM_FRAGMENT) { + unPairFragment_->RefreshFragment(); + unPairFragment_->GetFragmentView()->SetVisible(true); + } + if (imageAnimator_->GetState() == false) { + StartBtScan(); + } +} + +void SettingBluetoothPage::ShowResultGroup(int16_t value) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowResultGroup value: %d", value); + StopBtScan(); + if (value == CONNECT_BLUETOOTH_FAIL_FRAGMENT) { + failFragment_->RefreshFragment(); + failFragment_->GetFragmentView()->SetVisible(true); + } else if (value == CONNECT_BLUETOOTH_SUCCESS_FRAGMENT) { + successFragment_->RefreshFragment(); + successFragment_->GetFragmentView()->SetVisible(true); + } +} + +void SettingBluetoothPage::StartBtScan() +{ + imageAnimator_->SetVisible(true); + searchBtnTextLabel_->SetVisible(true); + noDeviceLabel_->SetVisible(false); + resetResearchButton_->SetVisible(false); + optionList_->SetPosition(SETTING_LIST_POSITION_X, + searchBtnTextLabel_->GetY() + SETTING_CONTENT_OFFSE5T_SEARCH); + BtScan(); +} + +bool SettingBluetoothPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), RESEARCH_BUTTON) == 0) { + StartBtScan(); + } else if (strcmp(view.GetParent()->GetViewId(), OPTION_LIST) == 0) { + int16_t viewIndex = view.GetViewIndex(); + if (viewIndex < 0 || viewIndex >= g_bluetoothOptionData.size()) { + return true; + } + IconTextNavigationItemData itemData = g_bluetoothOptionData[viewIndex]; + if (itemData.pageId == SettingPageId::CONNECT_NEW_PHONE_PAGE) { + StopBtScan(); + scroll_->SetVisible(false); + connectNewPhoneFragment_->GetFragmentView()->SetVisible(true); + } else { + NativeAbility::GetInstance().SwitchPageInSlice(itemData.pageId, + TransitionType::TRANSITION_INVALID, true); + } + } else if (strcmp(view.GetParent()->GetViewId(), BT_LIST) == 0) { + // 点击搜索到的设备进行连接 + SettingBluetoothItemGroup *listItemViewID = dynamic_cast(&view); + BtCaseInfo item = listItemViewID->GetItem(); + SettingBluetoothModel::GetInstance()->SetSelectedDeviceInfo(&item); + std::string connState = item.connect_status; + bd_addr_t addr; + bool flag_connect = IsDeviceConnect(); + // 当前设备为已连接 或没有设备被连接时 才会处理点击事件 + if ((connState == "已连接") || (!flag_connect)) { + SettingBluetoothModel::GetInstance()->SetDeviceName(reinterpret_cast(item.deviceName)); + (void)memcpy_s(addr.addr, BD_ADDR_LEN, item.addr, BD_ADDR_LEN); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingBluetoothPage::OnClick addr: %02x%02x%02x%02x%02x%02x", + addr.addr[SETTING_ADDR5], addr.addr[SETTING_ADDR4], addr.addr[SETTING_ADDR3], + addr.addr[SETTING_ADDR2], addr.addr[1], addr.addr[0]); + if (connState == "") { + errcode_t retVal = SettingBluetoothModel::GetInstance()->ConnectRemoteDevice(&addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice ret = %d", retVal); + if (retVal != 0) { + UpdateBtListContent(view.GetViewIndex()); + SettingBluetoothModel::GetInstance()->SetConnectResultPage(true); + } + } else if (connState == "已连接" || connState == "连接已经断开") { + StopBtScan(); + scroll_->SetVisible(false); + reconnectionFragment_->RefreshFragment(); + reconnectionFragment_->GetFragmentView()->SetVisible(true); + } + } + } + scroll_->Invalidate(); + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardAddPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardAddPage.cpp new file mode 100644 index 000000000..0efc79efc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardAddPage.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardAddPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingCardModel.h" +#include "settings/page/SettingCardAddPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::CARD_ADD_PAGE, SettingCardAddPage, false); + +static constexpr int16_t SETTING_CARD_ADD_LIST_Y = 125; +static constexpr int16_t SETTING_CARD_ADD_LIST_HEIGHT = 397; +static constexpr int16_t SETTING_CARD_ADD_LIST_DISTANCE = 1000; +static constexpr int16_t SETTING_CARD_ADD_LIST_BLANK = 40; +static constexpr int16_t SETTING_CARD_ADD_LIST_SELECTPOS = HORIZONTAL_RESOLUTION / 4; +static constexpr int16_t SETTING_CARD_ADD_TITLE_X = 100; +static constexpr int16_t SETTING_CARD_ADD_TITLE_Y = 39; +static constexpr int16_t SETTING_CARD_ADD_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_CARD_ADD_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_CARD_ADD_TITLE_FSIZE = 38; +static const char* SETTING_CARD_ADD_TITLE_TEXT = "添加卡片"; + +void SettingCardAddPage::OnStart(void* data) +{ + list_ = new UISimpleList(); + if (list_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardAddPage::OnStart list_ new fail"); + return; + } + list_->SetDirection(UIAbstractScroll::HORIZONTAL); + list_->SetBoundaryIntercept(DragEvent::DIRECTION_LEFT_TO_RIGHT, false); + list_->SetPosition(0, SETTING_CARD_ADD_LIST_Y, HORIZONTAL_RESOLUTION, SETTING_CARD_ADD_LIST_HEIGHT); + list_->SetScrollBlankSize(SETTING_CARD_ADD_LIST_BLANK); + list_->SetSelectPosition(SETTING_CARD_ADD_LIST_SELECTPOS); + list_->SetMaxScrollDistance(SETTING_CARD_ADD_LIST_DISTANCE); + list_->SetDraggable(true); + list_->SetThrowDrag(true); + list_->EnableAutoAlign(true); + list_->SetIntercept(false); + + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardAddPage::OnStart title_ new fail"); + return; + } + title_->SetPosition(SETTING_CARD_ADD_TITLE_X, SETTING_CARD_ADD_TITLE_Y); + title_->Resize(SETTING_CARD_ADD_TITLE_WIDTH, SETTING_CARD_ADD_TITLE_HEIGHT); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_CARD_ADD_TITLE_FSIZE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetText(SETTING_CARD_ADD_TITLE_TEXT); + + AddViewToPageContainer(list_); + AddViewToPageContainer(title_); +} + +void SettingCardAddPage::OnResume() +{ + std::vector& cardData = SettingCardModel::GetInstance().GetCardData(); + if (cardData.size() == 0) { + list_->SetVisible(false); + } else { + list_->ClearAll(); + for(auto& it : cardData) { + it.contextPtr = this; + + Contents cont; + cont.createFunc = SettingCardAddPage::OnSimpleListCreate; + cont.updateFunc = SettingCardAddPage::OnSimpleListUpdate; + cont.type = 0; + cont.data = ⁢ + list_->AddContent(cont); + } + list_->SetVisible(true); + list_->RefreshList(); + } +} + +void SettingCardAddPage::OnStop() +{ + if (list_ != nullptr) { + delete list_; + list_ = nullptr; + } + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } +} + +bool SettingCardAddPage::OnClick(UIView& view, const ClickEvent& event) +{ + int16_t index = view.GetViewIndex(); + std::vector& cardData = SettingCardModel::GetInstance().GetCardData(); + SettingCardItemData& currData = cardData[index]; + + if (!currData.isSelect) { + SettingCardModel::GetInstance().AddCard(currData.index); + SettingCardModel::GetInstance().RefreshCardData(); + + if (cardData.size() == 0) { + list_->SetVisible(false); + } + list_->RefreshList(); + } + return true; +} + +UIView* SettingCardAddPage::OnSimpleListCreate(uint8_t type) +{ + UNUSED(type); + return new SettingCardAddItemGroup(); +} + +void SettingCardAddPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + if (view == nullptr || data == nullptr) { + return; + } + SettingCardAddItemGroup* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + SettingCardItemData* itemData = static_cast(data); + SettingCardAddPage* page = static_cast(itemData->contextPtr); + itemGroup->UpdateItemGroup(itemData); + itemGroup->SetOnClickListener(page); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardEffectPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardEffectPage.cpp new file mode 100644 index 000000000..8dea21176 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardEffectPage.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardEffecPage + * Create: 2025-04 + */ +#include "SlicePageFactory.h" +#include "NativeRegisterManager.h" +#include "PageTransitionMgr.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "settings/SettingView.h" +#include "settings/common/SettingCommon.h" +#include "settings/page/SettingCardEffectPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::CARD_EFFECT_PAGE, SettingCardEffecPage, false); +static SettingCardEffecPage *g_pSettingCardEffecPage = nullptr; +static constexpr uint8_t SETTINGS_ITEM_FONT_SIZE = 40; +static constexpr int16_t SETTINGS_RESIZE_SIZE_WIDTH = HORIZONTAL_RESOLUTION; +static constexpr int16_t SETTINGS_RESIZE_SIZE_HEIGHT = 60; +static constexpr int16_t SETTING_TITLE_POSITION_X = 0; +static constexpr int16_t SETTING_TITLE_POSITION_Y = 20; +static constexpr int16_t SETTING_LIST_POSITION_X = 0; +static constexpr int16_t SETTING_LIST_POSITION_Y = 0; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 100; +static constexpr int16 MAX_SCR_DIS = 454; +static constexpr int16 SNUM_2 = 2; + +SettingCardEffecPage::SettingCardEffecPage() +{ + g_pSettingCardEffecPage = this; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingCardEffecPage::SettingCardEffecPage"); +} + +SettingCardEffecPage::~SettingCardEffecPage() +{ + g_pSettingCardEffecPage = nullptr; + if (titleText_ != nullptr) { + delete titleText_; + titleText_ = nullptr; + } + + contentList_->ClearAll(); + if (contentList_ != nullptr) { + delete contentList_; + contentList_ = nullptr; + } + effectListDatas_.clear(); +} + +void SettingCardEffecPage::OnStart(void* data) +{ + titleText_ = new UILabel(); + if (titleText_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingCardEffecPage::OnStart::title is nullptr"); + return; + } + titleText_->SetPosition(SETTING_TITLE_POSITION_X, SETTING_TITLE_POSITION_Y); + titleText_->Resize(SETTINGS_RESIZE_SIZE_WIDTH, SETTINGS_RESIZE_SIZE_HEIGHT); + titleText_->SetText("卡片动效"); + titleText_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTINGS_ITEM_FONT_SIZE); + titleText_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleText_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + titleText_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + titleText_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + titleText_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + contentList_ = new UISimpleList(); + if (contentList_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingCardEffecPage::OnStart::contentList_ is nullptr"); + return; + } + contentList_->SetDirection(UIAbstractScroll::HORIZONTAL); + contentList_->SetBoundaryIntercept(DragEvent::DIRECTION_LEFT_TO_RIGHT, false); + contentList_->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y); + contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position + contentList_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::RIGHT); + contentList_->SetDraggable(true); + contentList_->SetThrowDrag(true); + contentList_->SetLoopState(false); + contentList_->EnableAutoAlign(true); + contentList_->SetScrollStateListener(this); + AddViewToPageContainer(contentList_); + AddViewToPageContainer(titleText_); + + SettingCardModel::GetInstance().InitEffectItem(); + SetCardEffectListData(SettingCardModel::GetInstance().GetEffectListItems()); +} + +bool SettingCardEffecPage::OnClick(UIView& view, const ClickEvent& event) +{ + CardEffectID swipeId = CardEffectID::UI_INVALIDE; + SettingCardEffectItemGroup* setSwipeEffectView = dynamic_cast(&view); + if (setSwipeEffectView == nullptr) { + return false; + } + swipeId = setSwipeEffectView->GetViewId(event); + if (swipeId != CardEffectID::UI_INVALIDE) { + SettingCardModel::GetInstance().SetSwipeEffectStyle(swipeId); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + return true; +} + +void SettingCardEffecPage::OnItemSelected(int16 index, UIView* view) +{ + UNUSED(index); + if (view != nullptr) { + itemGroupSele_ = static_cast(view); + itemGroupSele_->SelectedChange(); + + if (preItemGroupSele_ != nullptr && preItemGroupSele_ != itemGroupSele_) { + preItemGroupSele_->Reset(); + } + preItemGroupSele_ = itemGroupSele_; + } +} + +UIView* SettingCardEffecPage::OnSimpleListCreate(uint8_t type) +{ + SettingCardEffectItemGroup* itemGroup = new SettingCardEffectItemGroup(); + if (itemGroup == nullptr) { + return nullptr; + } + itemGroup->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + itemGroup->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + itemGroup->SetTouchable(true); + itemGroup->SetOnClickListener(g_pSettingCardEffecPage); + return itemGroup; +} + +void SettingCardEffecPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SettingCardEffectItemGroup* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + CardEffectPair* content = static_cast(data); + itemGroup->SetItemInfo(content->first, content->second); +} + +void SettingCardEffecPage::SetCardEffectListData(const std::map &effectMap) +{ + contentList_->ClearAll(); + uint16_t selectIndex = static_cast( + SettingCardModel::GetInstance().GetSwipeEffectStyle()) / SNUM_2; + effectListDatas_.clear(); + for (auto currentIt = effectMap.begin(); currentIt != effectMap.end(); ++currentIt) { + auto nextIt = std::next(currentIt); + CardEffectPair swipeEffectData; + swipeEffectData.first = currentIt->second; + if (nextIt != effectMap.end()) { + swipeEffectData.second = nextIt->second; + currentIt = nextIt; + } else { + SettingCardEffectSample sample; + swipeEffectData.second = sample; + } + effectListDatas_.push_back(swipeEffectData); + } + int index = 1; + for (auto currentIt = effectListDatas_.begin(); currentIt != effectListDatas_.end(); ++currentIt) { + Contents content; + content.createFunc = OnSimpleListCreate; + content.updateFunc = OnSimpleListUpdate; + content.type = index++; + content.data = reinterpret_cast(&*currentIt); + contentList_->AddContent(content); + } + + contentList_->ScrollTo(selectIndex); + contentList_->ScrollBy(-SNUM_2); + contentList_->RefreshList(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardMgrPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardMgrPage.cpp new file mode 100644 index 000000000..5dc122022 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardMgrPage.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardMgrPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingCardModel.h" +#include "settings/page/SettingCardMgrPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::CARD_MGR_PAGE, SettingCardMgrPage, false); + +static constexpr int16_t SETTING_CARD_MGR_LIST_X = 0; +static constexpr int16_t SETTING_CARD_MGR_LIST_Y = 110; +static constexpr int16_t SETTING_CARD_MGR_LIST_WIDTH = 454; +static constexpr int16_t SETTING_CARD_MGR_LIST_HEIGHT = 245; +static constexpr int16_t SETTING_CARD_MGR_LIST_BLANK = 40; +static constexpr int16_t SETTING_CARD_MGR_LIST_SELECTPOS = HORIZONTAL_RESOLUTION / 2; +static constexpr int16_t SETTING_CARD_MGR_LIST_DISTANCE = 1000; + +static constexpr int16_t SETTING_CARD_MGR_ADD_X = 184; +static constexpr int16_t SETTING_CARD_MGR_ADD_Y = 16; +static constexpr int16_t SETTING_CARD_MGR_ADD_WIDTH = 85; +static constexpr int16_t SETTING_CARD_MGR_ADD_HEIGHT = 85; + +static constexpr int16_t SETTING_CARD_MGR_DEL_X = 179; +static constexpr int16_t SETTING_CARD_MGR_DEL_Y = 354; +static constexpr int16_t SETTING_CARD_MGR_DEL_WIDTH = 96; +static constexpr int16_t SETTING_CARD_MGR_DEL_HEIGHT = 96; + +void SettingCardMgrPage::OnStart(void* data) +{ + InitListView(); + InitButtonView(); + AddViewToPageContainer(list_); + AddViewToPageContainer(addButton_); + AddViewToPageContainer(delButton_); +} + +void SettingCardMgrPage::OnResume() +{ + std::vector& cardData = SettingCardModel::GetInstance().GetCardData(); + list_->SetVisible(false); + list_->ClearAll(); + for (auto& it : cardData) { + if (!it.isSelect) { + continue; + } + Contents cont; + cont.createFunc = SettingCardMgrPage::OnSimpleListCreate; + cont.updateFunc = SettingCardMgrPage::OnSimpleListUpdate; + cont.type = 0; + cont.data = ⁢ + list_->AddContent(cont); + list_->SetVisible(true); + } + list_->RefreshList(); +} + +void SettingCardMgrPage::OnStop() +{ + if (list_ != nullptr) { + delete list_; + list_ = nullptr; + } + if (addButton_ != nullptr) { + delete addButton_; + addButton_ = nullptr; + } + if (delButton_ != nullptr) { + delete delButton_; + delButton_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_CARD_MGR_ADD, SETTING_IMAGE); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_CARD_MGR_DEL, SETTING_IMAGE); +} + +bool SettingCardMgrPage::OnClick(UIView& view, const ClickEvent& event) +{ + if (strcmp(view.GetViewId(), "add") == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SettingPageId::CARD_ADD_PAGE, + TransitionType::TRANSITION_INVALID, true); + } else if (strcmp(view.GetViewId(), "del") == 0) { + uint16_t selectIndex = list_->GetSelectView()->GetViewIndex(); + std::vector& cardData = SettingCardModel::GetInstance().GetCardData(); + + // 更新系统数据 + SettingCardModel::GetInstance().DeleteCard(cardData[selectIndex].index); + SettingCardModel::GetInstance().RefreshCardData(); + + // 更新界面数据 + list_->RemoveContent(selectIndex); + list_->SetVisible(false); + for (auto& it : cardData) { + if (it.isSelect) { + list_->SetVisible(true); + break; + } + } + list_->RefreshList(); + } + return true; +} + +void SettingCardMgrPage::InitListView() +{ + list_ = new UISimpleList(); + if (list_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardMgrPage::InitListView list_ new fail"); + return; + } + list_->SetDirection(UIAbstractScroll::HORIZONTAL); + list_->SetBoundaryIntercept(DragEvent::DIRECTION_LEFT_TO_RIGHT, false); + list_->SetPosition(SETTING_CARD_MGR_LIST_X, SETTING_CARD_MGR_LIST_Y); + list_->Resize(SETTING_CARD_MGR_LIST_WIDTH, SETTING_CARD_MGR_LIST_HEIGHT); + list_->SetScrollBlankSize(SETTING_CARD_MGR_LIST_BLANK); + list_->SetSelectPosition(SETTING_CARD_MGR_LIST_SELECTPOS); + list_->SetMaxScrollDistance(SETTING_CARD_MGR_LIST_DISTANCE); + list_->SetDraggable(true); + list_->SetThrowDrag(true); + list_->EnableAutoAlign(true); + list_->SetIntercept(false); +} + +void SettingCardMgrPage::InitButtonView() +{ + addButton_ = new UIButton(); + if (addButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardMgrPage::InitButtonView addButton_ new fail"); + return; + } + addButton_->SetPosition(SETTING_CARD_MGR_ADD_X, SETTING_CARD_MGR_ADD_Y); + addButton_->Resize(SETTING_CARD_MGR_ADD_WIDTH, SETTING_CARD_MGR_ADD_HEIGHT); + addButton_->SetViewId("add"); + addButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + addButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + addButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + ImageInfo* addImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CARD_MGR_ADD, SETTING_IMAGE); + addButton_->SetImageSrc(addImage, addImage); + addButton_->SetOnClickListener(this); + + delButton_ = new UIButton(); + if (delButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardMgrPage::InitButtonView delButton_ new fail"); + return; + } + delButton_->SetPosition(SETTING_CARD_MGR_DEL_X, SETTING_CARD_MGR_DEL_Y); + delButton_->Resize(SETTING_CARD_MGR_DEL_WIDTH, SETTING_CARD_MGR_DEL_HEIGHT); + delButton_->SetViewId("del"); + ImageInfo* delImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CARD_MGR_DEL, SETTING_IMAGE); + delButton_->SetImageSrc(delImage, delImage); + delButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + delButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + delButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + delButton_->SetOnClickListener(this); +} + +UIView* SettingCardMgrPage::OnSimpleListCreate(uint8_t type) +{ + UNUSED(type); + return new SettingCardMgrItemGroup(); +} + +void SettingCardMgrPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + if (view == nullptr || data == nullptr) { + return; + } + SettingCardMgrItemGroup* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + SettingCardItemData* itemData = static_cast(data); + itemGroup->UpdateItemGroup(itemData); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardPage.cpp new file mode 100644 index 000000000..3e7dc7163 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingCardPage.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingCardPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingCardModel.h" +#include "settings/page/SettingCardPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::CARD_PAGE, SettingCardPage, false); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 30; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingCardPage *g_pSettingCardPage{nullptr}; + +void SettingCardPage::OnStart(void* data) +{ + g_pSettingCardPage = this; + content_ = new UISimpleList(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardPage::OnStart content_ new fail"); + return; + } + content_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + content_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + content_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + content_->SetDraggable(true); + content_->SetThrowDrag(true); + content_->EnableAutoAlign(true); + content_->SetMaxScrollDistance(MAX_SCR_DIS); + + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingCardPage::OnStart scroll_ new fail"); + return; + } + scroll_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scroll_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scroll_->SetThrowDrag(true); + scroll_->SetIntercept(true); + scroll_->Add(content_); + AddViewToPageContainer(scroll_); +} + +void SettingCardPage::OnResume() +{ + content_->ClearAll(); + for(auto& it : SettingCardModel::GetInstance().GetCardUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingCardPage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + content_->AddContent(cont); + } + content_->RefreshList(); +} + +void SettingCardPage::OnStop() +{ + g_pSettingCardPage = nullptr; + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } +} + +bool SettingCardPage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t viewId = (uintptr_t)view.GetViewId(); + if (viewId == (uintptr_t)ICON_TEXT_NAVIGATION) { + int16_t viewIndex = view.GetViewIndex(); + auto& cardUnionData = SettingCardModel::GetInstance().GetCardUnionData(); + if (viewIndex < 0 || viewIndex > cardUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = cardUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_NAVIGATION) { + IconTextNavigationItemData* data = static_cast(itemData.GetUnionItemData()); + NativeAbility::GetInstance().SwitchPageInSlice(data->pageId, + TransitionType::TRANSITION_INVALID, true); + } + return true; + } + return false; +} + +void SettingCardPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingCardPage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingCardPage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueFail.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueFail.cpp new file mode 100644 index 000000000..1f6b8eb97 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueFail.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectBlueFail + * Created: 2025-06-05 + */ +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "ui_resource_settings.h" +#include "main/LoadImg.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingConnectBlueFail.h" + +namespace OHOS { +static constexpr int16_t SETTING_IMG_X = 100; +static constexpr int16_t SETTING_IMG_Y = -50; +static constexpr int16_t SETTING_WATCH_Y = 180; +static constexpr int16_t SETTING_WATCH_HEIGHT = 40; +static constexpr int16_t SETTING_WATCH_FONT = 36; +static constexpr int16_t SETTING_CONTENT_Y = 230; +static constexpr int16_t SETTING_CONYENT_HEIGHT = 40; +static constexpr int16_t SETTING_BTN_X = 65; +static constexpr int16_t SETTING_BTN_Y = 359; +static constexpr int16_t SETTING_BTN_WIDTH = 324; +static constexpr int16_t SETTING_BTN_HEIGHT = 101; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; + +void SettingConnectBlueFail::OnCreateView(void* data) +{ + InitFailFragment(); +} + +void SettingConnectBlueFail::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (img_ != nullptr) { + delete img_; + img_ = nullptr; + } + if (watchNameLabel_ != nullptr) { + delete watchNameLabel_; + watchNameLabel_ = nullptr; + } + if (connectStatusLabel_ != nullptr) { + delete connectStatusLabel_; + connectStatusLabel_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } +} + +void SettingConnectBlueFail::InitFailFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + img_ = new UIImageView(); + if (img_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitFailFragment img_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(img_, SETTING_IMAGE, IMAGE_SURPRISE); + img_->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + + watchNameLabel_ = new UILabel(); + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitFailFragment watchNameLabel_ new fail"); + return; + } + watchNameLabel_->SetPosition(0, SETTING_WATCH_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + watchNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + watchNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + watchNameLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); + + connectStatusLabel_ = new UILabel(); + if (connectStatusLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitFailFragment connectStatusLabel_ new fail"); + return; + } + connectStatusLabel_->SetPosition(0, SETTING_CONTENT_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + connectStatusLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + connectStatusLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + connectStatusLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + connectStatusLabel_->SetText("连接失败,请稍后再试"); + + confirmButton_ = new UILabelButton(); + if (confirmButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitFailFragment confirmButton_ new fail"); + return; + } + LOADIMG::LoadBtnImage(confirmButton_, SETTING_IMAGE, IMAGE_OK_DOWN, IMAGE_OK_DOWN); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + confirmButton_->SetPosition(SETTING_BTN_X, SETTING_BTN_Y, SETTING_BTN_WIDTH, SETTING_BTN_HEIGHT); + confirmButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + confirmButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + confirmButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + confirmButton_->SetViewId(CONFIRM_BUTTON); + confirmButton_->SetOnClickListener(this); + confirmButton_->SetVisible(true); + + fragmentView_.Add(img_); + fragmentView_.Add(watchNameLabel_); + fragmentView_.Add(connectStatusLabel_); + fragmentView_.Add(confirmButton_); +} + +void SettingConnectBlueFail::RefreshFragment() +{ + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshFragment fail"); + return; + } + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); +} + +bool SettingConnectBlueFail::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + bool state = SettingBluetoothPage::GetInstance()->GetImageAnimatorState(); + if (state == false) { + SettingBluetoothPage::GetInstance()->StartBtScan(); + } + fragmentView_.SetVisible(false); + } + return true; +} + +bool SettingConnectBlueFail::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectBlueFail::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectBlueFail::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueSuccess.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueSuccess.cpp new file mode 100644 index 000000000..1e640b5cc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectBlueSuccess.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectBlueSuccess + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "ui_resource_settings.h" +#include "main/LoadImg.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingConnectBlueSuccess.h" + +namespace OHOS { +static constexpr int16_t SETTING_IMG_X = 85; +static constexpr int16_t SETTING_IMG_Y = -50; +static constexpr int16_t SETTING_WATCH_Y = 180; +static constexpr int16_t SETTING_WATCH_HEIGHT = 40; +static constexpr int16_t SETTING_WATCH_FONT = 36; +static constexpr int16_t SETTING_BTN_FONT = 40; +static constexpr int16_t SETTING_CONTENT_Y = 230; +static constexpr int16_t SETTING_CONYENT_HEIGHT = 40; +static constexpr int16_t SETTING_BTN_X = 65; +static constexpr int16_t SETTING_BTN_Y = 359; +static constexpr int16_t SETTING_BTN_WIDTH = 324; +static constexpr int16_t SETTING_BTN_HEIGHT = 101; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; + +void SettingConnectBlueSuccess::OnCreateView(void* data) +{ + InitSuccessFragment(); +} + +void SettingConnectBlueSuccess::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (img_ != nullptr) { + delete img_; + img_ = nullptr; + } + if (watchNameLabel_ != nullptr) { + delete watchNameLabel_; + watchNameLabel_ = nullptr; + } + if (connectStatusLabel_ != nullptr) { + delete connectStatusLabel_; + connectStatusLabel_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } +} + +void SettingConnectBlueSuccess::InitSuccessFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + img_ = new UIImageView(); + if (img_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSuccessFragment img_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(img_, SETTING_IMAGE, IMAGE_OK); + img_->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + + watchNameLabel_ = new UILabel(); + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSuccessFragment watchNameLabel_ new fail"); + return; + } + watchNameLabel_->SetPosition(0, SETTING_WATCH_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + watchNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + watchNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + watchNameLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); + + connectStatusLabel_ = new UILabel(); + if (connectStatusLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSuccessFragment connectStatusLabel_ new fail"); + return; + } + connectStatusLabel_->SetPosition(0, SETTING_CONTENT_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + connectStatusLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + connectStatusLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + connectStatusLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + connectStatusLabel_->SetText("连接成功"); + + confirmButton_ = new UILabelButton(); + if (confirmButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSuccessFragment confirmButton_ new fail"); + return; + } + LOADIMG::LoadBtnImage(confirmButton_, SETTING_IMAGE, IMAGE_OK_DOWN, IMAGE_OK_DOWN); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + confirmButton_->SetPosition(SETTING_BTN_X, SETTING_BTN_Y, SETTING_BTN_WIDTH, SETTING_BTN_HEIGHT); + confirmButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + confirmButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_BTN_FONT); + confirmButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + confirmButton_->SetViewId(CONFIRM_BUTTON); + confirmButton_->SetOnClickListener(this); + confirmButton_->SetVisible(true); + + fragmentView_.Add(img_); + fragmentView_.Add(watchNameLabel_); + fragmentView_.Add(connectStatusLabel_); + fragmentView_.Add(confirmButton_); +} + +void SettingConnectBlueSuccess::RefreshFragment() +{ + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshFragment fail"); + return; + } + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); +} + +bool SettingConnectBlueSuccess::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + bool state = SettingBluetoothPage::GetInstance()->GetImageAnimatorState(); + if (state == false) { + SettingBluetoothPage::GetInstance()->StartBtScan(); + } + fragmentView_.SetVisible(false); + } + return true; +} + +bool SettingConnectBlueSuccess::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectBlueSuccess::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectBlueSuccess::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectNewPhone.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectNewPhone.cpp new file mode 100644 index 000000000..287c61576 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectNewPhone.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectNewPhone + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "uiservice/ui_service.h" +#include "main/LoadImg.h" +#include "ui_resource_settings.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingConnectNewPhone.h" + +namespace OHOS { +static constexpr int16_t SETTING_CONNECT_CANCEL_WIDTH = 85; +static constexpr int16_t SETTING_CONNECT_CANCEL_Y = 300; +static constexpr int16_t SETTING_CONNECT_CANCEL_X = 114; +static constexpr int16_t SETTING_CONNECT_CONFIRM_X = 254; +static constexpr int16_t SETTING_CONNECT_TEXTFIRST_Y = 100; +static constexpr int16_t SETTING_CONNECT_TEXTSECOND_Y = 150; +static constexpr int16_t SETTING_CONNECT_TEXTTHIRD_Y = 200; +static constexpr int16_t SETTING_UNPAIR_TEXT_HEIGHT = 50; +static constexpr int16_t SETTING_UNPAIR_TEXT_FONT = 34; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; +static constexpr char *CANCEL_BUTTON = "cancelButton"; + +void SettingConnectNewPhone::OnCreateView(void* data) +{ + InitNewPhoneFragment(); +} + +void SettingConnectNewPhone::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (textFirst_ != nullptr) { + delete textFirst_; + textFirst_ = nullptr; + } + if (textSecond_ != nullptr) { + delete textSecond_; + textSecond_ = nullptr; + } + if (textThird_ != nullptr) { + delete textThird_; + textThird_ = nullptr; + } + if (cancel_ != nullptr) { + delete cancel_; + cancel_ = nullptr; + } + if (confirm_ != nullptr) { + delete confirm_; + confirm_ = nullptr; + } +} + +void SettingConnectNewPhone::InitNewPhoneFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + std::string str1 = "将断开已连接的手机,"; + std::string str2 = "同一账号的新手机会保留"; + std::string str3 = "个人数据,是否继续?"; + textFirst_ = new UILabel(); + if (textFirst_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitNewPhoneFragment textFirst_ new fail"); + return; + } + textFirst_->SetPosition(0, SETTING_CONNECT_TEXTFIRST_Y, RESOLUTION_WIDTH, SETTING_UNPAIR_TEXT_HEIGHT); + textFirst_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textFirst_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_TEXT_FONT); + textFirst_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + textFirst_->SetText(str1.c_str()); + + textSecond_ = new UILabel(); + if (textSecond_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitNewPhoneFragment textSecond_ new fail"); + return; + } + textSecond_->SetPosition(0, SETTING_CONNECT_TEXTSECOND_Y, RESOLUTION_WIDTH, SETTING_UNPAIR_TEXT_HEIGHT); + textSecond_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textSecond_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_TEXT_FONT); + textSecond_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + textSecond_->SetText(str2.c_str()); + + textThird_ = new UILabel(); + if (textThird_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitNewPhoneFragment textThird_ new fail"); + return; + } + textThird_->SetPosition(0, SETTING_CONNECT_TEXTTHIRD_Y, RESOLUTION_WIDTH, SETTING_UNPAIR_TEXT_HEIGHT); + textThird_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textThird_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_TEXT_FONT); + textThird_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + textThird_->SetText(str3.c_str()); + + cancel_ = new UIImageView(); + if (cancel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitNewPhoneFragment cancel_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(cancel_, SETTING_IMAGE, IMAGE_CANCEL); + cancel_->SetPosition(SETTING_CONNECT_CANCEL_X, + SETTING_CONNECT_CANCEL_Y, SETTING_CONNECT_CANCEL_WIDTH, SETTING_CONNECT_CANCEL_WIDTH); + cancel_->SetTouchable(true); + cancel_->SetViewId(CANCEL_BUTTON); + cancel_->SetOnClickListener(this); + cancel_->SetVisible(true); + + confirm_ = new UIButton(); + if (confirm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitNewPhoneFragment confirm_ new fail"); + return; + } + confirm_->SetPosition(SETTING_CONNECT_CONFIRM_X, + SETTING_CONNECT_CANCEL_Y, SETTING_CONNECT_CANCEL_WIDTH, SETTING_CONNECT_CANCEL_WIDTH); + confirm_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + confirm_->SetViewId(CONFIRM_BUTTON); + confirm_->SetOnClickListener(this); + confirm_->SetVisible(true); + LOADIMG::LoadBtnImage(confirm_, SETTING_IMAGE, IMAGE_OK_BLUE, IMAGE_OK_BLUE); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::PRESSED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::RELEASED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::INACTIVE); + + fragmentView_.Add(textFirst_); + fragmentView_.Add(textSecond_); + fragmentView_.Add(textThird_); + fragmentView_.Add(cancel_); + fragmentView_.Add(confirm_); +} + +bool SettingConnectNewPhone::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), CANCEL_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + } else if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(CONNECT_OPEN_FRAGMENT); + } + return true; +} + +bool SettingConnectNewPhone::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectNewPhone::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectNewPhone::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectionOpen.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectionOpen.cpp new file mode 100644 index 000000000..37da7455a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingConnectionOpen.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingConnectionOpen + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "main/LoadImg.h" +#include "ui_resource_settings.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingConnectionOpen.h" + +namespace OHOS { +static constexpr int16_t SETTING_IMG_X = 85; +static constexpr int16_t SETTING_IMG_Y = -50; +static constexpr int16_t SETTING_WATCH_Y = 180; +static constexpr int16_t SETTING_WATCH_HEIGHT = 45; +static constexpr int16_t SETTING_WATCH_FONT = 36; +static constexpr int16_t SETTING_CONTENT_Y = 230; +static constexpr int16_t SETTING_CONYENT_HEIGHT = 40; +static constexpr int16_t SETTING_BTN_FONT = 40; +static constexpr int16_t SETTING_BTN_X = 65; +static constexpr int16_t SETTING_BTN_Y = 359; +static constexpr int16_t SETTING_BTN_WIDTH = 324; +static constexpr int16_t SETTING_BTN_HEIGHT = 101; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; +static SettingConnectionOpen *g_pSettingConnectionOpen{nullptr}; + +void SettingConnectionOpen::OnCreateView(void* data) +{ + InitConnectionOpenFragment(); + g_pSettingConnectionOpen = this; +} + +void SettingConnectionOpen::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (img_ != nullptr) { + delete img_; + img_ = nullptr; + } + if (watchNameLabel_ != nullptr) { + delete watchNameLabel_; + watchNameLabel_ = nullptr; + } + if (connectStatusLabel_ != nullptr) { + delete connectStatusLabel_; + connectStatusLabel_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } +} + +void SettingConnectionOpen::InitConnectionOpenFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + img_ = new UIImageView(); + if (img_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitConnectionOpenFragment img_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(img_, SETTING_IMAGE, IMAGE_OK); + img_->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + + watchNameLabel_ = new UILabel(); + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitConnectionOpenFragment watchNameLabel_ new fail"); + return; + } + watchNameLabel_->SetPosition(0, SETTING_WATCH_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + watchNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + watchNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + watchNameLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + watchNameLabel_->SetText(SettingBluetoothModel::GetInstance()->GetWatchName()); + + connectStatusLabel_ = new UILabel(); + if (connectStatusLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitConnectionOpenFragment connectStatusLabel_ new fail"); + return; + } + connectStatusLabel_->SetPosition(0, SETTING_CONTENT_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + connectStatusLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + connectStatusLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_CONYENT_HEIGHT); + connectStatusLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + connectStatusLabel_->SetText("连接已打开"); + + confirmButton_ = new UILabelButton(); + if (confirmButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitConnectionOpenFragment confirmButton_ new fail"); + return; + } + LOADIMG::LoadBtnImage(confirmButton_, SETTING_IMAGE, IMAGE_OK_DOWN, IMAGE_OK_DOWN); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + confirmButton_->SetPosition(SETTING_BTN_X, SETTING_BTN_Y, SETTING_BTN_WIDTH, SETTING_BTN_HEIGHT); + confirmButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + confirmButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_BTN_FONT); + confirmButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + confirmButton_->SetViewId(CONFIRM_BUTTON); + confirmButton_->SetOnClickListener(this); + confirmButton_->SetVisible(true); + + fragmentView_.Add(img_); + fragmentView_.Add(watchNameLabel_); + fragmentView_.Add(connectStatusLabel_); + fragmentView_.Add(confirmButton_); +} + +void SettingConnectionOpen::RefreshFragment() +{ + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshFragment fail"); + return; + } + watchNameLabel_->SetText(SettingBluetoothModel::GetInstance()->GetWatchName()); +} + +bool SettingConnectionOpen::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + SettingBluetoothModel::GetInstance()->SetConnectFragmentStatus(false); + } + return true; +} + +bool SettingConnectionOpen::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectionOpen::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingConnectionOpen::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialPage.cpp new file mode 100644 index 000000000..a68dc54f7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialPage.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopDialPage + * Create: 2025-06-01 + */ +#include "common/screen.h" +#include "components/ui_swipe_view_nested.h" +#include "gfx_utils/graphic_math.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingDesktopModel.h" +#include "settings/page/SettingDesktopDialPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DESKTOP_DIAL_PAGE, SettingDesktopDialPage, false); + +static constexpr int16_t SETTING_ROLLER_ITEM_WIDTH = 250; +static constexpr int16_t SETTING_ROLLER_ITEM_HEIHT = 250; +static constexpr int16_t SETTING_ROLLER_ITEM_PADDING = 80; +static constexpr float SETTING_ROLLER_BASE_ANGLE = 360.0; +static constexpr float SETTING_ROLLER_HALF_BASE_ANGLE = 180.0; + +static constexpr int16_t SETTING_DIAL_BUTTON_X = -454; +static constexpr int16_t SETTING_DIAL_BUTTON_Y = 363; +static constexpr int16_t SETTING_DIAL_BUTTON_WDITH = 454*3; +static constexpr int16_t SETTING_DIAL_BUTTON_HEIGHT = 454*3; +static constexpr int16_t SETTING_DIAL_BUTTON_RADIUS = 454*3; +#define SETTING_DIAL_BUTTON_COLOR Color::GetColorFromRGB(13, 159, 251) // 0xFF0D9FFB + +static constexpr int16_t SETTING_DIAL_BUTTON_LABEL_X = 105; +static constexpr int16_t SETTING_DIAL_BUTTON_LABEL_Y = 375; +static constexpr int16_t SETTING_DIAL_BUTTON_LABEL_WIDTH = 244; +static constexpr int16_t SETTING_DIAL_BUTTON_LABEL_HEIGHT = 54; +static constexpr int16_t SETTING_DIAL_BUTTON_LABEL_FSIZE = 38; +static const char* SETTING_DIAL_BUTTON_LABEL_TEXT = "设置"; + +static constexpr int16_t SETTING_DIAL_TITLE_X = 100; +static constexpr int16_t SETTING_DIAL_TITLE_Y = 39; +static constexpr int16_t SETTING_DIAL_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_DIAL_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_DIAL_TITLE_FSZIE = 38; + +void SettingDesktopDialPage::OnStart(void* data) +{ + InitDialView(); + InitCtrlView(); + AddViewToPageContainer(itemLabel_); + AddViewToPageContainer(coverflow_); + AddViewToPageContainer(rollerView_); +} + +void SettingDesktopDialPage::OnResume() +{ + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); // 取消跟手返回 + SettingDesktopModel::GetInstance().LoadAllDial(); + const auto& dialInfo = SettingDesktopModel::GetInstance().GetDialInfo(); + itemIndex_ = SettingDesktopModel::GetInstance().GetPageIndex(); + + if (SettingDesktopModel::GetInstance().GetDialStyle() == DialStyle::ROLLER) { + itemCount_ = 0; // 重置计数 + for (const auto& iter : dialInfo) { + rollerView_->AddItem(iter.dialName, iter.preImageInfo) ? itemCount_++ : itemCount_; + } + rollerView_->SetCurrentItem(dialInfo[itemIndex_].dialName); + rollerView_->SetVisible(true); + } else { // DialStyle::COVERFLOW风格 + for (const auto& iter : dialInfo) { + coverflow_->Add(iter.dialName.c_str(), iter.preImageInfo); + } + coverflow_->SetCurrentPage(itemIndex_); + coverflow_->SetVisible(true); + } + itemLabel_->SetText(dialInfo[itemIndex_].dialName.c_str()); +} + +void SettingDesktopDialPage::OnPause() +{ + if (SettingDesktopModel::GetInstance().GetDialStyle() == DialStyle::COVERFLOW) { + coverflow_->ClearAll(); + } else { + rollerView_->ClearAll(); + } + SettingDesktopModel::GetInstance().ClearDialInfo(); +} + +void SettingDesktopDialPage::OnStop() +{ + if (coverflow_ != nullptr) { + delete coverflow_; + coverflow_ = nullptr; + } + if (rollerView_ != nullptr) { + delete rollerView_; + rollerView_ = nullptr; + } + if (itemLabel_ != nullptr) { + delete itemLabel_; + itemLabel_ = nullptr; + } +} + +bool SettingDesktopDialPage::OnClick(UIView& view, const ClickEvent& event) +{ + SettingDesktopModel::GetInstance().SaveDialSetting(itemIndex_); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + return true; +} + +bool SettingDesktopDialPage::OnScroll() +{ + int16_t windowCenterX = HORIZONTAL_RESOLUTION / 2; + int16_t windowDistance = windowCenterX; + int16_t currItemDistance = 0; + uint16_t currItemIndex = 0; + for (uint16_t i = 0; i < coverflow_->GetChildrenNumber(); i++) { + Rect itemRect = coverflow_->GetViewByIndex(i)->GetOrigRect(); + int16_t itemCenterX = itemRect.GetLeft() + itemRect.GetWidth() / 2; + int16_t itemDistance = MATH_ABS(itemCenterX - windowCenterX); + if (windowDistance > itemDistance) { // 和中心点距离最小的组件是当前显示页面 + currItemIndex = i; + currItemDistance = itemDistance; + windowDistance = itemDistance; + } + } + if (currItemIndex != itemIndex_) { + itemIndex_ = currItemIndex; + const auto& dialInfo = SettingDesktopModel::GetInstance().GetDialInfo(); + itemLabel_->SetText(dialInfo[itemIndex_].dialName.c_str()); + } + // 公式: 透明度 = 最大透明度- 最大透明度*(组件中心点/窗口中心点); 当组件中心点=窗口中心点时, OPA的值最大 + uint16_t opa = OPA_OPAQUE - (uint16_t)((int32_t)OPA_OPAQUE * currItemDistance / windowCenterX); + itemLabel_->SetStyle(STYLE_TEXT_OPA, opa); + return true; +} + +void SettingDesktopDialPage::OnScroll(UIRollerView* roller, std::string currentItemName, float currentItemAngle) +{ + const float baseAngle = SETTING_ROLLER_BASE_ANGLE; + const float halfBaseAngle = SETTING_ROLLER_HALF_BASE_ANGLE; + if (FloatMoreEqual(currentItemAngle, halfBaseAngle)) { + currentItemAngle -= baseAngle; + } + if (currentItemAngle < 0) { + currentItemAngle = -currentItemAngle; + } + float maxAngle = baseAngle / itemCount_; + float coef = 1.0 - 1.0 / (maxAngle) * currentItemAngle; + itemLabel_->SetStyle(STYLE_TEXT_OPA, coef * OPA_OPAQUE); + itemLabel_->SetText(currentItemName.c_str()); + auto& dialInfo = SettingDesktopModel::GetInstance().GetDialInfo(); + for (uint8_t i = 0; i < dialInfo.size(); ++i) { + if (dialInfo[i].dialName == currentItemName) { + itemIndex_ = i; + } + } +} + +void SettingDesktopDialPage::InitDialView() +{ + coverflow_ = new UICoverflowView(); + if (coverflow_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopDialPage::InitDialView coverflow_ new fail"); + return; + } + coverflow_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + coverflow_->SetOnCoverflowListener(this); + coverflow_->SetOnClickListener(this); + coverflow_->SetThrowDrag(true); + coverflow_->SetIntercept(true); + coverflow_->SetVisible(false); + + rollerView_ = new UIRollerView(); + if (rollerView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopDialPage::InitDialView rollerView_ new fail"); + return; + } + rollerView_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + rollerView_->SetItemSize(SETTING_ROLLER_ITEM_WIDTH, SETTING_ROLLER_ITEM_HEIHT); + rollerView_->SetThrowDrag(true); + rollerView_->SetIntercept(true); + rollerView_->SetItemPadding(SETTING_ROLLER_ITEM_PADDING); + rollerView_->SetOnScrollListener(this); + rollerView_->SetOnClickListener(this); + rollerView_->SetVisible(false); +} + +void SettingDesktopDialPage::InitCtrlView() +{ + itemLabel_ = new UILabel(); + if (itemLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopDialPage::InitCtrlView itemLabel_ new fail"); + return; + } + itemLabel_->SetPosition(SETTING_DIAL_TITLE_X, SETTING_DIAL_TITLE_Y); + itemLabel_->Resize(SETTING_DIAL_TITLE_WIDTH, SETTING_DIAL_TITLE_HEIGHT); + itemLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + itemLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_DIAL_TITLE_FSZIE); + itemLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialStylePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialStylePage.cpp new file mode 100644 index 000000000..4dbb82358 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopDialStylePage.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopDialStylePage + * Create: 2025-06-01 + */ +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingDesktopModel.h" +#include "settings/page/SettingDesktopDialStylePage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DESKTOP_DIAL_STYLE_PAGE, SettingDesktopDialStylePage, false); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 96; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingDesktopDialStylePage *g_pSettingDesktopDialStylePage{nullptr}; + +void SettingDesktopDialStylePage::OnStart(void *data) +{ + g_pSettingDesktopDialStylePage = this; + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopDialStylePage::OnStart scroll_ new fail"); + return; + } + scroll_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scroll_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scroll_->SetThrowDrag(true); + scroll_->SetIntercept(true); + + content_ = new UISimpleList(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopDialStylePage::OnStart content_ new fail"); + return; + } + content_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + content_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + content_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + content_->SetDraggable(true); + content_->SetThrowDrag(true); + content_->SetMaxScrollDistance(MAX_SCR_DIS); + scroll_->Add(content_); + AddViewToPageContainer(scroll_); +} + +void SettingDesktopDialStylePage::OnResume() +{ + content_->ClearAll(); + for(auto& it : SettingDesktopModel::GetInstance().GetDialStyleUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingDesktopDialStylePage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + content_->AddContent(cont); + } + content_->RefreshList(); +} + +void SettingDesktopDialStylePage::OnStop() +{ + g_pSettingDesktopDialStylePage = nullptr; + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } +} + +bool SettingDesktopDialStylePage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t viewId = (uintptr_t)view.GetViewId(); + if (viewId == (uintptr_t)ICON_TEXT_TOGGLE) { + int16_t viewIndex = view.GetViewIndex(); + auto& dialStyleUnionData = SettingDesktopModel::GetInstance().GetDialStyleUnionData(); + if (viewIndex < 0 || viewIndex > dialStyleUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = dialStyleUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_TOGGLE) { + IconTextToggleItemData* data = static_cast(itemData.GetUnionItemData()); + SettingDesktopModel::GetInstance().SetDialStyleDataSelect(data->textContent); + + // 刷新UnionData + SettingDesktopModel::GetInstance().GetDialStyleUnionData(); + content_->RefreshList(); + } + } + return true; +} + + +void SettingDesktopDialStylePage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDesktopDialStylePage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDesktopDialStylePage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopHomePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopHomePage.cpp new file mode 100644 index 000000000..d2a5ff487 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopHomePage.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopHomePage + * Create: 2025-06-01 + */ +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingDesktopModel.h" +#include "settings/page/SettingDesktopHomePage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DESKTOP_HOME_PAGE, SettingDesktopHomePage, false); + +static constexpr int16_t SETTING_DESKTOP_HOME_LIST_Y = 130; +static constexpr int16_t SETTING_DESKTOP_HOME_LSIT_HEIGHT = 205; +static constexpr int16_t SETTING_DESKTOP_HOME_LIST_BLANK = 0; +static constexpr int16_t SETTING_DESKTOP_HOME_LIST_DISTANCE = 1000; +static constexpr int16_t SETTING_DESKTOP_HOME_LIST_SELECTPOS = HORIZONTAL_RESOLUTION / 4; + +static constexpr int16_t SETTING_DESKTOP_HOME_TITLE_X = 100; +static constexpr int16_t SETTING_DESKTOP_HOME_TITLE_Y = 39; +static constexpr int16_t SETTING_DESKTOP_HOME_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_DESKTOP_HOME_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_DESKTOP_HOME_TITLE_FSIZE = 38; +static const char* SETTING_DESKTOP_HOME_TITLE_TEXT = "桌面风格"; + +void SettingDesktopHomePage::OnStart(void* data) +{ + list_ = new UISimpleList(); + if (list_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopHomePage::OnStart list_ new fail"); + return; + } + list_->SetDirection(UIAbstractScroll::HORIZONTAL); + list_->SetBoundaryIntercept(DragEvent::DIRECTION_LEFT_TO_RIGHT, false); + list_->SetPosition(0, SETTING_DESKTOP_HOME_LIST_Y); + list_->Resize(HORIZONTAL_RESOLUTION, SETTING_DESKTOP_HOME_LSIT_HEIGHT); + list_->SetScrollBlankSize(SETTING_DESKTOP_HOME_LIST_BLANK); + list_->SetSelectPosition(SETTING_DESKTOP_HOME_LIST_SELECTPOS); + list_->SetDraggable(true); + list_->SetThrowDrag(true); + list_->EnableAutoAlign(true); + list_->SetMaxScrollDistance(SETTING_DESKTOP_HOME_LIST_DISTANCE); + list_->SetIntercept(false); + + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopHomePage::OnStart title_ new fail"); + return; + } + title_->SetPosition(SETTING_DESKTOP_HOME_TITLE_X, SETTING_DESKTOP_HOME_TITLE_Y); + title_->Resize(SETTING_DESKTOP_HOME_TITLE_WIDTH, SETTING_DESKTOP_HOME_TITLE_HEIGHT); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_DESKTOP_HOME_TITLE_FSIZE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetText(SETTING_DESKTOP_HOME_TITLE_TEXT); + + AddViewToPageContainer(list_); + AddViewToPageContainer(title_); +} + +void SettingDesktopHomePage::OnResume() +{ + list_->ClearAll(); + for(auto& it : SettingDesktopModel::GetInstance().GetDesktopHomeData()) { + it.contextPtr = this; + Contents cont; + cont.createFunc = SettingDesktopHomePage::OnSimpleListCreate; + cont.updateFunc = SettingDesktopHomePage::OnSimpleListUpdate; + cont.type = 0; + cont.data = ⁢ + list_->AddContent(cont); + } + list_->RefreshList(); +} + +void SettingDesktopHomePage::OnStop() +{ + if (list_ != nullptr) { + delete list_; + list_ = nullptr; + } + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } +} + +bool SettingDesktopHomePage::OnClick(UIView& view, const ClickEvent& event) +{ + int16_t index = view.GetViewIndex(); + int16_t currIndex = SettingDesktopModel::GetInstance().GetDesktopHomeDataSelect(); + auto& desktopHomeData = SettingDesktopModel::GetInstance().GetDesktopHomeData(); + if (index != currIndex && index >= 0 && (size_t)index < desktopHomeData.size()) { + SettingDesktopModel::GetInstance().SetDesktopHomeDataSelect((DesktopStyle)desktopHomeData[index].style); + list_->RefreshList(); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + return true; +} + +UIView* SettingDesktopHomePage::OnSimpleListCreate(uint8_t type) +{ + UNUSED(type); + return new SettingDesktopHomeItemGroup(); +} + +void SettingDesktopHomePage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + if (view == nullptr || data == nullptr) { + return; + } + SettingDesktopHomeItemGroup* itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + SettingDesktopHomeItemData* itemData = static_cast(data); + SettingDesktopHomePage* page = static_cast(itemData->contextPtr); + itemGroup->UpdateItemGroup(itemData); + itemGroup->SetOnClickListener(page); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopPage.cpp new file mode 100644 index 000000000..51d08e213 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDesktopPage.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingDesktopModel.h" +#include "settings/page/SettingDesktopPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DESKTOP_PAGE, SettingDesktopPage, false); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 96; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingDesktopPage *g_pSettingDesktopPage{nullptr}; + +void SettingDesktopPage::OnStart(void *data) +{ + g_pSettingDesktopPage = this; + content_ = new UISimpleList(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::OnStart content_ new fail"); + return; + } + content_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + content_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + content_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + content_->SetDraggable(true); + content_->SetThrowDrag(true); + content_->SetMaxScrollDistance(MAX_SCR_DIS); + + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::OnStart scroll_ new fail"); + return; + } + scroll_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scroll_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scroll_->SetThrowDrag(true); + scroll_->SetIntercept(true); + scroll_->SetOnDragListener(this); + scroll_->Add(content_); + AddViewToPageContainer(scroll_); +} + +void SettingDesktopPage::OnResume() +{ + content_->ClearAll(); + for (SettingUnionItemData& it : SettingDesktopModel::GetInstance().GetDesktopUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingDesktopPage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + content_->AddContent(cont); + } + content_->RefreshList(); +} + +void SettingDesktopPage::OnStop() +{ + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } + g_pSettingDesktopPage = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::~SettingDesktopPage"); +} + +bool SettingDesktopPage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t viewId = (uintptr_t)view.GetViewId(); + if (viewId == (uintptr_t)ICON_TEXT_NAVIGATION) { + int16_t viewIndex = view.GetViewIndex(); + auto& desktopUnionData = SettingDesktopModel::GetInstance().GetDesktopUnionData(); + if (viewIndex < 0 || viewIndex > desktopUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = desktopUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_NAVIGATION) { + IconTextNavigationItemData* data = static_cast(itemData.GetUnionItemData()); + NativeAbility::GetInstance().SwitchPageInSlice(data->pageId, + TransitionType::TRANSITION_INVALID, true); + } + } + return true; +} + +void SettingDesktopPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDesktopPage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDesktopPage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayBrightnessPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayBrightnessPage.cpp new file mode 100644 index 000000000..44cf3e168 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayBrightnessPage.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayBrightnessPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingDisplayModel.h" +#include "settings/page/SettingDisplayBrightnessPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DISPLAY_BRIGHTNESS_PAGE, SettingDisplayBrightnessPage, false); + +static constexpr int8_t SETTING_DISPLAY_TEMP_STR_LEN = 10; +static constexpr uint8_t SETTING_DISPLAY_BRIGHTNESS_MAX = 100; +static constexpr uint8_t SETTING_DISPLAY_BRIGHTNESS_MIN = 0; +static constexpr int16_t SETTING_DISPLAY_BRIGHTNESS_AUTO_TIME = 300; + +static constexpr int16_t SETTING_DISPLAY_BRI_TITLE_X = 100; +static constexpr int16_t SETTING_DISPLAY_BRI_TITLE_Y = 39; +static constexpr int16_t SETTING_DISPLAY_BRI_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_DISPLAY_BRI_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_DISPLAY_BRI_TITLE_FSIZE = 38; +static const char* SETTING_DISPLAY_BRI_TITLE_TEXT = "调整亮度"; + +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_X = 127; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_Y = 127; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_WIDTH = 200; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_HEIGHT = 200; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_LINE_WIDTH = 25; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESS_RADIUS = 100; +static constexpr int16_t SETTING_DISPLAY_BRI_START_ANGLE = 360; +static constexpr int16_t SETTING_DISPLAY_BRI_END_ANGLE = 0; + +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESSNUM_X = 173; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESSNUM_Y = 187; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESSNUM_WIDTH = 108; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESSNUM_HEIGHT = 60; +static constexpr int16_t SETTING_DISPLAY_BRI_PROGRESSNUM_FSIZE = 59; + +static constexpr int16_t SETTING_DISPLAY_BRI_ADD_X = 343; +static constexpr int16_t SETTING_DISPLAY_BRI_ADD_Y = 187; +static constexpr int16_t SETTING_DISPLAY_BRI_ADD_WIDTH = 80; +static constexpr int16_t SETTING_DISPLAY_BRI_ADD_HEIGHT = 80; +static constexpr int16_t SETTING_DISPLAY_BRI_ADD_OPA = 37; +static const char* SETTING_DISPLAY_BRI_ADD_BUTTON_ID = "add"; + +static constexpr int16_t SETTING_DISPLAY_BRI_SUB_X = 31; +static constexpr int16_t SETTING_DISPLAY_BRI_SUB_Y = 187; +static constexpr int16_t SETTING_DISPLAY_BRI_SUB_WIDTH = 80; +static constexpr int16_t SETTING_DISPLAY_BRI_SUB_HEIGHT = 80; +static constexpr int16_t SETTING_DISPLAY_BRI_SUB_OPA = 37; +static const char* SETTING_DISPLAY_BRI_SUB_BUTTON_ID = "sub"; + +void SettingDisplayBrightnessPage::OnStart(void* data) +{ + InitProgressView(); + InitButtonView(); + AddViewToPageContainer(title_); + AddViewToPageContainer(progress_); + AddViewToPageContainer(progressNum_); + AddViewToPageContainer(add_); + AddViewToPageContainer(sub_); +} + +void SettingDisplayBrightnessPage::OnResume() +{ + char temp[SETTING_DISPLAY_TEMP_STR_LEN] = ""; + uint8_t brightness = SettingDisplayModel::GetInstance().GetBrightness(); + progress_->SetValue(brightness); + if (sprintf_s(temp, sizeof(temp), "%u", brightness) > 0) { + progressNum_->SetText(temp); + } +} + +void SettingDisplayBrightnessPage::OnPause() +{ + animator_->Stop(); +} + +void SettingDisplayBrightnessPage::OnStop() +{ + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (progress_ != nullptr) { + delete progress_; + progress_ = nullptr; + } + if (progressNum_ != nullptr) { + delete progressNum_; + progressNum_ = nullptr; + } + if (add_ != nullptr) { + delete add_; + add_ = nullptr; + } + if (sub_ != nullptr) { + delete sub_; + sub_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_DESKTOP_BRIGHTNESS_FG, SETTING_IMAGE); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_DISPLAY_BRIGHTNESS_ADD, SETTING_IMAGE); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_DISPLAY_BRIGHTNESS_SUB, SETTING_IMAGE); +} + +bool SettingDisplayBrightnessPage::OnClick(UIView &view, const ClickEvent &event) +{ + char temp[SETTING_DISPLAY_TEMP_STR_LEN] = ""; + if (strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_ADD_BUTTON_ID) == 0) { + uint8_t brightness = SettingDisplayModel::GetInstance().GetBrightness(); + if (brightness != SETTING_DISPLAY_BRIGHTNESS_MAX) { + brightness++; + SettingDisplayModel::GetInstance().SetBrightness(brightness); + progress_->SetValue(brightness); + if (sprintf_s(temp, sizeof(temp), "%u", brightness) > 0) { + progressNum_->SetText(temp); + } + } + } else if (strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_SUB_BUTTON_ID) == 0) { + uint8_t brightness = SettingDisplayModel::GetInstance().GetBrightness(); + if (brightness != SETTING_DISPLAY_BRIGHTNESS_MIN) { + brightness--; + SettingDisplayModel::GetInstance().SetBrightness(brightness); + progress_->SetValue(brightness); + if (sprintf_s(temp, sizeof(temp), "%u", brightness) > 0) { + progressNum_->SetText(temp); + } + } + } + return true; +} + +bool SettingDisplayBrightnessPage::OnLongPress(UIView& view, const LongPressEvent& event) +{ + if (strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_ADD_BUTTON_ID) == 0) { + if (curLongPressButton_ == nullptr) { + curLongPressButton_ = add_; + animator_->Start(); + } + } else if (strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_SUB_BUTTON_ID) == 0) { + if (curLongPressButton_ == nullptr) { + curLongPressButton_ = sub_; + animator_->Start(); + } + } + return true; +} + +bool SettingDisplayBrightnessPage::OnRelease(UIView& view, const ReleaseEvent& event) +{ + animator_->Stop(); + curLongPressButton_ = nullptr; + return true; +} + +bool SettingDisplayBrightnessPage::OnDragEnd(UIView& view, const DragEvent& event) +{ + if (view.GetViewId() && + (strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_ADD_BUTTON_ID) == 0 || + strcmp(view.GetViewId(), SETTING_DISPLAY_BRI_SUB_BUTTON_ID) == 0)) { + animator_->Stop(); + curLongPressButton_ = nullptr; + } + return false; +} + +void SettingDisplayBrightnessPage::Callback(UIView* view) +{ + static uint32_t lastRunTime = 0; + uint32_t currRunTime = animator_->GetRunTime(); + if (currRunTime - lastRunTime < SETTING_DISPLAY_BRIGHTNESS_AUTO_TIME) { + return; + } + lastRunTime = currRunTime; + char temp[SETTING_DISPLAY_TEMP_STR_LEN] = ""; + uint8_t brightness = SettingDisplayModel::GetInstance().GetBrightness(); + if (curLongPressButton_ == add_ && brightness != SETTING_DISPLAY_BRIGHTNESS_MAX) { + brightness++; + } else if (curLongPressButton_ == sub_ && brightness != SETTING_DISPLAY_BRIGHTNESS_MIN) { + brightness--; + } + SettingDisplayModel::GetInstance().SetBrightness(brightness); + progress_->SetValue(brightness); + if (sprintf_s(temp, sizeof(temp), "%u", brightness) > 0) { + progressNum_->SetText(temp); + } +} + +void SettingDisplayBrightnessPage::InitProgressView() +{ + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitProgressView title_ new fail"); + return; + } + title_->SetPosition(SETTING_DISPLAY_BRI_TITLE_X, SETTING_DISPLAY_BRI_TITLE_Y); + title_->Resize(SETTING_DISPLAY_BRI_TITLE_WIDTH, SETTING_DISPLAY_BRI_TITLE_HEIGHT); + title_->SetTextColor(Color::White()); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_DISPLAY_BRI_TITLE_FSIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetText(SETTING_DISPLAY_BRI_TITLE_TEXT); + + progress_ = new UICircleProgress(); + if (progress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitProgressView progress_ new fail"); + return; + } + progress_->SetPosition(SETTING_DISPLAY_BRI_PROGRESS_X, SETTING_DISPLAY_BRI_PROGRESS_Y); + progress_->Resize(SETTING_DISPLAY_BRI_PROGRESS_WIDTH, SETTING_DISPLAY_BRI_PROGRESS_HEIGHT); + ImageInfo* fgImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DESKTOP_BRIGHTNESS_FG, SETTING_IMAGE); + ImageInfo* bgImage = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DESKTOP_BRIGHTNESS_BG, SETTING_IMAGE); + progress_->SetImage(fgImage, bgImage); + progress_->SetBackgroundStyle(STYLE_LINE_WIDTH, SETTING_DISPLAY_BRI_PROGRESS_LINE_WIDTH); + progress_->SetForegroundStyle(STYLE_LINE_WIDTH, SETTING_DISPLAY_BRI_PROGRESS_LINE_WIDTH); + progress_->SetProgressImagePosition(0, 0); + progress_->SetBackgroundImagePosition(0, 0); + progress_->SetCenterPosition(SETTING_DISPLAY_BRI_PROGRESS_RADIUS, SETTING_DISPLAY_BRI_PROGRESS_RADIUS); + progress_->SetRadius(SETTING_DISPLAY_BRI_PROGRESS_RADIUS); + progress_->SetStartAngle(SETTING_DISPLAY_BRI_START_ANGLE); + progress_->SetEndAngle(SETTING_DISPLAY_BRI_END_ANGLE); + + progressNum_ = new UILabel(); + if (progressNum_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitProgressView progressNum_ new fail"); + return; + } + progressNum_->SetPosition(SETTING_DISPLAY_BRI_PROGRESSNUM_X, SETTING_DISPLAY_BRI_PROGRESSNUM_Y); + progressNum_->Resize(SETTING_DISPLAY_BRI_PROGRESSNUM_WIDTH, SETTING_DISPLAY_BRI_PROGRESSNUM_HEIGHT); + progressNum_->SetTextColor(Color::White()); + progressNum_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_DISPLAY_BRI_PROGRESSNUM_FSIZE); + progressNum_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); +} + +void SettingDisplayBrightnessPage::InitButtonView() +{ + add_ = new UIButton(); + if (add_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitButtonView add_ new fail"); + return; + } + add_->SetPosition(SETTING_DISPLAY_BRI_ADD_X, SETTING_DISPLAY_BRI_ADD_Y); + add_->Resize(SETTING_DISPLAY_BRI_ADD_WIDTH, SETTING_DISPLAY_BRI_ADD_HEIGHT); + ImageInfo* addImage = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DISPLAY_BRIGHTNESS_ADD, SETTING_IMAGE); + add_->SetImageSrc(addImage, addImage); + add_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + add_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + add_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_BRI_ADD_OPA, UIButton::RELEASED); + add_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_BRI_ADD_OPA, UIButton::PRESSED); + add_->SetViewId(SETTING_DISPLAY_BRI_ADD_BUTTON_ID); + add_->SetDraggable(true); + add_->SetOnClickListener(this); + add_->SetOnTouchListener(this); + add_->SetOnLongPressListener(this); + add_->SetOnDragListener(this); + add_->SetIntercept(true); + + sub_ = new UIButton(); + if (sub_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitButtonView sub_ new fail"); + return; + } + sub_->SetPosition(SETTING_DISPLAY_BRI_SUB_X, SETTING_DISPLAY_BRI_SUB_Y); + sub_->Resize(SETTING_DISPLAY_BRI_SUB_WIDTH, SETTING_DISPLAY_BRI_SUB_HEIGHT); + ImageInfo* subImage = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DISPLAY_BRIGHTNESS_SUB, SETTING_IMAGE); + sub_->SetImageSrc(subImage, subImage); + sub_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + sub_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + sub_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_BRI_SUB_OPA, UIButton::RELEASED); + sub_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_BRI_SUB_OPA, UIButton::PRESSED); + sub_->SetViewId(SETTING_DISPLAY_BRI_SUB_BUTTON_ID); + sub_->SetDraggable(true); + sub_->SetOnClickListener(this); + sub_->SetOnTouchListener(this); + sub_->SetOnLongPressListener(this); + sub_->SetOnDragListener(this); + sub_->SetIntercept(true); + + animator_ = new Animator(this, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayBrightness::InitButtonView animator_ new fail"); + return; + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayPage.cpp new file mode 100644 index 000000000..2bd2f53af --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayPage.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayPage + * Create: 2025-06-01 + */ +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingDisplayModel.h" +#include "settings/page/SettingDisplayPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DISPLAY_PAGE, SettingDisplayPage, false); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 96; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingDisplayPage *g_pSettingDisplayPage{nullptr}; + +void SettingDisplayPage::OnStart(void *data) +{ + g_pSettingDisplayPage = this; + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayPage::OnStart scroll_ new fail"); + return; + } + scroll_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scroll_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scroll_->SetThrowDrag(true); + scroll_->SetTouchable(true); + scroll_->SetDraggable(true); + scroll_->SetIntercept(true); + + content_ = new UISimpleList(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayPage::OnStart content_ new fail"); + return; + } + content_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + content_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + content_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + content_->SetDraggable(true); + content_->SetThrowDrag(true); + content_->SetMaxScrollDistance(MAX_SCR_DIS); + scroll_->Add(content_); + AddViewToPageContainer(scroll_); +} + +void SettingDisplayPage::OnResume() +{ + content_->ClearAll(); + for(auto& it : SettingDisplayModel::GetInstance().GetDisplayUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingDisplayPage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + content_->AddContent(cont); + } + content_->RefreshList(); +} + +void SettingDisplayPage::OnStop() +{ + g_pSettingDisplayPage = nullptr; + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } +} + +bool SettingDisplayPage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t viewId = (uintptr_t)view.GetViewId(); + if (viewId == (uintptr_t)ICON_TEXT_TOGGLE) { + int16_t viewIndex = view.GetViewIndex(); + auto& displayUnionData = SettingDisplayModel::GetInstance().GetDisplayUnionData(); + if (viewIndex < 0 || viewIndex > displayUnionData.size()) { + return true; + } + + SettingDisplayModel::GetInstance().SetAutoAdjustBrightness( + !SettingDisplayModel::GetInstance().GetAutoAdjustBrightness()); + SettingDisplayModel::GetInstance().RefreshDisplayUnionDataForAutoAdjustBrightness(); + content_->RefreshList(); + } else if (viewId == (uintptr_t)ICON_TEXT_NAVIGATION) { + int16_t viewIndex = view.GetViewIndex(); + auto& displayUnionData = SettingDisplayModel::GetInstance().GetDisplayUnionData(); + if (viewIndex < 0 || viewIndex > displayUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = displayUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_NAVIGATION) { + IconTextNavigationItemData* data = static_cast(itemData.GetUnionItemData()); + NativeAbility::GetInstance().SwitchPageInSlice(data->pageId, + TransitionType::TRANSITION_INVALID, true); + } + } + return true; +} + +void SettingDisplayPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDisplayPage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingDisplayPage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayScreenOffPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayScreenOffPage.cpp new file mode 100644 index 000000000..24710998e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplayScreenOffPage.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplayScreenOffPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingDisplayModel.h" +#include "settings/page/SettingDisplayScreenOffPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DISPLAY_SCREEN_OFF_PAGE, + SettingDisplayScreenOffPage, false); + +static constexpr int16_t SETTING_DISPLAY_SCREEN_TITLE_X = 100; +static constexpr int16_t SETTING_DISPLAY_SCREEN_TITLE_Y = 39; +static constexpr int16_t SETTING_DISPLAY_SCREEN_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_DISPLAY_SCREEN_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_DISPLAY_SCREEN_TITLE_FSIZE = 38; +static const char* SETTING_DISPLAY_SCREEN_TITLE_TEXT = "熄屏时间"; + +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_X = 64; +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_Y = 118; +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_WIDTH = 321; +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_HEIGHT = 218; +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_FSIZE = 44; +static constexpr int16_t SETTING_DISPLAY_SCREEN_PICKER_ITEM_HEIGHT = 84; + +static constexpr int16_t SETTING_DISPLAY_SCREEN_BUTTON_X = 63; +static constexpr int16_t SETTING_DISPLAY_SCREEN_BUTTON_Y = 358; +static constexpr int16_t SETTING_DISPLAY_SCREEN_BUTTON_WIDTH = 328; +static constexpr int16_t SETTING_DISPLAY_SCREEN_BUTTON_HEIGHT = 94; +static constexpr int16_t SETTING_DISPLAY_SCREEN_BUTTON_BG_OPA = 51; +static const char* SETTING_DISPLAY_SCREEN_BUTTON_ID = "button"; + +void SettingDisplayScreenOffPage::OnStart(void* data) +{ + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayScreenOffTimePage::OnStart title_ new fail"); + return; + } + title_->SetPosition(SETTING_DISPLAY_SCREEN_TITLE_X, SETTING_DISPLAY_SCREEN_TITLE_Y); + title_->Resize(SETTING_DISPLAY_SCREEN_TITLE_WIDTH, SETTING_DISPLAY_SCREEN_TITLE_HEIGHT); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_DISPLAY_SCREEN_TITLE_FSIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetTextColor(Color::White()); + title_->SetText(SETTING_DISPLAY_SCREEN_TITLE_TEXT); + + picker_ = new UIPicker(); + if (picker_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayScreenOffTimePage::OnStart picker_ new fail"); + return; + } + picker_->SetPosition(SETTING_DISPLAY_SCREEN_PICKER_X, SETTING_DISPLAY_SCREEN_PICKER_Y); + picker_->Resize(SETTING_DISPLAY_SCREEN_PICKER_WIDTH, SETTING_DISPLAY_SCREEN_PICKER_HEIGHT); + picker_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + picker_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_DISPLAY_SCREEN_PICKER_FSIZE); + picker_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_DISPLAY_SCREEN_PICKER_FSIZE); + picker_->SetItemHeight(SETTING_DISPLAY_SCREEN_PICKER_ITEM_HEIGHT); + picker_->SetTextColor(SETTING_LIST_DEFAULT_BG_COLOR, Color::White()); + picker_->SetIntercept(true); + + button_ = new UIButton(); + if (button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplayScreenOffTimePage::OnStart button_ new fail"); + return; + } + button_->SetPosition(SETTING_DISPLAY_SCREEN_BUTTON_X, SETTING_DISPLAY_SCREEN_BUTTON_Y); + button_->Resize(SETTING_DISPLAY_SCREEN_BUTTON_WIDTH, SETTING_DISPLAY_SCREEN_BUTTON_HEIGHT); + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DISPLAY_OK, SETTING_IMAGE); + button_->SetImageSrc(image, image); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_SCREEN_BUTTON_BG_OPA, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_SCREEN_BUTTON_BG_OPA, UIButton::PRESSED); + button_->SetStyleForState(STYLE_IMAGE_OPA, OPA_OPAQUE, UIButton::RELEASED); + button_->SetStyleForState(STYLE_IMAGE_OPA, OPA_OPAQUE, UIButton::PRESSED); + button_->SetViewId(SETTING_DISPLAY_SCREEN_BUTTON_ID); + button_->SetOnClickListener(this); + + AddViewToPageContainer(title_); + AddViewToPageContainer(picker_); + AddViewToPageContainer(button_); +} + +void SettingDisplayScreenOffPage::OnResume() +{ + const char** data = SettingDisplayModel::GetInstance().GetScreenOffTimeAllStr(); + uint8_t size = SettingDisplayModel::GetInstance().GetScreenOffTimeAllStrSize(); + uint8_t selectIndex = SettingDisplayModel::GetInstance().GetScreenOffTimeIndex(); + picker_->SetValues(data, size); + picker_->SetSelected(selectIndex); +} + +void SettingDisplayScreenOffPage::OnStop() +{ + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (picker_ != nullptr) { + delete picker_; + picker_ = nullptr; + } + if (button_ != nullptr) { + delete button_; + button_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_DISPLAY_OK, SETTING_IMAGE); +} + +bool SettingDisplayScreenOffPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SETTING_DISPLAY_SCREEN_BUTTON_ID) == 0) { + uint8_t index = picker_->GetSelected(); + SettingDisplayModel::GetInstance().SetScreenOffTimeIndex(index); + NativeAbility::GetInstance().BackToPrevSlicePage(); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplaySteadyOnPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplaySteadyOnPage.cpp new file mode 100644 index 000000000..f1ea1ea14 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingDisplaySteadyOnPage.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDisplaySteadyOnPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingDisplayModel.h" +#include "settings/page/SettingDisplaySteadyOnPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::DISPLAY_STEADY_ON_PAGE, + SettingDisplaySteadyOnPage, false); + +static constexpr int16_t SETTING_DISPLAY_STEADY_TITLE_X = 100; +static constexpr int16_t SETTING_DISPLAY_STEADY_TITLE_Y = 39; +static constexpr int16_t SETTING_DISPLAY_STEADY_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_DISPLAY_STEADY_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_DISPLAY_STEADY_TITLE_FSIZE = 38; +static const char* SETTING_DISPLAY_STEADY_TITLE_TEXT = "长亮时刻"; + +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_X = 64; +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_Y = 118; +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_WIDTH = 321; +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_HEIGHT = 218; +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_FSIZE = 44; +static constexpr int16_t SETTING_DISPLAY_STEADY_PICKER_ITEM_HEIGHT = 84; + +static constexpr int16_t SETTING_DISPLAY_STEADY_BUTTON_X = 63; +static constexpr int16_t SETTING_DISPLAY_STEADY_BUTTON_Y = 358; +static constexpr int16_t SETTING_DISPLAY_STEADY_BUTTON_WIDTH = 328; +static constexpr int16_t SETTING_DISPLAY_STEADY_BUTTON_HEIGHT = 94; +static constexpr int16_t SETTING_DISPLAY_STEADY_BUTTON_BG_OPA = 51; +static const char* SETTING_DISPLAY_STEADY_BUTTON_ID = "button"; + +void SettingDisplaySteadyOnPage::OnStart(void* data) +{ + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplaySteadyOnTimePage::OnStart title_ new fail"); + return; + } + title_->SetPosition(SETTING_DISPLAY_STEADY_TITLE_X, SETTING_DISPLAY_STEADY_TITLE_Y); + title_->Resize(SETTING_DISPLAY_STEADY_TITLE_WIDTH, SETTING_DISPLAY_STEADY_TITLE_HEIGHT); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_DISPLAY_STEADY_TITLE_FSIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetTextColor(Color::White()); + title_->SetText(SETTING_DISPLAY_STEADY_TITLE_TEXT); + + picker_ = new UIPicker(); + if (picker_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplaySteadyOnTimePage::OnStart picker_ new fail"); + return; + } + picker_->SetPosition(SETTING_DISPLAY_STEADY_PICKER_X, SETTING_DISPLAY_STEADY_PICKER_Y); + picker_->Resize(SETTING_DISPLAY_STEADY_PICKER_WIDTH, SETTING_DISPLAY_STEADY_PICKER_HEIGHT); + picker_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + picker_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_DISPLAY_STEADY_PICKER_FSIZE); + picker_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_DISPLAY_STEADY_PICKER_FSIZE); + picker_->SetItemHeight(SETTING_DISPLAY_STEADY_PICKER_ITEM_HEIGHT); + picker_->SetTextColor(SETTING_LIST_DEFAULT_BG_COLOR, Color::White()); + picker_->SetIntercept(true); + + button_ = new UIButton(); + if (button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingDisplaySteadyOnTimePage::OnStart button_ new fail"); + return; + } + button_->SetPosition(SETTING_DISPLAY_STEADY_BUTTON_X, SETTING_DISPLAY_STEADY_BUTTON_Y); + button_->Resize(SETTING_DISPLAY_STEADY_BUTTON_WIDTH, SETTING_DISPLAY_STEADY_BUTTON_HEIGHT); + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_DISPLAY_OK, SETTING_IMAGE); + button_->SetImageSrc(image, image); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_STEADY_BUTTON_BG_OPA, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, SETTING_DISPLAY_STEADY_BUTTON_BG_OPA, UIButton::PRESSED); + button_->SetStyleForState(STYLE_IMAGE_OPA, OPA_OPAQUE, UIButton::RELEASED); + button_->SetStyleForState(STYLE_IMAGE_OPA, OPA_OPAQUE, UIButton::PRESSED); + button_->SetViewId(SETTING_DISPLAY_STEADY_BUTTON_ID); + button_->SetOnClickListener(this); + + AddViewToPageContainer(title_); + AddViewToPageContainer(picker_); + AddViewToPageContainer(button_); +} + +void SettingDisplaySteadyOnPage::OnResume() +{ + const char** data = SettingDisplayModel::GetInstance().GetSteadyOnTimeAllStr(); + uint8_t size = SettingDisplayModel::GetInstance().GetSteadyOnTimeAllStrSize(); + uint8_t selectIndex = SettingDisplayModel::GetInstance().GetSteadyOnTimeIndex(); + picker_->SetValues(data, size); + picker_->SetSelected(selectIndex); +} + +void SettingDisplaySteadyOnPage::OnStop() +{ + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (picker_ != nullptr) { + delete picker_; + picker_ = nullptr; + } + if (button_ != nullptr) { + delete button_; + button_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_DISPLAY_OK, SETTING_IMAGE); +} + +bool SettingDisplaySteadyOnPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SETTING_DISPLAY_STEADY_BUTTON_ID) == 0) { + uint8_t index = picker_->GetSelected(); + SettingDisplayModel::GetInstance().SetSteadyOnTimeIndex(index); + NativeAbility::GetInstance().BackToPrevSlicePage(); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingMainPage.cpp new file mode 100644 index 000000000..75c301e2e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingMainPage.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingDesktopModel.h" +#include "settings/page/SettingMainPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::MAIN_PAGE, SettingMainPage, true); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 96; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingMainPage *g_pSettingMainPage = nullptr; + +void SettingMainPage::OnStart(void *data) +{ + g_pSettingMainPage = this; + simpleList_ = new UISimpleList(); + if (simpleList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart simpleList_ new fail"); + return; + } + simpleList_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + simpleList_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + simpleList_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + simpleList_->SetTouchable(true); + simpleList_->SetDraggable(true); + simpleList_->SetThrowDrag(true); + simpleList_->SetMaxScrollDistance(MAX_SCR_DIS); + scrollView_ = new UIScrollViewNested(); + if (scrollView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart scrollView_ new fail"); + return; + } + scrollView_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scrollView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scrollView_->SetThrowDrag(true); + scrollView_->Add(simpleList_); + AddViewToPageContainer(scrollView_); + if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // 滑动跟手返回 + scrollView_->SetOnDragListener(this); + } +} + +void SettingMainPage::OnResume() +{ + simpleList_->ClearAll(); + for(auto& it : SettingMainModel::GetInstance().GetMainUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingMainPage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + simpleList_->AddContent(cont); + } + simpleList_->RefreshList(); +} + +void SettingMainPage::OnStop() +{ + g_pSettingMainPage = this; + if (scrollView_ != nullptr) { + scrollView_->RemoveAll(); + delete scrollView_; + scrollView_ = nullptr; + } + if (simpleList_ != nullptr) { + delete simpleList_; + simpleList_ = nullptr; + } +} + +bool SettingMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return false; +} + +bool SettingMainPage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t simpleListViewId = (uintptr_t)view.GetViewId(); + if (simpleListViewId == (uintptr_t)ICON_TEXT_NAVIGATION) { + int16_t viewIndex = view.GetViewIndex(); + auto& mainUnionData = SettingMainModel::GetInstance().GetMainUnionData(); + if (viewIndex < 0 || viewIndex > mainUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = mainUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_NAVIGATION) { + IconTextNavigationItemData* data = static_cast(itemData.GetUnionItemData()); + NativeAbility::GetInstance().SwitchPageInSlice(data->pageId, + TransitionType::TRANSITION_INVALID, true); + } + } + return true; +} + +void SettingMainPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingMainPage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingMainPage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingPowerPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingPowerPage.cpp new file mode 100644 index 000000000..9931d7d62 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingPowerPage.cpp @@ -0,0 +1,289 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPowerPage + * Create: 2025-06-01 + */ +#include +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "common/screen.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingPowerModel.h" +#include "settings/page/SettingPowerPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::POWER_PAGE, SettingPowerPage, false); + +#define SETTING_POWER_LEVEL_ARRAY_SIZE 10 +#define SETTING_VIEW_TEXT_SIZE 16 +static constexpr int16_t SETTING_POWER_SCROLL_BLANK = 60; +static constexpr int16_t SETTING_POWER_TITLE_X = 100; +static constexpr int16_t SETTING_POWER_TITLE_Y = 39; +static constexpr int16_t SETTING_POWER_TITLE_WIDTH = 254; +static constexpr int16_t SETTING_POWER_TITLE_HEIGHT = 53; +static constexpr int16_t SETTING_POWER_TITLE_FSIZE = 38; +static const char* SETTING_POWER_TITLE_TEXT = "电量"; + +static constexpr int16_t SETTING_POWER_POWERDESC_X = 76; +static constexpr int16_t SETTING_POWER_POWERDESC_Y = 113; +static constexpr int16_t SETTING_POWER_POWERDESC_WIDTH = 193; +static constexpr int16_t SETTING_POWER_POWERDESC_HEIGHT = 55; +static constexpr int16_t SETTING_POWER_POWERDESC_FSIZE = 48; +static const char* SETTING_POWER_POWERDESC_TEXT = "当前电量"; + +static constexpr int16_t SETTING_POWER_BATTERYPERCENTAGE_X = 286; +static constexpr int16_t SETTING_POWER_BATTERYPERCENTAGE_Y = 113; +static constexpr int16_t SETTING_POWER_BATTERYPERCENTAGE_WIDTH = 122; +static constexpr int16_t SETTING_POWER_BATTERYPERCENTAGE_HEIGHT = 55; +static constexpr int16_t SETTING_POWER_BATTERYPERCENTAGE_FSIZE = 48; +#define SETTING_POWER_BATTERYPERCENTAGE_COLOR Color::GetColorFromRGB(9, 148, 69) + +static constexpr int16_t SETTING_POWER_TIME_X = 145; +static constexpr int16_t SETTING_POWER_TIME_Y = 172; +static constexpr int16_t SETTING_POWER_TIME_WIDTH = 165; +static constexpr int16_t SETTING_POWER_TIME_HEIGHT = 55; +static constexpr int16_t SETTING_POWER_TIME_FSIZE = 36; + +static constexpr int16_t SETTING_POWER_GROUP_X = 20; +static constexpr int16_t SETTING_POWER_GROUP_Y = 234; +static constexpr int16_t SETTING_POWER_GROUP_WIDTH = 414; +static constexpr int16_t SETTING_POWER_GROUP_HEIGHT = 91; +static constexpr int16_t SETTING_POWER_GROUP_RADIUS = 48; + +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_X = 34; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_Y = 29; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_WIDTH = 128; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_HEIGHT = 38; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_FSIZE = 32; +static const char* SETTING_POWER_GROUP_BATTERY_TEXT = "电池健康"; + +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_LEVEL_X = 295; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_LEVEL_Y = 29; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_LEVEL_WIDTH = 84; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_LEVEL_HEIGHT = 38; +static constexpr int16_t SETTING_POWER_GROUP_BATTERY_LEVEL_FSIZE = 32; + +static constexpr int16_t SETTING_POWER_DETAILSDESC_X = 59; +static constexpr int16_t SETTING_POWER_DETAILSDESC_Y = 365; +static constexpr int16_t SETTING_POWER_DETAILSDESC_WIDTH = 336; +static constexpr int16_t SETTING_POWER_DETAILSDESC_LINE_HEIGHT = 36; +static constexpr int16_t SETTING_POWER_DETAILSDESC_FSIZE = 24; + +void SettingPowerPage::OnStart(void* data) +{ + scrollView_ = new UIScrollViewNested(); + if (scrollView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::OnStart scrollView_ new fail"); + return; + } + scrollView_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scrollView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scrollView_->SetScrollBlankSize(SETTING_POWER_SCROLL_BLANK, UIAbstractScroll::Direction::BOTTOM); + scrollView_->SetThrowDrag(true); + scrollView_->SetIntercept(true); + InitPowerView(); + InitBatteryStatusView(); + InitNotify(); + batteryStatusGroup_->Add(batteryLabel_); + batteryStatusGroup_->Add(batteryLevel_); + scrollView_->Add(title_); + scrollView_->Add(powerDesc_); + scrollView_->Add(batteryPercentage_); + scrollView_->Add(timeLabel_); + scrollView_->Add(batteryStatusGroup_); + scrollView_->Add(detailsDesc_); + AddViewToPageContainer(scrollView_); +} + +void SettingPowerPage::OnResume() +{ + char tempBuffer[SETTING_POWER_LEVEL_ARRAY_SIZE] = ""; + if (sprintf_s(tempBuffer, sizeof(tempBuffer), "%u%%", + SettingPowerModel::GetInstance().GetBatteryPowerLevel()) > 0) { + batteryPercentage_->SetText(tempBuffer); + batteryLevel_->SetText(tempBuffer); + } + detailsDesc_->SetText(SettingPowerModel::GetInstance().GetPowerModelNotify()); + timeAnimator_->Start(); +} + +void SettingPowerPage::OnPause() +{ + timeAnimator_->Stop(); +} + +void SettingPowerPage::OnStop() +{ + if (scrollView_ != nullptr) { + scrollView_->RemoveAll(); + delete scrollView_; + scrollView_ = nullptr; + } + if (batteryStatusGroup_ != nullptr) { + batteryStatusGroup_->RemoveAll(); + delete batteryStatusGroup_; + batteryStatusGroup_ = nullptr; + } + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (powerDesc_ != nullptr) { + delete powerDesc_; + powerDesc_ = nullptr; + } + if (batteryPercentage_ != nullptr) { + delete batteryPercentage_; + batteryPercentage_ = nullptr; + } + if (timeLabel_ != nullptr) { + delete timeLabel_; + timeLabel_ = nullptr; + } + if (batteryLabel_ != nullptr) { + delete batteryLabel_; + batteryLabel_ = nullptr; + } + if (batteryLevel_ != nullptr) { + delete batteryLevel_; + batteryLevel_ = nullptr; + } + if (detailsDesc_ != nullptr) { + delete detailsDesc_; + detailsDesc_ = nullptr; + } + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } +} + +void SettingPowerPage::Callback(UIView* view) +{ + char temp[SETTING_VIEW_TEXT_SIZE]; + time_t seconds = time(nullptr); + struct tm tm_data; +#if !defined(_WIN32) + localtime_r(&seconds, &tm_data); +#else + localtime_s(&tm_data, &seconds); +#endif + if (sprintf_s(temp, sizeof(temp), "今天%02d:%02d", tm_data.tm_hour, tm_data.tm_min) > 0) { + ((UILabel*)view)->SetText(temp); + } +} + +void SettingPowerPage::InitPowerView() +{ + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitPowerView title_ new fail"); + return; + } + title_->SetPosition(SETTING_POWER_TITLE_X, SETTING_POWER_TITLE_Y); + title_->Resize(SETTING_POWER_TITLE_WIDTH, SETTING_POWER_TITLE_HEIGHT); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_POWER_TITLE_FSIZE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetText(SETTING_POWER_TITLE_TEXT); + + powerDesc_ = new UILabel(); + if (powerDesc_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitPowerView powerDesc_ new fail"); + return; + } + powerDesc_->SetPosition(SETTING_POWER_POWERDESC_X, SETTING_POWER_POWERDESC_Y); + powerDesc_->Resize(SETTING_POWER_POWERDESC_WIDTH, SETTING_POWER_POWERDESC_HEIGHT); + powerDesc_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + powerDesc_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_POWERDESC_FSIZE); + powerDesc_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + powerDesc_->SetText(SETTING_POWER_POWERDESC_TEXT); + + batteryPercentage_ = new UILabel(); + if (batteryPercentage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitPowerView batteryPercentage_ new fail"); + return; + } + batteryPercentage_->SetPosition(SETTING_POWER_BATTERYPERCENTAGE_X, SETTING_POWER_BATTERYPERCENTAGE_Y); + batteryPercentage_->Resize(SETTING_POWER_BATTERYPERCENTAGE_WIDTH, SETTING_POWER_BATTERYPERCENTAGE_HEIGHT); + batteryPercentage_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + batteryPercentage_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_BATTERYPERCENTAGE_FSIZE); + batteryPercentage_->SetStyle(STYLE_TEXT_COLOR, SETTING_POWER_BATTERYPERCENTAGE_COLOR.full); + + timeLabel_ = new UILabel(); + if (timeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitPowerView timeLabel_ new fail"); + return; + } + timeLabel_->SetPosition(SETTING_POWER_TIME_X, SETTING_POWER_TIME_Y); + timeLabel_->Resize(SETTING_POWER_TIME_WIDTH, SETTING_POWER_TIME_HEIGHT); + timeLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_TIME_FSIZE); + timeLabel_->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); +} + +void SettingPowerPage::InitBatteryStatusView() +{ + batteryStatusGroup_ = new UIViewGroup(); + if (batteryStatusGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitBatteryStatusView batteryStatusGroup_ new fail"); + return; + } + batteryStatusGroup_->SetPosition(SETTING_POWER_GROUP_X, SETTING_POWER_GROUP_Y); + batteryStatusGroup_->Resize(SETTING_POWER_GROUP_WIDTH, SETTING_POWER_GROUP_HEIGHT); + batteryStatusGroup_->SetStyle(STYLE_BACKGROUND_COLOR, SETTING_LIST_DEFAULT_BG_COLOR.full); + batteryStatusGroup_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + batteryStatusGroup_->SetStyle(STYLE_BORDER_RADIUS, SETTING_POWER_GROUP_RADIUS); + + batteryLabel_ = new UILabel(); + if (batteryLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitBatteryStatusView batteryLabel_ new fail"); + return; + } + batteryLabel_->SetPosition(SETTING_POWER_GROUP_BATTERY_X, SETTING_POWER_GROUP_BATTERY_Y); + batteryLabel_->Resize(SETTING_POWER_GROUP_BATTERY_WIDTH, SETTING_POWER_GROUP_BATTERY_HEIGHT); + batteryLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + batteryLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_GROUP_BATTERY_FSIZE); + batteryLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + batteryLabel_->SetText(SETTING_POWER_GROUP_BATTERY_TEXT); + + batteryLevel_ = new UILabel(); + if (batteryLevel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::InitBatteryStatusView batteryLevel_ new fail"); + return; + } + batteryLevel_->SetPosition(SETTING_POWER_GROUP_BATTERY_LEVEL_X, SETTING_POWER_GROUP_BATTERY_LEVEL_Y); + batteryLevel_->Resize(SETTING_POWER_GROUP_BATTERY_LEVEL_WIDTH, SETTING_POWER_GROUP_BATTERY_LEVEL_HEIGHT); + batteryLevel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + batteryLevel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_GROUP_BATTERY_LEVEL_FSIZE); + batteryLevel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); +} + +void SettingPowerPage::InitNotify() +{ + detailsDesc_ = new UILabel(); + if (detailsDesc_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::OnStart::batteryPercentage_ new fail"); + return; + } + detailsDesc_->SetPosition(SETTING_POWER_DETAILSDESC_X, SETTING_POWER_DETAILSDESC_Y); + detailsDesc_->Resize(SETTING_POWER_DETAILSDESC_WIDTH, SETTING_POWER_DETAILSDESC_LINE_HEIGHT); + detailsDesc_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + detailsDesc_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + detailsDesc_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_POWER_DETAILSDESC_FSIZE); + detailsDesc_->SetStyle(STYLE_LINE_HEIGHT, SETTING_POWER_DETAILSDESC_LINE_HEIGHT); + detailsDesc_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + timeAnimator_ = new Animator(this, timeLabel_, 0, true); + if (timeAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPowerPage::OnStart::timeAnimator_ new fail"); + return; + } +} +}; \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingQrcodeConnPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingQrcodeConnPage.cpp new file mode 100644 index 000000000..62f52fd99 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingQrcodeConnPage.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingQrcodeConnPage + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/common/SettingCommon.h" +#include "settings/model/SettingQrcodeConnModel.h" +#include "settings/page/SettingQrcodeConnPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::QRCODE_CONN_PAGE, SettingQrcodeConnPage, false); +static const uint32_t QRCODE_POS_X = 101; +static const uint32_t QRCODE_POS_Y = 85; +static const uint32_t QRCODE_WIDTH = 232; +static const uint32_t QRCODE_HEIGHT = 232; +static const uint32_t PAD_SIZE = 10; +static const uint32_t QRCODE_CONTENT_POS_Y = 350; +static const uint32_t QRCODE_CONTENT_HEIGHT = 50; +static const uint32_t QRCODE_CONTENT_FONT = 36; + +SettingQrcodeConnPage::SettingQrcodeConnPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::SettingQrcodeConnPage"); +} + +SettingQrcodeConnPage::~SettingQrcodeConnPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (qrcode_ != nullptr) { + delete qrcode_; + qrcode_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::~SettingQrcodeConnPage"); +} + +void SettingQrcodeConnPage::InitView() +{ + group_ = new UIScrollViewNested(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::InitView::group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_OPA, 0); + + qrcode_ = new UIQrcode(); + if (qrcode_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::InitView::qrcode_ new fail"); + return; + } + qrcode_->SetPosition(QRCODE_POS_X, QRCODE_POS_Y, QRCODE_WIDTH, QRCODE_HEIGHT); + qrcode_->SetQrcodeInfo(SettingBluetoothModel::GetInstance()->GetWatchName()); + qrcode_->SetStyle(STYLE_PADDING_LEFT, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_RIGHT, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_TOP, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_BOTTOM, PAD_SIZE); + group_->Add(qrcode_); + + content_ = new UILabel(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::InitView::content_ new fail"); + return; + } + content_->SetPosition(0, QRCODE_CONTENT_POS_Y, RESOLUTION_WIDTH, QRCODE_CONTENT_HEIGHT); + content_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + content_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, QRCODE_CONTENT_FONT); + content_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + content_->SetText("扫码连接设备"); + group_->Add(content_); + AddViewToPageContainer(group_); +} + +void SettingQrcodeConnPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingQrcodeConnPage::OnStart"); + InitView(); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnectSecondConfirm.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnectSecondConfirm.cpp new file mode 100644 index 000000000..f698a69e6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnectSecondConfirm.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingReconnectSecondConfirm + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "ui_resource_settings.h" +#include "main/LoadImg.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingReconnectSecondConfirm.h" + +namespace OHOS { +static constexpr int16_t SETTING_ADDR2 = 2; +static constexpr int16_t SETTING_ADDR3 = 3; +static constexpr int16_t SETTING_ADDR4 = 4; +static constexpr int16_t SETTING_ADDR5 = 5; +static constexpr int16_t SETTING_RECO_TITLE_Y = 60; +static constexpr int16_t SETTING_RECO_TITLE_HEIGHT = 40; +static constexpr int16_t SETTING_RECO_TITLE_FONT = 38; +static constexpr int16_t SETTING_RECO_CONTENT1_Y = 135; +static constexpr int16_t SETTING_RECO_CONTENT2_X = 30; +static constexpr int16_t SETTING_RECO_CONTENT2_Y = 180; +static constexpr int16_t SETTING_RECO_CONTENT3_Y = 225; +static constexpr int16_t SETTING_RECO_CONTENT_Y = 130; +static constexpr int16_t SETTING_RECO_CONYENT_HEIGHT = 115; +static constexpr int16_t SETTING_RECO_CONYENT1_HEIGHT = 50; +static constexpr int16_t SETTING_RECO_CONTENT_FONT = 35; +static constexpr int16_t SETTING_RECO_CONYENT_WIDTH = 394; +static constexpr int16_t SETTING_RECO_BTN_WIDTH = 85; +static constexpr int16_t SETTING_RECO_BTN_Y = 300; +static constexpr int16_t SETTING_RECO_BTN_X1 = 114; +static constexpr int16_t SETTING_RECO_BTN_X2 = 254; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; +static constexpr char *CANCEL_BUTTON = "cancelButton"; + +void SettingReconnectSecondConfirm::OnCreateView(void* data) +{ + InitSecondConfirmFragment(); +} + +void SettingReconnectSecondConfirm::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (contentFirst_ != nullptr) { + delete contentFirst_; + contentFirst_ = nullptr; + } + if (contentSecond_ != nullptr) { + delete contentSecond_; + contentSecond_ = nullptr; + } + if (contentThird_ != nullptr) { + delete contentThird_; + contentThird_ = nullptr; + } + if (cancel_ != nullptr) { + delete cancel_; + cancel_ = nullptr; + } + if (confirm_ != nullptr) { + delete confirm_; + confirm_ = nullptr; + } +} + +void SettingReconnectSecondConfirm::InitSecondConfirmFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment title_ new fail"); + return; + } + title_->SetPosition(0, SETTING_RECO_TITLE_Y, RESOLUTION_WIDTH, SETTING_RECO_TITLE_HEIGHT); + if (SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus()) { + title_->SetText("确定断开连接?"); + } else { + title_->SetText("确定重新连接?"); + } + + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_RECO_TITLE_FONT); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + std::string str1 = SettingBluetoothModel::GetInstance()->GetDeviceName(); + std::string str = ""; + std::string str2 = ""; + if (SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus()) { + str = "此操作将会断开您与"; + str2 = "以下设备的连接:"; + } else { + str = "此操作您将会与以下"; + str2 = "设备进行重新连接:"; + } + contentFirst_ = new UILabel(); + if (contentFirst_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment contentFirst_ new fail"); + return; + } + contentFirst_->SetPosition(0, SETTING_RECO_CONTENT1_Y, + RESOLUTION_WIDTH, SETTING_RECO_CONYENT1_HEIGHT); + contentFirst_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + contentFirst_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_RECO_CONTENT_FONT); + contentFirst_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + contentFirst_->SetText(str.c_str()); + + contentSecond_ = new UILabel(); + if (contentSecond_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment contentSecond_ new fail"); + return; + } + contentSecond_->SetPosition(SETTING_RECO_CONTENT2_X, SETTING_RECO_CONTENT2_Y, + SETTING_RECO_CONYENT_WIDTH, SETTING_RECO_CONYENT1_HEIGHT); + contentSecond_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + contentSecond_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_RECO_CONTENT_FONT); + contentSecond_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + contentSecond_->SetText(str2.c_str()); + + contentThird_ = new UILabel(); + if (contentThird_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment contentThird_ new fail"); + return; + } + contentThird_->SetPosition(0, SETTING_RECO_CONTENT3_Y, + RESOLUTION_WIDTH, SETTING_RECO_CONYENT1_HEIGHT); + contentThird_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + contentThird_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_RECO_CONTENT_FONT); + contentThird_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + contentThird_->SetText(str1.c_str()); + + cancel_ = new UIImageView(); + if (cancel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment cancel_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(cancel_, SETTING_IMAGE, IMAGE_CANCEL); + cancel_->SetPosition(SETTING_RECO_BTN_X1, SETTING_RECO_BTN_Y, SETTING_RECO_BTN_WIDTH, SETTING_RECO_BTN_WIDTH); + cancel_->SetTouchable(true); + cancel_->SetViewId(CANCEL_BUTTON); + cancel_->SetOnClickListener(this); + cancel_->SetVisible(true); + confirm_ = new UILabelButton(); + if (confirm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitSecondConfirmFragment confirm_ new fail"); + return; + } + confirm_->SetPosition(SETTING_RECO_BTN_X2, SETTING_RECO_BTN_Y, SETTING_RECO_BTN_WIDTH, SETTING_RECO_BTN_WIDTH); + confirm_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + confirm_->SetViewId(CONFIRM_BUTTON); + confirm_->SetOnClickListener(this); + confirm_->SetVisible(true); + LOADIMG::LoadBtnImage(confirm_, SETTING_IMAGE, IMAGE_OK_BLUE, IMAGE_OK_BLUE); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::PRESSED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::RELEASED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::INACTIVE); + + fragmentView_.Add(title_); + fragmentView_.Add(contentFirst_); + fragmentView_.Add(contentSecond_); + fragmentView_.Add(contentThird_); + fragmentView_.Add(cancel_); + fragmentView_.Add(confirm_); +} + +bool SettingReconnectSecondConfirm::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingReconnectSecondConfirm OnClick"); + UNUSED(event); + if (strcmp(view.GetViewId(), CANCEL_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + } else if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + bd_addr_t addr; + BtCaseInfo *info = SettingBluetoothModel::GetInstance()->GetSelectedDeviceInfo(); + if (memcpy_s(addr.addr, BD_ADDR_LEN, info->addr, BD_ADDR_LEN) != EOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s failed"); + return false; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SettingReconnectSecondConfirmPage addr: %02x%02x%02x%02x%02x%02x", + addr.addr[SETTING_ADDR5], addr.addr[SETTING_ADDR4], addr.addr[SETTING_ADDR3], + addr.addr[SETTING_ADDR2], addr.addr[1], addr.addr[0]); + if (SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus()) { + errcode_t retVal = gap_disconnect_remote_device(&addr); // 断开连接 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Disconnect SelectedDevice retVal = %d", retVal); + if (retVal == 0) { + SettingBluetoothModel::GetInstance()->UpdateDisconnectStatusForDevice(addr); + SettingBluetoothModel::GetInstance()->SetConnectResultPage(false); + SettingBluetoothModel::GetInstance()->SetBlueToothConnectStatus(false); + } + } else { + if (SettingBluetoothModel::GetInstance()->ConnectRemoteDevice(&addr) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "connect SelectedDevice"); + SettingBluetoothModel::GetInstance()->SetLastConnedAddr(&addr); + SettingBluetoothModel::GetInstance()->UpdateConnectStatusForDevice(); + SettingBluetoothModel::GetInstance()->SetConnectResultPage(true); + SettingBluetoothModel::GetInstance()->SetBlueToothConnectStatus(true); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice failed"); + } + } + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + } + return true; +} + +void SettingReconnectSecondConfirm::RefreshFragment() +{ + if (contentFirst_ == nullptr || contentSecond_ == nullptr || contentThird_ == nullptr || + title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshFragment fail"); + return; + } + std::string str1 = SettingBluetoothModel::GetInstance()->GetDeviceName(); + std::string str = ""; + std::string str2 = ""; + bool status = SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus(); + if (status) { + str = "此操作将会断开您与"; + str2 = "以下设备的连接:"; + title_->SetText("确定断开连接?"); + } else { + str = "此操作您将会与以下"; + str2 = "设备进行重新连接:"; + title_->SetText("确定重新连接?"); + } + contentFirst_->SetText(str.c_str()); + contentSecond_->SetText(str2.c_str()); + contentThird_->SetText(str1.c_str()); +} + + +bool SettingReconnectSecondConfirm::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingReconnectSecondConfirm::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingReconnectSecondConfirm::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnection.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnection.cpp new file mode 100644 index 000000000..f12d149b7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingReconnection.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingReconnection + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "main/LoadImg.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/page/SettingReconnection.h" + +namespace OHOS { +static constexpr int16_t SETTING_WATCH_Y = 105; +static constexpr int16_t SETTING_WATCH_HEIGHT = 40; +static constexpr int16_t SETTING_WATCH_FONT = 36; +static constexpr int16_t SETTING_CONTENT_Y = 155; +static constexpr int16_t SETTING_CONYENT_HEIGHT = 40; +static constexpr int16_t SETTING_RECO_X = 111; +static constexpr int16_t SETTING_RECO1_Y = 230; +static constexpr int16_t SETTING_RECO2_Y = 321; +static constexpr int16_t SETTING_RECO_WIDTH = 232; +static constexpr int16_t SETTING_RECO_HEIGHT = 76; +static constexpr int16_t SETTING_RECO_FONT = 32; +static constexpr int16_t SETTING_RECO_BTN_WIDTH = 90; +static constexpr int16_t SETTING_RECO_BTN_Y = 320; +static constexpr int16_t SETTING_RECO_BTN_X1 = 85; +static constexpr int16_t SETTING_RECO_BTN_X2 = 279; +static constexpr char *RECONNECT_BUTTON = "reconnectionButton"; +static constexpr char *UNPAIR_BUTTON = "unpairButton"; + +void SettingReconnection::OnCreateView(void* data) +{ + InitReconnectionFragment(); +} + +void SettingReconnection::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (watchNameLabel_ != nullptr) { + delete watchNameLabel_; + watchNameLabel_ = nullptr; + } + if (connectStatusLabel_ != nullptr) { + delete connectStatusLabel_; + connectStatusLabel_ = nullptr; + } + if (reconnectionButton_ != nullptr) { + delete reconnectionButton_; + reconnectionButton_ = nullptr; + } + if (unpair_ != nullptr) { + delete unpair_; + unpair_ = nullptr; + } +} + +void SettingReconnection::InitReconnectionFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + watchNameLabel_ = new UILabel(); + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitReconnectionFragment watchNameLabel_ new fail"); + return; + } + watchNameLabel_->SetPosition(0, SETTING_WATCH_Y, RESOLUTION_WIDTH, SETTING_WATCH_HEIGHT); + watchNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + watchNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + watchNameLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); + + connectStatusLabel_ = new UILabel(); + if (connectStatusLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitReconnectionFragment connectStatusLabel_ new fail"); + return; + } + connectStatusLabel_->SetPosition(0, SETTING_CONTENT_Y, RESOLUTION_WIDTH, SETTING_CONYENT_HEIGHT); + connectStatusLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + connectStatusLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_WATCH_FONT); + connectStatusLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + if (SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus()) { + connectStatusLabel_->SetText("已连接"); + } else { + connectStatusLabel_->SetText("未连接"); + } + + reconnectionButton_ = new UILabelButton(); + if (reconnectionButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitReconnectionFragment recButton_ new fail"); + return; + } + reconnectionButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::PRESSED); + reconnectionButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::RELEASED); + reconnectionButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::INACTIVE); + reconnectionButton_->SetPosition(SETTING_RECO_X, SETTING_RECO1_Y, SETTING_RECO_WIDTH, SETTING_RECO_HEIGHT); + if (SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus()) { + reconnectionButton_->SetText("断开连接"); + } else { + reconnectionButton_->SetText("重新连接"); + } + + reconnectionButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_RECO_FONT); + reconnectionButton_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + reconnectionButton_->SetViewId(RECONNECT_BUTTON); + reconnectionButton_->SetOnClickListener(this); + reconnectionButton_->SetVisible(true); + + unpair_ = new UIImageView(); + if (unpair_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitReconnectionFragment unpair_ new fail"); + return; + } + unpair_->SetPosition(SETTING_RECO_X, SETTING_RECO2_Y, SETTING_RECO_WIDTH, SETTING_RECO_HEIGHT); + LOADIMG::LoadImageViewImg(unpair_, SETTING_IMAGE, IMAGE_UNPAIR); + unpair_->SetTouchable(true); + unpair_->SetViewId(UNPAIR_BUTTON); + unpair_->SetOnClickListener(this); + + fragmentView_.Add(watchNameLabel_); + fragmentView_.Add(connectStatusLabel_); + fragmentView_.Add(reconnectionButton_); + fragmentView_.Add(unpair_); +} + +void SettingReconnection::RefreshFragment() +{ + if (reconnectionButton_ == nullptr || connectStatusLabel_ == nullptr || watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshFragment fail"); + return; + } + bool status = SettingBluetoothModel::GetInstance()->GetBlueToothConnectStatus(); + if (status) { + reconnectionButton_->SetText("断开连接"); + } else { + reconnectionButton_->SetText("重新连接"); + } + if (status) { + connectStatusLabel_->SetText("已连接"); + } else { + connectStatusLabel_->SetText("未连接"); + } + std::string str = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str.c_str()); +} + +bool SettingReconnection::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick"); + UNUSED(event); + if (strcmp(view.GetViewId(), RECONNECT_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(RECONNECT_SECOND_CONFIRM_FRAGMENT); + } else if (strcmp(view.GetViewId(), UNPAIR_BUTTON) == 0) { + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(UNPAIR_CONFIRM_FRAGMENT); + } + return true; +} + +bool SettingReconnection::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingReconnection::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool SettingReconnection::OnDragEnd(UIView& view, const DragEvent& event) +{ + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOperationPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOperationPage.cpp new file mode 100644 index 000000000..e3d7114ed --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOperationPage.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemOperationPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingSystemModel.h" +#include "settings/page/SettingSystemOperationPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::SYSTEM_OPERATION_PAGE, SettingSystemOperationPage, false); + +#define SYSTEM_SLIDER_LABEL_TEXT_SIZE 20 +#define SETTING_SYSTEM_OPERATION_POWEROFF_FG_COLOR Color::GetColorFromRGB(250, 60, 60) // 0xFA3C3CFF +#define SETTING_SYSTEM_OPERATION_RESTART_FG_COLOR Color::GetColorFromRGB(100, 206, 122) // 0x6ACE7AFF +#define SETTING_SYSTEM_OPERATION_RESUME_FG_COLOR Color::GetColorFromRGB(153, 153, 153) // 0x999999FF + +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_X = 55; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_Y = 135; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_WIDTH = 349; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_HEIGHT = 96; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_RADIUS = 88; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_KNOBWIDTH = 84; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_RANGE_MAX = 349; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_RANGE_MIN = 0; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_START_POINT = 50; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_START_RANG_MAX = 110; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_START_RANG_MIN = 10; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_END_POINT = 299; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_RIGHT_POINT = 249; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDE_BORDER_WIDTH = 16; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDE_FG_OPA = 128; + +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_LABEL_X = 177; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_LABEL_Y = 164; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_LABEL_WIDTH = 192; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_LABEL_HEIGHT = 38; +static constexpr int16_t SETTING_SYSTEM_OPERATION_SLIDER_LABEL_FSIZE = 32; + +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_X = 184; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_Y = 294; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_WIDTH = 85; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_HEIGHT = 85; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_RADIUS = 45; + +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_LABEL_X = 194; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_LABEL_Y = 394; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_LABEL_WIDTH = 64; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_LABEL_HEIGHT = 38; +static constexpr int16_t SETTING_SYSTEM_OPERATION_BUTTON_LABEL_FSIZE = 32; +static const char* SETTING_SYSTEM_OPERATION_BUTTON_LABEL_TEXT = "取消"; + +SettingSystemOperationPage::SettingSystemOperationPage() +{ + std::map tempData = { + {"关机", {SETTING_SYSTEM_OPERATION_POWEROFF_FG_COLOR, IMAGE_SYSTEM_LIST_POWEROFF}}, + {"重启", {SETTING_SYSTEM_OPERATION_RESTART_FG_COLOR, IMAGE_SYSTEM_LIST_RESTART}}, + {"恢复出厂", {SETTING_SYSTEM_OPERATION_RESUME_FG_COLOR, IMAGE_SYSTEM_LIST_RESUME}}, + }; + operationData_.swap(tempData); +} + +void SettingSystemOperationPage::OnStart(void* data) +{ + operationName_ = static_cast(data); + InitSliderView(); + InitButtonView(); + RefreshSlider(); + AddViewToPageContainer(slider_); + AddViewToPageContainer(button_); + AddViewToPageContainer(sliderLabel_); + AddViewToPageContainer(buttonDescription_); +} + +void SettingSystemOperationPage::OnResume() +{ + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); // 取消跟手返回 + if (sliderLabel_ != nullptr) { + char temp[SYSTEM_SLIDER_LABEL_TEXT_SIZE]; + if (sprintf_s(temp, sizeof(temp), "滑动%s", operationName_.c_str()) > 0) { + sliderLabel_->SetText(temp); + } + } +} + +void SettingSystemOperationPage::OnStop() +{ + if (slider_ != nullptr) { + delete slider_; + slider_ = nullptr; + } + if (sliderLabel_ != nullptr) { + delete sliderLabel_; + sliderLabel_ = nullptr; + } + if (button_ != nullptr) { + delete button_; + button_ = nullptr; + } + if (buttonDescription_ != nullptr) { + delete buttonDescription_; + buttonDescription_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(operationData_[operationName_].sliderKnobImage, SETTING_IMAGE); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_SYSTEM_OPERATION_CLOSE, SETTING_IMAGE); +} + +bool SettingSystemOperationPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), "slider") == 0) { + // Slide的click需要视为无效点击 + slider_->SetValue(SETTING_SYSTEM_OPERATION_SLIDER_START_POINT); + } else if (strcmp(view.GetViewId(), "button") == 0) { + NativeAbility::GetInstance().BackToPrevSlicePage(); + } + return true; +} + +void SettingSystemOperationPage::OnChange(int32_t value) +{ + // 若滑动开始的坐标在这个区域则允许滑动 + if (value > SETTING_SYSTEM_OPERATION_SLIDER_START_RANG_MIN && + value < SETTING_SYSTEM_OPERATION_SLIDER_START_RANG_MAX) { + sliderBegin_ = true; + } + // 若起点不在指定区域 或 往不允许的滑动区域滑动, 则重置为区域起点 + if (!sliderBegin_ || value < SETTING_SYSTEM_OPERATION_SLIDER_START_POINT) { + slider_->SetValue(SETTING_SYSTEM_OPERATION_SLIDER_START_POINT); + } + // 若起点在指定区域, 终点超过允许的滑动区域, 则重置为区域终点 + if (sliderBegin_ && value > SETTING_SYSTEM_OPERATION_SLIDER_END_POINT) { + slider_->SetValue(SETTING_SYSTEM_OPERATION_SLIDER_END_POINT); + } + // 按照滑动坐标修改label的透明度 滑动坐标[50, 299] label透明度[255, 6] + uint8_t labelOPA = OPA_OPAQUE - (slider_->GetValue() - SETTING_SYSTEM_OPERATION_SLIDER_START_POINT); + sliderLabel_->SetStyle(STYLE_TEXT_OPA, labelOPA); +} + +void SettingSystemOperationPage::OnRelease(int32_t value) +{ + if (sliderBegin_ && value > SETTING_SYSTEM_OPERATION_SLIDER_RIGHT_POINT) { + SettingSystemModel::GetInstance().SystemOperation(operationName_.c_str()); + } + slider_->SetValue(SETTING_SYSTEM_OPERATION_SLIDER_START_POINT); + sliderLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sliderBegin_ = false; +} + +void SettingSystemOperationPage::InitSliderView() +{ + slider_ = new UISlider(); + if (slider_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOperationPage::InitSliderView slider_ new fail"); + return; + } + slider_->SetPosition(SETTING_SYSTEM_OPERATION_SLIDER_X, SETTING_SYSTEM_OPERATION_SLIDER_Y); + slider_->Resize(SETTING_SYSTEM_OPERATION_SLIDER_WIDTH, SETTING_SYSTEM_OPERATION_SLIDER_HEIGHT); + slider_->SetViewId("slider"); + slider_->SetSliderRadius(SETTING_SYSTEM_OPERATION_SLIDER_RADIUS, SETTING_SYSTEM_OPERATION_SLIDER_RADIUS); + slider_->SetKnobWidth(SETTING_SYSTEM_OPERATION_SLIDER_KNOBWIDTH); + slider_->SetRange(SETTING_SYSTEM_OPERATION_SLIDER_RANGE_MAX, SETTING_SYSTEM_OPERATION_SLIDER_RANGE_MIN); + slider_->SetValue(SETTING_SYSTEM_OPERATION_SLIDER_START_POINT); + slider_->SetSliderEventListener(this); + slider_->SetOnClickListener(this); + slider_->SetIntercept(true); + + sliderLabel_ = new UILabel(); + if (sliderLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOperationPage::InitSliderView sliderlabel new fail"); + return; + } + sliderLabel_->SetPosition(SETTING_SYSTEM_OPERATION_SLIDER_LABEL_X, SETTING_SYSTEM_OPERATION_SLIDER_LABEL_Y); + sliderLabel_->Resize(SETTING_SYSTEM_OPERATION_SLIDER_LABEL_WIDTH, SETTING_SYSTEM_OPERATION_SLIDER_LABEL_HEIGHT); + sliderLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sliderLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYSTEM_OPERATION_SLIDER_LABEL_FSIZE); + sliderLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sliderLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sliderLabel_->SetStyle(STYLE_BACKGROUND_COLOR, SETTING_LIST_DEFAULT_BG_COLOR.full); +} + +void SettingSystemOperationPage::InitButtonView() +{ + button_ = new UIButton(); + if (button_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOperationPage::InitButtonView button_ new fail"); + return; + } + button_->SetPosition(SETTING_SYSTEM_OPERATION_BUTTON_X, SETTING_SYSTEM_OPERATION_BUTTON_Y); + button_->Resize(SETTING_SYSTEM_OPERATION_BUTTON_WIDTH, SETTING_SYSTEM_OPERATION_BUTTON_HEIGHT); + button_->SetViewId("button"); + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SYSTEM_OPERATION_CLOSE, SETTING_IMAGE); + button_->SetImageSrc(image, image); + button_->SetStyle(STYLE_BORDER_RADIUS, SETTING_SYSTEM_OPERATION_BUTTON_RADIUS); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + button_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + button_->SetOnClickListener(this); + + buttonDescription_ = new UILabel(); + if (buttonDescription_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOperationPage::InitButtonView buttonlabel new fail"); + return; + } + buttonDescription_->SetPosition(SETTING_SYSTEM_OPERATION_BUTTON_LABEL_X, SETTING_SYSTEM_OPERATION_BUTTON_LABEL_Y); + buttonDescription_->Resize(SETTING_SYSTEM_OPERATION_BUTTON_LABEL_WIDTH, SETTING_SYSTEM_OPERATION_BUTTON_LABEL_HEIGHT); + buttonDescription_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + buttonDescription_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYSTEM_OPERATION_BUTTON_LABEL_FSIZE); + buttonDescription_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + buttonDescription_->SetText(SETTING_SYSTEM_OPERATION_BUTTON_LABEL_TEXT); +} + +void SettingSystemOperationPage::RefreshSlider() +{ + slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, SETTING_LIST_DEFAULT_BG_COLOR.full); + slider_->SetForegroundStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + slider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + slider_->SetForegroundStyle(STYLE_BORDER_OPA, OPA_TRANSPARENT); + slider_->SetForegroundStyle(STYLE_BORDER_WIDTH, SETTING_SYSTEM_OPERATION_SLIDE_BORDER_WIDTH); + slider_->SetForegroundStyle(STYLE_BACKGROUND_OPA, SETTING_SYSTEM_OPERATION_SLIDE_FG_OPA); + + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + operationData_[operationName_].sliderKnobImage, SETTING_IMAGE); + slider_->SetKnobImage(image); + slider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, operationData_[operationName_].sliderBgColor.full); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOtaPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOtaPage.cpp new file mode 100644 index 000000000..ebc2c7229 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemOtaPage.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemOtaPage + * Create: 2025-06-01 + */ +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingSystemModel.h" +#include "settings/page/SettingSystemOtaPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::SYSTEM_OTA_PAGE, SettingSystemOtaPage, false); + +#define SETTING_MID_UPGRADE_LABEL_TEXT_SIZE 4 +#define SETTING_SYS_OTA_MIDPRORESS_BG_LINE_COLOR Color::GetColorFromRGB(217, 217, 217) +#define SETTING_SYS_OTA_MIDPRORESS_FG_LINE_COLOR Color::GetColorFromRGB(68, 132, 255) +static constexpr int16_t SETTING_SYS_OTA_MAX_PERCENTER = 100; +static constexpr int16_t SETTING_SYS_OTA_PREBUTTON_X = 154; +static constexpr int16_t SETTING_SYS_OTA_PREBUTTON_Y = 130; +static constexpr int16_t SETTING_SYS_OTA_PREBUTTON_WIDTH = 146; +static constexpr int16_t SETTING_SYS_OTA_PREBUTTON_HEIGHT = 146; + +static constexpr int16_t SETTING_SYS_OTA_PRELABEL_X = 20; +static constexpr int16_t SETTING_SYS_OTA_PRELABEL_Y = 326; +static constexpr int16_t SETTING_SYS_OTA_PRELABEL_WIDTH = 414; +static constexpr int16_t SETTING_SYS_OTA_PRELABEL_HEIGHT = 44; +static constexpr int16_t SETTING_SYS_OTA_PRELABEL_FSIZE = 36; + +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_X = 89; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_Y = 92; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_WIDTH = 276; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_HEIGHT = 276; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_LINEWIDTH = 20; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_CENTPOS_X = 138; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_CENTPOS_Y = 138; +static constexpr int16_t SETTING_SYS_OTA_MIDPRORESS_RADUIS = 138; + +static constexpr int16_t SETTING_SYS_OTA_MIDLABEL_X = 160; +static constexpr int16_t SETTING_SYS_OTA_MIDLABEL_Y = 163; +static constexpr int16_t SETTING_SYS_OTA_MIDLABEL_WIDTH = 102; +static constexpr int16_t SETTING_SYS_OTA_MIDLABEL_HEIGHT = 72; +static constexpr int16_t SETTING_SYS_OTA_MIDLABEL_FSIZE = 60; + +static constexpr int16_t SETTING_SYS_OTA_MIDPERCENT_X = 160+102; +static constexpr int16_t SETTING_SYS_OTA_MIDPERCENT_Y = 187; +static constexpr int16_t SETTING_SYS_OTA_MIDPERCENT_WIDTH = 32; +static constexpr int16_t SETTING_SYS_OTA_MIDPERCENT_HEIGHT = 40; +static constexpr int16_t SETTING_SYS_OTA_MIDPERCENT_FSIZE = 36; +static const char* SETTING_SYS_OTA_MIDPERCENT_TEXT = "%"; + +static constexpr int16_t SETTING_SYS_OTA_MIDMESSAGE_X = 15; +static constexpr int16_t SETTING_SYS_OTA_MIDMESSAGE_Y = 246; +static constexpr int16_t SETTING_SYS_OTA_MIDMESSAGE_WIDTH = 424; +static constexpr int16_t SETTING_SYS_OTA_MIDMESSAGE_HEIGHT = 44; +static constexpr int16_t SETTING_SYS_OTA_MIDMESSAGE_FSIZE = 36; + +void SettingSystemOtaPage::OnStart(void* data) +{ + InitPreGroupView(); + InitMidCircleView(); + InitMidMessageView(); + preUpgradeGroup_->Add(preUpgradeButton_); + preUpgradeGroup_->Add(preUpgradeLabel_); + midUpgradeGroup_->Add(midUpgradeProress_); + midUpgradeGroup_->Add(midUpgradeLabel_); + midUpgradeGroup_->Add(midUpgradePercent_); + midUpgradeGroup_->Add(midUpgradeMessage_); + AddViewToPageContainer(preUpgradeGroup_); + AddViewToPageContainer(midUpgradeGroup_); +} + +void SettingSystemOtaPage::OnResume() +{ + // 判断是否正在升级中 + if (!SettingSystemModel::GetInstance().GetOtaIsUpgrade()) { + preUpgradeGroup_->SetVisible(true); + midUpgradeGroup_->SetVisible(false); + // 检查OTA升级包是否存在 + if (SettingSystemModel::GetInstance().GetOtaPackageSize() != 0) { + preUpgradeButton_->Enable(); + ImageInfo* image = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SYSTEM_OTA_UPDATE, SETTING_IMAGE); + preUpgradeButton_->SetImageSrc(image, image); + preUpgradeLabel_->SetText("点击开始升级"); + preUpgradeButton_->SetOnClickListener(this); + } else { + ImageInfo* image = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SYSTEM_OTA_UNUPDATE, SETTING_IMAGE); + preUpgradeButton_->Disable(); + preUpgradeButton_->SetImageSrc(image, image); + preUpgradeLabel_->SetText("暂无可升级镜像"); + preUpgradeButton_->SetOnClickListener(nullptr); + } + } else { + preUpgradeGroup_->SetVisible(false); + midUpgradeGroup_->SetVisible(true); + upgradeAnimator_->Start(); + } +} + +void SettingSystemOtaPage::OnPause() +{ + upgradeAnimator_->Stop(); +} + +void SettingSystemOtaPage::OnStop() +{ + if (upgradeAnimator_ != nullptr) { + delete upgradeAnimator_; + upgradeAnimator_ = nullptr; + } + if (preUpgradeGroup_ != nullptr) { + preUpgradeGroup_->RemoveAll(); + delete preUpgradeGroup_; + preUpgradeGroup_ = nullptr; + } + if (midUpgradeGroup_ != nullptr) { + midUpgradeGroup_->RemoveAll(); + delete midUpgradeGroup_; + midUpgradeGroup_ = nullptr; + } + if (preUpgradeButton_ != nullptr) { + delete preUpgradeButton_; + preUpgradeButton_ = nullptr; + } + if (preUpgradeLabel_ != nullptr) { + delete preUpgradeLabel_; + preUpgradeLabel_ = nullptr; + } + if (midUpgradeProress_ != nullptr) { + delete midUpgradeProress_; + midUpgradeProress_ = nullptr; + } + if (midUpgradeLabel_ != nullptr) { + delete midUpgradeLabel_; + midUpgradeLabel_ = nullptr; + } + if (midUpgradePercent_ != nullptr) { + delete midUpgradePercent_; + midUpgradePercent_ = nullptr; + } + if (midUpgradeMessage_ != nullptr) { + delete midUpgradeMessage_; + midUpgradeMessage_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_SYSTEM_OTA_UPDATE, SETTING_IMAGE); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(IMAGE_SYSTEM_OTA_UNUPDATE, SETTING_IMAGE); +} + +bool SettingSystemOtaPage::OnClick(UIView &view, const ClickEvent &event) +{ + preUpgradeGroup_->SetVisible(false); + midUpgradeGroup_->SetVisible(true); + SettingSystemModel::GetInstance().StartOtaNativeUpgrade(); + upgradeAnimator_->Start(); + return true; +} + +void SettingSystemOtaPage::Callback(UIView* view) +{ + char temp[SETTING_MID_UPGRADE_LABEL_TEXT_SIZE] = ""; + uint8_t percent = SettingSystemModel::GetInstance().GetOtaNativeUpgradePercent(); + std::string message = SettingSystemModel::GetInstance().GetOtaNativeUpgradeMessage(); + if (sprintf_s(temp, sizeof(temp), "%u", percent) > 0) { + midUpgradeLabel_->SetText(temp); + } + midUpgradeProress_->SetValue(percent); + midUpgradeMessage_->SetText(message.c_str()); + if (percent >= SETTING_SYS_OTA_MAX_PERCENTER || !SettingSystemModel::GetInstance().GetOtaIsUpgrade()) { + upgradeAnimator_->Stop(); + } +} + +void SettingSystemOtaPage::InitPreGroupView() +{ + upgradeAnimator_ = new Animator(this, nullptr, 0, true); + if (upgradeAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitPreGroupView upgradeAnimator_ new fail"); + return; + } + preUpgradeGroup_ = new UIViewGroup(); + if (preUpgradeGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitPreGroupView preUpgradeGroup_ new fail"); + return; + } + preUpgradeGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + preUpgradeGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + preUpgradeGroup_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + + preUpgradeButton_ = new UIButton(); + if (preUpgradeButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitPreGroupView preUpgradeButton_ new fail"); + return; + } + preUpgradeButton_->SetPosition(SETTING_SYS_OTA_PREBUTTON_X, SETTING_SYS_OTA_PREBUTTON_Y); + preUpgradeButton_->Resize(SETTING_SYS_OTA_PREBUTTON_WIDTH, SETTING_SYS_OTA_PREBUTTON_WIDTH); + preUpgradeButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + preUpgradeButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + + preUpgradeLabel_ = new UILabel(); + if (preUpgradeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitPreGroupView preUpgradeLabel_ new fail"); + return; + } + preUpgradeLabel_->SetPosition(SETTING_SYS_OTA_PRELABEL_X, SETTING_SYS_OTA_PRELABEL_Y); + preUpgradeLabel_->Resize(SETTING_SYS_OTA_PRELABEL_WIDTH, SETTING_SYS_OTA_PRELABEL_HEIGHT); + preUpgradeLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + preUpgradeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYS_OTA_PRELABEL_FSIZE); + preUpgradeLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); +} + +void SettingSystemOtaPage::InitMidCircleView() +{ + midUpgradeGroup_ = new UIViewGroup(); + if (midUpgradeGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitMidCircleView midUpgradeGroup_ new fail"); + return; + } + midUpgradeGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + midUpgradeGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + midUpgradeGroup_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + + midUpgradeProress_ = new UICircleProgress(); + if (midUpgradeProress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitMidCircleView preUpgradeButton_ new fail"); + return; + } + midUpgradeProress_->SetPosition(SETTING_SYS_OTA_MIDPRORESS_X, SETTING_SYS_OTA_MIDPRORESS_Y); + midUpgradeProress_->Resize(SETTING_SYS_OTA_MIDPRORESS_WIDTH, SETTING_SYS_OTA_MIDPRORESS_HEIGHT); + midUpgradeProress_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + midUpgradeProress_->SetBackgroundStyle(STYLE_LINE_COLOR, SETTING_SYS_OTA_MIDPRORESS_BG_LINE_COLOR.full); + midUpgradeProress_->SetBackgroundStyle(STYLE_LINE_WIDTH, SETTING_SYS_OTA_MIDPRORESS_LINEWIDTH); + midUpgradeProress_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + midUpgradeProress_->SetForegroundStyle(STYLE_LINE_COLOR, SETTING_SYS_OTA_MIDPRORESS_FG_LINE_COLOR.full); + midUpgradeProress_->SetForegroundStyle(STYLE_LINE_WIDTH, SETTING_SYS_OTA_MIDPRORESS_LINEWIDTH); + midUpgradeProress_->SetCenterPosition(SETTING_SYS_OTA_MIDPRORESS_CENTPOS_X, SETTING_SYS_OTA_MIDPRORESS_CENTPOS_Y); + midUpgradeProress_->SetRadius(SETTING_SYS_OTA_MIDPRORESS_RADUIS); +} + +void SettingSystemOtaPage::InitMidMessageView() +{ + midUpgradeLabel_ = new UILabel(); + if (midUpgradeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitMidMessageView preUpgradeLabel_ new fail"); + return; + } + midUpgradeLabel_->SetPosition(SETTING_SYS_OTA_MIDLABEL_X, SETTING_SYS_OTA_MIDLABEL_Y); + midUpgradeLabel_->Resize(SETTING_SYS_OTA_MIDLABEL_WIDTH, SETTING_SYS_OTA_MIDLABEL_HEIGHT); + midUpgradeLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + midUpgradeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYS_OTA_MIDLABEL_FSIZE); + midUpgradeLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + midUpgradePercent_ = new UILabel(); + if (midUpgradePercent_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitMidMessageView midUpgradePercent_ new fail"); + return; + } + midUpgradePercent_->SetPosition(SETTING_SYS_OTA_MIDPERCENT_X, SETTING_SYS_OTA_MIDPERCENT_Y); + midUpgradePercent_->Resize(SETTING_SYS_OTA_MIDPERCENT_WIDTH, SETTING_SYS_OTA_MIDPERCENT_HEIGHT); + midUpgradePercent_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + midUpgradePercent_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYS_OTA_MIDPERCENT_FSIZE); + midUpgradePercent_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + midUpgradePercent_->SetText("%"); + + midUpgradeMessage_ = new UILabel(); + if (midUpgradeMessage_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemOtaPage::InitMidMessageView midUpgradeMessage_ new fail"); + return; + } + midUpgradeMessage_->SetPosition(SETTING_SYS_OTA_MIDMESSAGE_X, SETTING_SYS_OTA_MIDMESSAGE_Y); + midUpgradeMessage_->Resize(SETTING_SYS_OTA_MIDMESSAGE_WIDTH, SETTING_SYS_OTA_MIDMESSAGE_HEIGHT); + midUpgradeMessage_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + midUpgradeMessage_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_SYS_OTA_MIDMESSAGE_FSIZE); + midUpgradeMessage_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemPage.cpp new file mode 100644 index 000000000..3fc8663b0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/SettingSystemPage.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingSystemPage + * Create: 2025-06-01 + */ +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "settings/model/SettingMainModel.h" +#include "settings/model/SettingSystemModel.h" +#include "settings/page/SettingSystemPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SettingPageId::SYSTEM_PAGE, SettingSystemPage, false); + +static constexpr int16_t SETTING_LIST_POSITION_X = 14; +static constexpr int16_t SETTING_LIST_WIDTH = 426; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 96; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 SNUM_2 = 2; +static SettingSystemPage *g_pSettingSystemPage = nullptr; + +void SettingSystemPage::OnStart(void* data) +{ + g_pSettingSystemPage = this; + content_ = new UISimpleList(); + if (content_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemPage::OnStart content_ new fail"); + return; + } + content_->SetPosition(SETTING_LIST_POSITION_X, 0, SETTING_LIST_WIDTH, HORIZONTAL_RESOLUTION); + content_->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE, UIAbstractScroll::Direction::BOTTOM); + content_->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); + content_->SetDraggable(true); + content_->SetThrowDrag(true); + content_->SetMaxScrollDistance(MAX_SCR_DIS); + + scroll_ = new UIScrollViewNested(); + if (scroll_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingSystemPage::OnStart scroll_ new fail"); + return; + } + scroll_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scroll_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scroll_->SetThrowDrag(true); + scroll_->SetIntercept(true); + scroll_->Add(content_); + AddViewToPageContainer(scroll_); +} + +void SettingSystemPage::OnResume() +{ + content_->ClearAll(); + for(auto& it : SettingSystemModel::GetInstance().GetSystemUnionData()) { + Contents cont; + cont.createFunc = SettingMainModel::OnSimpleListCreate; + cont.updateFunc = SettingSystemPage::OnSimpleListUpdate; + cont.type = it.GetUnionItemType(); + cont.data = ⁢ + content_->AddContent(cont); + } + content_->RefreshList(); +} + +void SettingSystemPage::OnStop() +{ + g_pSettingSystemPage = nullptr; + if (scroll_ != nullptr) { + scroll_->RemoveAll(); + delete scroll_; + scroll_ = nullptr; + } + if (content_ != nullptr) { + delete content_; + content_ = nullptr; + } +} + +bool SettingSystemPage::OnClick(UIView& view, const ClickEvent& event) +{ + uintptr_t viewId = (uintptr_t)view.GetViewId(); + if (viewId == (uintptr_t)ICON_TEXT_NAVIGATION) { + int16_t viewIndex = view.GetViewIndex(); + auto& sysUnionData = SettingSystemModel::GetInstance().GetSystemUnionData(); + if (viewIndex < 0 || viewIndex > sysUnionData.size()) { + return true; + } + + SettingUnionItemData& itemData = sysUnionData[viewIndex]; + if (itemData.GetUnionItemType() == ICON_TEXT_NAVIGATION) { + IconTextNavigationItemData* data = static_cast(itemData.GetUnionItemData()); + NativeAbility::GetInstance().SwitchPageInSlice(data->pageId, TransitionType::TRANSITION_INVALID, + true, (void*)data->textContent, strlen(data->textContent) + 1); + } + } + return true; +} + +void SettingSystemPage::OnSimpleListUpdate(UIView* view, void* data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + if (type == SettingUnionItemType::PLAIN_TEXT) { + PlainTextItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + PlainTextItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + } else if(type == SettingUnionItemType::ICON_TEXT_TOGGLE) { + IconTextToggleItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextToggleItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingSystemPage); + } else if(type == SettingUnionItemType::ICON_TEXT_NAVIGATION) { + IconTextNavigationItemView *itemGroup = dynamic_cast(view); + if (itemGroup == nullptr) { + return; + } + IconTextNavigationItemData* itemData = static_cast(data); + itemGroup->UpdateViewData(itemData); + itemGroup->SetOnClickListener(g_pSettingSystemPage); + } + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/UnPairSecondConfirm.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/UnPairSecondConfirm.cpp new file mode 100644 index 000000000..f61af5728 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/settings/src/page/UnPairSecondConfirm.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UnPairSecondConfirm + * Created: 2025-06-05 + */ + +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "ui_resource_settings.h" +#include "main/LoadImg.h" +#include "settings/page/SettingBluetoothPage.h" +#include "settings/model/SettingBluetoothModel.h" +#include "settings/page/UnPairSecondConfirm.h" + +namespace OHOS { +static constexpr int16_t SETTING_ADDR2 = 2; +static constexpr int16_t SETTING_ADDR3 = 3; +static constexpr int16_t SETTING_ADDR4 = 4; +static constexpr int16_t SETTING_ADDR5 = 5; +static constexpr int16_t SETTING_UNPAIR_TITLE_Y = 60; +static constexpr int16_t SETTING_UNPAIR_TITLE_HEIGHT = 40; +static constexpr int16_t SETTING_UNPAIR_TITLE_FONT = 38; +static constexpr int16_t SETTING_UNPAIR_CONTENT1_X = 30; +static constexpr int16_t SETTING_UNPAIR_CONTENT1_Y = 135; +static constexpr int16_t SETTING_UNPAIR_CONTENT2_Y = 180; +static constexpr int16_t SETTING_UNPAIR_CONTENT3_Y = 225; +static constexpr int16_t SETTING_UNPAIR_CONYENT_WIDTH = 394; +static constexpr int16_t SETTING_UNPAIR_CONYENT_HEIGHT = 50; +static constexpr int16_t SETTING_UNPAIR_CONTENT2_HEIGHT = 115; +static constexpr int16_t SETTING_UNPAIR_CONTENT1_FONT = 35; +static constexpr int16_t SETTING_UNPAIR_BTN_WIDTH = 85; +static constexpr int16_t SETTING_UNPAIR_CANCEL_Y = 300; +static constexpr int16_t SETTING_UNPAIR_CANCEL_X = 114; +static constexpr int16_t SETTING_UNPAIR_CONFIRM_X = 254; +static constexpr char *CONFIRM_BUTTON = "confirmButton"; +static constexpr char *CANCEL_BUTTON = "cancelButton"; + +void UnPairSecondConfirm::OnCreateView(void* data) +{ + InitUnpairFragment(); +} + +void UnPairSecondConfirm::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (contentFirst_ != nullptr) { + delete contentFirst_; + contentFirst_ = nullptr; + } + if (contentSecond_ != nullptr) { + delete contentSecond_; + contentSecond_ = nullptr; + } + if (watchNameLabel_ != nullptr) { + delete watchNameLabel_; + watchNameLabel_ = nullptr; + } + if (cancel_ != nullptr) { + delete cancel_; + cancel_ = nullptr; + } + if (confirm_ != nullptr) { + delete confirm_; + confirm_ = nullptr; + } +} + +void UnPairSecondConfirm::InitUnpairFragment() +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment title_ new fail"); + return; + } + title_->SetPosition(0, SETTING_UNPAIR_TITLE_Y, RESOLUTION_WIDTH, SETTING_UNPAIR_TITLE_HEIGHT); + title_->SetText("确定取消配对?"); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_UNPAIR_TITLE_FONT); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + std::string str1 = SettingBluetoothModel::GetInstance()->GetDeviceName(); + std::string str = "此操作将会取消您与"; + std::string str2 = "以下设备的配对:"; + contentFirst_ = new UILabel(); + if (contentFirst_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment contentFirst_ new fail"); + return; + } + contentFirst_->SetPosition(0, SETTING_UNPAIR_CONTENT1_Y, + RESOLUTION_WIDTH, SETTING_UNPAIR_CONYENT_HEIGHT); + contentFirst_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + contentFirst_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_CONTENT1_FONT); + contentFirst_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + contentFirst_->SetText(str.c_str()); + + contentSecond_ = new UILabel(); + if (contentSecond_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment contentSecond_ new fail"); + return; + } + contentSecond_->SetPosition(SETTING_UNPAIR_CONTENT1_X, SETTING_UNPAIR_CONTENT2_Y, + SETTING_UNPAIR_CONYENT_WIDTH, SETTING_UNPAIR_CONYENT_HEIGHT); + contentSecond_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + contentSecond_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_CONTENT1_FONT); + contentSecond_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + contentSecond_->SetText(str2.c_str()); + + watchNameLabel_ = new UILabel(); + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment watchNameLabel_ new fail"); + return; + } + watchNameLabel_->SetPosition(0, SETTING_UNPAIR_CONTENT3_Y, + RESOLUTION_WIDTH, SETTING_UNPAIR_CONYENT_HEIGHT); + watchNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + watchNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_UNPAIR_CONTENT1_FONT); + watchNameLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + watchNameLabel_->SetText(str1.c_str()); + + cancel_ = new UIImageView(); + if (cancel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment cancel_ new fail"); + return; + } + LOADIMG::LoadImageViewImg(cancel_, SETTING_IMAGE, IMAGE_CANCEL); + cancel_->SetPosition(SETTING_UNPAIR_CANCEL_X, + SETTING_UNPAIR_CANCEL_Y, SETTING_UNPAIR_BTN_WIDTH, SETTING_UNPAIR_BTN_WIDTH); + cancel_->SetTouchable(true); + cancel_->SetViewId(CANCEL_BUTTON); + cancel_->SetOnClickListener(this); + cancel_->SetVisible(true); + confirm_ = new UILabelButton(); + if (confirm_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::InitUnpairFragment confirm_ new fail"); + return; + } + confirm_->SetPosition(SETTING_UNPAIR_CONFIRM_X, + SETTING_UNPAIR_CANCEL_Y, SETTING_UNPAIR_BTN_WIDTH, SETTING_UNPAIR_BTN_WIDTH); + confirm_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + confirm_->SetViewId(CONFIRM_BUTTON); + confirm_->SetOnClickListener(this); + confirm_->SetVisible(true); + LOADIMG::LoadBtnImage(confirm_, SETTING_IMAGE, IMAGE_OK_BLUE, IMAGE_OK_BLUE); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::PRESSED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::RELEASED); + confirm_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Blue().full, UIButton::INACTIVE); + + fragmentView_.Add(title_); + fragmentView_.Add(contentFirst_); + fragmentView_.Add(contentSecond_); + fragmentView_.Add(watchNameLabel_); + fragmentView_.Add(cancel_); + fragmentView_.Add(confirm_); +} + +void UnPairSecondConfirm::RefreshFragment() +{ + if (watchNameLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::RefreshFragment fail"); + return; + } + std::string str1 = SettingBluetoothModel::GetInstance()->GetDeviceName(); + watchNameLabel_->SetText(str1.c_str()); +} + +bool UnPairSecondConfirm::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UnPairSecondConfirm::OnClick"); + UNUSED(event); + if (strcmp(view.GetViewId(), CANCEL_BUTTON) == 0) { + // 此处仅退出页面,耳机仍存在,需要通知主页面 此时存在耳机列表,蓝牙主页通过该变量做出对应的显示 + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + } else if (strcmp(view.GetViewId(), CONFIRM_BUTTON) == 0) { + SettingBluetoothModel::GetInstance()->HandleUnpairRequest(); + bd_addr_t clickAddr; + (void)memcpy_s(clickAddr.addr, BD_ADDR_LEN, + SettingBluetoothModel::GetInstance()->GetSelectedDeviceInfo()->addr, BD_ADDR_LEN); + std::list &bluetoothCaseList = SettingBluetoothModel::GetInstance()->GetScansDevicesList(); + for (auto it = bluetoothCaseList.begin(); it != bluetoothCaseList.end(); it++) { + if ((clickAddr.addr[0] == it->addr[0]) && (clickAddr.addr[1] == it->addr[1]) + && (clickAddr.addr[SETTING_ADDR2] == it->addr[SETTING_ADDR2]) + && (clickAddr.addr[SETTING_ADDR3] == it->addr[SETTING_ADDR3]) + && (clickAddr.addr[SETTING_ADDR4] == it->addr[SETTING_ADDR4]) + && (clickAddr.addr[SETTING_ADDR5] == it->addr[SETTING_ADDR5])) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick unpair device_name:%s", it->deviceName); + bluetoothCaseList.erase(it); + } + } + fragmentView_.SetVisible(false); + SettingBluetoothPage::GetInstance()->LoadFindDeviceList(); + SettingBluetoothPage::GetInstance()->ChangeView(BT_MAIN_PAGE); + } + return true; +} + +bool UnPairSecondConfirm::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool UnPairSecondConfirm::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool UnPairSecondConfirm::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepDetailsPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepDetailsPage.cpp new file mode 100644 index 000000000..3fabd9e28 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepDetailsPage.cpp @@ -0,0 +1,587 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepDetailsPage + * Created: 2025-06-05 + */ +#include +#include +#include "ohos_timer.h" +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "sleep/SleepView.h" +#include "sleep/SleepModel.h" +#include "sleep/SleepDetailsPage.h" + +namespace OHOS { +static constexpr int16_t SLEEPDETAIL_SLEEP_X = 97; +static constexpr int16_t SLEEPDETAIL_SLEEP_Y = 31; +static constexpr int16_t SLEEPDETAIL_SLEEP_WIDTH = 260; +static constexpr int16_t SLEEPDETAIL_SLEEP_HEIGHT = 53; +static constexpr int16_t SLEEPDETAIL_SLEEP_FONT_SIZE = 38; +static constexpr int16_t SLEEPDETAIL_IMAGE1_X = 77; +static constexpr int16_t SLEEPDETAIL_IMAGE1_Y = 215; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_X = 103; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_Y = 205; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_WIDTH = 80; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_HEIGHT = 29; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_FONT_SIZE = 28; +static constexpr int16_t SLEEPDETAIL_IMAGE2_Y = 254; +static constexpr int16_t SLEEPDETAIL_IMAGE3_Y = 291; +static constexpr int16_t SLEEPDETAIL_IMAGE4_Y = 330; +static constexpr int16_t SLEEPDETAIL_RAPID_Y = 244; +static constexpr int16_t SLEEPDETAIL_RAPID_WIDTH = 150; +static constexpr int16_t SLEEPDETAIL_RAPID_HEIGHT = 38; +static constexpr int16_t SLEEPDETAIL_LIGHT_Y = 283; +static constexpr int16_t SLEEPDETAIL_DEEP_Y = 322; +static constexpr int16_t SLEEPDETAIL_GRAYBG_X = 62; +static constexpr int16_t SLEEPDETAIL_GRAYBG_Y = 185; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_X = 180; +static constexpr int16_t SLEEPDETAIL_ACTUAL_NORECODE_X = 96; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_Y = 100; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_WIDTH = 200; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_HEIGHT = 35; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_FONT_SIZE = 32; +static constexpr int16_t SLEEPDETAIL_LABEL_WIDTH = 160; +static constexpr int16_t SLEEPDETAIL_PADDING_RIGHT = 30; +static constexpr int16_t SLEEPDETAIL_SOBERINGTEXT_X = 220; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_NORECORD_X = 179; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_NORECORD_Y = 110; +static constexpr int16_t SLEEPDETAIL_SOBERTIMETEXT_X = 300; +static constexpr int16_t SLEEPDETAIL_SOBERTIMETEXT_Y = 190; +static constexpr int16_t SLEEPDETAIL_RAPIDTIMETEXT_Y = 230; +static constexpr int16_t SLEEPDETAIL_LIGHTIMETEXT_Y = 270; +static constexpr int16_t SLEEPDETAIL_DEEPIMETEXT_Y = 310; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE = 40; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT = 50; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMINUTES_FONT_SIZE = 40; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTE_X = 230; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTE_Y = 116; +static constexpr int16_t SLEEPDETAIL_ACTUALHOUR_X = 135; +static constexpr int16_t SLEEPDETAIL_ACTUALHOUR_Y = 100; +static constexpr int16_t SLEEPDETAIL_ACTUALHOURTEXT_X = 170; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTETEXT_X = 280; +static constexpr int16_t ACTUALHOURS_X = 140; +static constexpr int16_t ACTUALHOURSTEXT_X = 180; +static constexpr int16_t ACTUALMINUTESTEXT_X = 270; + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_DEATIL_PAGE, SleepDetailsPage, false); + +SleepDetailsPage::SleepDetailsPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepDetailsPage::SleepDetailsPage"); +} + +SleepDetailsPage::~SleepDetailsPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (sleepTitleLabel_ != nullptr) { + delete sleepTitleLabel_; + sleepTitleLabel_ = nullptr; + } + + if (actualSleepNorecordTimeLabel_ != nullptr) { + delete actualSleepNorecordTimeLabel_; + actualSleepNorecordTimeLabel_ = nullptr; + } + + if (actualSleepTimeHoursLabel_ != nullptr) { + delete actualSleepTimeHoursLabel_; + actualSleepTimeHoursLabel_ = nullptr; + } + + if (actualSleepTimeHoursUnitLabel_ != nullptr) { + delete actualSleepTimeHoursUnitLabel_; + actualSleepTimeHoursUnitLabel_ = nullptr; + } + + if (actualSleepTimeMinutesLabel_ != nullptr) { + delete actualSleepTimeMinutesLabel_; + actualSleepTimeMinutesLabel_ = nullptr; + } + + if (actualSleepTimeMinutesUnitLabel_ != nullptr) { + delete actualSleepTimeMinutesUnitLabel_; + actualSleepTimeMinutesUnitLabel_ = nullptr; + } + + if (grayBgImg_ != nullptr) { + delete grayBgImg_; + grayBgImg_ = nullptr; + } + + if (redPointImg_ != nullptr) { + delete redPointImg_; + redPointImg_ = nullptr; + } + + if (soberingTimeLabel_ != nullptr) { + delete soberingTimeLabel_; + soberingTimeLabel_ = nullptr; + } + + if (soberingTimeUnitLabel_ != nullptr) { + delete soberingTimeUnitLabel_; + soberingTimeUnitLabel_ = nullptr; + } + + if (orangePointImg_ != nullptr) { + delete orangePointImg_; + orangePointImg_ = nullptr; + } + + if (rapidEyeMovementLabel_ != nullptr) { + delete rapidEyeMovementLabel_; + rapidEyeMovementLabel_ = nullptr; + } + + if (rapidEyeMovementUnitLabel_ != nullptr) { + delete rapidEyeMovementUnitLabel_; + rapidEyeMovementUnitLabel_ = nullptr; + } + + if (greenPointImg_ != nullptr) { + delete greenPointImg_; + greenPointImg_ = nullptr; + } + + if (lightSleepTimeLabel_ != nullptr) { + delete lightSleepTimeLabel_; + lightSleepTimeLabel_ = nullptr; + } + + if (lightSleepTimeUnitLabel_ != nullptr) { + delete lightSleepTimeUnitLabel_; + lightSleepTimeUnitLabel_ = nullptr; + } + + if (bluePointImg_ != nullptr) { + delete bluePointImg_; + bluePointImg_ = nullptr; + } + + if (deepSleepTimeLabel_ != nullptr) { + delete deepSleepTimeLabel_; + deepSleepTimeLabel_ = nullptr; + } + + if (deepSleepTimeUnitLabel_ != nullptr) { + delete deepSleepTimeUnitLabel_; + deepSleepTimeUnitLabel_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(SLEEP_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepDetailsPage::~SleepDetailsPage"); +} + +void SleepDetailsPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ is nullptr"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group_->SetViewId("sleepDetails"); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(bgImg_, SLEEP_IMAGE, IMAGE_SLEEP_BACKGROUND); + bgImg_->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group_->Add(bgImg_); + + sleepTitleLabel_ = new UILabel(); + if (sleepTitleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepTitleLabel_ is nullptr"); + return; + } + sleepTitleLabel_->SetPosition(SLEEPDETAIL_SLEEP_X, SLEEPDETAIL_SLEEP_Y); + sleepTitleLabel_->Resize(SLEEPDETAIL_SLEEP_WIDTH, SLEEPDETAIL_SLEEP_HEIGHT); + sleepTitleLabel_->SetText("睡眠"); + sleepTitleLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleepTitleLabel_->SetTextColor(Color::White()); + sleepTitleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPDETAIL_SLEEP_FONT_SIZE); + sleepTitleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(sleepTitleLabel_); + + InitPage(); + + if (GetRecord() == true) { + InitDetailPage(); + } else { + InitNoDeatilPage(); + }; + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + AddViewToPageContainer(group_); +} + +void SleepDetailsPage::InitSoberingTime() +{ + redPointImg_ = new UIImageView(); + if (redPointImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "redPointImg_ is nullptr"); + return; + } + redPointImg_->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE1_Y); + LOADIMG::LoadImageViewImg(redPointImg_, SLEEP_IMAGE, IMAGE_SLEEP_RED_CIR); + group_->Add(redPointImg_); + soberingTimeLabel_ = new UILabel(); + if (soberingTimeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTimeLabel_ is nullptr"); + return; + } + soberingTimeLabel_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_SOBERINGTIME_Y); + soberingTimeLabel_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + soberingTimeLabel_->SetText("清醒"); + soberingTimeLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + soberingTimeLabel_->SetTextColor(Color::White()); + soberingTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTimeLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(soberingTimeLabel_); +} + +void SleepDetailsPage::InitRapidEyeMovement() +{ + orangePointImg_ = new UIImageView(); + if (orangePointImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "orangePointImg_ is nullptr"); + return; + } + orangePointImg_->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE2_Y); + LOADIMG::LoadImageViewImg(orangePointImg_, SLEEP_IMAGE, IMAGE_SLEEP_ORANGE_CIR); + group_->Add(orangePointImg_); + + rapidEyeMovementLabel_ = new UILabel(); + if (rapidEyeMovementLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovementLabel_ is nullptr"); + return; + } + rapidEyeMovementLabel_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_RAPID_Y); + rapidEyeMovementLabel_->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovementLabel_->SetText("快速动眼"); + rapidEyeMovementLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + rapidEyeMovementLabel_->SetTextColor(Color::White()); + rapidEyeMovementLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovementLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(rapidEyeMovementLabel_); +} + +void SleepDetailsPage::InitLightSleepTime() +{ + greenPointImg_ = new UIImageView(); + if (greenPointImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "greenPointImg_ is nullptr"); + return; + } + greenPointImg_->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE3_Y); + LOADIMG::LoadImageViewImg(greenPointImg_, SLEEP_IMAGE, IMAGE_SLEEP_GREEN_CIR); + group_->Add(greenPointImg_); + + lightSleepTimeLabel_ = new UILabel(); + if (lightSleepTimeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTimeLabel_ is nullptr"); + return; + } + lightSleepTimeLabel_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_LIGHT_Y); + lightSleepTimeLabel_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + lightSleepTimeLabel_->SetText("浅睡"); + lightSleepTimeLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + lightSleepTimeLabel_->SetTextColor(Color::White()); + lightSleepTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTimeLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(lightSleepTimeLabel_); +} + +void SleepDetailsPage::InitDeepSleepTime() +{ + bluePointImg_ = new UIImageView(); + if (bluePointImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluePointImg_ is nullptr"); + return; + } + bluePointImg_->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE4_Y); + LOADIMG::LoadImageViewImg(bluePointImg_, SLEEP_IMAGE, IMAGE_SLEEP_BLUE_CIR); + group_->Add(bluePointImg_); + + deepSleepTimeLabel_ = new UILabel(); + if (deepSleepTimeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTimeLabel_ is nullptr"); + return; + } + deepSleepTimeLabel_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_DEEP_Y); + deepSleepTimeLabel_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + deepSleepTimeLabel_->SetText("深睡"); + deepSleepTimeLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + deepSleepTimeLabel_->SetTextColor(Color::White()); + deepSleepTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTimeLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(deepSleepTimeLabel_); +} + +void SleepDetailsPage::InitPage() +{ + grayBgImg_ = new UIImageView(); + if (grayBgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "grayBgImg_ is nullptr"); + return; + } + grayBgImg_->SetPosition(SLEEPDETAIL_GRAYBG_X, SLEEPDETAIL_GRAYBG_Y); + LOADIMG::LoadImageViewImg(grayBgImg_, SLEEP_IMAGE, IMAGE_SLEEP_RECORD_BG); + group_->Add(grayBgImg_); + + // 加载详情四项 + InitSoberingTime(); + InitRapidEyeMovement(); + InitLightSleepTime(); + InitDeepSleepTime(); +} + +void SleepDetailsPage::LoadDeatilActualSleepTime() +{ + actualSleepTimeHoursLabel_ = new UILabel(); + if (actualSleepTimeHoursLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHoursLabel_ is nullptr"); + return; + } + actualSleepTimeHoursLabel_->SetPosition(SLEEPDETAIL_ACTUALHOUR_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeHoursLabel_->Resize(SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + actualSleepTimeHoursLabel_->SetTextColor(Color::White()); + actualSleepTimeHoursLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE); + group_->Add(actualSleepTimeHoursLabel_); + + actualSleepTimeHoursUnitLabel_ = new UILabel(); + if (actualSleepTimeHoursUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHoursUnitLabel_ is nullptr"); + return; + } + actualSleepTimeHoursUnitLabel_->SetText("小时"); + actualSleepTimeHoursUnitLabel_->SetPosition(SLEEPDETAIL_ACTUALHOURTEXT_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeHoursUnitLabel_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + actualSleepTimeHoursUnitLabel_->SetTextColor(Color::White()); + actualSleepTimeHoursUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + group_->Add(actualSleepTimeHoursUnitLabel_); + + actualSleepTimeMinutesLabel_ = new UILabel(); + if (actualSleepTimeMinutesLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeMinutesLabel_ is nullptr"); + return; + } + + actualSleepTimeMinutesLabel_->SetPosition(SLEEPDETAIL_ACTUALMINUTE_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeMinutesLabel_->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + actualSleepTimeMinutesLabel_->SetTextColor(Color::White()); + actualSleepTimeMinutesLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_FONT_SIZE); + group_->Add(actualSleepTimeMinutesLabel_); + + actualSleepTimeMinutesUnitLabel_ = new UILabel(); + if (actualSleepTimeMinutesUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHoursLabel_ is nullptr"); + return; + } + + actualSleepTimeMinutesUnitLabel_->SetText("分钟"); + actualSleepTimeMinutesUnitLabel_->SetPosition(SLEEPDETAIL_ACTUALMINUTETEXT_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeMinutesUnitLabel_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + actualSleepTimeMinutesUnitLabel_->SetTextColor(Color::White()); + actualSleepTimeMinutesUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + group_->Add(actualSleepTimeMinutesUnitLabel_); +} + +void SleepDetailsPage::InitActualSleepTime(std::tuple timeTuple) +{ + LoadDeatilActualSleepTime(); + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + actualSleepTimeHoursLabel_->SetText(std::to_string(hours).c_str()); + actualSleepTimeMinutesLabel_->SetText(std::to_string(minutes).c_str()); +} + +void SleepDetailsPage::InitDetailPage() +{ + InitActualSleepTime(SleepModel::GetInstance().GetSleepTime()); + + soberingTimeUnitLabel_ = new UILabel(); + if (soberingTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTimeUnitLabel_ is nullptr"); + return; + } + soberingTimeUnitLabel_->SetText((SetTimeUnit(SleepModel::GetInstance().GetSoberingTime())).c_str()); + soberingTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_SOBERINGTIME_Y); + soberingTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + soberingTimeUnitLabel_->SetTextColor(Color::White()); + soberingTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + soberingTimeUnitLabel_->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group_->Add(soberingTimeUnitLabel_); + + rapidEyeMovementUnitLabel_ = new UILabel(); + if (rapidEyeMovementUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovementUnitLabel_ is nullptr"); + return; + } + rapidEyeMovementUnitLabel_->SetText((SetTimeUnit(SleepModel::GetInstance().GetRapidEyeMovementTime())).c_str()); + rapidEyeMovementUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_RAPID_Y); + rapidEyeMovementUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovementUnitLabel_->SetTextColor(Color::White()); + rapidEyeMovementUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovementUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + rapidEyeMovementUnitLabel_->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group_->Add(rapidEyeMovementUnitLabel_); + + lightSleepTimeUnitLabel_ = new UILabel(); + if (lightSleepTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTimeUnitLabel_ is nullptr"); + return; + } + lightSleepTimeUnitLabel_->SetText((SetTimeUnit(SleepModel::GetInstance().GetLightSleepTime())).c_str()); + lightSleepTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_LIGHT_Y); + lightSleepTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + lightSleepTimeUnitLabel_->SetTextColor(Color::White()); + lightSleepTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + lightSleepTimeUnitLabel_->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group_->Add(lightSleepTimeUnitLabel_); + + deepSleepTimeUnitLabel_ = new UILabel(); + if (deepSleepTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTimeUnitLabel_ is nullptr"); + return; + } + deepSleepTimeUnitLabel_->SetText((SetTimeUnit(SleepModel::GetInstance().GetDeepSleepTime())).c_str()); + deepSleepTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_DEEP_Y); + deepSleepTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + deepSleepTimeUnitLabel_->SetTextColor(Color::White()); + deepSleepTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + deepSleepTimeUnitLabel_->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group_->Add(deepSleepTimeUnitLabel_); +} + +void SleepDetailsPage::InitNoDeatilPage() +{ + actualSleepNorecordTimeLabel_ = new UILabel(); + if (actualSleepNorecordTimeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepNorecordTimeLabel_ is nullptr"); + return; + } + actualSleepNorecordTimeLabel_->SetText("无记录"); + actualSleepNorecordTimeLabel_->SetPosition(SLEEPDETAIL_ACTUALSLEEP_NORECORD_X, SLEEPDETAIL_ACTUALSLEEP_NORECORD_Y); + actualSleepNorecordTimeLabel_->Resize(SLEEPDETAIL_ACTUAL_NORECODE_X, SLEEPDETAIL_SOBERINGTIME_WIDTH); + actualSleepNorecordTimeLabel_->SetTextColor(Color::White()); + actualSleepNorecordTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEP_FONT_SIZE); + group_->Add(actualSleepNorecordTimeLabel_); + + soberingTimeUnitLabel_ = new UILabel(); + if (soberingTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTimeUnitLabel_ is nullptr"); + return; + } + soberingTimeUnitLabel_->SetText("--"); + soberingTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_SOBERINGTIME_Y); + soberingTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + soberingTimeUnitLabel_->SetTextColor(Color::White()); + soberingTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group_->Add(soberingTimeUnitLabel_); + + rapidEyeMovementUnitLabel_ = new UILabel(); + if (rapidEyeMovementUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovementUnitLabel_ is nullptr"); + return; + } + rapidEyeMovementUnitLabel_->SetText("--"); + rapidEyeMovementUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_RAPID_Y); + rapidEyeMovementUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovementUnitLabel_->SetTextColor(Color::White()); + rapidEyeMovementUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovementUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group_->Add(rapidEyeMovementUnitLabel_); + + lightSleepTimeUnitLabel_ = new UILabel(); + if (lightSleepTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTimeUnitLabel_ is nullptr"); + return; + } + lightSleepTimeUnitLabel_->SetText("--"); + lightSleepTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_LIGHT_Y); + lightSleepTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + lightSleepTimeUnitLabel_->SetTextColor(Color::White()); + lightSleepTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group_->Add(lightSleepTimeUnitLabel_); + + deepSleepTimeUnitLabel_ = new UILabel(); + if (deepSleepTimeUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTimeUnitLabel_ is nullptr"); + return; + } + deepSleepTimeUnitLabel_->SetText("--"); + deepSleepTimeUnitLabel_->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_DEEP_Y); + deepSleepTimeUnitLabel_->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + deepSleepTimeUnitLabel_->SetTextColor(Color::White()); + deepSleepTimeUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTimeUnitLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group_->Add(deepSleepTimeUnitLabel_); +} + +std::string SleepDetailsPage::SetTimeUnit(std::tuple timeTuple) +{ + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + std::string str = ""; + if ((hours == 0) && (minutes != 0)) { + str = std::to_string(minutes) + "分钟"; + } else if ((hours != 0) && (minutes == 0)) { + str = std::to_string(hours) + "小时"; + } else if ((hours != 0) && (minutes != 0)) { + str = std::to_string(hours) + "小时" + std::to_string(minutes) + "分钟"; + } else if ((hours == 0) && (minutes == 0)) { + str = "---"; + } + return str; +} + +bool SleepDetailsPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + if (GetRecord() == false) { + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_TARGET_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + } else if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} + +bool SleepDetailsPage::GetRecord() +{ + if (SleepModel::GetInstance().GetRecord()) { + return true; + } + return false; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepMainPage.cpp new file mode 100644 index 000000000..fd9e06930 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepMainPage.cpp @@ -0,0 +1,655 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepMainPage + * Created: 2025-06-05 + */ + +#include +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "common/image_cache_manager.h" +#include "diag_service.h" +#include "msg_center_device.h" +#include "diag_common.h" +#include "sleep/SleepTargetTime.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepMainPage.h" + +namespace OHOS { +static constexpr int16_t SLEEPMAIN_SLEEP_X = 97; +static constexpr int16_t SLEEPMAIN_SLEEP_Y = 31; +static constexpr int16_t SLEEPMAIN_SLEEP_WIDTH = 260; +static constexpr int16_t SLEEPMAIN_SLEEP_HEIGHT = 53; +static constexpr int16_t SLEEPMAIN_SLEEP_FONT_SIZE = 38; +static constexpr int16_t SLEEPMAIN_NORECORD_X = 179; +static constexpr int16_t SLEEPMAIN_NORECORD_Y = 260; +static constexpr int16_t SLEEPMAIN_NORECORD_WIDTH = 96; +static constexpr int16_t SLEEPMAIN_NORECORD_HEIGHT = 48; +static constexpr int16_t SLEEPMAIN_NORECORD_FONT_SIZE = 32; +static constexpr int16_t SLEEPMAIN_TIPS_X = 78; +static constexpr int16_t SLEEPMAIN_TIPS_Y = 310; +static constexpr int16_t SLEEPMAIN_TIPS_WIDTH = 300; +static constexpr int16_t SLEEPMAIN_TIPS_HEIGHT = 130; +static constexpr int16_t SLEEPMAIN_TIPS_FONT_SIZE = 24; +static constexpr int16_t SLEEPMAIN_TIPS_FONT_SIZE_TWO = 28; +static constexpr int16_t SLEEPMAIN_SCORE_X = 164; +static constexpr int16_t SLEEPMAIN_SCORE_Y = 129; +static constexpr int16_t SLEEPMAIN_SCORE_WIDTH = 95; +static constexpr int16_t SLEEPMAIN_SCORE_HEIGHT = 65; +static constexpr int16_t SLEEPMAIN_SCORE_FONT_SIZE = 56; +static constexpr int16_t SLEEPMAIN_MOONNORECORD_X = 154; +static constexpr int16_t SLEEPMAIN_MOONNORECORD_Y = 60; +static constexpr int16_t SLEEPMAIN_SCORETEXT_FONT_SIZE = 21; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_1 = 20; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_2 = 40; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_3 = 60; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_4 = 80; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_5 = 100; +static constexpr int16_t SLEEP_FONT_SIZE_LARGE = 40; +static constexpr int16_t SLEEPMAIN_SCORETEXT_X = 265; +static constexpr int16_t SLEEPMAIN_SCORETEXT_Y = 161; +static constexpr int16_t SLEEP_LABEL_WIDTH = 48; +static constexpr int16_t SLEEP_LABEL_HEIGHT = 29; +static constexpr int16_t SLEEP_TIME_LABEL_WIDTH = 100; +static constexpr int16_t SLEEP_TIME_LABEL_HEIGHT = 50; +static constexpr int16_t SLEEPMAIN_SETTING_X = 280; +static constexpr int16_t SLEEPMAIN_SETTING_Y = 374; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTE_X = 230; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTE_Y = 319; +static constexpr int16_t SLEEPMAIN_ACTUALHOUR_X = 135; +static constexpr int16_t ACTUALMINUTES_Y = 303; +static constexpr int16_t SLEEPMAIN_ACTUALHOURTEXT_X = 170; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE = 32; +static constexpr int16_t SLEEPMAIN_HEIGHT = 50; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTETEXT_X = 280; +static constexpr int16_t SLEEPMAIN_CIR_HIGHT = 444; +static constexpr int16_t SLEEPMAIN_CIR_X = 228; +static constexpr int16_t SLEEPMAIN_CIR_Y = 228; +static constexpr int16_t SLEEPMAIN_CIR_RADIUS = 215; +static constexpr int16_t SLEEPMAIN_CIR_ANGLE = 360; +static constexpr int16_t SLEEPMAIN_CIR_RANGE = 100; +static constexpr int16_t SLEEPMAIN_CIR_LINE_WIDTH = 10; +static constexpr int16_t SLEEPMAIN_SCORE = 100; +static constexpr int16_t SLEEPMAIN_RATE = 100; +static constexpr float MINUTE_HOUR = 60.0f; +static constexpr int16_t TARGETTIME_LABEL_Y = 363; +static constexpr int16_t TARGETTIMEBUTTON_X = 137; +static constexpr int16_t TARGETTIME_LABEL_WIDTH = 184; +static constexpr int16_t TARGETTIME_LABEL_HEIGHT = 46; +static constexpr int16_t MAIN_SLEEP_COLOR_R = 181; +static constexpr int16_t MAIN_SLEEP_COLOR_G = 402; +static constexpr int16_t MAIN_SLEEP_COLOR_B = 255; +static constexpr int16_t MAIN_SLEEP_OPT = 110; +static constexpr int16_t MAIN_SLEEP_RANGE = 10; +static constexpr int16_t MAIN_SLEEP_POSX_2 = 2; +static constexpr int16_t MAIN_SLEEP_POSX_3 = 3; +static constexpr int16_t MAIN_SLEEP_POSX_4 = 4; +static constexpr int16_t MAIN_SLEEP_MOON_POSX = 198; +static constexpr int16_t MAIN_SLEEP_SCORE_HEIGHT = 192; +static constexpr int16_t MAIN_SLEEP_SCORE_X = 131; +static constexpr int16_t MAIN_SLEEP_SCORE_Y = 200; +static constexpr int16_t MAIN_SLEEP_STAR1_X = 145; +static constexpr int16_t MAIN_SLEEP_STAR2_X = 180; +static constexpr int16_t MAIN_SLEEP_STAR3_X = 215; +static constexpr int16_t MAIN_SLEEP_STAR4_X = 250; +static constexpr int16_t MAIN_SLEEP_STAR5_X = 285; +static constexpr int16_t MAIN_SLEEP_STAR_Y = 255; +static constexpr int16_t MAIN_SLEEP_SCORE_TEXT_FONT_SIZE = 55; +static constexpr int16_t MAIN_SLEEP_STAR_NUM = 5; +static constexpr int16_t SLEEP_MOON_NO_RECORD_X = 128; +static constexpr char *TARGET_TIME = "targetTime"; +static constexpr int16_t g_posX[MAIN_SLEEP_STAR_NUM] = {MAIN_SLEEP_STAR1_X, MAIN_SLEEP_STAR2_X, MAIN_SLEEP_STAR3_X, MAIN_SLEEP_STAR4_X, + MAIN_SLEEP_STAR5_X}; +static constexpr int16_t g_posY = MAIN_SLEEP_STAR_Y; + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_MAIN_PAGE, SleepMainPage, true); + +SleepMainPage::SleepMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepMainPage::SleepMainPage"); +} + +SleepMainPage::~SleepMainPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (imageViewMain_ != nullptr) { + delete imageViewMain_; + imageViewMain_ = nullptr; + } + + if (sleepTitleLabel_ != nullptr) { + delete sleepTitleLabel_; + sleepTitleLabel_ = nullptr; + } + + if (moonNoRecordImg_ != nullptr) { + delete moonNoRecordImg_; + moonNoRecordImg_ = nullptr; + } + + if (moonImg_ != nullptr) { + delete moonImg_; + moonImg_ = nullptr; + } + + if (noRecordLabel_ != nullptr) { + delete noRecordLabel_; + noRecordLabel_ = nullptr; + } + + if (tipsLabel_ != nullptr) { + delete tipsLabel_; + tipsLabel_ = nullptr; + } + + if (sleepScoresLabel_ != nullptr) { + delete sleepScoresLabel_; + sleepScoresLabel_ = nullptr; + } + + if (scoreUnitLabel_ != nullptr) { + delete scoreUnitLabel_; + scoreUnitLabel_ = nullptr; + } + + if (sleepScoreTextLabel_ != nullptr) { + delete sleepScoreTextLabel_; + sleepScoreTextLabel_ = nullptr; + } + + if (scoreStarImg1_ != nullptr) { + delete scoreStarImg1_; + scoreStarImg1_ = nullptr; + } + + if (scoreStarImg2_ != nullptr) { + delete scoreStarImg2_; + scoreStarImg2_ = nullptr; + } + + if (scoreStarImg3_ != nullptr) { + delete scoreStarImg3_; + scoreStarImg3_ = nullptr; + } + if (scoreStarImg4_ != nullptr) { + delete scoreStarImg4_; + scoreStarImg4_ = nullptr; + } + + if (scoreStarImg5_ != nullptr) { + delete scoreStarImg5_; + scoreStarImg5_ = nullptr; + } + + if (settingImg_ != nullptr) { + delete settingImg_; + settingImg_ = nullptr; + } + + if (targetTimeLabel_ != nullptr) { + delete targetTimeLabel_; + targetTimeLabel_ = nullptr; + } + + if (targetSleepTimeHoursLabel_ != nullptr) { + delete targetSleepTimeHoursLabel_; + targetSleepTimeHoursLabel_ = nullptr; + } + + if (targetSleepTimeHoursUnitLabel_ != nullptr) { + delete targetSleepTimeHoursUnitLabel_; + targetSleepTimeHoursUnitLabel_ = nullptr; + } + + if (targetSleepTimeMinutesLabel_ != nullptr) { + delete targetSleepTimeMinutesLabel_; + targetSleepTimeMinutesLabel_ = nullptr; + } + + if (targetSleepTimeMinutesUnitLabel_ != nullptr) { + delete targetSleepTimeMinutesUnitLabel_; + targetSleepTimeMinutesUnitLabel_ = nullptr; + } + + if (targetTimeButton_ != nullptr) { + delete targetTimeButton_; + targetTimeButton_ = nullptr; + } + + if (circleProgress_ != nullptr) { + delete circleProgress_; + circleProgress_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(SLEEP_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepMainPage::~SleepMainPage"); +} + +void SleepMainPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ is nullptr"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group_->SetViewId("sleepMain"); + + imageViewMain_ = new UIImageView(); + if (imageViewMain_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imageViewMain_ is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(imageViewMain_, SLEEP_IMAGE, IMAGE_SLEEP_BACKGROUND); + imageViewMain_->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group_->Add(imageViewMain_); + + if (GetRecord() == false) { + InitNoRecordPage(); + } else { + InitRecordPage(); + } + + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + AddViewToPageContainer(group_); +} + +void SleepMainPage::InitNoRecordPage() +{ + sleepTitleLabel_ = new UILabel(); + if (sleepTitleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepTitleLabel_ is nullptr"); + return; + } + sleepTitleLabel_->SetPosition(SLEEPMAIN_SLEEP_X, SLEEPMAIN_SLEEP_Y); + sleepTitleLabel_->Resize(SLEEPMAIN_SLEEP_WIDTH, SLEEPMAIN_SLEEP_HEIGHT); + sleepTitleLabel_->SetText("睡眠"); + sleepTitleLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleepTitleLabel_->SetTextColor(Color::White()); + sleepTitleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPMAIN_SLEEP_FONT_SIZE); + sleepTitleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(sleepTitleLabel_); + + moonNoRecordImg_ = new UIImageView(); + if (moonNoRecordImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "moonNoRecordImg_ is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(moonNoRecordImg_, SLEEP_IMAGE, IMAGE_SLEEP_NORECORD_SLEEP); + moonNoRecordImg_->SetPosition(SLEEP_MOON_NO_RECORD_X, SLEEPMAIN_MOONNORECORD_Y); + group_->Add(moonNoRecordImg_); + + noRecordLabel_ = new UILabel(); + if (noRecordLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "noRecordLabel_ is nullptr"); + return; + } + noRecordLabel_->SetPosition(SLEEPMAIN_NORECORD_X, SLEEPMAIN_NORECORD_Y); + noRecordLabel_->Resize(SLEEPMAIN_NORECORD_WIDTH, SLEEPMAIN_NORECORD_HEIGHT); + noRecordLabel_->SetText("无记录"); + noRecordLabel_->SetTextColor(Color::White()); + noRecordLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_NORECORD_FONT_SIZE); + noRecordLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(noRecordLabel_); + + tipsLabel_ = new UILabel(); + if (tipsLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsLabel_ is nullptr"); + return; + } + tipsLabel_->SetPosition(SLEEPMAIN_TIPS_X, SLEEPMAIN_TIPS_Y); + tipsLabel_->Resize(SLEEPMAIN_TIPS_WIDTH, SLEEPMAIN_TIPS_HEIGHT); + tipsLabel_->SetText("睡眠时间过短或睡眠中动作幅度大,手表可能检测不到睡眠"); + tipsLabel_->SetTextColor(Color::White()); + tipsLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE_TWO); + tipsLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(tipsLabel_); +} + +void SleepMainPage::InitRecordPage() +{ + SleepModel::GetInstance().SendData(); + InitCircleProgress(); + moonImg_ = new UIImageView(); + if (moonImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "moonImg_ is nullptr"); + return; + } + moonImg_->SetPosition(MAIN_SLEEP_MOON_POSX, TARGETTIME_LABEL_HEIGHT); + LOADIMG::LoadImageViewImg(moonImg_, SLEEP_IMAGE, IMAGE_SLEEP_RECORD_SLEEP); + group_->Add(moonImg_); + + sleepScoresLabel_ = new UILabel(); + if (sleepScoresLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepScoresLabel_ is nullptr"); + return; + } + sleepScoresLabel_->SetText(std::to_string(GetSleepingScores()).c_str()); + sleepScoresLabel_->SetPosition(SLEEPMAIN_SCORE_X, SLEEPMAIN_SCORE_Y); + sleepScoresLabel_->Resize(SLEEPMAIN_SCORE_WIDTH, SLEEPMAIN_SCORE_HEIGHT); + sleepScoresLabel_->SetTextColor(Color::White()); + sleepScoresLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleepScoresLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPMAIN_SCORE_FONT_SIZE); + sleepScoresLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group_->Add(sleepScoresLabel_); + + scoreUnitLabel_ = new UILabel(); + if (scoreUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreUnitLabel_ is nullptr"); + return; + } + scoreUnitLabel_->SetText("分"); + scoreUnitLabel_->SetPosition(SLEEPMAIN_SCORETEXT_X, SLEEPMAIN_SCORETEXT_Y); + scoreUnitLabel_->Resize(MAIN_SLEEP_SCORE_TEXT_FONT_SIZE, SLEEPMAIN_TIPS_FONT_SIZE); + scoreUnitLabel_->SetTextColor(Color::White()); + scoreUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_SCORETEXT_FONT_SIZE); + group_->Add(scoreUnitLabel_); + ScoreDisplay(); + + sleepScoreTextLabel_ = new UILabel(); + if (sleepScoreTextLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepScoreTextLabel_ is nullptr"); + return; + } + sleepScoreTextLabel_->SetText("夜间睡眠得分"); + sleepScoreTextLabel_->Resize(MAIN_SLEEP_SCORE_HEIGHT, SLEEPMAIN_NORECORD_HEIGHT); + sleepScoreTextLabel_->SetPosition(MAIN_SLEEP_SCORE_X, MAIN_SLEEP_SCORE_Y); + sleepScoreTextLabel_->SetTextColor(Color::White()); + sleepScoreTextLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE); + group_->Add(sleepScoreTextLabel_); + + // 显示具体睡觉时间 + LoadActualSleepTime(SleepModel::GetInstance().GetSleepTime()); + + // 加载目标按钮 + LoadTargetTimeButton(SleepModel::GetInstance().GetTargetTime()); +} + +void SleepMainPage::InitScoreDisplayPicture() +{ + scoreStarImg1_ = new UIImageView(); + if (scoreStarImg1_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreStarImg1_ is nullptr"); + return; + } + scoreStarImg1_->SetPosition(g_posX[0], g_posY); + group_->Add(scoreStarImg1_); + + scoreStarImg2_ = new UIImageView(); + if (scoreStarImg2_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreStarImg2_ is nullptr"); + return; + } + scoreStarImg2_->SetPosition(g_posX[1], g_posY); + group_->Add(scoreStarImg2_); + + scoreStarImg3_ = new UIImageView(); + if (scoreStarImg3_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreStarImg3_ is nullptr"); + return; + } + scoreStarImg3_->SetPosition(g_posX[MAIN_SLEEP_POSX_2], g_posY); + group_->Add(scoreStarImg3_); + + scoreStarImg4_ = new UIImageView(); + if (scoreStarImg4_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreStarImg4_ is nullptr"); + return; + } + scoreStarImg4_->SetPosition(g_posX[MAIN_SLEEP_POSX_3], g_posY); + group_->Add(scoreStarImg4_); + + scoreStarImg5_ = new UIImageView(); + if (scoreStarImg5_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreStarImg5_ is nullptr"); + return; + } + scoreStarImg5_->SetPosition(g_posX[MAIN_SLEEP_POSX_4], g_posY); + group_->Add(scoreStarImg5_); +} + +void SleepMainPage::ScoreDisplay() +{ + InitScoreDisplayPicture(); + if (GetSleepingScores() < SLEEP_SCORE_THRESHOLD_1) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_1 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_2) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_2 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_3) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_3 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_4) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_4 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_5) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_GRAY); + } else if (GetSleepingScores() == SLEEP_SCORE_THRESHOLD_5) { + LOADIMG::LoadImageViewImg(scoreStarImg1_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg2_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg3_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg4_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreStarImg5_, SLEEP_IMAGE, IMAGE_SLEEP_STAR_YELLOW); + } +} + +void SleepMainPage::InitSleepTimeLabel() +{ + targetSleepTimeHoursLabel_ = new UILabel(); + if (targetSleepTimeHoursLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeHoursLabel_ is nullptr"); + return; + } + targetSleepTimeHoursLabel_->SetPosition(SLEEPMAIN_ACTUALHOUR_X, ACTUALMINUTES_Y); + targetSleepTimeHoursLabel_->Resize(SLEEPMAIN_HEIGHT, SLEEPMAIN_HEIGHT); + targetSleepTimeHoursLabel_->SetTextColor(Color::White()); + targetSleepTimeHoursLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEP_FONT_SIZE_LARGE); + group_->Add(targetSleepTimeHoursLabel_); + + targetSleepTimeHoursUnitLabel_ = new UILabel(); + if (targetSleepTimeHoursUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeHoursUnitLabel_ is nullptr"); + return; + } + targetSleepTimeHoursUnitLabel_->SetPosition(SLEEPMAIN_ACTUALHOURTEXT_X, SLEEPMAIN_ACTUALMINUTE_Y); + targetSleepTimeHoursUnitLabel_->Resize(SLEEP_LABEL_WIDTH, SLEEP_LABEL_HEIGHT); + targetSleepTimeHoursUnitLabel_->SetTextColor(Color::White()); + targetSleepTimeHoursUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + targetSleepTimeHoursUnitLabel_->SetText("小时"); + group_->Add(targetSleepTimeHoursUnitLabel_); + + targetSleepTimeMinutesLabel_ = new UILabel(); + if (targetSleepTimeMinutesLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeMinutesLabel_ is nullptr"); + return; + } + targetSleepTimeMinutesLabel_->SetPosition(SLEEPMAIN_ACTUALMINUTE_X, ACTUALMINUTES_Y); + targetSleepTimeMinutesLabel_->Resize(SLEEP_TIME_LABEL_WIDTH, SLEEP_TIME_LABEL_HEIGHT); + targetSleepTimeMinutesLabel_->SetTextColor(Color::White()); + targetSleepTimeMinutesLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEP_FONT_SIZE_LARGE); + group_->Add(targetSleepTimeMinutesLabel_); + + targetSleepTimeMinutesUnitLabel_ = new UILabel(); + if (targetSleepTimeMinutesUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeMinutesUnitLabel_ is nullptr"); + return; + } + targetSleepTimeMinutesUnitLabel_->SetPosition(SLEEPMAIN_ACTUALMINUTETEXT_X, SLEEPMAIN_ACTUALMINUTE_Y); + targetSleepTimeMinutesUnitLabel_->Resize(SLEEP_LABEL_WIDTH, SLEEP_LABEL_HEIGHT); + targetSleepTimeMinutesUnitLabel_->SetTextColor(Color::White()); + targetSleepTimeMinutesUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + targetSleepTimeMinutesUnitLabel_->SetText("分钟"); + group_->Add(targetSleepTimeMinutesUnitLabel_); +} + +void SleepMainPage::LoadTargetTimeButton(std::tuple timeTuple) +{ + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + std::string str = ""; + if ((hours == 0) && (minutes != 0)) { + str = std::to_string(minutes) + "分钟"; + } else if ((hours != 0) && (minutes == 0)) { + str = std::to_string(hours) + "小时"; + } else if ((hours != 0) && (minutes != 0)) { + if (minutes < MAIN_SLEEP_RANGE && hours >= MAIN_SLEEP_RANGE) { + str = " " + std::to_string(hours) + ":0" + std::to_string(minutes); + } else if (hours < MAIN_SLEEP_RANGE && minutes >= MAIN_SLEEP_RANGE) { + str = " 0" + std::to_string(hours) + ":" + std::to_string(minutes); + } else if (minutes < MAIN_SLEEP_RANGE && hours < MAIN_SLEEP_RANGE) { + str = " 0" + std::to_string(hours) + ":0" + std::to_string(minutes); + } else if (minutes >= MAIN_SLEEP_RANGE && hours >= MAIN_SLEEP_RANGE) { + str = " " + std::to_string(hours) + ":" + std::to_string(minutes); + } + } + targetTimeButton_ = new UILabelButton(); + if (targetTimeButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetTimeButton_ is nullptr"); + return; + } + targetTimeButton_->SetPosition(TARGETTIMEBUTTON_X, TARGETTIME_LABEL_Y); + targetTimeButton_->SetViewId(TARGET_TIME); + targetTimeButton_->SetOnClickListener(this); + targetTimeButton_->SetStyle( + STYLE_BACKGROUND_COLOR, + Color::GetColorFromRGBA(MAIN_SLEEP_COLOR_R, MAIN_SLEEP_COLOR_G, MAIN_SLEEP_COLOR_B, MAIN_SLEEP_OPT).full); + targetTimeButton_->SetStyleForState( + STYLE_BACKGROUND_COLOR, + Color::GetColorFromRGBA(MAIN_SLEEP_COLOR_R, MAIN_SLEEP_COLOR_G, MAIN_SLEEP_COLOR_B, MAIN_SLEEP_OPT).full, + UIButton::PRESSED); + targetTimeButton_->Resize(TARGETTIME_LABEL_WIDTH, TARGETTIME_LABEL_HEIGHT); + targetTimeButton_->SetTextColor(Color::White()); + targetTimeButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + group_->Add(targetTimeButton_); + + targetTimeLabel_ = new UILabel(); + if (targetTimeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetTimeLabel_ is nullptr"); + return; + } + std::string targetUnit = "目标" + str; + targetTimeLabel_->SetText(targetUnit.c_str()); + targetTimeLabel_->SetPosition(SLEEPMAIN_MOONNORECORD_X, TARGETTIME_LABEL_Y); + targetTimeLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + targetTimeLabel_->Resize(TARGETTIME_LABEL_WIDTH, TARGETTIME_LABEL_HEIGHT); + targetTimeLabel_->SetTextColor(Color::White()); + targetTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + targetTimeLabel_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group_->Add(targetTimeLabel_); + + settingImg_ = new UIImageView(); + if (settingImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "settingImg_ is nullptr"); + return; + } + settingImg_->SetPosition(SLEEPMAIN_SETTING_X, SLEEPMAIN_SETTING_Y); + LOADIMG::LoadImageViewImg(settingImg_, SLEEP_IMAGE, IMAGE_SLEEP_SETTING); + group_->Add(settingImg_); +} + +void SleepMainPage::LoadActualSleepTime(std::tuple timeTuple) +{ + InitSleepTimeLabel(); + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + targetSleepTimeHoursLabel_->SetText(std::to_string(hours).c_str()); + targetSleepTimeMinutesLabel_->SetText(std::to_string(minutes).c_str()); +} + +void SleepMainPage::InitCircleProgress() +{ + circleProgress_ = new UICircleProgress(); + if (circleProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgress_ is nullptr"); + return; + } + circleProgress_->SetPosition(0, 0); + circleProgress_->Resize(SLEEPMAIN_CIR_HIGHT, SLEEPMAIN_CIR_HIGHT); + circleProgress_->SetCenterPosition(SLEEPMAIN_CIR_X, SLEEPMAIN_CIR_Y); + circleProgress_->SetRadius(SLEEPMAIN_CIR_RADIUS); + circleProgress_->SetStartAngle(0); + circleProgress_->SetEndAngle(SLEEPMAIN_CIR_ANGLE); + circleProgress_->SetRange(0, SLEEPMAIN_CIR_RANGE); + circleProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0xFF6f29a0); + circleProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xFFB566FF); + circleProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, SLEEPMAIN_CIR_LINE_WIDTH); + circleProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, SLEEPMAIN_CIR_LINE_WIDTH); + group_->Add(circleProgress_); + circleProgress_->SetValue(GetSleepingScores()); + circleProgress_->Invalidate(); +} + +uint32_t SleepMainPage::GetSleepingScores() +{ + uint32_t hours = SleepModel::GetInstance().GetSleepTimeHours(); + uint32_t minutes = SleepModel::GetInstance().GetSleepTimeMinutes(); + std::tuple timeTuple = SleepModel::GetInstance().GetTargetTime(); + uint32_t timeHours = std::get<0>(timeTuple); + uint32_t timeMinutes = std::get<1>(timeTuple); + if (((hours * MINUTE_HOUR) + minutes) > ((timeHours * MINUTE_HOUR) + timeMinutes)) { + return SLEEPMAIN_SCORE; + } else { + float score = ((hours * MINUTE_HOUR) + minutes) / ((timeHours * MINUTE_HOUR) + timeMinutes); + return uint32_t(score * SLEEPMAIN_RATE); + } +} + +bool SleepMainPage::GetRecord() +{ + if (SleepModel::GetInstance().GetRecord()) { + return true; + } + return false; +} + +bool SleepMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(view); + if (strcmp(view.GetViewId(), TARGET_TIME) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_TARGET_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SleepMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_DEATIL_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepModel.cpp new file mode 100644 index 000000000..2fd9530c3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepModel.cpp @@ -0,0 +1,271 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepModel + * Created: 2025-06-05 + */ + +#include +#include +#include +#include +#include "main/HealthModel.h" +#include "uiservice/ui_service.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "ui_test_group.h" +#include "graphic_timer.h" +#include "ohos_timer.h" +#include "sleep/SleepModel.h" + +namespace OHOS { +static constexpr uint64_t SLEEPMODEL_MINUTE_HOUR = 60; +static constexpr uint64_t SLEEPMODEL_HOUR = 23; +static constexpr uint64_t SLEEPMODEL_MINUTE = 59; +static constexpr uint64_t SLEEPMODEL_ERROR = 100; + +SleepModel::SleepModel() {} + +SleepModel::~SleepModel() {} + +void SleepModel::LoadData() +{ + if (GetRecord() == false) { + SetSleepDataVec(); + SetSoberingTime(); + SetRapidEyeMovementTime(); + SetLightSleepTime(); + SetDeepSleepTime(); + } +} + +bool SleepModel::GetRecord() +{ + if (sleepDataVector_.empty() == true) { + return false; + } + return true; +} + +std::string SleepModel::GetTodayDate() +{ + time_t now = time(nullptr); + struct tm *timeinfo = localtime(&now); + char buffer[80]; + strftime(buffer, sizeof(buffer), "%Y-%m-%d", timeinfo); + return std::string(buffer); +} + +uint8_t *SleepModel::SerializeSleepData(const SleepData *sleepData, size_t *outSize) +{ + if (sleepData == nullptr) { + return nullptr; + } + size_t dataSize = sizeof(SleepData); + *outSize = dataSize; + uint8_t *buffer = new uint8_t[dataSize]; + uint8_t isSendValue = sleepData->isSended ? 1 : 0; + memcpy_s(buffer, sizeof(isSendValue), &isSendValue, sizeof(isSendValue)); + memcpy_s(buffer + offsetof(SleepData, date), sizeof(sleepData->date), sleepData->date, sizeof(sleepData->date)); + memcpy_s(buffer + offsetof(SleepData, type), sizeof(sleepData->type), &sleepData->type, sizeof(sleepData->type)); + memcpy_s(buffer + offsetof(SleepData, typeSleepStart), sizeof(sleepData->typeSleepStart), sleepData->typeSleepStart, + sizeof(sleepData->typeSleepStart)); + memcpy_s(buffer + offsetof(SleepData, typeSleepEnd), sizeof(sleepData->typeSleepEnd), sleepData->typeSleepEnd, + sizeof(sleepData->typeSleepEnd)); + memcpy_s(buffer + offsetof(SleepData, sleepStart), sizeof(sleepData->sleepStart), sleepData->sleepStart, + sizeof(sleepData->sleepStart)); + memcpy_s(buffer + offsetof(SleepData, sleepEnd), sizeof(sleepData->sleepEnd), sleepData->sleepEnd, + sizeof(sleepData->sleepEnd)); + return buffer; +} + +void SleepModel::SendData() +{ + // 发送数据 + size_t dataSize; + for (int i = 0; i < sleepDataVector_.size(); i++) { + if (sleepDataVector_[i].isSended == true) { + continue; + } + uint8_t *serializedData = SerializeSleepData(&sleepDataVector_[i], &dataSize); + errcode_t ret; +#ifdef _WIN32 + ret = 0; +#else + ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SLEEP_DATA, serializedData, dataSize); + delete[] serializedData; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "send sleep data ret = %d", ret); + if (ret == 0) { + sleepDataVector_[i].isSended = true; + } +#endif + } +} + +// sleepDataVector打桩数据,后续需要客户适配传感器自实现 +void SleepModel::SetSleepDataVec() +{ +#ifndef _WIN32 + std::string today = GetTodayDate(); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_DEEP, (today + " 00:00:00").c_str(), + (today + " 00:30:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_EYEMOVE, (today + " 00:30:00").c_str(), + (today + " 03:00:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_LIGHT, (today + " 03:00:00").c_str(), + (today + " 03:30:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_SOBER, (today + " 03:30:00").c_str(), + (today + " 05:30:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_LIGHT, (today + " 05:30:00").c_str(), + (today + " 06:00:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_EYEMOVE, (today + " 06:00:00").c_str(), + (today + " 07:30:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); + + sleepDataVector_.push_back({false, today.c_str(), SLEEP_TYPE_DEEP, (today + " 07:30:00").c_str(), + (today + " 07:50:00").c_str(), (today + " 00:00:00").c_str(), + (today + " 07:50:00").c_str()}); +#endif +} + +SleepModel &SleepModel::GetInstance() +{ + static SleepModel instance; + return instance; +} + +std::tuple SleepModel::GetSoberingTime() +{ + return MinutesToHours(soberingTime_); +} + +std::tuple SleepModel::GetRapidEyeMovementTime() +{ + return MinutesToHours(eyeMoveTime_); +} + +std::tuple SleepModel::GetLightSleepTime() +{ + return MinutesToHours(lightTime_); +} + +std::tuple SleepModel::GetDeepSleepTime() +{ + return MinutesToHours(deepTime_); +} + +std::tuple SleepModel::GetSleepTime() +{ + return MinutesToHours(GetTotalSleepTime()); +} + +std::tuple SleepModel::MinutesToHours(uint32_t minutes) +{ + if (minutes == 0) { + return std::make_tuple(0, 0); + } + int hours = minutes / SLEEPMODEL_MINUTE_HOUR; + int remainingMinutes = minutes % SLEEPMODEL_MINUTE_HOUR; + + if (hours > SLEEPMODEL_HOUR || remainingMinutes > SLEEPMODEL_MINUTE) { + return std::make_tuple(SLEEPMODEL_ERROR, 0); + } + + return std::make_tuple(hours, remainingMinutes); +} + +uint32_t SleepModel::GetSleepTimeHours() +{ + std::tuple timeTuple = GetSleepTime(); + return std::get<0>(timeTuple); +} + +uint32_t SleepModel::GetSleepTimeMinutes() +{ + std::tuple timeTuple = GetSleepTime(); + return std::get<1>(timeTuple); +} + +void SleepModel::SetTargetTime(uint32_t minute) +{ + sleepTarget_ = minute; +} + +std::tuple SleepModel::GetTargetTime() +{ + return MinutesToHours(sleepTarget_); +} + +uint32_t SleepModel::TimeDiffInMinutes(const std::string &timeStr1, const std::string &timeStr2) +{ + std::tm tm1 = {}; + std::tm tm2 = {}; + + std::istringstream iss1(timeStr1); + std::istringstream iss2(timeStr2); + + iss1 >> std::get_time(&tm1, "%Y-%m-%d %H:%M:%S"); + if (iss1.fail()) { + return -1; + } + + iss2 >> std::get_time(&tm2, "%Y-%m-%d %H:%M:%S"); + if (iss2.fail()) { + return -1; + } + + std::time_t t1 = std::mktime(&tm1); + std::time_t t2 = std::mktime(&tm2); + if (t1 == -1 || t2 == -1) { + return -1; + } + + double diff_seconds = std::difftime(t2, t1); + return static_cast(diff_seconds / SLEEPMODEL_MINUTE_HOUR); +} + +// 遍历vector中的结构体 获取对应类型的时间差 +uint32_t SleepModel::GetDetailData(int type) +{ + uint32_t min = 0; + for (size_t i = 0; i < sleepDataVector_.size(); ++i) { + if (sleepDataVector_[i].type == type) { + min += TimeDiffInMinutes(sleepDataVector_[i].typeSleepStart, sleepDataVector_[i].typeSleepEnd); + } + } + return min; +} + +// 获取总睡觉时间的时间差 +uint32_t SleepModel::GetTotalSleepTime() +{ + uint32_t time = TimeDiffInMinutes(sleepDataVector_[0].sleepStart, sleepDataVector_[0].sleepEnd); + return time; +} + +void SleepModel::SetSoberingTime() +{ + soberingTime_ = GetDetailData(SLEEP_TYPE_SOBER); +} +void SleepModel::SetRapidEyeMovementTime() +{ + eyeMoveTime_ = GetDetailData(SLEEP_TYPE_EYEMOVE); +} +void SleepModel::SetLightSleepTime() +{ + lightTime_ = GetDetailData(SLEEP_TYPE_LIGHT); +} +void SleepModel::SetDeepSleepTime() +{ + deepTime_ = GetDetailData(SLEEP_TYPE_DEEP); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepPresenter.cpp new file mode 100644 index 000000000..76ced784e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepPresenter + * Created: 2025-06-05 + */ + +#include "NativeRegisterManager.h" +#include "sleep/SleepView.h" +#include "sleep/SleepPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_SLEEPING, SleepView, SleepPresenter, SLEEP_ICON, SLEEP_ICON, "睡眠"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepSleepingPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepSleepingPage.cpp new file mode 100644 index 000000000..ac175632f --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepSleepingPage.cpp @@ -0,0 +1,372 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepSleepingPage + * Created: 2025-06-05 + */ + +#include +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "common/image_cache_manager.h" +#include "diag_service.h" +#include "msg_center_device.h" +#include "diag_common.h" +#include "sleep/SleepTargetTime.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepSleepingPage.h" + +namespace OHOS { + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_SLEEP_PAGE, SleepSleepingPage, false); + +static constexpr int16_t SLEEPING_SLEEP_X = 97; +static constexpr int16_t SLEEPING_SLEEP_Y = 31; +static constexpr int16_t SLEEPING_SLEEP_WIDTH = 260; +static constexpr int16_t SLEEPING_SLEEP_HEIGHT = 53; +static constexpr int16_t SLEEPING_SLEEP_FONT_SIZE = 38; +static constexpr int16_t SLEEPING_NORECORD_X = 135; +static constexpr int16_t SLEEPING_NORECORD_Y = 220; +static constexpr int16_t SLEEPING_NORECORD_WIDTH = 200; +static constexpr int16_t SLEEPING_NORECORD_HEIGHT = 48; +static constexpr int16_t SLEEPING_NORECORD_FONT_SIZE = 32; +static constexpr int16_t SLEEPING_TIPS_FONT_SIZE = 24; +static constexpr int16_t SLEEPING_FONT_SIZE_LARGE = 40; +static constexpr int16_t SLEEPING_LABEL_WIDTH = 48; +static constexpr int16_t SLEEPING_LABEL_HEIGHT = 29; +static constexpr int16_t SLEEPING_TIME_LABEL_WIDTH = 95; +static constexpr int16_t SLEEPING_TIME_LABEL_HEIGHT = 50; +static constexpr int16_t SLEEPING_ACTUALMINUTE_X = 230; +static constexpr int16_t SLEEPING_ACTUALMINUTE_Y = 314; +static constexpr int16_t ACTUALMINUTES_X = 180; +static constexpr int16_t ACTUALMINUTES_Y = 298; +static constexpr int16_t SLEEPING_HEIGHT = 50; +static constexpr int16_t SLEEPING_CIR_HIGHT = 444; +static constexpr int16_t SLEEPING_CIR_X = 228; +static constexpr int16_t SLEEPING_CIR_Y = 228; +static constexpr int16_t SLEEPING_CIR_RADIUS = 215; +static constexpr int16_t SLEEPING_CIR_ANGLE = 360; +static constexpr int16_t SLEEPING_CIR_LINE_WIDTH = 10; +static constexpr int16_t SLEEPING_TIMETEXT_HIGHT = 95; +static constexpr int16_t SLEEPING_MOON_POSX = 178; +static constexpr int16_t SLEEPING_TIME_ELAPSED = 5; +static constexpr int16_t SLEEPING_BG_X = 120; +static constexpr int16_t SLEEPING_BG_Y = 295; +static constexpr int16_t SLEEPING_TIME_MINUTE_X = 157; +static constexpr int16_t SLEEPING_TIME_HOUR_X = 128; +static constexpr int16_t SLEEPING_TIME_HOUR_TEXT_X = 178; +static constexpr int16_t SLEEPING_TIME_MINUTE1_X = 238; +static constexpr int16_t SLEEPING_TIME_MINUTE1_TEXT_X = 288; + +SleepSleepingPage::SleepSleepingPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepSleepingPage::SleepSleepingPage"); +} + +SleepSleepingPage::~SleepSleepingPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (sleepTitleLabel_ != nullptr) { + delete sleepTitleLabel_; + sleepTitleLabel_ = nullptr; + } + + if (moonImg_ != nullptr) { + delete moonImg_; + moonImg_ = nullptr; + } + + if (sleepingLabel_ != nullptr) { + delete sleepingLabel_; + sleepingLabel_ = nullptr; + } + + if (sleepTimeBgImg_ != nullptr) { + delete sleepTimeBgImg_; + sleepTimeBgImg_ = nullptr; + } + + if (targetSleepTimeHoursLabel_ != nullptr) { + delete targetSleepTimeHoursLabel_; + targetSleepTimeHoursLabel_ = nullptr; + } + + if (targetSleepTimeHoursUnitLabel_ != nullptr) { + delete targetSleepTimeHoursUnitLabel_; + targetSleepTimeHoursUnitLabel_ = nullptr; + } + + if (targetSleepTimeMinutesLabel_ != nullptr) { + delete targetSleepTimeMinutesLabel_; + targetSleepTimeMinutesLabel_ = nullptr; + } + + if (targetSleepTimeMinutesUnitLabel_ != nullptr) { + delete targetSleepTimeMinutesUnitLabel_; + targetSleepTimeMinutesUnitLabel_ = nullptr; + } + + if (circleProgress_ != nullptr) { + delete circleProgress_; + circleProgress_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(SLEEP_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepSleepingPage::~SleepSleepingPage"); +} + +void SleepSleepingPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ is nullptr"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(bgImg_, SLEEP_IMAGE, IMAGE_SLEEP_BACKGROUND); + bgImg_->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group_->Add(bgImg_); + sleepTitleLabel_ = new UILabel(); + if (sleepTitleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepTitleLabel_ is nullptr"); + return; + } + sleepTitleLabel_->SetPosition(SLEEPING_SLEEP_X, SLEEPING_SLEEP_Y); + sleepTitleLabel_->Resize(SLEEPING_SLEEP_WIDTH, SLEEPING_SLEEP_HEIGHT); + sleepTitleLabel_->SetText("睡眠"); + sleepTitleLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleepTitleLabel_->SetTextColor(Color::White()); + sleepTitleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPING_SLEEP_FONT_SIZE); + sleepTitleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(sleepTitleLabel_); + + moonImg_ = new UIImageView(); + if (moonImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "moonImg_ is nullptr"); + return; + } + moonImg_->SetPosition(SLEEPING_MOON_POSX, SLEEPING_TIMETEXT_HIGHT); + LOADIMG::LoadImageViewImg(moonImg_, SLEEP_IMAGE, IMAGE_SLEEP_SLEEPING_MOON); + group_->Add(moonImg_); + + sleepingLabel_ = new UILabel(); + if (sleepingLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepingLabel_ is nullptr"); + return; + } + sleepingLabel_->SetPosition(SLEEPING_NORECORD_X, SLEEPING_NORECORD_Y); + sleepingLabel_->Resize(SLEEPING_NORECORD_WIDTH, SLEEPING_NORECORD_HEIGHT); + sleepingLabel_->SetText("正在睡眠"); + sleepingLabel_->SetTextColor(Color::White()); + sleepingLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPING_NORECORD_FONT_SIZE); + sleepingLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(sleepingLabel_); + + InitCircleProgress(); + InitSleepTimeLabel(); + LoadTargetTimeForHourAndMin(SleepModel::GetInstance().GetTargetTime()); + SleepModel::GetInstance().LoadData(); + + callBack_ = new SleepAnimatorCallback(this); + if (callBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack_ is nullptr"); + return; + } + animator_ = new Animator(callBack_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "animator_ is nullptr"); + return; + } + + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + animator_->Start(); + gettimeofday(&startTime_, nullptr); + AddViewToPageContainer(group_); +} + +void SleepSleepingPage::OnPause() +{ + animator_->Stop(); +} + +void SleepSleepingPage::SleepAnimatorCallback::Callback(UIView *view) +{ + (void)view; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint32_t elapsed_seconds = current_time.tv_sec - page_->startTime_.tv_sec; + if (elapsed_seconds == SLEEPING_TIME_ELAPSED) { + page_->StopAnimator(); + } +} + +void SleepSleepingPage::StopAnimator() +{ + animator_->Stop(); + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); +} + +void SleepSleepingPage::InitSleepTimeLabel() +{ + sleepTimeBgImg_ = new UIImageView(); + if (sleepTimeBgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepTimeBgImg_ is nullptr"); + return; + } + sleepTimeBgImg_->SetPosition(SLEEPING_BG_X, SLEEPING_BG_Y); + LOADIMG::LoadImageViewImg(sleepTimeBgImg_, SLEEP_IMAGE, IMAGE_SLEEP_SLEEPING_TIME); + group_->Add(sleepTimeBgImg_); + + targetSleepTimeHoursLabel_ = new UILabel(); + if (targetSleepTimeHoursLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeHoursLabel_ is nullptr"); + return; + } + targetSleepTimeHoursLabel_->SetTextColor(Color::White()); + targetSleepTimeHoursLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPING_FONT_SIZE_LARGE); + targetSleepTimeHoursLabel_->SetVisible(false); + + targetSleepTimeHoursUnitLabel_ = new UILabel(); + if (targetSleepTimeHoursUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeHoursUnitLabel_ is nullptr"); + return; + } + targetSleepTimeHoursUnitLabel_->SetText("小时"); + targetSleepTimeHoursUnitLabel_->Resize(SLEEPING_LABEL_WIDTH, SLEEPING_LABEL_HEIGHT); + targetSleepTimeHoursUnitLabel_->SetTextColor(Color::White()); + targetSleepTimeHoursUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPING_TIPS_FONT_SIZE); + targetSleepTimeHoursUnitLabel_->SetVisible(false); + + targetSleepTimeMinutesLabel_ = new UILabel(); + if (targetSleepTimeMinutesLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeMinutesLabel_ is nullptr"); + return; + } + targetSleepTimeMinutesLabel_->Resize(SLEEPING_TIME_LABEL_WIDTH, SLEEPING_TIME_LABEL_HEIGHT); + targetSleepTimeMinutesLabel_->SetTextColor(Color::White()); + targetSleepTimeMinutesLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, SLEEPING_FONT_SIZE_LARGE); + targetSleepTimeMinutesLabel_->SetVisible(false); + + targetSleepTimeMinutesUnitLabel_ = new UILabel(); + if (targetSleepTimeMinutesUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetSleepTimeMinutesUnitLabel_ is nullptr"); + return; + } + targetSleepTimeMinutesUnitLabel_->SetText("分钟"); + targetSleepTimeMinutesUnitLabel_->Resize(SLEEPING_LABEL_WIDTH, SLEEPING_LABEL_HEIGHT); + targetSleepTimeMinutesUnitLabel_->SetTextColor(Color::White()); + targetSleepTimeMinutesUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPING_TIPS_FONT_SIZE); + targetSleepTimeMinutesUnitLabel_->SetVisible(false); +} + +void SleepSleepingPage::LoadTargetTimeForHourAndMin(std::tuple timeTuple) +{ + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + if ((hours == 0) && (minutes != 0)) { + targetSleepTimeMinutesLabel_->SetPosition(SLEEPING_TIME_MINUTE_X, ACTUALMINUTES_Y); + targetSleepTimeMinutesLabel_->SetVisible(true); + targetSleepTimeMinutesLabel_->SetText(std::to_string(minutes).c_str()); + targetSleepTimeMinutesLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(targetSleepTimeMinutesLabel_); + + targetSleepTimeMinutesUnitLabel_->SetPosition(SLEEPING_ACTUALMINUTE_X, SLEEPING_ACTUALMINUTE_Y); + targetSleepTimeMinutesUnitLabel_->SetVisible(true); + group_->Add(targetSleepTimeMinutesUnitLabel_); + } else if ((hours != 0) && (minutes == 0)) { + targetSleepTimeHoursLabel_->SetPosition(ACTUALMINUTES_X, ACTUALMINUTES_Y); + targetSleepTimeHoursLabel_->Resize(SLEEPING_HEIGHT, SLEEPING_HEIGHT); + targetSleepTimeHoursLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + targetSleepTimeHoursLabel_->SetVisible(true); + targetSleepTimeHoursLabel_->SetText(std::to_string(hours).c_str()); + group_->Add(targetSleepTimeHoursLabel_); + + targetSleepTimeHoursUnitLabel_->SetPosition(SLEEPING_ACTUALMINUTE_X, SLEEPING_ACTUALMINUTE_Y); + targetSleepTimeHoursUnitLabel_->SetVisible(true); + group_->Add(targetSleepTimeHoursUnitLabel_); + } else if ((hours != 0) && (minutes != 0)) { + targetSleepTimeHoursLabel_->SetPosition(SLEEPING_TIME_HOUR_X, ACTUALMINUTES_Y); + targetSleepTimeHoursLabel_->Resize(SLEEPING_HEIGHT, SLEEPING_HEIGHT); + targetSleepTimeHoursLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + targetSleepTimeHoursLabel_->SetVisible(true); + targetSleepTimeHoursLabel_->SetText(std::to_string(hours).c_str()); + group_->Add(targetSleepTimeHoursLabel_); + + targetSleepTimeHoursUnitLabel_->SetPosition(SLEEPING_TIME_HOUR_TEXT_X, SLEEPING_ACTUALMINUTE_Y); + targetSleepTimeHoursUnitLabel_->Resize(SLEEPING_HEIGHT, SLEEPING_LABEL_HEIGHT); + targetSleepTimeHoursUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + targetSleepTimeHoursUnitLabel_->SetVisible(true); + group_->Add(targetSleepTimeHoursUnitLabel_); + + targetSleepTimeMinutesLabel_->SetPosition(SLEEPING_TIME_MINUTE1_X, ACTUALMINUTES_Y); + targetSleepTimeMinutesLabel_->Resize(SLEEPING_HEIGHT, SLEEPING_HEIGHT); + targetSleepTimeMinutesLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + targetSleepTimeMinutesLabel_->SetVisible(true); + targetSleepTimeMinutesLabel_->SetText(std::to_string(minutes).c_str()); + group_->Add(targetSleepTimeMinutesLabel_); + + targetSleepTimeMinutesUnitLabel_->SetPosition(SLEEPING_TIME_MINUTE1_TEXT_X, SLEEPING_ACTUALMINUTE_Y); + targetSleepTimeMinutesUnitLabel_->Resize(SLEEPING_HEIGHT, SLEEPING_LABEL_HEIGHT); + targetSleepTimeMinutesUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + targetSleepTimeMinutesUnitLabel_->SetVisible(true); + group_->Add(targetSleepTimeMinutesUnitLabel_); + } +} + +void SleepSleepingPage::InitCircleProgress() +{ + circleProgress_ = new UICircleProgress(); + if (circleProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgress_ is nullptr"); + return; + } + circleProgress_->SetPosition(0, 0); + circleProgress_->Resize(SLEEPING_CIR_HIGHT, SLEEPING_CIR_HIGHT); + circleProgress_->SetCenterPosition(SLEEPING_CIR_X, SLEEPING_CIR_Y); + circleProgress_->SetRadius(SLEEPING_CIR_RADIUS); + circleProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0xFF6f29a0); + circleProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xFFB566FF); + circleProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, SLEEPING_CIR_LINE_WIDTH); + circleProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, SLEEPING_CIR_LINE_WIDTH); + circleProgress_->SetStartAngle(0); + circleProgress_->SetEndAngle(SLEEPING_CIR_ANGLE); + circleProgress_->SetRange(SLEEPING_TIME_ELAPSED, 0); + circleProgress_->SetValue(SLEEPING_TIME_ELAPSED); + group_->Add(circleProgress_); + circleProgress_->Invalidate(); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepTargetTime.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepTargetTime.cpp new file mode 100644 index 000000000..3f9c450d6 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sleep/src/SleepTargetTime.cpp @@ -0,0 +1,322 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepTargetTime + * Created: 2025-06-05 + */ +#include +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "common/image_cache_manager.h" +#include "sleep/SleepMainPage.h" +#include "sleep/SleepPresenter.h" +#include "sleep/SleepView.h" +#include "sleep/SleepTargetTime.h" + +namespace OHOS { +static constexpr uint8_t BACKGROUND_FONT = 40; +static constexpr uint8_t HIGHTLIGHT_FONT = 55; +static constexpr int16_t TARGET_SLEEP_SETTARGET_X = 120; +static constexpr int16_t TARGET_SLEEP_SETTARGET_Y = 40; +static constexpr int16_t TARGET_SLEEP_SETTARGET_WIDTH = 200; +static constexpr int16_t TARGET_SLEEP_SETTARGET_HIGHT = 38; +static constexpr int16_t TARGET_SLEEP_SETTARGET_FONT_SIZE = 32; +static constexpr int16_t TARGET_SLEEP_START_X = 112; +static constexpr int16_t TARGET_SLEEP_START_Y = 347; +static constexpr int16_t TARGET_SLEEP_START_WIDTH = 232; +static constexpr int16_t TARGET_SLEEP_START_HIGHT = 76; +static constexpr int16_t TARGET_SLEEP_PICKER2_X = 270; +static constexpr int16_t TARGET_SLEEP_PICKER_Y = 132; +static constexpr int16_t TARGET_SLEEP_PICKER_WIDTH = 80; +static constexpr int16_t TARGET_SLEEP_PICKER_HIGHT = 185; +static constexpr int16_t TARGET_SLEEP_PICKER_BORDER = 3; +static constexpr int16_t TARGET_SLEEP_PICKER_RADIUS = 11; +static constexpr int16_t TARGET_SLEEP_PICKER_ITEM = 70; +static constexpr int16_t TARGET_SLEEP_PICKER_HOUR = 24; +static constexpr int16_t TARGET_SLEEP_PICKER_MINUTE = 60; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_X = 131; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL2_X = 273; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_Y = 99; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL2_Y = 90; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_WIDTH = 55; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_HEIGHT = 30; +static constexpr uint8_t TIMERLABEL_FONT = 24; +static constexpr int16_t TARGET_SLEEP_COLOR_R = 181; +static constexpr int16_t TARGET_SLEEP_COLOR_G = 402; +static constexpr int16_t TARGET_SLEEP_COLOR_B = 255; +static constexpr int16_t TARGET_SLEEP_PICKER1_X = 115; +static constexpr int16_t TARGET_SLEEP_PICKER2_Y = 255; +static constexpr char *START_BUTTON = "start"; +static constexpr char *HOUR_PICKER = "hourPicker"; +static constexpr char *MIN_PICKER = "minPicker"; + +// 时间选择器分钟列 +static const char *g_uiPickerMinute[] = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", + "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", + "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", + "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}; + +// 时间选择器小时列 +static const char *g_uiPickerHour[] = {"00", "01", "02", "03", "04", "05", "06", "07", + "08", "09", "10", "11", "12", "13", "14", "15", + "16", "17", "18", "19", "20", "21", "22", "23"}; + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_TARGET_PAGE, SleepTargetTime, false); + +SleepTargetTime::SleepTargetTime() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepTargetTime::SleepTargetTime"); +} + +SleepTargetTime::~SleepTargetTime() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (targetTitleLabel_ != nullptr) { + delete targetTitleLabel_; + targetTitleLabel_ = nullptr; + } + + if (timerUnitLabel_ != nullptr) { + delete timerUnitLabel_; + timerUnitLabel_ = nullptr; + } + + if (startButton_ != nullptr) { + delete startButton_; + startButton_ = nullptr; + } + + for (int i = 0; i < PICKER_COUNT; i++) { + if (timerPicker_[i] != nullptr) { + delete timerPicker_[i]; + timerPicker_[i] = nullptr; + } + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(SLEEP_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepTargetTime::~SleepTargetTime"); +} + +void SleepTargetTime::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ is nullptr"); + return; + } + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + targetTitleLabel_ = new UILabel(); + if (targetTitleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetTitleLabel_ is nullptr"); + return; + } + targetTitleLabel_->SetPosition(TARGET_SLEEP_SETTARGET_X, TARGET_SLEEP_SETTARGET_Y); + targetTitleLabel_->Resize(TARGET_SLEEP_SETTARGET_WIDTH, TARGET_SLEEP_SETTARGET_HIGHT); + targetTitleLabel_->SetText("设置目标"); + targetTitleLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + targetTitleLabel_->SetTextColor(Color::White()); + targetTitleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, TARGET_SLEEP_SETTARGET_FONT_SIZE); + targetTitleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(targetTitleLabel_); + + InitStartButton(); + CreateLabel(); + CreatePicker(); + + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + AddViewToPageContainer(group_); +} + +void SleepTargetTime::InitStartButton() +{ + startButton_ = new UILabelButton(); + if (startButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startButton_ is nullptr"); + return; + } + startButton_->SetPosition(TARGET_SLEEP_START_X, TARGET_SLEEP_START_Y); + startButton_->Resize(TARGET_SLEEP_START_WIDTH, TARGET_SLEEP_START_HIGHT); + startButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + startButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + startButton_->SetViewId(START_BUTTON); + startButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TARGET_SLEEP_SETTARGET_FONT_SIZE); + startButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Purple().full); + startButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::White().full, UIButton::PRESSED); + startButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::White().full, UIButton::RELEASED); + startButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + startButton_->SetText("开始"); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_START_GRAY, IMAGE_SLEEP_START_GRAY); + startButton_->SetOnClickListener(this); + startButton_->Disable(); + group_->Add(startButton_); +} + +void SleepTargetTime::SetPickerTime() +{ + std::tuple time = SleepModel::GetInstance().GetTargetTime(); + uint32_t timeHours = std::get<0>(time); + uint32_t timeMinutes = std::get<1>(time); + timerPicker_[0]->SetSelected(timeHours); + timerPicker_[1]->SetSelected(timeMinutes); +} + +void SleepTargetTime::CreatePicker() +{ + int posX[PICKER_COUNT] = {TARGET_SLEEP_PICKER1_X, TARGET_SLEEP_PICKER2_Y}; + int posY = TARGET_SLEEP_PICKER_Y; + for (int i = 0; i < PICKER_COUNT; i++) { + if (timerPicker_[i] == nullptr) { + timerPicker_[i] = new UIPicker(); + } + timerPicker_[i]->SetPosition(posX[i], posY); + timerPicker_[i]->Resize(TARGET_SLEEP_PICKER_WIDTH, TARGET_SLEEP_PICKER_HIGHT); + timerPicker_[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timerPicker_[i]->SetStyle(STYLE_BORDER_WIDTH, TARGET_SLEEP_PICKER_BORDER); + timerPicker_[i]->SetStyle(STYLE_BORDER_RADIUS, TARGET_SLEEP_PICKER_RADIUS); + timerPicker_[i]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[i]->SetItemHeight(TARGET_SLEEP_PICKER_ITEM); + timerPicker_[i]->SetLoopState(true); + timerPicker_[i]->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + timerPicker_[i]->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + timerPicker_[i]->SetTextColor(Color::Gray(), Color::White()); + if (i == 0) { + timerPicker_[i]->SetValues(g_uiPickerHour, TARGET_SLEEP_PICKER_HOUR); + } else { + timerPicker_[i]->SetValues(g_uiPickerMinute, TARGET_SLEEP_PICKER_MINUTE); + } + timerPicker_[i]->SetOnClickListener(this); + timerPicker_[i]->SetOnDragListener(this); + timerPicker_[i]->RegisterSelectedListener(this); + timerPicker_[i]->SetDraggable(true); + group_->Add(timerPicker_[i]); + } + + timerPicker_[0]->SetViewId(HOUR_PICKER); + timerPicker_[1]->SetViewId(MIN_PICKER); + if (SleepModel::GetInstance().GetRecord() == true) { + startButton_->SetTextColor(Color::White()); + startButton_->Enable(); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_SETTIMEBTN, IMAGE_SLEEP_SETTIMEBTN); + SetPickerTime(); + } else { + timerPicker_[0]->SetSelected(0); + timerPicker_[1]->SetSelected(0); + } +} + +bool SleepTargetTime::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), START_BUTTON) == 0) { + uint8_t hour = std::stoi(g_uiPickerHour[timerPicker_[0]->GetSelected()]); + uint8_t minute = std::stoi(g_uiPickerMinute[timerPicker_[1]->GetSelected()]); + SleepModel::GetInstance().SetTargetTime((hour * TARGET_SLEEP_PICKER_MINUTE) + minute); + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_SLEEP_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void SleepTargetTime::CreateLabel() +{ + timerUnitLabel_ = new UILabel(); + if (timerUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timerUnitLabel_ is nullptr"); + return; + } + timerUnitLabel_->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL_Y); + timerUnitLabel_->Resize(TARGET_SLEEP_TIMERLABEL_WIDTH, TARGET_SLEEP_TIMERLABEL_HEIGHT); + timerUnitLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + timerUnitLabel_->SetText("小时"); + timerUnitLabel_->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFB566FF); + timerUnitLabel_->SetTextColor(Color::Black()); + timerUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timerUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMERLABEL_FONT); + timerUnitLabel_->SetVisible(false); + group_->Add(timerUnitLabel_); +} + +bool SleepTargetTime::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SLEEPING_PAGES::SLEEPING_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + if (strcmp(view.GetViewId(), HOUR_PICKER) == 0) { + timerPicker_[0]->SetStyle( + STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerUnitLabel_->SetVisible(true); + timerUnitLabel_->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerUnitLabel_->SetText("小时"); + timerUnitLabel_->Invalidate(); + } else if (strcmp(view.GetViewId(), MIN_PICKER) == 0) { + timerPicker_[1]->SetStyle( + STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerUnitLabel_->SetVisible(true); + timerUnitLabel_->SetPosition(TARGET_SLEEP_TIMERLABEL2_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerUnitLabel_->SetText("分钟"); + timerUnitLabel_->Invalidate(); + } + return true; +} + +void SleepTargetTime::OnPickerStoped(UIPicker &picker) +{ + if (strcmp(picker.GetViewId(), HOUR_PICKER) == 0) { + uint16_t hour = picker.GetSelected(); + picker.SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + picker.Invalidate(); + if ((hour == 0) && (timerPicker_[1]->GetSelected() == 0)) { + startButton_->Disable(); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_START_GRAY, IMAGE_SLEEP_START_GRAY); + } else { + startButton_->SetTextColor(Color::White()); + startButton_->Enable(); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_SETTIMEBTN, IMAGE_SLEEP_SETTIMEBTN); + } + timerUnitLabel_->SetVisible(true); + timerUnitLabel_->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerUnitLabel_->SetText("小时"); + timerUnitLabel_->Invalidate(); + } else if (strcmp(picker.GetViewId(), MIN_PICKER) == 0) { + uint16_t minute = picker.GetSelected(); + picker.SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + picker.Invalidate(); + if ((minute == 0) && (timerPicker_[0]->GetSelected() == 0)) { + startButton_->Disable(); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_START_GRAY, IMAGE_SLEEP_START_GRAY); + } else { + startButton_->SetTextColor(Color::White()); + startButton_->Enable(); + LOADIMG::LoadBtnImage(startButton_, SLEEP_IMAGE, IMAGE_SLEEP_SETTIMEBTN, IMAGE_SLEEP_SETTIMEBTN); + } + timerUnitLabel_->SetVisible(true); + timerUnitLabel_->SetPosition(TARGET_SLEEP_TIMERLABEL2_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerUnitLabel_->SetText("分钟"); + timerUnitLabel_->Invalidate(); + } +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportCountdownPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportCountdownPage.cpp new file mode 100644 index 000000000..f08e4ad7a --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportCountdownPage.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportCountdownPage + * Create: 2025-06-06 + */ + +#include +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportCountdownPage.h" + +namespace OHOS { +static constexpr uint16_t TEXT_X = 164; +static constexpr uint16_t TEXT_Y = 154; +static constexpr uint16_t TEXT_W = 132; +static constexpr uint16_t TEXT_H = 132; +static constexpr uint16_t TEXT_FONT = 120; +static constexpr uint16_t PROCESS_X = 90; +static constexpr uint16_t PROCESS_Y = 90; +static constexpr uint16_t PROCESS_W = 273; +static constexpr uint16_t PROCESS_H = 273; +static constexpr uint16_t PROCESS_CENTER_X = 135; +static constexpr uint16_t PROCESS_CENTER_Y = 135; +static constexpr uint16_t PROCESS_MAX_RANGE = 100; +static constexpr uint16_t PROCESS_RADIUS = 120; +static constexpr uint16_t PROCESS_START_ANGLE = 360; +static constexpr uint16_t PROCESS_LINE_WIDTH = 20; +static constexpr uint16_t COUNTDOWN_TIME = 3; +static constexpr uint32_t MICRO_SECONDS_PER_SECOND = 1000000; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_COUNTDOWN, SportCountdownPage, false); + +void SportCountdownPage::UpdateCountdownView(uint64_t time) +{ + uint8_t reminTime = COUNTDOWN_TIME - (time / MICRO_SECONDS_PER_SECOND); + if (reminTime != 0) { + countdownText_->SetText(std::to_string(reminTime).c_str()); + } + double precent = static_cast(time) / (COUNTDOWN_TIME * MICRO_SECONDS_PER_SECOND); + countdownProgress_->SetValue(precent * PROCESS_MAX_RANGE); +} + +void SportCountdownPage::SportCountdownAnimatorCallback::Callback(UIView *view) +{ + UNUSED(view); + struct timeval currTime = {0}; + gettimeofday(&currTime, nullptr); + uint64_t time = ((uint64_t)currTime.tv_sec * MICRO_SECONDS_PER_SECOND + currTime.tv_usec) - + ((uint64_t)page_->startTime_.tv_sec * MICRO_SECONDS_PER_SECOND + page_->startTime_.tv_usec); + page_->UpdateCountdownView(time); + if (time / MICRO_SECONDS_PER_SECOND >= COUNTDOWN_TIME) { + page_->animator_->Stop(); + SportModel::GetInstance().StartSport(true); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_DATA, + TransitionType::TRANSITION_INVALID, false); + } +} + +SportCountdownPage::~SportCountdownPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (countdownText_ != nullptr) { + delete countdownText_; + countdownText_ = nullptr; + } + if (countdownProgress_ != nullptr) { + delete countdownProgress_; + countdownProgress_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportCountdownPage::~SportCountdownPage"); +} + +void SportCountdownPage::OnStart(void *data) +{ + gettimeofday(&startTime_, nullptr); + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportCountdownPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + countdownText_ = new UILabel(); + if (countdownText_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportCountdownPage countdownText_ new fail"); + return; + } + countdownText_->SetPosition(TEXT_X, TEXT_Y, TEXT_W, TEXT_H); + countdownText_->SetFont(BOLD_VECTOR_FONT_FILENAME, TEXT_FONT); + countdownText_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(countdownText_); + + countdownProgress_ = new UICircleProgress(); + if (countdownProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportCountdownPage new countdownProgress_ fail"); + return; + } + countdownProgress_->SetPosition(PROCESS_X, PROCESS_Y, PROCESS_W, PROCESS_H); + countdownProgress_->SetCenterPosition(PROCESS_CENTER_X, PROCESS_CENTER_Y); + countdownProgress_->SetRange(PROCESS_MAX_RANGE, 0); + countdownProgress_->SetRadius(PROCESS_RADIUS); + countdownProgress_->SetStartAngle(PROCESS_START_ANGLE); + countdownProgress_->SetEndAngle(0); + countdownProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff14d3dd); + countdownProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, PROCESS_LINE_WIDTH); + countdownProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0xff549490); + countdownProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, PROCESS_LINE_WIDTH); + group_->Add(countdownProgress_); + AddViewToPageContainer(group_); + + callback_ = new SportCountdownAnimatorCallback(this); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportCountdownPage::OnStart callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportCountdownPage::OnStart new Animator animator_ fail"); + return; + } +} + +void SportCountdownPage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } +} + +void SportCountdownPage::OnResume() +{ + if (animator_ != nullptr) { + if (animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } +} + +bool SportCountdownPage::OnDrag(UIView &view, const DragEvent &event) +{ + return false; +} + +bool SportCountdownPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportDataPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportDataPage.cpp new file mode 100644 index 000000000..1b26a0e89 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportDataPage.cpp @@ -0,0 +1,632 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportDataPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "settings/model/SettingPowerModel.h" +#include "sport/SportView.h" +#include "sport/SportDataPage.h" + +namespace OHOS { +static constexpr uint16_t TARGET_HALF = 2; +static constexpr uint16_t NUM_ONE = 1; +static constexpr uint16_t NUM_THOUSAND = 1000; +static constexpr uint16_t BATTERY_LEVEL1 = 10; +static constexpr uint16_t BATTERY_LEVEL2 = 20; +static constexpr uint16_t BATTERY_LEVEL3 = 40; +static constexpr uint16_t BATTERY_LEVEL4 = 70; +static constexpr uint16_t BATTERY_LEVEL5 = 100; +static constexpr uint16_t UNIT_SECS_PER_MIN = 60; +static constexpr uint16_t HAND_POSITION_XPOS = 224; +static constexpr uint16_t HAND_POSITION_YPOS = 4; +static constexpr uint16_t HAND_CENTER_XPOS = 3; +static constexpr uint16_t HAND_CENTER_YPOS = 223; +static constexpr uint16_t HAND_WIDTH = 2; +static constexpr uint16_t HAND_HEIGHT = 5; +static constexpr uint16_t HEARTBEAT_MIN = 116; +static constexpr uint16_t HEARTBEAT_MID = 156; +static constexpr uint16_t HEARTBEAT_MAX = 195; +static constexpr uint16_t HEARTBEAT_CONVERT_UNIT = 600; +static constexpr uint16_t HEARTBEAT_BASE1 = 24000; +static constexpr uint16_t HEARTBEAT_BASE2 = 36000; +static constexpr uint16_t HEARTBEAT_IMAGE_X = 132; +static constexpr uint16_t HEARTBEAT_IMAGE_Y = 174; +static constexpr uint16_t BATTERY_ICON_X = 160; +static constexpr uint16_t BATTERY_ICON_Y = 405; +static constexpr uint16_t BATTERY_LABEL_FONT = 20; +static constexpr uint16_t BATTERY_LABEL_X = 164; +static constexpr uint16_t BATTERY_LABEL_Y = 405; +static constexpr uint16_t BATTERY_LABEL_W = 35; +static constexpr uint16_t BATTERY_LABEL_H = 20; +static constexpr uint16_t TIME_LABEL_FONT = 32; +static constexpr uint16_t TIME_LABEL_X = 219; +static constexpr uint16_t TIME_LABEL_Y = 395; +static constexpr uint16_t TIME_LABEL_W = 84; +static constexpr uint16_t TIME_LABEL_H = 47; +static constexpr uint16_t TOP_VALUE_LABEL_FONT = 100; +static constexpr uint16_t VALUE_LABEL_FONT = 56; +static constexpr uint16_t UNIT_LABEL_FONT = 24; +static constexpr uint16_t TOP_VALUE_LABEL_X = 142; +static constexpr uint16_t TOP_VALUE_LABEL_Y = 73; +static constexpr uint16_t TOP_VALUE_LABEL_W = 172; +static constexpr uint16_t TOP_VALUE_LABEL_H = 100; +static constexpr uint16_t TOP_UNIT_LABEL_X = 160; +static constexpr uint16_t TOP_UNIT_LABEL_Y = 173; +static constexpr uint16_t TOP_UNIT_LABEL_W = 166; +static constexpr uint16_t TOP_UNIT_LABEL_H = 25; +static constexpr uint16_t LEFT_VALUE_LABEL_X = 44; +static constexpr uint16_t LEFT_VALUE_LABEL_Y = 212; +static constexpr uint16_t LEFT_VALUE_LABEL_W = 175; +static constexpr uint16_t LEFT_VALUE_LABEL_H = 56; +static constexpr uint16_t LEFT_UNIT_LABEL_X = 44; +static constexpr uint16_t LEFT_UNIT_LABEL_Y = 272; +static constexpr uint16_t LEFT_UNIT_LABEL_W = 175; +static constexpr uint16_t LEFT_UNIT_LABEL_H = 25; +static constexpr uint16_t RIGHT_VALUE_LABEL_X = 227; +static constexpr uint16_t RIGHT_VALUE_LABEL_Y = 212; +static constexpr uint16_t RIGHT_VALUE_LABEL_W = 175; +static constexpr uint16_t RIGHT_VALUE_LABEL_H = 56; +static constexpr uint16_t RIGHT_UNIT_LABEL_X = 227; +static constexpr uint16_t RIGHT_UNIT_LABEL_Y = 272; +static constexpr uint16_t RIGHT_UNIT_LABEL_W = 175; +static constexpr uint16_t RIGHT_UNIT_LABEL_H = 25; +static constexpr uint16_t BOTTOM_VALUE_LABEL_X = 120; +static constexpr uint16_t BOTTOM_VALUE_LABEL_Y = 309; +static constexpr uint16_t BOTTOM_VALUE_LABEL_W = 221; +static constexpr uint16_t BOTTOM_VALUE_LABEL_H = 56; +static constexpr uint16_t BOTTOM_UNIT_LABEL_X = 205; +static constexpr uint16_t BOTTOM_UNIT_LABEL_Y = 369; +static constexpr uint16_t BOTTOM_UNIT_LABEL_W = 50; +static constexpr uint16_t BOTTOM_UNIT_LABEL_H = 25; +static constexpr uint16_t SEP_LINE_X = 225; +static constexpr uint16_t SEP_LINE_Y = 220; +static constexpr uint16_t SEP_LINE_W = 2; +static constexpr uint16_t SEP_LINE_H = 80; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_DATA, SportDataPage, false); + +void SportDataPage::SportDataAnimatorCallback::Callback(UIView *view) +{ + UNUSED(view); + + uint16_t heartRate = SportModel::GetInstance().GetHeartRate(); + if (heartRate < HEARTBEAT_MIN) { + heartRate = HEARTBEAT_BASE2; + } else if (heartRate < HEARTBEAT_MID) { + heartRate = (heartRate - HEARTBEAT_MIN) * HEARTBEAT_CONVERT_UNIT + HEARTBEAT_BASE2; + } else if (heartRate < HEARTBEAT_MAX) { + heartRate = (heartRate - HEARTBEAT_MID) * HEARTBEAT_CONVERT_UNIT; + } else { + heartRate = HEARTBEAT_BASE1; + } + page_->sweepClock_->SetSweepTime24Hour(0, 0, heartRate); + page_->sweepClock_->Invalidate(); + + std::string currTime = GetCurrentTimeStr(); + page_->timeLabel_->SetText(currTime.c_str()); + page_->timeLabel_->Invalidate(); + + uint8_t battery = SettingPowerModel::GetInstance().GetBatteryPowerLevel(); + page_->batteryLabel_->SetText(std::to_string(battery).c_str()); + page_->batteryLabel_->Invalidate(); + + if (battery < BATTERY_LEVEL1) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY1); + } else if (battery < BATTERY_LEVEL2) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY2); + } else if (battery < BATTERY_LEVEL3) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY3); + } else if (battery < BATTERY_LEVEL4) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY4); + } else if (battery <= BATTERY_LEVEL5) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY5); + } + + page_->UpdateDataViewByType(); + page_->CheckTarget(); + page_->CheckRemind(); +} + +SportDataPage::~SportDataPage() +{ + if (sweepClock_ != nullptr) { + sweepClock_->RemoveAll(); + delete sweepClock_; + sweepClock_ = nullptr; + } + if (timeLabel_ != nullptr) { + delete timeLabel_; + timeLabel_ = nullptr; + } + if (batteryIcon_ != nullptr) { + delete batteryIcon_; + batteryIcon_ = nullptr; + } + if (batteryLabel_ != nullptr) { + delete batteryLabel_; + batteryLabel_ = nullptr; + } + if (heartRateScale_ != nullptr) { + delete heartRateScale_; + heartRateScale_ = nullptr; + } + if (heartRatePointer_ != nullptr) { + delete heartRatePointer_; + heartRatePointer_ = nullptr; + } + if (separateLine_ != nullptr) { + delete separateLine_; + separateLine_ = nullptr; + } + if (topValueLabel_ != nullptr) { + delete topValueLabel_; + topValueLabel_ = nullptr; + } + if (topUnitLabel_ != nullptr) { + delete topUnitLabel_; + topUnitLabel_ = nullptr; + } + if (leftValueLabel_ != nullptr) { + delete leftValueLabel_; + leftValueLabel_ = nullptr; + } + if (leftUnitLabel_ != nullptr) { + delete leftUnitLabel_; + leftUnitLabel_ = nullptr; + } + if (rightValueLabel_ != nullptr) { + delete rightValueLabel_; + rightValueLabel_ = nullptr; + } + if (rightUnitLabel_ != nullptr) { + delete rightUnitLabel_; + rightUnitLabel_ = nullptr; + } + if (bottomValueLabel_ != nullptr) { + delete bottomValueLabel_; + bottomValueLabel_ = nullptr; + } + if (bottomUnitLabel_ != nullptr) { + delete bottomUnitLabel_; + bottomUnitLabel_ = nullptr; + } + if (secondHand_ != nullptr) { + delete secondHand_; + secondHand_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportDataPage::~SportDataPage"); +} + +void SportDataPage::InitTimeLableVIew() +{ + timeLabel_ = new UILabel(); + if (timeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage timeLabel_ new fail"); + return; + } + timeLabel_->SetPosition(TIME_LABEL_X, TIME_LABEL_Y, TIME_LABEL_W, TIME_LABEL_H); + timeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT); + timeLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sweepClock_->Add(timeLabel_); +} + +void SportDataPage::InitBatteryView() +{ + batteryIcon_ = new UIImageView(); + if (batteryIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage batteryIcon_ new fail"); + return; + } + batteryIcon_->SetPosition(BATTERY_ICON_X, BATTERY_ICON_Y); + batteryIcon_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sweepClock_->Add(batteryIcon_); + + batteryLabel_ = new UILabel(); + if (batteryLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage batteryLabel_ new fail"); + return; + } + batteryLabel_->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, BATTERY_LABEL_W, BATTERY_LABEL_H); + batteryLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BATTERY_LABEL_FONT); + batteryLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sweepClock_->Add(batteryLabel_); +} + +void SportDataPage::ShowUpHeartRate() +{ + heartRateScale_ = new UIImageView(); + if (heartRateScale_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage heartRateScale_ new fail"); + return; + } + heartRateScale_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(heartRateScale_, SPORT_IMAGE, IMAGE_SPORT_SCALE); + sweepClock_->Add(heartRateScale_); + + heartRatePointer_ = new UIImageView(); + if (heartRatePointer_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage heartRatePointer_ new fail"); + return; + } + heartRatePointer_->SetPosition(HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y); + LOADIMG::LoadImageViewImg(heartRatePointer_, SPORT_IMAGE, IMAGE_SPORT_HEART2); + sweepClock_->Add(heartRatePointer_); + + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_CLIMBING) { + heartRatePointer_->SetVisible(false); + } else { + heartRatePointer_->SetVisible(true); + } +} + +void SportDataPage::ShowUpTopView() +{ + topValueLabel_ = new UILabel(); + if (topValueLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage topValueLabel_ new fail"); + return; + } + topValueLabel_->SetPosition(TOP_VALUE_LABEL_X, TOP_VALUE_LABEL_Y, TOP_VALUE_LABEL_W, TOP_VALUE_LABEL_H); + topValueLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + topValueLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TOP_VALUE_LABEL_FONT); + sweepClock_->Add(topValueLabel_); + + topUnitLabel_ = new UILabel(); + if (topUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage topUnitLabel_ new fail"); + return; + } + topUnitLabel_->SetPosition(TOP_UNIT_LABEL_X, TOP_UNIT_LABEL_Y, TOP_UNIT_LABEL_W, TOP_UNIT_LABEL_H); + topUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + topUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + sweepClock_->Add(topUnitLabel_); +} + +void SportDataPage::ShowUpLeftView() +{ + leftValueLabel_ = new UILabel(); + if (leftValueLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage leftValueLabel_ new fail"); + return; + } + leftValueLabel_->SetPosition(LEFT_VALUE_LABEL_X, LEFT_VALUE_LABEL_Y, LEFT_VALUE_LABEL_W, LEFT_VALUE_LABEL_H); + leftValueLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + leftValueLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + sweepClock_->Add(leftValueLabel_); + + leftUnitLabel_ = new UILabel(); + if (leftUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage leftUnitLabel_ new fail"); + return; + } + leftUnitLabel_->SetPosition(LEFT_UNIT_LABEL_X, LEFT_UNIT_LABEL_Y, LEFT_UNIT_LABEL_W, LEFT_UNIT_LABEL_H); + leftUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + leftUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + sweepClock_->Add(leftUnitLabel_); +} + +void SportDataPage::ShowUpRightView() +{ + rightValueLabel_ = new UILabel(); + if (rightValueLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage rightValueLabel_ new fail"); + return; + } + rightValueLabel_->SetPosition(RIGHT_VALUE_LABEL_X, RIGHT_VALUE_LABEL_Y, RIGHT_VALUE_LABEL_W, RIGHT_VALUE_LABEL_H); + rightValueLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rightValueLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + sweepClock_->Add(rightValueLabel_); + + rightUnitLabel_ = new UILabel(); + if (rightUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage rightUnitLabel_ new fail"); + return; + } + rightUnitLabel_->SetPosition(RIGHT_UNIT_LABEL_X, RIGHT_UNIT_LABEL_Y, RIGHT_UNIT_LABEL_W, RIGHT_UNIT_LABEL_H); + rightUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rightUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + sweepClock_->Add(rightUnitLabel_); +} + +void SportDataPage::ShowUpBottomView() +{ + bottomValueLabel_ = new UILabel(); + if (bottomValueLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage bottomValueLabel_ new fail"); + return; + } + bottomValueLabel_->SetPosition(BOTTOM_VALUE_LABEL_X, BOTTOM_VALUE_LABEL_Y, BOTTOM_VALUE_LABEL_W, + BOTTOM_VALUE_LABEL_H); + bottomValueLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + bottomValueLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + sweepClock_->Add(bottomValueLabel_); + + bottomUnitLabel_ = new UILabel(); + if (bottomUnitLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage bottomUnitLabel_ new fail"); + return; + } + bottomUnitLabel_->SetPosition(BOTTOM_UNIT_LABEL_X, BOTTOM_UNIT_LABEL_Y, BOTTOM_UNIT_LABEL_W, BOTTOM_UNIT_LABEL_H); + bottomUnitLabel_->SetText("时间"); + bottomUnitLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + bottomUnitLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + sweepClock_->Add(bottomUnitLabel_); +} + +void SportDataPage::ShowUpSeparateLine() +{ + separateLine_ = new UICanvas(); + if (separateLine_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage ShowUpSeparateLine new fail"); + return; + } + separateLine_->SetPosition(SEP_LINE_X, SEP_LINE_Y, SEP_LINE_W, SEP_LINE_H); + separateLine_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + sweepClock_->Add(separateLine_); +} + +void SportDataPage::OnStart(void *data) +{ + sweepClock_ = new UISweepClock(); + if (sweepClock_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage sweepClock_ new fail"); + return; + } + sweepClock_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + sweepClock_->SetOnDragListener(this); + sweepClock_->SetDraggable(true); + sweepClock_->SetTouchable(true); + + secondHand_ = new Image(); + if (secondHand_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return; + } + LOADIMG::LoadImageImg(secondHand_, SPORT_IMAGE, IMAGE_SPORT_TRIANGLE); + sweepClock_->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand_, + {HAND_POSITION_XPOS, HAND_POSITION_YPOS}, {HAND_CENTER_XPOS, HAND_CENTER_YPOS}); + sweepClock_->SetHandLine(UISweepClock::HandType::HOUR_HAND, {HAND_POSITION_XPOS, HAND_POSITION_YPOS}, + {HAND_CENTER_XPOS, HAND_CENTER_YPOS}, Color::White(), HAND_WIDTH, HAND_HEIGHT, + OPA_TRANSPARENT); + sweepClock_->SetHandLine(UISweepClock::HandType::MINUTE_HAND, {HAND_POSITION_XPOS, HAND_POSITION_YPOS}, + {HAND_CENTER_XPOS, HAND_CENTER_YPOS}, Color::White(), HAND_WIDTH, HAND_HEIGHT, + OPA_TRANSPARENT); + sweepClock_->SetWorkMode(UISweepClock::WorkMode::NORMAL); + + ShowUpHeartRate(); + InitTimeLableVIew(); + InitBatteryView(); + ShowUpTopView(); + ShowUpLeftView(); + ShowUpRightView(); + ShowUpBottomView(); + ShowUpSeparateLine(); + AddViewToPageContainer(sweepClock_); + + callback_ = new SportDataAnimatorCallback(this); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage::OnStart callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportDataPage::OnStart new Animator animator_ fail"); + return; + } +} + +void SportDataPage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } +} + +void SportDataPage::OnResume() +{ + if (animator_ != nullptr) { + if (animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } +} + +bool SportDataPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + SportModel::GetInstance().PauseAndReport(true); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_PAUSE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportDataPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} + +void SportDataPage::UpdateDataViewByType() +{ + uint32_t elapsedTime = SportModel::GetInstance().GetElapsedTime(); + std::string sportTimeStr = FormatSportTime(elapsedTime); + bottomValueLabel_->SetText(sportTimeStr.c_str()); + + SportType sportType = SportModel::GetInstance().GetSportType(); + sport_info_t *sportInfo = SportModel::GetInstance().GetSportInfo(sportType); + if (sportType == SPORT_TYPE_OUTDOOR_RUNNING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.heartRate).c_str()); + topUnitLabel_->SetText("心率(次/分钟)"); + leftValueLabel_->SetText(CalculateSpeed(sportInfo->data.distance, elapsedTime).c_str()); + leftUnitLabel_->SetText("配速(/km)"); + rightValueLabel_->SetText(ConvertDistance(sportInfo->data.distance).c_str()); + rightUnitLabel_->SetText("距离(km)"); + } else if (sportType == SPORT_TYPE_INDOOR_RUNNING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.heartRate).c_str()); + topUnitLabel_->SetText("心率(次/分钟)"); + leftValueLabel_->SetText(CalculateSpeed(sportInfo->data.distance, elapsedTime).c_str()); + leftUnitLabel_->SetText("配速(/km)"); + rightValueLabel_->SetText(ConvertDistance(sportInfo->data.distance).c_str()); + rightUnitLabel_->SetText("距离(km)"); + } else if (sportType == SPORT_TYPE_CYCLING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.heartRate).c_str()); + topUnitLabel_->SetText("心率(次/分钟)"); + leftValueLabel_->SetText(CalculateSpeed(sportInfo->data.distance, elapsedTime).c_str()); + leftUnitLabel_->SetText("配速(/km)"); + rightValueLabel_->SetText(ConvertDistance(sportInfo->data.distance).c_str()); + rightUnitLabel_->SetText("距离(km)"); + } else if (sportType == SPORT_TYPE_CLIMBING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.altitude).c_str()); + topUnitLabel_->SetText("海拔(m)"); + leftValueLabel_->SetText(std::to_string(sportInfo->data.ascent).c_str()); + leftUnitLabel_->SetText("累计上升(m)"); + rightValueLabel_->SetText(std::to_string(sportInfo->data.descent).c_str()); + rightUnitLabel_->SetText("累计下降(m)"); + } else if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.heartRate).c_str()); + topUnitLabel_->SetText("心率(次/分钟)"); + leftValueLabel_->SetText(std::to_string(sportInfo->data.calorie).c_str()); + leftUnitLabel_->SetText("热量(kcal)"); + rightValueLabel_->SetText(ConvertDistance(sportInfo->data.distance).c_str()); + rightUnitLabel_->SetText("距离(km)"); + } else if (sportType == SPORT_TYPE_OUTDOOR_SWIMMING) { + topValueLabel_->SetText(std::to_string(sportInfo->data.heartRate).c_str()); + topUnitLabel_->SetText("心率(次/分钟)"); + leftValueLabel_->SetText(std::to_string(sportInfo->data.calorie).c_str()); + leftUnitLabel_->SetText("热量(kcal)"); + rightValueLabel_->SetText(ConvertDistance(sportInfo->data.distance).c_str()); + rightUnitLabel_->SetText("距离(km)"); + } +} + +void SportDataPage::CheckTarget() +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (!sportInfo->isTargetSetted) { + return; + } + if (sportInfo->targetType == SPORT_TARGET_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + if (!sportInfo->targetComplete && sportInfo->data.lap >= sportInfo->targetValue) { + sportInfo->targetComplete = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } else if (!sportInfo->targetHalf && sportInfo->data.lap >= sportInfo->targetValue / TARGET_HALF) { + sportInfo->targetHalf = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } else { + if (!sportInfo->targetComplete && sportInfo->data.distance >= sportInfo->targetValue * NUM_THOUSAND) { + sportInfo->targetComplete = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } else if (!sportInfo->targetHalf && + sportInfo->data.distance >= sportInfo->targetValue * NUM_THOUSAND / TARGET_HALF) { + sportInfo->targetHalf = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } + } else if (sportInfo->targetType == SPORT_TARGET_TIME) { + uint32_t elapsedTime = SportModel::GetInstance().GetElapsedTime(); + if (!sportInfo->targetComplete && elapsedTime >= sportInfo->targetValue * UNIT_SECS_PER_MIN) { + sportInfo->targetComplete = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } else if (!sportInfo->targetHalf && elapsedTime >= sportInfo->targetValue * UNIT_SECS_PER_MIN / TARGET_HALF) { + sportInfo->targetHalf = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } else if (sportInfo->targetType == SPORT_TARGET_CALORIE) { + if (!sportInfo->targetComplete && sportInfo->data.calorie >= sportInfo->targetValue) { + sportInfo->targetComplete = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } else if (!sportInfo->targetHalf && sportInfo->data.calorie >= sportInfo->targetValue / TARGET_HALF) { + sportInfo->targetHalf = true; + sportInfo->promptType = SPORT_SET_TYPE_TARGET; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } +} + +void SportDataPage::CheckRemind() +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->enableHeartRemind) { + if (sportInfo->data.heartRate >= GetHeartRateRangeBounder(sportInfo->heartRange) && + sportInfo->data.heartRate < GetHeartRateRangeBounder(sportInfo->heartRange + NUM_ONE)) { + if (!sportInfo->isHeartReminded) { + sportInfo->isHeartReminded = true; + sportInfo->promptType = SPORT_SET_TYPE_HEARTRATE; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } else { + sportInfo->isHeartReminded = false; + } + } + + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_NONE || !sportInfo->isRemindSetted) { + return; + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + if (sportInfo->data.lap >= (sportInfo->remindTimes + NUM_ONE) * sportInfo->remindValue) { + sportInfo->remindTimes++; + sportInfo->promptType = SPORT_SET_TYPE_REMIND; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } else { + if (sportInfo->data.distance >= + (sportInfo->remindTimes + NUM_ONE) * sportInfo->remindValue * NUM_THOUSAND) { + sportInfo->remindTimes++; + sportInfo->promptType = SPORT_SET_TYPE_REMIND; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + uint32_t elapsedTime = SportModel::GetInstance().GetElapsedTime(); + if (elapsedTime >= (sportInfo->remindTimes + NUM_ONE) * sportInfo->remindValue * UNIT_SECS_PER_MIN) { + sportInfo->remindTimes++; + sportInfo->promptType = SPORT_SET_TYPE_REMIND; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangeItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangeItemView.cpp new file mode 100644 index 000000000..a516c158d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangeItemView.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportHeartRateRangeItemView + * Create: 2025-06-06 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "sport/SportModel.h" +#include "sport/SportHeartRateRangeItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t TITLE_X = 39; +static constexpr uint16_t TITLE_Y = 17; +static constexpr uint16_t TITLE_W = 200; +static constexpr uint16_t TITLE_H = 29; +static constexpr uint16_t TITLE_FONT = 24; +static constexpr uint16_t RANGE_X = 39; +static constexpr uint16_t RANGE_Y = 50; +static constexpr uint16_t RANGE_W = 264; +static constexpr uint16_t RANGE_H = 39; +static constexpr uint16_t RANGE_FONT = 32; +static constexpr uint16_t BUTTON_X = 350; +static constexpr uint16_t BUTTON_Y = 32; +static constexpr uint16_t BUTTON_W = 44; +static constexpr uint16_t BUTTON_H = 44; + +SportHeartRateRangeItemView::SportHeartRateRangeItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + title_.SetPosition(TITLE_X, TITLE_Y, TITLE_W, TITLE_H); + title_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT); + title_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + title_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + title_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + range_.SetPosition(RANGE_X, RANGE_Y, RANGE_W, RANGE_H); + range_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, RANGE_FONT); + range_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + range_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + button_.SetPosition(BUTTON_X, BUTTON_Y, BUTTON_W, BUTTON_H); + button_.SetImages(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_RADIO1, SPORT_IMAGE), + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_RADIO0, SPORT_IMAGE)); + + Add(&bgImage_); + Add(&title_); + Add(&range_); + Add(&button_); +} + +SportHeartRateRangeItemView::~SportHeartRateRangeItemView() +{ + Remove(&bgImage_); + Remove(&title_); + Remove(&range_); + Remove(&button_); +} + +void SportHeartRateRangeItemView::SetItemInfo(const SportHeartRateRangeItem &itemInfo) +{ + title_.SetText(itemInfo.title); + range_.SetText(GetHeartRateRangeDescription(itemInfo.itemId)); + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->heartRange == itemInfo.itemId) { + button_.SetState(UICheckBox::UICheckBoxState::SELECTED); + } else { + button_.SetState(UICheckBox::UICheckBoxState::UNSELECTED); + } + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangePage.cpp new file mode 100644 index 000000000..1200835c0 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportHeartRateRangePage.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportHeartRateRangePage + * Create: 2025-06-06 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportPresenter.h" +#include "sport/SportHeartRateRangePage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 485; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t TOP_BLANK_SIZE = 38; +static constexpr uint16_t BOTTOM_BLANK_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_HEARTRATE_RANGE, SportHeartRateRangePage, false); + +static SportHeartRateRangePage *g_SportHeartRateRangePageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportHeartRateRangeItemView *item = new SportHeartRateRangeItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportHeartRateRangePageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportHeartRateRangeItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportHeartRateRangeItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportHeartRateRangePage::SportHeartRateRangePage() +{ + g_SportHeartRateRangePageInstance = this; +} + +SportHeartRateRangePage::~SportHeartRateRangePage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (heartRateRangeList_ != nullptr) { + delete heartRateRangeList_; + heartRateRangeList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportHeartRateRangePage::~SportHeartRateRangePage"); +} + +void SportHeartRateRangePage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportHeartRateRangePage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("心率范围"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportHeartRateRangePage::CreateUIList() +{ + heartRateRangeList_ = new UISimpleList(); + if (heartRateRangeList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportHeartRateRangePage heartRateRangeList_ new fail"); + return; + } + heartRateRangeList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + heartRateRangeList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + heartRateRangeList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + heartRateRangeList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < SPORT_HEARTRATE_RANGE_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&heartRateRanges_[i]); + heartRateRangeList_->AddContent(content); + } + heartRateRangeList_->RefreshList(); + group_->Add(heartRateRangeList_); +} + +void SportHeartRateRangePage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportHeartRateRangePage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetReboundSize(REBOUND_SIZE, UIAbstractScroll::Direction::BOTTOM); + group_->SetScrollBlankSize(TOP_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + group_->SetScrollBlankSize(BOTTOM_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportHeartRateRangePage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND_HEARTRATE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportHeartRateRangePage::OnClick(UIView &view, const ClickEvent &event) +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (strcmp(view.GetViewId(), SPORT_HEARTRATE_RANGE_ITEM_1) == 0) { + sportInfo->heartRange = SPORT_HEARTRATE_RANGE_ITEM1; + } else if (strcmp(view.GetViewId(), SPORT_HEARTRATE_RANGE_ITEM_2) == 0) { + sportInfo->heartRange = SPORT_HEARTRATE_RANGE_ITEM2; + } else if (strcmp(view.GetViewId(), SPORT_HEARTRATE_RANGE_ITEM_3) == 0) { + sportInfo->heartRange = SPORT_HEARTRATE_RANGE_ITEM3; + } else if (strcmp(view.GetViewId(), SPORT_HEARTRATE_RANGE_ITEM_4) == 0) { + sportInfo->heartRange = SPORT_HEARTRATE_RANGE_ITEM4; + } + heartRateRangeList_->RefreshList(); + SportModel::GetInstance().SaveConfig(SPORT_CONFIG_INFO); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND_HEARTRATE, + TransitionType::TRANSITION_INVALID, false); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuItemView.cpp new file mode 100644 index 000000000..f4eb22478 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuItemView.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMenuItemView + * Create: 2025-06-06 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "ui_resource_sport.h" +#include "main/LoadImg.h" +#include "sport/SportMenuItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 10; +static constexpr uint16_t ICON_X = 16; +static constexpr uint16_t ICON_Y = 25; +static constexpr uint16_t LABEL_X = 124; +static constexpr uint16_t LABEL_Y = 47; +static constexpr uint16_t LABEL_W = 166; +static constexpr uint16_t LABEL_H = 40; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t IMAGE_X = 344; +static constexpr uint16_t IMAGE_Y = 44; + +SportMenuItemView::SportMenuItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + + LOADIMG::LoadImageViewImg(&settingImage_, SPORT_IMAGE, IMAGE_SPORT_SETTING); + settingImage_.SetPosition(IMAGE_X, IMAGE_Y); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&settingImage_); +} + +SportMenuItemView::~SportMenuItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&settingImage_); +} + +void SportMenuItemView::SetItemInfo(const SportMenuItem &itemInfo) +{ + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, itemInfo.bgId); + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuPage.cpp new file mode 100644 index 000000000..f91d3d6a4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMenuPage.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMenuPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportMenuPage.h" + +namespace OHOS { +static constexpr uint16_t TITLI_LABEL_FONT = 38; +static constexpr uint16_t TITLI_LABEL_X = 100; +static constexpr uint16_t TITLI_LABEL_Y = 38; +static constexpr uint16_t TITLI_LABEL_W = 253; +static constexpr uint16_t TITLI_LABEL_H = 53; +static constexpr uint16_t LIST_X = 19; +static constexpr uint16_t LIST_Y = 108; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 780; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 129; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t BLANK_SIZE = 100; +static constexpr uint16_t SETTINGS_START_XPOS = 364; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_MENU, SportMenuPage, true); + +static SportMenuPage *g_SportMenuPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportMenuItemView *item = new SportMenuItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportMenuPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportMenuItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportMenuItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportMenuPage::SportMenuPage() +{ + g_SportMenuPageInstance = this; +} + +SportMenuPage::~SportMenuPage() +{ + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(SPORT_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadSportImage fail"); + } + + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (sportList_ != nullptr) { + delete sportList_; + sportList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportMenuPage::~SportMenuPage"); +} + +void SportMenuPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMenuPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG); + group_->Add(background_); +} + +void SportMenuPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMenuPage titleLabel_ new fail"); + return; + } + + titleLabel_->SetPosition(TITLI_LABEL_X, TITLI_LABEL_Y, TITLI_LABEL_W, TITLI_LABEL_H); + titleLabel_->SetText("运动"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, TITLI_LABEL_FONT); + group_->Add(titleLabel_); +} + +void SportMenuPage::CreateUIList() +{ + sportList_ = new UISimpleList(); + if (sportList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMenuPage sportList_ new fail"); + return; + } + + sportList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + sportList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sportList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + sportList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < SPORT_TYPE_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&sportMenu_[i]); + sportList_->AddContent(content); + } + sportList_->RefreshList(); + group_->Add(sportList_); +} + +void SportMenuPage::OnStart(void *data) +{ + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(SPORT_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadSportImage fail"); + return; + } + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMenuPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetYScrollBarVisible(true); + group_->SetReboundSize(REBOUND_SIZE, UIAbstractScroll::Direction::BOTTOM); + group_->SetScrollBlankSize(BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportMenuPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} + +bool SportMenuPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_ITEM_OUTDOOR_RUNNING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_OUTDOOR_RUNNING); + } else if (strcmp(view.GetViewId(), SPORT_ITEM_INDOOR_RUNNING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_INDOOR_RUNNING); + } else if (strcmp(view.GetViewId(), SPORT_ITEM_CYCLING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_CYCLING); + } else if (strcmp(view.GetViewId(), SPORT_ITEM_CLIMBING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_CLIMBING); + } else if (strcmp(view.GetViewId(), SPORT_ITEM_INDOOR_SWIMMING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_INDOOR_SWIMMING); + } else if (strcmp(view.GetViewId(), SPORT_ITEM_OUTDOOR_SWIMMING) == 0) { + SportModel::GetInstance().SetSportType(SPORT_TYPE_OUTDOOR_SWIMMING); + } + + bool isSettingClicked = event.GetCurrentPos().x > SETTINGS_START_XPOS ? true : false; + if (isSettingClicked) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_SETTINGS, + TransitionType::TRANSITION_INVALID, false); + } else { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_PREPARE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMistouchPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMistouchPage.cpp new file mode 100644 index 000000000..f4f8c227e --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportMistouchPage.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportMistouchPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "ui_resource_sport.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportMistouchPage.h" + +namespace OHOS { +static constexpr uint16_t TITLE_X = 100; +static constexpr uint16_t TITLE_Y = 39; +static constexpr uint16_t TITLE_W = 253; +static constexpr uint16_t TITLE_H = 53; +static constexpr uint16_t TITLE_FONT = 38; +static constexpr uint16_t SCREEN_BG_X = 19; +static constexpr uint16_t SCREEN_BG_Y = 107; +static constexpr uint16_t SCREEN_ICON_X = 27; +static constexpr uint16_t SCREEN_ICON_Y = 115; +static constexpr uint16_t SCREEN_TITLE_X = 100; +static constexpr uint16_t SCREEN_TITLE_Y = 134; +static constexpr uint16_t SCREEN_TITLE_W = 222; +static constexpr uint16_t SCREEN_TITLE_H = 39; +static constexpr uint16_t SCREEN_TITLE_FONT = 32; +static constexpr uint16_t SCREEN_BUTTON_X = 323; +static constexpr uint16_t SCREEN_BUTTON_Y = 131; +static constexpr uint16_t SCREEN_BUTTON_W = 82; +static constexpr uint16_t SCREEN_BUTTON_H = 47; +static constexpr uint16_t SCREEN_TEXT_X = 19; +static constexpr uint16_t SCREEN_TEXT_Y = 224; +static constexpr uint16_t SCREEN_TEXT_W = 415; +static constexpr uint16_t SCREEN_TEXT_H = 146; +static constexpr uint16_t SCREEN_TEXT_FONT = 36; +static constexpr uint16_t CROWN_BG_X = 19; +static constexpr uint16_t CROWN_BG_Y = 394; +static constexpr uint16_t CROWN_ICON_X = 27; +static constexpr uint16_t CROWN_ICON_Y = 402; +static constexpr uint16_t CROWN_TITLE_X = 100; +static constexpr uint16_t CROWN_TITLE_Y = 421; +static constexpr uint16_t CROWN_TITLE_W = 222; +static constexpr uint16_t CROWN_TITLE_H = 39; +static constexpr uint16_t CROWN_TITLE_FONT = 32; +static constexpr uint16_t CROWN_BUTTON_X = 323; +static constexpr uint16_t CROWN_BUTTON_Y = 417; +static constexpr uint16_t CROWN_BUTTON_W = 82; +static constexpr uint16_t CROWN_BUTTON_H = 47; +static constexpr uint16_t CROWN_TEXT_X = 19; +static constexpr uint16_t CROWN_TEXT_Y = 510; +static constexpr uint16_t CROWN_TEXT_W = 415; +static constexpr uint16_t CROWN_TEXT_H = 146; +static constexpr uint16_t CROWN_TEXT_FONT = 36; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t TOP_BLANK_SIZE = 36; +static constexpr uint16_t BOTTOM_BLANK_SIZE = 100; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_MISTOUCH, SportMistouchPage, false); + +SportMistouchPage::~SportMistouchPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + if (bgScreen_ != nullptr) { + delete bgScreen_; + bgScreen_ = nullptr; + } + if (imageScreen_ != nullptr) { + delete imageScreen_; + imageScreen_ = nullptr; + } + if (titleScreen_ != nullptr) { + delete titleScreen_; + titleScreen_ = nullptr; + } + if (buttonScreen_ != nullptr) { + delete buttonScreen_; + buttonScreen_ = nullptr; + } + if (textScreen_ != nullptr) { + delete textScreen_; + textScreen_ = nullptr; + } + if (bgCrown_ != nullptr) { + delete bgCrown_; + bgCrown_ = nullptr; + } + if (imageCrown_ != nullptr) { + delete imageCrown_; + imageCrown_ = nullptr; + } + if (titleCrown_ != nullptr) { + delete titleCrown_; + titleCrown_ = nullptr; + } + if (buttonCrown_ != nullptr) { + delete buttonCrown_; + buttonCrown_ = nullptr; + } + if (textCrown_ != nullptr) { + delete textCrown_; + textCrown_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportMistouchPage::~SportMistouchPage"); +} + +void SportMistouchPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetElastic(true); + group_->SetYScrollBarVisible(true); + group_->SetReboundSize(REBOUND_SIZE); + group_->SetScrollBlankSize(TOP_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + group_->SetScrollBlankSize(BOTTOM_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage title_ new fail"); + return; + } + title_->SetPosition(TITLE_X, TITLE_Y, TITLE_W, TITLE_H); + title_->SetText("运动防误触"); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, TITLE_FONT); + group_->Add(title_); + + bgScreen_ = new UIImageView(); + if (bgScreen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage bgScreen_ new fail"); + return; + } + bgScreen_->SetPosition(SCREEN_BG_X, SCREEN_BG_Y); + LOADIMG::LoadImageViewImg(bgScreen_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + group_->Add(bgScreen_); + + buttonScreen_ = new UIToggleButton(); + if (buttonScreen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage buttonScreen_ new fail"); + return; + } + buttonScreen_->SetPosition(SCREEN_BUTTON_X, SCREEN_BUTTON_Y, SCREEN_BUTTON_W, SCREEN_BUTTON_H); + buttonScreen_->SetViewId(SPORT_MISTOUCH_SCREEN_BUTTON); + buttonScreen_->SetImages(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE1, SPORT_IMAGE), + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE0, SPORT_IMAGE)); + buttonScreen_->SetState(false); + buttonScreen_->SetOnClickListener(this); + group_->Add(buttonScreen_); + + titleScreen_ = new UILabel(); + if (titleScreen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage titleScreen_ new fail"); + return; + } + titleScreen_->SetPosition(SCREEN_TITLE_X, SCREEN_TITLE_Y, SCREEN_TITLE_W, SCREEN_TITLE_H); + titleScreen_->SetText("自动锁定屏幕"); + titleScreen_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleScreen_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SCREEN_TITLE_FONT); + group_->Add(titleScreen_); + + imageScreen_ = new UIImageView(); + if (imageScreen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage imageScreen_ new fail"); + return; + } + imageScreen_->SetPosition(SCREEN_ICON_X, SCREEN_ICON_Y); + LOADIMG::LoadImageViewImg(imageScreen_, SPORT_IMAGE, IMAGE_SPORT_SCREEN); + group_->Add(imageScreen_); + + textScreen_ = new UILabel(); + if (textScreen_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage textScreen_ new fail"); + return; + } + textScreen_->SetPosition(SCREEN_TEXT_X, SCREEN_TEXT_Y, SCREEN_TEXT_W, SCREEN_TEXT_H); + textScreen_->SetText("开启后,运动中熄屏将自动锁定屏幕触摸功能,长按表冠可解锁。"); + textScreen_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + textScreen_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textScreen_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SCREEN_TEXT_FONT); + group_->Add(textScreen_); + + bgCrown_ = new UIImageView(); + if (bgCrown_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage bgCrown_ new fail"); + return; + } + bgCrown_->SetPosition(CROWN_BG_X, CROWN_BG_Y); + LOADIMG::LoadImageViewImg(bgCrown_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + group_->Add(bgCrown_); + + buttonCrown_ = new UIToggleButton(); + if (buttonCrown_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage buttonCrown_ new fail"); + return; + } + buttonCrown_->SetPosition(CROWN_BUTTON_X, CROWN_BUTTON_Y, CROWN_BUTTON_W, CROWN_BUTTON_H); + buttonCrown_->SetViewId(SPORT_MISTOUCH_CROWN_BUTTON); + buttonCrown_->SetImages(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE1, SPORT_IMAGE), + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE0, SPORT_IMAGE)); + buttonCrown_->SetState(false); + buttonCrown_->SetOnClickListener(this); + group_->Add(buttonCrown_); + + titleCrown_ = new UILabel(); + if (titleCrown_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage titleCrown_ new fail"); + return; + } + titleCrown_->SetPosition(CROWN_TITLE_X, CROWN_TITLE_Y, CROWN_TITLE_W, CROWN_TITLE_H); + titleCrown_->SetText("自动锁定表冠"); + titleCrown_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleCrown_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CROWN_TITLE_FONT); + group_->Add(titleCrown_); + + imageCrown_ = new UIImageView(); + if (imageCrown_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage imageCrown_ new fail"); + return; + } + imageCrown_->SetPosition(CROWN_ICON_X, CROWN_ICON_Y); + LOADIMG::LoadImageViewImg(imageCrown_, SPORT_IMAGE, IMAGE_SPORT_CROWN); + group_->Add(imageCrown_); + + textCrown_ = new UILabel(); + if (textCrown_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportMistouchPage textCrown_ new fail"); + return; + } + textCrown_->SetPosition(CROWN_TEXT_X, CROWN_TEXT_Y, CROWN_TEXT_W, CROWN_TEXT_H); + textCrown_->SetText("开启后,运动中熄屏将自动锁定表冠点按、旋钮功能,长按表冠可解锁。"); + textCrown_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + textCrown_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textCrown_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CROWN_TEXT_FONT); + group_->Add(textCrown_); + + AddViewToPageContainer(group_); +} + +bool SportMistouchPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_SETTINGS, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportMistouchPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_MISTOUCH_SCREEN_BUTTON) == 0) { + // 暂不支持 + } else if (strcmp(view.GetViewId(), SPORT_MISTOUCH_CROWN_BUTTON) == 0) { + // 暂不支持 + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportModel.cpp new file mode 100644 index 000000000..a9c54bf9b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportModel.cpp @@ -0,0 +1,495 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportModel + * Create: 2025-06-06 + */ + +#include +#include +#include +#include "wearable_log.h" +#include "msg_center_device.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "sport/SportModel.h" + +namespace OHOS { +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_HUNDRED = 100; +static constexpr uint16_t NUM_THOUSAND = 1000; +static constexpr uint16_t UNIT_SECS_PER_MIN = 60; +static constexpr uint16_t UNIT_SECS_PER_HOUR = 3600; +static const uint16_t COUNT_TIMES = 100; +static const uint16_t DISTANCE_RANGE = 200; +static const uint16_t HEARTRATE_MIN_VALUE = 116; +static const uint16_t HEARTRATE_MAX_VALUE = 195; +static const uint16_t CALORIE_RANGE = 8; +static const uint16_t ALTITUDE_RANGE = 4; +static const uint16_t ASCENT_RANGE = 7; +static const uint16_t DESCENT_RANGE = 6; +static const uint16_t g_targetDistanceValues[] = {1, 3, 5, 7, 10, 15, 20, 25, 30, 40}; // 距离Picker值集,单位为km +static const uint16_t g_targetTimeValues[] = {10, 20, 30, 60, 120, 180, 200}; // 时间Picker值集,单位为分钟 +static const uint16_t g_targetCalorieValues[] = {100, 200, 300, 500, 600, 800, 1000}; // 热量Picker值集,单位为千卡 +static const uint16_t g_targetLapValues[] = {1, 2, 4, 6, 8, 10, 12, 16, 20, 30}; // 室内游泳趟数Picker值集,单位为趟 +static const char *g_remindHeartRateRange[] = {"116-136次/分", "136-156次/分", "156-176次/分", "176-195次/分"}; +static const uint16_t g_heartRateRangeBounder[] = {116, 136, 156, 176, 195}; +static const char *SPORT_INFO_FILE = SPORT_CONFIG_PATH "sport_info.dat"; +static const char *SPORT_RECORD_FILE = SPORT_CONFIG_PATH "sport_record.dat"; + +std::string GetCurrentTimeStr() +{ + struct tm localTime; + time_t seconds = time(nullptr); + localtime_r(&seconds, &localTime); + std::string currTime; + if (localTime.tm_hour < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_hour) + ":"; + if (localTime.tm_min < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_min); + return currTime; +} + +std::string ConvertDistance(uint32_t distance) +{ + std::string distanceStr; + uint32_t distanceIntPart = distance / NUM_THOUSAND; + uint32_t distanceFractionalPart = (distance % NUM_THOUSAND) / NUM_TEN; + if (distanceIntPart > NUM_HUNDRED) { + distanceStr = std::to_string(distanceIntPart); + } else if (distanceIntPart > NUM_TEN) { + distanceStr = std::to_string(distanceIntPart) + "." + std::to_string(distanceFractionalPart / NUM_TEN); + } else { + if (distanceFractionalPart < NUM_TEN) { + distanceStr = std::to_string(distanceIntPart) + ".0" + std::to_string(distanceFractionalPart); + } else { + distanceStr = std::to_string(distanceIntPart) + "." + std::to_string(distanceFractionalPart); + } + } + return distanceStr; +} + +std::string FormatSportTime(uint32_t uiSportTime) +{ + std::string strSportTime; + std::string hours; + std::string minute; + std::string seconds; + uint32_t hour = uiSportTime / UNIT_SECS_PER_HOUR; + uiSportTime %= UNIT_SECS_PER_HOUR; + uint32_t min = uiSportTime / UNIT_SECS_PER_MIN; + uiSportTime %= UNIT_SECS_PER_MIN; + uint32_t sec = uiSportTime; + if (hour >= 0 && hour < NUM_TEN) { + hours = "0" + std::to_string(hour); + } else { + hours = std::to_string(hour); + } + if (min >= 0 && min < NUM_TEN) { + minute = "0" + std::to_string(min); + } else { + minute = std::to_string(min); + } + if (sec >= 0 && sec < NUM_TEN) { + seconds = "0" + std::to_string(sec); + } else { + seconds = std::to_string(sec); + } + strSportTime = hours + ":" + minute + ":" + seconds; + return strSportTime; +} + +std::string CalculateSpeed(uint32_t distance, uint32_t time) +{ + if (distance == 0) { + return "00'00\""; + } + std::string speedStr; + uint64_t speed = time * NUM_THOUSAND / distance; + uint64_t min = speed / UNIT_SECS_PER_MIN; + uint64_t sec = speed % UNIT_SECS_PER_MIN; + speedStr = std::to_string(min) + "'"; + if (sec >= 0 && sec < NUM_TEN) { + speedStr += "0"; + } + speedStr += std::to_string(sec) + "\""; + return speedStr; +} + +const char *GetHeartRateRangeDescription(uint8_t range) +{ + return g_remindHeartRateRange[range]; +} + +uint16_t GetHeartRateRangeBounder(uint8_t index) +{ + return g_heartRateRangeBounder[index]; +} + +#if defined(_WIN32) +void SportModel::SportAnimatorCallback::Callback(UIView *view) +{ + static uint64_t count = 0; + static bool increase = true; + if (count++ % COUNT_TIMES == 0) { + uint32_t randNum = rand(); + uint32_t distance = randNum % DISTANCE_RANGE; + uint16_t calorie = randNum % CALORIE_RANGE; + uint16_t altitude = randNum % ALTITUDE_RANGE; + uint16_t ascent = randNum % ASCENT_RANGE; + uint16_t descent = randNum % DESCENT_RANGE; + + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + sportInfo->data.distance += distance; + if (sportInfo->data.heartRate < HEARTRATE_MIN_VALUE) { + sportInfo->data.heartRate = HEARTRATE_MIN_VALUE; + increase = true; + } + if (sportInfo->data.heartRate > HEARTRATE_MAX_VALUE) { + sportInfo->data.heartRate = HEARTRATE_MAX_VALUE; + increase = false; + } + if (increase) { + sportInfo->data.heartRate++; + } else { + sportInfo->data.heartRate--; + } + sportInfo->data.calorie += calorie; + sportInfo->data.altitude += altitude; + sportInfo->data.ascent += ascent; + sportInfo->data.descent += descent; + sportInfo->data.lap++; + } +} +#else +static void GenerateDataCallback(void *data) +{ + static bool increase = true; + uint32_t randNum = rand(); + uint32_t distance = randNum % DISTANCE_RANGE; + uint16_t calorie = randNum % CALORIE_RANGE; + uint16_t altitude = randNum % ALTITUDE_RANGE; + uint16_t ascent = randNum % ASCENT_RANGE; + uint16_t descent = randNum % DESCENT_RANGE; + + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + sportInfo->data.distance += distance; + if (sportInfo->data.heartRate < HEARTRATE_MIN_VALUE) { + sportInfo->data.heartRate = HEARTRATE_MIN_VALUE; + increase = true; + } + if (sportInfo->data.heartRate > HEARTRATE_MAX_VALUE) { + sportInfo->data.heartRate = HEARTRATE_MAX_VALUE; + increase = false; + } + if (increase) { + sportInfo->data.heartRate++; + } else { + sportInfo->data.heartRate--; + } + sportInfo->data.calorie += calorie; + sportInfo->data.altitude += altitude; + sportInfo->data.ascent += ascent; + sportInfo->data.descent += descent; + sportInfo->data.lap++; + + if (!SportModel::GetInstance().IsStartByWatch()) { + msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_DATA, &sportInfo->data, + sizeof(sport_data_t)); + } +} + +void SportModel::InitGenerateSportData() +{ + uint32_t tick = GetOSTick(2000); + generateDataHandle_ = new GraphicTimer(tick, GenerateDataCallback, nullptr, true); + if (generateDataHandle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportModel::InitGenerateSportData new GraphicTimer failed!!"); + return; + } +} + +void SportModel::StartGenerateSportData() +{ + if (generateDataHandle_ != nullptr) { + bool retTimer = generateDataHandle_->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartGenerateSportData failed!!"); + if (generateDataHandle_ != nullptr) { + delete generateDataHandle_; + generateDataHandle_ = nullptr; + } + return; + } + } +} + +void SportModel::StopGenerateSportData() +{ + if (generateDataHandle_ != nullptr) { + generateDataHandle_->Stop(); + } +} +#endif + +SportModel::SportModel() +{ + LoadConfig(); +#if defined(_WIN32) + callback_ = new SportAnimatorCallback(); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportModel::SportModel callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportModel::SportModel new Animator animator_ fail"); + return; + } +#else + InitGenerateSportData(); +#endif +} + +SportModel::~SportModel() {} + +SportModel &SportModel::GetInstance() +{ + static SportModel instance; + return instance; +} + +void SportModel::SetSportType(SportType sportType) +{ + curSport_ = sportType; +} + +SportType SportModel::GetSportType(void) +{ + return curSport_; +} + +void SportModel::SetTargetValue(uint16_t index) +{ + SportTarget target = info_[curSport_].targetType; + if (target == SPORT_TARGET_DISTANCE) { + if (curSport_ == SPORT_TYPE_INDOOR_SWIMMING) { + info_[curSport_].targetValue = g_targetLapValues[index]; + } else { + info_[curSport_].targetValue = g_targetDistanceValues[index]; + } + } else if (target == SPORT_TARGET_TIME) { + info_[curSport_].targetValue = g_targetTimeValues[index]; + } else if (target == SPORT_TARGET_CALORIE) { + info_[curSport_].targetValue = g_targetCalorieValues[index]; + } +} + +void SportModel::SetRemindValue(uint16_t index) +{ + SportRemindInterval remind = info_[curSport_].remindType; + if (remind == SPORT_REMIND_INTERVAL_DISTANCE) { + if (curSport_ == SPORT_TYPE_INDOOR_SWIMMING) { + info_[curSport_].remindValue = g_targetLapValues[index]; + } else { + info_[curSport_].remindValue = g_targetDistanceValues[index]; + } + } else if (remind == SPORT_REMIND_INTERVAL_TIME) { + info_[curSport_].remindValue = g_targetTimeValues[index]; + } + info_[curSport_].remindIndex = index; +} + +uint32_t SportModel::GetElapsedTime() +{ + if (state_ == SportState::RUNNING) { + uint32_t now = time(nullptr); + return info_[curSport_].data.elapsedTime + (now - info_[curSport_].startTimeTemp); + } + return info_[curSport_].data.elapsedTime; +} + +void SportModel::SetGpsSignal(GpsSignal gpsSignal) +{ + gpsSignal_ = gpsSignal; +} + +GpsSignal SportModel::GetGpsSignal(void) +{ + return gpsSignal_; +} + +uint16_t SportModel::GetHeartRate(void) +{ + return info_[curSport_].data.heartRate; +} + +sport_info_t *SportModel::GetSportInfo(SportType type) +{ + return &info_[type]; +} + +sport_info_t *SportModel::GetCurrSportInfo() +{ + return GetSportInfo(curSport_); +} + +void SportModel::StartSport(bool startedByWatch) +{ + if (state_ == SportState::STOPPED) { + state_ = SportState::RUNNING; + isStartByWatch_ = startedByWatch; + info_[curSport_].targetHalf = false; + info_[curSport_].targetComplete = false; + info_[curSport_].isHeartReminded = false; + info_[curSport_].remindTimes = 0; + (void)memset_s(&(info_[curSport_].data), sizeof(info_[curSport_].data), 0, sizeof(sport_data_t)); + info_[curSport_].data.startTime = time(nullptr); + info_[curSport_].startTimeTemp = info_[curSport_].data.startTime; +#if defined(_WIN32) + animator_->Start(); +#else + StartGenerateSportData(); +#endif + } +} + +void SportModel::PauseAndReport(bool isReport) +{ + if (state_ == SportState::RUNNING) { + state_ = SportState::PAUSED; + info_[curSport_].data.elapsedTime += time(nullptr) - info_[curSport_].startTimeTemp; +#if defined(_WIN32) + animator_->Stop(); +#else + StopGenerateSportData(); + if (isReport) { + sport_control_t control = {0}; + control.action = static_cast(SPORT_ACTION_PAUSE); + control.type = static_cast(curSport_); + msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_ACTION, &control, + sizeof(sport_control_t)); + } +#endif + } +} + +void SportModel::ResumeAndReport(bool isReport) +{ + if (state_ == SportState::PAUSED) { + state_ = SportState::RUNNING; + info_[curSport_].startTimeTemp = time(nullptr); +#if defined(_WIN32) + animator_->Start(); +#else + StartGenerateSportData(); + if (isReport) { + sport_control_t control = {0}; + control.action = static_cast(SPORT_ACTION_RESUME); + control.type = static_cast(curSport_); + msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_ACTION, &control, + sizeof(sport_control_t)); + } +#endif + } +} + +void SportModel::StopAndReport(bool isReport) +{ + if (state_ != SportState::STOPPED) { + state_ = SportState::STOPPED; + info_[curSport_].data.type = static_cast(curSport_); + info_[curSport_].data.endTime = time(nullptr); +#if defined(_WIN32) + animator_->Stop(); +#else + StopGenerateSportData(); + if (isReport) { + sport_control_t control = {0}; + control.action = static_cast(SPORT_ACTION_STOP); + control.type = static_cast(curSport_); + msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_ACTION, &control, + sizeof(sport_control_t)); + } +#endif + } +} + +bool SportModel::IsStartByWatch() +{ + return isStartByWatch_; +} + +void SportModel::AddRecord() +{ + if (isStartByWatch_) { + records_.push_back(info_[curSport_].data); + } + SaveConfig(SPORT_CONFIG_RECORD); +} + +std::vector &SportModel::GetRecord() +{ + return records_; +} + +void SportModel::ClearRecord() +{ + records_.clear(); + std::remove(SPORT_RECORD_FILE); +} + +void SportModel::LoadConfig() +{ + std::ifstream infoFile(SPORT_INFO_FILE, std::ios::binary); + if (infoFile) { + for (uint8_t i = 0; i < SPORT_TYPE_MAX; i++) { + infoFile.read(reinterpret_cast(&info_[i]), sizeof(sport_info_t)); + } + infoFile.close(); + } + std::ifstream recordFile(SPORT_RECORD_FILE, std::ios::binary); + if (recordFile) { + uint16_t num = 0; + recordFile.read(reinterpret_cast(&num), sizeof(uint16_t)); + for (uint8_t i = 0; i < num; i++) { + sport_data_t data; + recordFile.read(reinterpret_cast(&data), sizeof(sport_data_t)); + records_.push_back(data); + } + recordFile.close(); + } +} + +void SportModel::SaveConfig(uint8_t config) +{ + if (config == SPORT_CONFIG_INFO) { + std::ofstream infoFile(SPORT_INFO_FILE, std::ios::binary); + if (infoFile) { + infoFile.write(reinterpret_cast(&info_), SPORT_TYPE_MAX * sizeof(sport_info_t)); + infoFile.close(); + } + } else if (config == SPORT_CONFIG_RECORD) { + std::ofstream recordFile(SPORT_RECORD_FILE, std::ios::binary); + if (recordFile) { + uint16_t num = records_.size(); + recordFile.write(reinterpret_cast(&num), sizeof(uint16_t)); + for (uint8_t i = 0; i < num; i++) { + recordFile.write(reinterpret_cast(&records_[i]), sizeof(sport_data_t)); + } + recordFile.close(); + } + } +} + +void SportModel::ClearData() +{ + std::remove(SPORT_INFO_FILE); + std::remove(SPORT_RECORD_FILE); +} +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPausePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPausePage.cpp new file mode 100644 index 000000000..8a490f702 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPausePage.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPausePage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportPausePage.h" + +namespace OHOS { +static constexpr uint16_t NUM_THOUSAND = 1000; +static constexpr uint16_t TIME_LABEL_FONT = 48; +static constexpr uint16_t TIME_LABEL_X = 166; +static constexpr uint16_t TIME_LABEL_Y = 35; +static constexpr uint16_t TIME_LABEL_W = 122; +static constexpr uint16_t TIME_LABEL_H = 48; +static constexpr uint16_t TEXT_LABEL_FONT = 64; +static constexpr uint16_t TEXT_LABEL_X = 130; +static constexpr uint16_t TEXT_LABEL_Y = 151; +static constexpr uint16_t TEXT_LABEL_W = 194; +static constexpr uint16_t TEXT_LABEL_H = 80; +static constexpr uint16_t BUTTON_X1 = 54; +static constexpr uint16_t BUTTON_X2 = 217; +static constexpr uint16_t BUTTON_Y = 250; +static constexpr uint16_t BUTTON_W = 184; +static constexpr uint16_t BUTTON_H = 184; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_PAUSE, SportPausePage, false); + +void SportPausePage::SportPauseAnimatorCallback::Callback(UIView *view) +{ + UILabel *timeLabel = dynamic_cast(view); + if (timeLabel == nullptr) { + return; + } + std::string currTime = GetCurrentTimeStr(); + timeLabel->SetText(currTime.c_str()); + timeLabel->Invalidate(); +} + +SportPausePage::~SportPausePage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (timeLabel_ != nullptr) { + delete timeLabel_; + timeLabel_ = nullptr; + } + if (textLabel_ != nullptr) { + delete textLabel_; + textLabel_ = nullptr; + } + if (continueButton_ != nullptr) { + delete continueButton_; + continueButton_ = nullptr; + } + if (finishButton_ != nullptr) { + delete finishButton_; + finishButton_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportPausePage::~SportPausePage"); +} + +void SportPausePage::CreateUILabel() +{ + timeLabel_ = new UILabel(); + if (timeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage timeLabel_ new fail"); + return; + } + timeLabel_->SetPosition(TIME_LABEL_X, TIME_LABEL_Y, TIME_LABEL_W, TIME_LABEL_H); + timeLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT); + group_->Add(timeLabel_); + + textLabel_ = new UILabel(); + if (textLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage textLabel_ new fail"); + return; + } + textLabel_->SetPosition(TEXT_LABEL_X, TEXT_LABEL_Y, TEXT_LABEL_W, TEXT_LABEL_H); + textLabel_->SetText("已暂停"); + textLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_LABEL_FONT); + group_->Add(textLabel_); + + callback_ = new SportPauseAnimatorCallback(); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage::OnStart callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, timeLabel_, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage::OnStart new Animator animator_ fail"); + return; + } +} + +void SportPausePage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } +} + +void SportPausePage::OnResume() +{ + if (animator_ != nullptr) { + if (animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } +} + +void SportPausePage::CreateUIButton() +{ + finishButton_ = new UILabelButton(); + if (finishButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage finishButton_ new fail"); + return; + } + finishButton_->SetPosition(BUTTON_X1, BUTTON_Y, BUTTON_W, BUTTON_H); + finishButton_->SetViewId(SPORT_PAUSE_FINISH_BUTTON); + finishButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + finishButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + finishButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(finishButton_, SPORT_IMAGE, IMAGE_SPORT_STOP, IMAGE_SPORT_STOP); + finishButton_->SetOnClickListener(this); + group_->Add(finishButton_); + + continueButton_ = new UILabelButton(); + if (continueButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage continueButton_ new fail"); + return; + } + continueButton_->SetPosition(BUTTON_X2, BUTTON_Y, BUTTON_W, BUTTON_H); + continueButton_->SetViewId(SPORT_PAUSE_CONTINUE_BUTTON); + continueButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + continueButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + continueButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(continueButton_, SPORT_IMAGE, IMAGE_SPORT_START, IMAGE_SPORT_START); + continueButton_->SetOnClickListener(this); + group_->Add(continueButton_); +} + +void SportPausePage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPausePage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreateUILabel(); + CreateUIButton(); + AddViewToPageContainer(group_); +} + +bool SportPausePage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + SportModel::GetInstance().ResumeAndReport(true); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_DATA, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportPausePage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_PAUSE_CONTINUE_BUTTON) == 0) { + SportModel::GetInstance().ResumeAndReport(true); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_DATA, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SPORT_PAUSE_FINISH_BUTTON) == 0) { + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->data.distance < NUM_THOUSAND) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_PROMPT, + TransitionType::TRANSITION_INVALID, false); + } else { + SportModel::GetInstance().StopAndReport(true); + SportModel::GetInstance().AddRecord(); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_MENU, + TransitionType::TRANSITION_INVALID, false); + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPreparePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPreparePage.cpp new file mode 100644 index 000000000..041bba018 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPreparePage.cpp @@ -0,0 +1,422 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPreparePage + * Create: 2025-06-06 + */ + +#include +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "settings/model/SettingPowerModel.h" +#include "sport/SportView.h" +#include "sport/SportPreparePage.h" + +namespace OHOS { +static constexpr uint16_t LOCATING_OVERTIME_SECOND = 2; +static constexpr uint16_t BATTERY_LEVEL1 = 10; +static constexpr uint16_t BATTERY_LEVEL2 = 20; +static constexpr uint16_t BATTERY_LEVEL3 = 40; +static constexpr uint16_t BATTERY_LEVEL4 = 70; +static constexpr uint16_t BATTERY_LEVEL5 = 100; +static constexpr uint16_t HEARTBEAT_IMAGE_X = 351; +static constexpr uint16_t HEARTBEAT_IMAGE_Y = 223; +static constexpr uint16_t HEARTBEAT_LABEL_X = 329; +static constexpr uint16_t HEARTBEAT_LABEL_Y = 182; +static constexpr uint16_t HEARTBEAT_LABEL_W = 102; +static constexpr uint16_t HEARTBEAT_LABEL_H = 48; +static constexpr uint16_t HEARTBEAT_LABEL_FONT = 32; +static constexpr uint16_t BATTERY_ICON_X = 159; +static constexpr uint16_t BATTERY_ICON_Y = 31; +static constexpr uint16_t BATTERY_LABEL_FONT = 20; +static constexpr uint16_t BATTERY_LABEL_X = 163; +static constexpr uint16_t BATTERY_LABEL_Y = 31; +static constexpr uint16_t BATTERY_LABEL_W = 35; +static constexpr uint16_t BATTERY_LABEL_H = 22; +static constexpr uint16_t GPS_X = 48; +static constexpr uint16_t GPS_Y = 225; +static constexpr uint16_t SIGNAL_X = 44; +static constexpr uint16_t SIGNAL_Y = 175; +static constexpr uint16_t TIME_LABEL_FONT = 32; +static constexpr uint16_t TIME_LABEL_X = 214; +static constexpr uint16_t TIME_LABEL_Y = 23; +static constexpr uint16_t TIME_LABEL_W = 82; +static constexpr uint16_t TIME_LABEL_H = 47; +static constexpr uint16_t LOCATING_LABEL_FONT = 32; +static constexpr uint16_t LOCATING_LABEL_X = 165; +static constexpr uint16_t LOCATING_LABEL_Y = 80; +static constexpr uint16_t LOCATING_LABEL_W = 164; +static constexpr uint16_t LOCATING_LABEL_H = 34; +static constexpr uint16_t CENTER_IMAGE_X = 132; +static constexpr uint16_t CENTER_IMAGE_Y = 132; +static constexpr uint16_t GO_BUTTON_X = 63; +static constexpr uint16_t GO_BUTTON_Y = 361; +static constexpr uint16_t GO_BUTTON_W = 328; +static constexpr uint16_t GO_BUTTON_H = 93; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_PREPARE, SportPreparePage, false); + +void SportPreparePage::SportPrepareAnimatorCallback::Callback(UIView *view) +{ + UNUSED(view); + + std::string currTime = GetCurrentTimeStr(); + page_->timeLabel_->SetText(currTime.c_str()); + page_->timeLabel_->Invalidate(); + + uint8_t battery = SettingPowerModel::GetInstance().GetBatteryPowerLevel(); + page_->batteryLabel_->SetText(std::to_string(battery).c_str()); + page_->batteryLabel_->Invalidate(); + + if (battery < BATTERY_LEVEL1) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY1); + } else if (battery < BATTERY_LEVEL2) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY2); + } else if (battery < BATTERY_LEVEL3) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY3); + } else if (battery < BATTERY_LEVEL4) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY4); + } else if (battery <= BATTERY_LEVEL5) { + LOADIMG::LoadImageViewImg(page_->batteryIcon_, SPORT_IMAGE, IMAGE_SPORT_BATTERY5); + } + + time_t now = time(nullptr); + if (!page_->isOverTime_ && (now - page_->startTime_ > LOCATING_OVERTIME_SECOND)) { + page_->isOverTime_ = true; + page_->InitGpsSignalImage(); + } +} + +SportPreparePage::~SportPreparePage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (timeLabel_ != nullptr) { + delete timeLabel_; + timeLabel_ = nullptr; + } + if (batteryIcon_ != nullptr) { + delete batteryIcon_; + batteryIcon_ = nullptr; + } + if (batteryLabel_ != nullptr) { + delete batteryLabel_; + batteryLabel_ = nullptr; + } + if (gpsImageView_ != nullptr) { + delete gpsImageView_; + gpsImageView_ = nullptr; + } + if (gpsSignalView_ != nullptr) { + delete gpsSignalView_; + gpsSignalView_ = nullptr; + } + if (heartRateImageView_ != nullptr) { + delete heartRateImageView_; + heartRateImageView_ = nullptr; + } + if (heartRateLabel_ != nullptr) { + delete heartRateLabel_; + heartRateLabel_ = nullptr; + } + if (locatingLabel_ != nullptr) { + delete locatingLabel_; + locatingLabel_ = nullptr; + } + if (goButton_ != nullptr) { + delete goButton_; + goButton_ = nullptr; + } + if (iconImageView_ != nullptr) { + delete iconImageView_; + iconImageView_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportPreparePage::~SportPreparePage"); +} + +void SportPreparePage::InitGpsSignalImage() +{ + locatingLabel_->SetVisible(false); + LOADIMG::LoadImageViewImg(gpsSignalView_, SPORT_IMAGE, IMAGE_SPORT_SIGNAL2); +} + +void SportPreparePage::InitTimeLableVIew() +{ + timeLabel_ = new UILabel(); + if (timeLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage timeLabel_ new fail"); + return; + } + timeLabel_->SetPosition(TIME_LABEL_X, TIME_LABEL_Y, TIME_LABEL_W, TIME_LABEL_H); + timeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT); + group_->Add(timeLabel_); +} + +void SportPreparePage::InitBatteryView() +{ + batteryIcon_ = new UIImageView(); + if (batteryIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage batteryIcon_ new fail"); + return; + } + batteryIcon_->SetPosition(BATTERY_ICON_X, BATTERY_ICON_Y); + batteryIcon_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(batteryIcon_); + + batteryLabel_ = new UILabel(); + if (batteryLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage batteryLabel_ new fail"); + return; + } + batteryLabel_->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, BATTERY_LABEL_W, BATTERY_LABEL_H); + batteryLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BATTERY_LABEL_FONT); + batteryLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(batteryLabel_); +} + +void SportPreparePage::InitCenterView() +{ + iconImageView_ = new UIImageView(); + if (iconImageView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage iconImageView_ new fail"); + return; + } + iconImageView_->SetPosition(CENTER_IMAGE_X, CENTER_IMAGE_Y); + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_OUTDOOR_RUNNING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_OUTDOOR_RUNNING2); + } else if (sportType == SPORT_TYPE_INDOOR_RUNNING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_INDOOR_RUNNING2); + } else if (sportType == SPORT_TYPE_CYCLING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_CYCLING2); + } else if (sportType == SPORT_TYPE_CLIMBING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_CLIMBING2); + } else if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_INDOOR_SWIMMING2); + } else if (sportType == SPORT_TYPE_OUTDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(iconImageView_, SPORT_IMAGE, IMAGE_SPORT_OUTDOOR_SWIMMING2); + } + group_->Add(iconImageView_); +} + +void SportPreparePage::InitGPSView() +{ + locatingLabel_ = new UILabel(); + if (locatingLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage locatingLabel_ new fail"); + return; + } + locatingLabel_->SetPosition(LOCATING_LABEL_X, LOCATING_LABEL_Y, LOCATING_LABEL_W, LOCATING_LABEL_H); + locatingLabel_->SetText("定位中..."); + locatingLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LOCATING_LABEL_FONT); + locatingLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(locatingLabel_); + + gpsSignalView_ = new UIImageView(); + if (gpsSignalView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage gpsSignalView_ new fail"); + return; + } + gpsSignalView_->SetPosition(SIGNAL_X, SIGNAL_Y); + GpsSignal signal = SportModel::GetInstance().GetGpsSignal(); + if (signal == SPORT_GPS_SIGNAL0) { + LOADIMG::LoadImageViewImg(gpsSignalView_, SPORT_IMAGE, IMAGE_SPORT_SIGNAL0); + } else if (signal == SPORT_GPS_SIGNAL1) { + LOADIMG::LoadImageViewImg(gpsSignalView_, SPORT_IMAGE, IMAGE_SPORT_SIGNAL1); + } else if (signal == SPORT_GPS_SIGNAL2) { + LOADIMG::LoadImageViewImg(gpsSignalView_, SPORT_IMAGE, IMAGE_SPORT_SIGNAL2); + } else if (signal == SPORT_GPS_SIGNAL3) { + LOADIMG::LoadImageViewImg(gpsSignalView_, SPORT_IMAGE, IMAGE_SPORT_SIGNAL3); + } + group_->Add(gpsSignalView_); + + gpsImageView_ = new UIImageView(); + if (gpsImageView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage gpsImageView_ new fail"); + return; + } + gpsImageView_->SetPosition(GPS_X, GPS_Y); + LOADIMG::LoadImageViewImg(gpsImageView_, SPORT_IMAGE, IMAGE_SPORT_GPS); + group_->Add(gpsImageView_); + + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_RUNNING || sportType == SPORT_TYPE_INDOOR_SWIMMING) { + locatingLabel_->SetVisible(false); + gpsSignalView_->SetVisible(false); + gpsImageView_->SetVisible(false); + } else { + locatingLabel_->SetVisible(true); + gpsSignalView_->SetVisible(true); + gpsImageView_->SetVisible(true); + } +} + +void SportPreparePage::InitHeartRateView() +{ + heartRateLabel_ = new UILabel(); + if (heartRateLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage heartRateLabel_ new fail"); + return; + } + heartRateLabel_->SetPosition(HEARTBEAT_LABEL_X, HEARTBEAT_LABEL_Y, HEARTBEAT_LABEL_W, HEARTBEAT_LABEL_H); + heartRateLabel_->SetText("95"); // 桩数据 + heartRateLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEARTBEAT_LABEL_FONT); + heartRateLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(heartRateLabel_); + + heartRateImageView_ = new UIImageView(); + if (heartRateImageView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage heartRateImageView_ new fail"); + return; + } + heartRateImageView_->SetPosition(HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y); + LOADIMG::LoadImageViewImg(heartRateImageView_, SPORT_IMAGE, IMAGE_SPORT_HEART1); + group_->Add(heartRateImageView_); +} + +void SportPreparePage::InitGoButtonView() +{ + goButton_ = new UILabelButton(); + if (goButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage goButton_ new fail"); + return; + } + goButton_->SetPosition(GO_BUTTON_X, GO_BUTTON_Y, GO_BUTTON_W, GO_BUTTON_H); + goButton_->SetViewId(SPORT_PREPARE_GO_BUTTON); + goButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + goButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + goButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_OUTDOOR_RUNNING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO1, IMAGE_SPORT_GO1); + } else if (sportType == SPORT_TYPE_INDOOR_RUNNING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO2, IMAGE_SPORT_GO2); + } else if (sportType == SPORT_TYPE_CYCLING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO3, IMAGE_SPORT_GO3); + } else if (sportType == SPORT_TYPE_CLIMBING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO4, IMAGE_SPORT_GO4); + } else if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO6, IMAGE_SPORT_GO6); + } else if (sportType == SPORT_TYPE_OUTDOOR_SWIMMING) { + LOADIMG::LoadBtnImage(goButton_, SPORT_IMAGE, IMAGE_SPORT_GO5, IMAGE_SPORT_GO5); + } + goButton_->SetOnClickListener(this); + group_->Add(goButton_); +} + +void SportPreparePage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_OUTDOOR_RUNNING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG6); + } else if (sportType == SPORT_TYPE_INDOOR_RUNNING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG1); + } else if (sportType == SPORT_TYPE_CYCLING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG4); + } else if (sportType == SPORT_TYPE_CLIMBING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG3); + } else if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG2); + } else if (sportType == SPORT_TYPE_OUTDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG5); + } + group_->Add(background_); +} + +void SportPreparePage::OnStart(void *data) +{ + startTime_ = time(nullptr); // 用于在 animator 回调中, 模拟显示 '定位中' + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + InitBackgroundView(); + InitTimeLableVIew(); + InitBatteryView(); + InitCenterView(); + InitGPSView(); + InitHeartRateView(); + InitGoButtonView(); + AddViewToPageContainer(group_); + + callback_ = new SportPrepareAnimatorCallback(this); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage::OnStart callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPreparePage::OnStart new Animator animator_ fail"); + return; + } +} + +void SportPreparePage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } +} + +void SportPreparePage::OnResume() +{ + if (animator_ != nullptr) { + if (animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } +} + +bool SportPreparePage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_MENU, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportPreparePage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_PREPARE_GO_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_COUNTDOWN, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPresenter.cpp new file mode 100644 index 000000000..b510e8509 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPresenter + * Create: 2025-06-06 + */ + +#include "NativeRegisterManager.h" +#include "sport/SportView.h" +#include "sport/SportPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_SPORT, SportView, SportPresenter, SPORT_ICON, SPORT_ICON, "运动"); +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPromptPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPromptPage.cpp new file mode 100644 index 000000000..f5d713259 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportPromptPage.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportPromptPage + * Create: 2025-06-06 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportModel.h" +#include "sport/SportPromptPage.h" + +namespace OHOS { +static constexpr uint16_t ICON_X = 173; +static constexpr uint16_t ICON_Y = 48; +static constexpr uint16_t LABEL_X = 24; +static constexpr uint16_t LABEL_Y = 177; +static constexpr uint16_t LABEL_W = 405; +static constexpr uint16_t LABEL_H = 100; +static constexpr uint16_t LABEL_FONT = 36; +static constexpr uint16_t BUTTON_X1 = 104; +static constexpr uint16_t BUTTON_X2 = 240; +static constexpr uint16_t BUTTON_Y = 296; +static constexpr uint16_t BUTTON_W = 109; +static constexpr uint16_t BUTTON_H = 109; +static const char *PROMPT_CONTENT = "本次运动距离过短,不会记录数据。是否结束?"; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_PROMPT, SportPromptPage, false); + +SportPromptPage::~SportPromptPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (promptLabel_ != nullptr) { + delete promptLabel_; + promptLabel_ = nullptr; + } + if (promptIcon_ != nullptr) { + delete promptIcon_; + promptIcon_ = nullptr; + } + if (cancelButton_ != nullptr) { + delete cancelButton_; + cancelButton_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportPromptPage::~SportPromptPage"); +} + +void SportPromptPage::CreateUILabel() +{ + promptIcon_ = new UIImageView(); + if (promptIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPromptPage promptIcon_ new fail"); + return; + } + promptIcon_->SetPosition(ICON_X, ICON_Y); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, IMAGE_SPORT_FACE); + group_->Add(promptIcon_); + + promptLabel_ = new UILabel(); + if (promptLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPromptPage promptLabel_ new fail"); + return; + } + promptLabel_->SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + promptLabel_->SetText(PROMPT_CONTENT); + promptLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + promptLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(promptLabel_); +} + +void SportPromptPage::CreateUIButton() +{ + cancelButton_ = new UIButton(); + if (cancelButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPromptPage cancelButton_ new fail"); + return; + } + cancelButton_->SetPosition(BUTTON_X1, BUTTON_Y, BUTTON_W, BUTTON_H); + cancelButton_->SetViewId(SPORT_PROMPT_CANCEL_BUTTON); + cancelButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + cancelButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + cancelButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(cancelButton_, SPORT_IMAGE, IMAGE_SPORT_CANCEL, IMAGE_SPORT_CANCEL); + cancelButton_->SetOnClickListener(this); + group_->Add(cancelButton_); + + confirmButton_ = new UIButton(); + if (confirmButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPromptPage confirmButton_ new fail"); + return; + } + confirmButton_->SetPosition(BUTTON_X2, BUTTON_Y, BUTTON_W, BUTTON_H); + confirmButton_->SetViewId(SPORT_PROMPT_CONFIRM_BUTTON); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_CONFIRM, IMAGE_SPORT_CONFIRM); + confirmButton_->SetOnClickListener(this); + group_->Add(confirmButton_); +} + +void SportPromptPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportPromptPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreateUILabel(); + CreateUIButton(); + AddViewToPageContainer(group_); +} + +bool SportPromptPage::OnDrag(UIView &view, const DragEvent &event) +{ + return true; +} + +bool SportPromptPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_PROMPT_CANCEL_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_PAUSE, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SPORT_PROMPT_CONFIRM_BUTTON) == 0) { + SportModel::GetInstance().StopAndReport(true); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_MENU, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRateItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRateItemView.cpp new file mode 100644 index 000000000..071a4edc4 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRateItemView.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindHeartRateItemView + * Create: 2025-06-06 + */ + +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "sport/SportModel.h" +#include "sport/SportRemindHeartRateItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 13; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 17; +static constexpr uint16_t LABEL_W = 207; +static constexpr uint16_t LABEL_H = 39; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t HITS_X = 100; +static constexpr uint16_t HITS_Y = 60; +static constexpr uint16_t HITS_W = 176; +static constexpr uint16_t HITS_H = 29; +static constexpr uint16_t HITS_FONT = 24; +static constexpr uint16_t IMAGE_X = 370; +static constexpr uint16_t IMAGE_Y = 38; +static constexpr uint16_t BUTTON_X = 304; +static constexpr uint16_t BUTTON_Y = 33; +static constexpr uint16_t BUTTON_W = 81; +static constexpr uint16_t BUTTON_H = 46; + +SportRemindHeartRateItemView::SportRemindHeartRateItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + hits_.SetPosition(HITS_X, HITS_Y, HITS_W, HITS_H); + hits_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, HITS_FONT); + hits_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + hits_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + hits_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + nextImage_.SetPosition(IMAGE_X, IMAGE_Y); + LOADIMG::LoadImageViewImg(&nextImage_, SPORT_IMAGE, IMAGE_SPORT_NEXT); + + button_.SetPosition(BUTTON_X, BUTTON_Y, BUTTON_W, BUTTON_H); + button_.SetImages(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE1, SPORT_IMAGE), + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_SPORT_TOGGLE0, SPORT_IMAGE)); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&hits_); + Add(&button_); + Add(&nextImage_); +} + +SportRemindHeartRateItemView::~SportRemindHeartRateItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&hits_); + Remove(&button_); + Remove(&nextImage_); +} + +void SportRemindHeartRateItemView::SetItemInfo(const SportRemindHeartRateItem &itemInfo) +{ + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (itemInfo.itemId == SPORT_REMIND_HEARTRATE_ENABLE) { + button_.SetVisible(true); + button_.SetState(sportInfo->enableHeartRemind); + if (sportInfo->enableHeartRemind) { + hits_.SetText("开启"); + } else { + hits_.SetText("关闭"); + } + nextImage_.SetVisible(false); + } else if (itemInfo.itemId == SPORT_REMIND_HEARTRATE_RANGE) { + button_.SetVisible(false); + nextImage_.SetVisible(true); + hits_.SetText(GetHeartRateRangeDescription(sportInfo->heartRange)); + } + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRatePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRatePage.cpp new file mode 100644 index 000000000..f8d781397 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindHeartRatePage.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindHeartRatePage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportRemindHeartRatePage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 324; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t LIST_REBOUND_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_REMIND_HEARTRATE, SportRemindHeartRatePage, false); + +static SportRemindHeartRatePage *g_SportRemindHeartRatePageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportRemindHeartRateItemView *item = new SportRemindHeartRateItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportRemindHeartRatePageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportRemindHeartRateItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportRemindHeartRateItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportRemindHeartRatePage::SportRemindHeartRatePage() +{ + g_SportRemindHeartRatePageInstance = this; +} + +SportRemindHeartRatePage::~SportRemindHeartRatePage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (remindHeartRateList_ != nullptr) { + delete remindHeartRateList_; + remindHeartRateList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportRemindHeartRatePage::~SportRemindHeartRatePage"); +} + +void SportRemindHeartRatePage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindHeartRatePage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("心率提醒"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportRemindHeartRatePage::CreateUIList() +{ + remindHeartRateList_ = new UISimpleList(); + if (remindHeartRateList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindHeartRatePage remindHeartRateList_ new fail"); + return; + } + remindHeartRateList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + remindHeartRateList_->SetThrowDrag(true); + remindHeartRateList_->SetDraggable(true); + remindHeartRateList_->SetReboundSize(LIST_REBOUND_SIZE); + remindHeartRateList_->EnableAutoAlign(true); + remindHeartRateList_->SetElastic(true); + remindHeartRateList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + for (uint8_t i = 0; i < SPORT_REMIND_HEARTRATE_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&remindHeartRates_[i]); + remindHeartRateList_->AddContent(content); + } + remindHeartRateList_->RefreshList(); + group_->Add(remindHeartRateList_); +} + +void SportRemindHeartRatePage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindHeartRatePage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportRemindHeartRatePage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportRemindHeartRatePage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_REMIND_HEARTRATE_ITEM_ENABLE) == 0) { + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + sportInfo->enableHeartRemind = !sportInfo->enableHeartRemind; + remindHeartRateList_->RefreshList(); + SportModel::GetInstance().SaveConfig(SPORT_CONFIG_INFO); + } else if (strcmp(view.GetViewId(), SPORT_REMIND_HEARTRATE_ITEM_RANGE) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_HEARTRATE_RANGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalItemView.cpp new file mode 100644 index 000000000..aab3e77cf --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalItemView.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindIntervalItemView + * Create: 2025-06-06 + */ + +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "sport/SportModel.h" +#include "sport/SportRemindIntervalItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 13; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 31; +static constexpr uint16_t LABEL_W = 179; +static constexpr uint16_t LABEL_H = 37; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t IMAGE_X = 370; +static constexpr uint16_t IMAGE_Y = 38; + +SportRemindIntervalItemView::SportRemindIntervalItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + nextImage_.SetPosition(IMAGE_X, IMAGE_Y); + LOADIMG::LoadImageViewImg(&nextImage_, SPORT_IMAGE, IMAGE_SPORT_NEXT); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&nextImage_); +} + +SportRemindIntervalItemView::~SportRemindIntervalItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&nextImage_); +} + +void SportRemindIntervalItemView::SetItemInfo(const SportRemindIntervalItem &itemInfo) +{ + SportType sportType = SportModel::GetInstance().GetSportType(); + if (itemInfo.itemId == SPORT_REMIND_INTERVAL_DISTANCE && sportType == SPORT_TYPE_INDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, IMAGE_SPORT_LAP); + label_.SetText("趟数"); + nextImage_.SetVisible(true); + } else { + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + nextImage_.SetVisible(true); + } + if (itemInfo.itemId == SPORT_REMIND_INTERVAL_NONE) { + nextImage_.SetVisible(false); + } + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalPage.cpp new file mode 100644 index 000000000..fb95d8ae3 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindIntervalPage.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindIntervalPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportRemindIntervalPage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 324; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t BLANK_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_REMIND_INTERVAL, SportRemindIntervalPage, false); + +static SportRemindIntervalPage *g_SportRemindIntervalPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportRemindIntervalItemView *item = new SportRemindIntervalItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportRemindIntervalPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportRemindIntervalItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportRemindIntervalItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportRemindIntervalPage::SportRemindIntervalPage() +{ + g_SportRemindIntervalPageInstance = this; +} + +SportRemindIntervalPage::~SportRemindIntervalPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (remindIntervalList_ != nullptr) { + delete remindIntervalList_; + remindIntervalList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportRemindIntervalPage::~SportRemindIntervalPage"); +} + +void SportRemindIntervalPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindIntervalPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG); + group_->Add(background_); +} + +void SportRemindIntervalPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindIntervalPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("间隔提醒"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportRemindIntervalPage::CreateUIList() +{ + remindIntervalList_ = new UISimpleList(); + if (remindIntervalList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindIntervalPage remindIntervalList_ new fail"); + return; + } + remindIntervalList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + remindIntervalList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + remindIntervalList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + remindIntervalList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < SPORT_REMIND_INTERVAL_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&remindIntervals_[i]); + remindIntervalList_->AddContent(content); + } + remindIntervalList_->RefreshList(); + group_->Add(remindIntervalList_); +} + +void SportRemindIntervalPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindIntervalPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetReboundSize(REBOUND_SIZE, UIAbstractScroll::Direction::BOTTOM); + group_->SetScrollBlankSize(BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportRemindIntervalPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportRemindIntervalPage::OnClick(UIView &view, const ClickEvent &event) +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (strcmp(view.GetViewId(), SPORT_REMIND_INTERVAL_ITEM_DISTANCE) == 0) { + sportInfo->setType = SPORT_SET_TYPE_REMIND; + sportInfo->remindTypeTemp = sportInfo->remindType; + sportInfo->remindType = SPORT_REMIND_INTERVAL_DISTANCE; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_SETTING, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SPORT_REMIND_INTERVAL_ITEM_TIME) == 0) { + sportInfo->setType = SPORT_SET_TYPE_REMIND; + sportInfo->remindTypeTemp = sportInfo->remindType; + sportInfo->remindType = SPORT_REMIND_INTERVAL_TIME; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_SETTING, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SPORT_REMIND_INTERVAL_ITEM_NONE) == 0) { + sportInfo->remindTypeTemp = sportInfo->remindType; + sportInfo->remindType = SPORT_REMIND_INTERVAL_NONE; + SportModel::GetInstance().SaveConfig(SPORT_CONFIG_INFO); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindItemView.cpp new file mode 100644 index 000000000..fc2276a2b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindItemView.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindItemView + * Create: 2025-06-06 + */ + +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "sport/SportModel.h" +#include "sport/SportRemindItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 13; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 17; +static constexpr uint16_t LABEL_W = 207; +static constexpr uint16_t LABEL_H = 39; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t HITS_X = 100; +static constexpr uint16_t HITS_Y = 60; +static constexpr uint16_t HITS_W = 176; +static constexpr uint16_t HITS_H = 29; +static constexpr uint16_t HITS_FONT = 24; +static constexpr uint16_t IMAGE_X = 370; +static constexpr uint16_t IMAGE_Y = 38; + +SportRemindItemView::SportRemindItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + hits_.SetPosition(HITS_X, HITS_Y, HITS_W, HITS_H); + hits_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, HITS_FONT); + hits_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + hits_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + hits_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + nextImage_.SetPosition(IMAGE_X, IMAGE_Y); + LOADIMG::LoadImageViewImg(&nextImage_, SPORT_IMAGE, IMAGE_SPORT_NEXT); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&hits_); + Add(&nextImage_); +} + +SportRemindItemView::~SportRemindItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&hits_); + Remove(&nextImage_); +} + +void SportRemindItemView::SetItemInfo(const SportRemindItem &itemInfo) +{ + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (itemInfo.itemId == SPORT_REMIND_INTERVAL) { + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_NONE || !sportInfo->isRemindSetted) { + hits_.SetText("无提醒"); + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + hits_.SetText((std::to_string(sportInfo->remindValue) + "趟").c_str()); + } else { + hits_.SetText((std::to_string(sportInfo->remindValue) + "km").c_str()); + } + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + hits_.SetText((std::to_string(sportInfo->remindValue) + "分钟").c_str()); + } + } else if (itemInfo.itemId == SPORT_REMIND_HEARTRATE) { + if (!sportInfo->enableHeartRemind) { + hits_.SetText("关闭"); + } else { + hits_.SetText("开启"); + } + } + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindPage.cpp new file mode 100644 index 000000000..84fe66d2b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportRemindPage.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportRemindPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportRemindPage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 324; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t LIST_REBOUND_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_REMIND, SportRemindPage, false); + +static SportRemindPage *g_SportRemindPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportRemindItemView *item = new SportRemindItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportRemindPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportRemindItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportRemindItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportRemindPage::SportRemindPage() +{ + g_SportRemindPageInstance = this; +} + +SportRemindPage::~SportRemindPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (remindList_ != nullptr) { + delete remindList_; + remindList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportRemindPage::~SportRemindPage"); +} + +void SportRemindPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG); + group_->Add(background_); +} + +void SportRemindPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("提醒"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportRemindPage::CreateUIList() +{ + remindList_ = new UISimpleList(); + if (remindList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindPage remindList_ new fail"); + return; + } + remindList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + remindList_->SetThrowDrag(true); + remindList_->SetDraggable(true); + remindList_->SetReboundSize(LIST_REBOUND_SIZE); + remindList_->EnableAutoAlign(true); + remindList_->SetElastic(true); + remindList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + for (uint8_t i = 0; i < SPORT_REMIND_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&reminds_[i]); + remindList_->AddContent(content); + } + remindList_->RefreshList(); + group_->Add(remindList_); +} + +void SportRemindPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportRemindPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportRemindPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_SETTINGS, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportRemindPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SPORT_REMIND_ITEM_INTERVAL) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND_INTERVAL, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SPORT_REMIND_ITEM_HEARTRATE) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND_HEARTRATE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsItemView.cpp new file mode 100644 index 000000000..0a8a5724d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsItemView.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportSettingsItemView + * Create: 2025-06-06 + */ + +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "sport/SportModel.h" +#include "sport/SportSettingsItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 13; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y1 = 17; +static constexpr uint16_t LABEL_Y2 = 31; +static constexpr uint16_t LABEL_W = 207; +static constexpr uint16_t LABEL_H = 39; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t HITS_X = 100; +static constexpr uint16_t HITS_Y = 60; +static constexpr uint16_t HITS_W = 176; +static constexpr uint16_t HITS_H = 29; +static constexpr uint16_t HITS_FONT = 24; +static constexpr uint16_t IMAGE_X = 370; +static constexpr uint16_t IMAGE_Y = 38; + +SportSettingsItemView::SportSettingsItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + hits_.SetPosition(HITS_X, HITS_Y, HITS_W, HITS_H); + hits_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, HITS_FONT); + hits_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + hits_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + hits_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + nextImage_.SetPosition(IMAGE_X, IMAGE_Y); + LOADIMG::LoadImageViewImg(&nextImage_, SPORT_IMAGE, IMAGE_SPORT_NEXT); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&hits_); + Add(&nextImage_); +} + +SportSettingsItemView::~SportSettingsItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&hits_); + Remove(&nextImage_); +} + +void SportSettingsItemView::SetItemInfo(const SportSettingsItem &itemInfo) +{ + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + SetViewId(itemInfo.viewId); + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (itemInfo.itemId == SPORT_SET_TYPE_TARGET) { + label_.SetPosition(LABEL_X, LABEL_Y1, LABEL_W, LABEL_H); + hits_.SetVisible(true); + if (!sportInfo->isTargetSetted) { + hits_.SetText("无目标"); + } else if (sportInfo->targetType == SPORT_TARGET_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + hits_.SetText((std::to_string(sportInfo->targetValue) + "趟").c_str()); + } else { + hits_.SetText((std::to_string(sportInfo->targetValue) + "km").c_str()); + } + } else if (sportInfo->targetType == SPORT_TARGET_TIME) { + hits_.SetText((std::to_string(sportInfo->targetValue) + "分钟").c_str()); + } else if (sportInfo->targetType == SPORT_TARGET_CALORIE) { + hits_.SetText((std::to_string(sportInfo->targetValue) + "千卡").c_str()); + } + } else if (itemInfo.itemId == SPORT_SET_TYPE_REMIND) { + label_.SetPosition(LABEL_X, LABEL_Y1, LABEL_W, LABEL_H); + hits_.SetVisible(true); + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + hits_.SetText((std::to_string(sportInfo->remindValue) + "趟").c_str()); + } else { + hits_.SetText((std::to_string(sportInfo->remindValue) + "km").c_str()); + } + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + hits_.SetText((std::to_string(sportInfo->remindValue) + "分钟").c_str()); + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_NONE || !sportInfo->isRemindSetted) { + if (sportInfo->enableHeartRemind) { + hits_.SetText(GetHeartRateRangeDescription(sportInfo->heartRange)); + } else { + hits_.SetText("无提醒"); + } + } + } else if (itemInfo.itemId == SPORT_SET_TYPE_MISTOUCH) { + label_.SetPosition(LABEL_X, LABEL_Y2, LABEL_W, LABEL_H); + hits_.SetVisible(false); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsPage.cpp new file mode 100644 index 000000000..8a5c8521b --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportSettingsPage.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportSettingsPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportSettingsPage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 324; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t BLANK_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_SETTINGS, SportSettingsPage, false); + +static SportSettingsPage *g_SportSettingsPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportSettingsItemView *item = new SportSettingsItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportSettingsPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportSettingsItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportSettingsItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportSettingsPage::SportSettingsPage() +{ + g_SportSettingsPageInstance = this; +} + +SportSettingsPage::~SportSettingsPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (settingList_ != nullptr) { + delete settingList_; + settingList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportSettingsPage::~SportSettingsPage"); +} + +void SportSettingsPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportSettingsPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG); + group_->Add(background_); +} + +void SportSettingsPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportSettingsPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("设置"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportSettingsPage::CreateUIList() +{ + settingList_ = new UISimpleList(); + if (settingList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportSettingsPage settingList_ new fail"); + return; + } + settingList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + settingList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + settingList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + settingList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < SPORT_SET_TYPE_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&settings_[i]); + settingList_->AddContent(content); + } + settingList_->RefreshList(); + group_->Add(settingList_); +} + +void SportSettingsPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportSettingsPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetReboundSize(REBOUND_SIZE, UIAbstractScroll::Direction::BOTTOM); + group_->SetScrollBlankSize(BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportSettingsPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_MENU, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportSettingsPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), SETTINGS_ITEM_TARGET) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SETTINGS_ITEM_REMIND) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } else if (strcmp(view.GetViewId(), SETTINGS_ITEM_MISTOUCH) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_MISTOUCH, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetItemView.cpp new file mode 100644 index 000000000..2afb6400d --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetItemView.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetItemView + * Create: 2025-06-06 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "sport/SportModel.h" +#include "sport/SportTargetItemView.h" + +namespace OHOS { +static constexpr uint16_t BG_X = 0; +static constexpr uint16_t BG_Y = 6; +static constexpr uint16_t ICON_X = 8; +static constexpr uint16_t ICON_Y = 13; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 31; +static constexpr uint16_t LABEL_W = 179; +static constexpr uint16_t LABEL_H = 37; +static constexpr uint16_t LABEL_FONT = 32; +static constexpr uint16_t IMAGE_X = 370; +static constexpr uint16_t IMAGE_Y = 38; + +SportTargetItemView::SportTargetItemView() +{ + bgImage_.SetPosition(BG_X, BG_Y); + LOADIMG::LoadImageViewImg(&bgImage_, SPORT_IMAGE, IMAGE_SPORT_ITEMBG); + + icon_.SetPosition(ICON_X, ICON_Y); + + label_.SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + nextImage_.SetPosition(IMAGE_X, IMAGE_Y); + LOADIMG::LoadImageViewImg(&nextImage_, SPORT_IMAGE, IMAGE_SPORT_NEXT); + + Add(&bgImage_); + Add(&icon_); + Add(&label_); + Add(&nextImage_); +} + +SportTargetItemView::~SportTargetItemView() +{ + Remove(&bgImage_); + Remove(&icon_); + Remove(&label_); + Remove(&nextImage_); +} + +void SportTargetItemView::SetItemInfo(const SportTargetItem &itemInfo) +{ + SportType sportType = SportModel::GetInstance().GetSportType(); + if (itemInfo.itemId == SPORT_TARGET_DISTANCE && sportType == SPORT_TYPE_INDOOR_SWIMMING) { + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, IMAGE_SPORT_LAP); + label_.SetText("趟数"); + } else { + LOADIMG::LoadImageViewImg(&icon_, SPORT_IMAGE, itemInfo.iconId); + label_.SetText(itemInfo.label); + } + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPage.cpp new file mode 100644 index 000000000..91e7843c5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPage.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportTargetPage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 38; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t LIST_X = 20; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 415; +static constexpr uint16_t LIST_H = 324; +static constexpr uint16_t LIST_ITEM_W = 415; +static constexpr uint16_t LIST_ITEM_H = 108; +static constexpr uint16_t REBOUND_SIZE = 60; +static constexpr uint16_t BLANK_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_TARGET, SportTargetPage, false); + +static SportTargetPage *g_SportTargetPageInstance = nullptr; + +static UIView *CreateViewCb(uint8_t type) +{ + SportTargetItemView *item = new SportTargetItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_W, LIST_ITEM_H); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + item->SetOnClickListener(g_SportTargetPageInstance); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + SportTargetItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + SportTargetItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +SportTargetPage::SportTargetPage() +{ + g_SportTargetPageInstance = this; +} + +SportTargetPage::~SportTargetPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (targetList_ != nullptr) { + delete targetList_; + targetList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportTargetPage::~SportTargetPage"); +} + +void SportTargetPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, SPORT_IMAGE, IMAGE_SPORT_BG); + group_->Add(background_); +} + +void SportTargetPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetText("目标"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportTargetPage::CreateUIList() +{ + targetList_ = new UISimpleList(); + if (targetList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPage targetList_ new fail"); + return; + } + targetList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + targetList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + targetList_->SetBoundaryIntercept(DragEvent::DIRECTION_TOP_TO_BOTTOM, false); + targetList_->SetBoundaryIntercept(DragEvent::DIRECTION_BOTTOM_TO_TOP, false); + + for (uint8_t i = 0; i < SPORT_TARGET_MAX; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + content.data = reinterpret_cast(&targets_[i]); + targetList_->AddContent(content); + } + targetList_->RefreshList(); + group_->Add(targetList_); +} + +void SportTargetPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + group_->SetReboundSize(REBOUND_SIZE, UIAbstractScroll::Direction::BOTTOM); + group_->SetScrollBlankSize(BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool SportTargetPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_SETTINGS, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportTargetPage::OnClick(UIView &view, const ClickEvent &event) +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + sportInfo->setType = SPORT_SET_TYPE_TARGET; + if (strcmp(view.GetViewId(), SPORT_TARGET_ITEM_DISTANCE) == 0) { + sportInfo->targetTypeTemp = sportInfo->targetType; + sportInfo->targetType = SPORT_TARGET_DISTANCE; + } else if (strcmp(view.GetViewId(), SPORT_TARGET_ITEM_TIME) == 0) { + sportInfo->targetTypeTemp = sportInfo->targetType; + sportInfo->targetType = SPORT_TARGET_TIME; + } else if (strcmp(view.GetViewId(), SPORT_TARGET_ITEM_CALORIE) == 0) { + sportInfo->targetTypeTemp = sportInfo->targetType; + sportInfo->targetType = SPORT_TARGET_CALORIE; + } + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET_SETTING, + TransitionType::TRANSITION_INVALID, false); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPromptPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPromptPage.cpp new file mode 100644 index 000000000..2c5c21171 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetPromptPage.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetPromptPage + * Create: 2025-06-06 + */ + +#include +#include "wearable_log.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportTargetPromptPage.h" + +namespace OHOS { +static constexpr uint16_t PAGE_VISIBLE_SECOND = 3; +static constexpr uint16_t PROMPT_DISTANCE_INDEX = 0; +static constexpr uint16_t PROMPT_TIME_INDEX = 1; +static constexpr uint16_t PROMPT_LAP_INDEX = 2; +static constexpr uint16_t IMAGE_X = 46; +static constexpr uint16_t IMAGE_Y = 72; +static constexpr uint16_t IMAGE_COMPLETE_X = 85; +static constexpr uint16_t IMAGE_COMPLETE_Y = 32; +static constexpr uint16_t IMAGE_HEART_X = 167; +static constexpr uint16_t IMAGE_HEART_Y = 118; +static constexpr uint16_t LABEL_X = 25; +static constexpr uint16_t LABEL_Y = 250; +static constexpr uint16_t LABEL_W = 404; +static constexpr uint16_t LABEL_H = 49; +static constexpr uint16_t LABEL_FONT = 36; +static const char *PROMPT_HALF_CONTENT = "本次运动目标已完成50%"; +static const char *PROMPT_FINISH_CONTENT = "本次运动目标已完成"; +static const int PROPMT_IMAGES[][10] = { + {IMAGE_SPORT_1KM, IMAGE_SPORT_3KM, IMAGE_SPORT_5KM, IMAGE_SPORT_7KM, IMAGE_SPORT_10KM, IMAGE_SPORT_15KM, + IMAGE_SPORT_20KM, IMAGE_SPORT_25KM, IMAGE_SPORT_30KM, IMAGE_SPORT_40KM}, + {IMAGE_SPORT_10MIN, IMAGE_SPORT_20MIN, IMAGE_SPORT_30MIN, IMAGE_SPORT_60MIN, IMAGE_SPORT_120MIN, IMAGE_SPORT_180MIN, + IMAGE_SPORT_200MIN}, + {IMAGE_SPORT_LAP1, IMAGE_SPORT_LAP2, IMAGE_SPORT_LAP4, IMAGE_SPORT_LAP6, IMAGE_SPORT_LAP8, IMAGE_SPORT_LAP10, + IMAGE_SPORT_LAP12, IMAGE_SPORT_LAP16, IMAGE_SPORT_LAP20, IMAGE_SPORT_LAP30}, +}; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_TARGET_PROMPT, SportTargetPromptPage, false); + +void SportTargetPromptPage::SportPromptAnimatorCallback::Callback(UIView *view) +{ + UNUSED(view); + + time_t now = time(nullptr); + if (now - page_->startTime_ > PAGE_VISIBLE_SECOND) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_DATA, + TransitionType::TRANSITION_INVALID, false); + } +} + +SportTargetPromptPage::~SportTargetPromptPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (promptIcon_ != nullptr) { + delete promptIcon_; + promptIcon_ = nullptr; + } + if (promptLabel_ != nullptr) { + delete promptLabel_; + promptLabel_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage::~SportTargetPromptPage"); +} + +void SportTargetPromptPage::CreatePromptView() +{ + promptIcon_ = new UIImageView(); + if (promptIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage promptIcon_ new fail"); + return; + } + promptIcon_->SetPosition(IMAGE_X, IMAGE_Y); + group_->Add(promptIcon_); + + promptLabel_ = new UILabel(); + if (promptLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage promptLabel_ new fail"); + return; + } + promptLabel_->SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + promptLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + promptLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(promptLabel_); + + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->promptType == SPORT_SET_TYPE_TARGET) { + if (sportInfo->targetComplete) { + promptLabel_->SetText(PROMPT_FINISH_CONTENT); + promptIcon_->SetPosition(IMAGE_COMPLETE_X, IMAGE_COMPLETE_Y); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, IMAGE_SPORT_FINISH); + } else if (sportInfo->targetHalf) { + promptLabel_->SetText(PROMPT_HALF_CONTENT); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, IMAGE_SPORT_HALF); + } + } else if (sportInfo->promptType == SPORT_SET_TYPE_REMIND) { + std::string promptStr; + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + promptStr = "第" + std::to_string(sportInfo->remindTimes) + "个" + + std::to_string(sportInfo->remindValue) + "趟已完成!"; + promptLabel_->SetText(promptStr.c_str()); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, + PROPMT_IMAGES[PROMPT_LAP_INDEX][sportInfo->remindIndex]); + } else { + promptStr = "第" + std::to_string(sportInfo->remindTimes) + "个" + + std::to_string(sportInfo->remindValue) + "公里已完成!"; + promptLabel_->SetText(promptStr.c_str()); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, + PROPMT_IMAGES[PROMPT_DISTANCE_INDEX][sportInfo->remindIndex]); + } + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + promptStr = "第" + std::to_string(sportInfo->remindTimes) + "个" + std::to_string(sportInfo->remindValue) + + "分钟已完成!"; + promptLabel_->SetText(promptStr.c_str()); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, + PROPMT_IMAGES[PROMPT_TIME_INDEX][sportInfo->remindIndex]); + } + } else if (sportInfo->promptType == SPORT_SET_TYPE_HEARTRATE) { + std::string promptStr = "当前心率" + std::to_string(sportInfo->data.heartRate) + "次/分!"; + promptLabel_->SetText(promptStr.c_str()); + promptIcon_->SetPosition(IMAGE_HEART_X, IMAGE_HEART_Y); + LOADIMG::LoadImageViewImg(promptIcon_, SPORT_IMAGE, IMAGE_SPORT_HEART3); + } +} + +void SportTargetPromptPage::OnStart(void *data) +{ + startTime_ = time(nullptr); + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreatePromptView(); + AddViewToPageContainer(group_); + + callback_ = new SportPromptAnimatorCallback(this); + if (callback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage::OnStart callback_ new fail"); + return; + } + + animator_ = new Animator(callback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetPromptPage::OnStart new Animator animator_ fail"); + return; + } +} + +void SportTargetPromptPage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } +} + +void SportTargetPromptPage::OnResume() +{ + if (animator_ != nullptr) { + if (animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } +} + +bool SportTargetPromptPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_DATA, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool SportTargetPromptPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetSettingPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetSettingPage.cpp new file mode 100644 index 000000000..c3a10c3d7 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/sport/src/SportTargetSettingPage.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SportTargetSettingPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "ui_resource_sport.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "sport/SportView.h" +#include "sport/SportTargetSettingPage.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 100; +static constexpr uint16_t LABELS_Y = 39; +static constexpr uint16_t LABELS_W = 253; +static constexpr uint16_t LABELS_H = 53; +static constexpr uint16_t LABELS_FONT = 38; +static constexpr uint16_t PICKER_X = 103; +static constexpr uint16_t PICKER_Y = 122; +static constexpr uint16_t PICKER_W = 247; +static constexpr uint16_t PICKER_H = 212; +static constexpr uint16_t BACKGROUND_FONT = 38; +static constexpr uint16_t HIGHTLIGHT_FONT = 44; +static constexpr uint16_t PICKER_ITEM_H = 65; +static constexpr uint16_t BUTTON_X = 63; +static constexpr uint16_t BUTTON_Y = 361; +static constexpr uint16_t BUTTON_W = 328; +static constexpr uint16_t BUTTON_H = 93; + +REGIST_SLICE_PAGE(VIEW_SPORT, SportPages::SPORT_PAGE_TARGET_SETTING, SportTargetSettingPage, false); + +SportTargetSettingPage::~SportTargetSettingPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (picker_ != nullptr) { + delete picker_; + picker_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportTargetSettingPage::~SportTargetSettingPage"); +} + +void SportTargetSettingPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetSettingPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABELS_FONT); + group_->Add(titleLabel_); +} + +void SportTargetSettingPage::CreateUIPicker() +{ + picker_ = new UIPicker(); + if (picker_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetSettingPage picker_ new fail"); + return; + } + picker_->SetPosition(PICKER_X, PICKER_Y, PICKER_W, PICKER_H); + picker_->SetItemHeight(PICKER_ITEM_H); + picker_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + picker_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + group_->Add(picker_); +} + +void SportTargetSettingPage::CreateUIButton() +{ + confirmButton_ = new UILabelButton(); + if (confirmButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetSettingPage confirmButton_ new fail"); + return; + } + confirmButton_->SetPosition(BUTTON_X, BUTTON_Y, BUTTON_W, BUTTON_H); + confirmButton_->SetViewId(TARGET_SETTING_CONFIRM_BUTTON); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->setType == SPORT_SET_TYPE_TARGET) { + if (sportInfo->targetType == SPORT_TARGET_DISTANCE) { + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_OK1, IMAGE_SPORT_OK1); + } else if (sportInfo->targetType == SPORT_TARGET_TIME) { + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_OK3, IMAGE_SPORT_OK3); + } else if (sportInfo->targetType == SPORT_TARGET_CALORIE) { + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_OK2, IMAGE_SPORT_OK2); + } + } else if (sportInfo->setType == SPORT_SET_TYPE_REMIND) { + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_OK1, IMAGE_SPORT_OK1); + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + LOADIMG::LoadBtnImage(confirmButton_, SPORT_IMAGE, IMAGE_SPORT_OK3, IMAGE_SPORT_OK3); + } + } + + confirmButton_->SetOnClickListener(this); + group_->Add(confirmButton_); +} + +void SportTargetSettingPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportTargetSettingPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + CreateUILabel(); + CreateUIPicker(); + CreateUIButton(); + AddViewToPageContainer(group_); + + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->setType == SPORT_SET_TYPE_TARGET) { + UpdateViewByTargetType(); + } else if (sportInfo->setType == SPORT_SET_TYPE_REMIND) { + UpdateViewByRemindType(); + } +} + +bool SportTargetSettingPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->setType == SPORT_SET_TYPE_TARGET) { + sportInfo->targetType = sportInfo->targetTypeTemp; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET, + TransitionType::TRANSITION_INVALID, false); + } else if (sportInfo->setType == SPORT_SET_TYPE_REMIND) { + sportInfo->remindType = sportInfo->remindTypeTemp; + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } + } + return true; +} + +bool SportTargetSettingPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), TARGET_SETTING_CONFIRM_BUTTON) == 0) { + uint16_t index = picker_->GetSelected(); + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->setType == SPORT_SET_TYPE_TARGET) { + SportModel::GetInstance().SetTargetValue(index); + sportInfo->isTargetSetted = true; + SportModel::GetInstance().SaveConfig(SPORT_CONFIG_INFO); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_TARGET, + TransitionType::TRANSITION_INVALID, false); + } else if (sportInfo->setType == SPORT_SET_TYPE_REMIND) { + SportModel::GetInstance().SetRemindValue(index); + sportInfo->isRemindSetted = true; + SportModel::GetInstance().SaveConfig(SPORT_CONFIG_INFO); + NativeAbility::GetInstance().SwitchPageInSlice(SportPages::SPORT_PAGE_REMIND, + TransitionType::TRANSITION_INVALID, false); + } + } + return true; +} + +void SportTargetSettingPage::UpdateViewByTargetType() +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->targetType == SPORT_TARGET_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + titleLabel_->SetText("趟数"); + const char *uiLapData[] = {"1趟", "2趟", "4趟", "6趟", "8趟", "10趟", "12趟", "16趟", "20趟", "30趟"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0x52, 0xe4, 0xeb)); + picker_->SetValues(uiLapData, sizeof(uiLapData) / sizeof(uiLapData[0])); + } else { + titleLabel_->SetText("距离"); + const char *uiDistanceData[] = {"1km", "3km", "5km", "7km", "10km", "15km", "20km", "25km", "30km", "40km"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0x52, 0xe4, 0xeb)); + picker_->SetValues(uiDistanceData, sizeof(uiDistanceData) / sizeof(uiDistanceData[0])); + } + } else if (sportInfo->targetType == SPORT_TARGET_TIME) { + titleLabel_->SetText("时间"); + const char *uiTimeData[] = {"10分钟", "20分钟", "30分钟", "60分钟", "120分钟", "180分钟", "200分钟"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0xff, 0x75, 0x00)); + picker_->SetValues(uiTimeData, sizeof(uiTimeData) / sizeof(uiTimeData[0])); + } else if (sportInfo->targetType == SPORT_TARGET_CALORIE) { + titleLabel_->SetText("热量"); + const char *uiCalorieData[] = {"100千卡", "200千卡", "300千卡", "500千卡", "600千卡", "800千卡", "1000千卡"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0xff, 0x4d, 0x4f)); + picker_->SetValues(uiCalorieData, sizeof(uiCalorieData) / sizeof(uiCalorieData[0])); + } + titleLabel_->Invalidate(); + picker_->Invalidate(); + confirmButton_->Invalidate(); +} + +void SportTargetSettingPage::UpdateViewByRemindType() +{ + sport_info_t *sportInfo = SportModel::GetInstance().GetCurrSportInfo(); + if (sportInfo->remindType == SPORT_REMIND_INTERVAL_DISTANCE) { + SportType sportType = SportModel::GetInstance().GetSportType(); + if (sportType == SPORT_TYPE_INDOOR_SWIMMING) { + titleLabel_->SetText("趟数"); + const char *uiLapData[] = {"1趟", "2趟", "4趟", "6趟", "8趟", "10趟", "12趟", "16趟", "20趟", "30趟"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0x52, 0xe4, 0xeb)); + picker_->SetValues(uiLapData, sizeof(uiLapData) / sizeof(uiLapData[0])); + } else { + titleLabel_->SetText("距离"); + const char *uiDistanceData[] = {"1km", "3km", "5km", "7km", "10km", "15km", "20km", "25km", "30km", "40km"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0x52, 0xe4, 0xeb)); + picker_->SetValues(uiDistanceData, sizeof(uiDistanceData) / sizeof(uiDistanceData[0])); + } + } else if (sportInfo->remindType == SPORT_REMIND_INTERVAL_TIME) { + titleLabel_->SetText("时间"); + const char *uiTimeData[] = {"10分钟", "20分钟", "30分钟", "60分钟", "120分钟", "180分钟", "200分钟"}; + picker_->SetTextColor(Color::Gray(), Color::GetColorFromRGB(0xff, 0x75, 0x00)); + picker_->SetValues(uiTimeData, sizeof(uiTimeData) / sizeof(uiTimeData[0])); + } + titleLabel_->Invalidate(); + picker_->Invalidate(); + confirmButton_->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp index 80c4cfe9f..2d6c6cfc9 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp @@ -1,18 +1,12 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: StopwatchItemView * Create: 2025-06-06 */ -#include "UiConfig.h" #include "stopwatch/StopwatchItemView.h" -#include "common/image_cache_manager.h" -#include "ui_stopwatch_resource.h" -#include "wearable_log.h" namespace OHOS { -static constexpr uint16_t STOPWATCH_ITEM_WIDTH = 312; -static constexpr uint16_t STOPWATCH_ITEM_HEIGHT = 60; static constexpr uint16_t STOPWATCH_ITEM_BG_XPOS = 6; static constexpr uint16_t STOPWATCH_ITEM_BG_YPOS = 8; static constexpr uint16_t STOPWATCH_ITEM_BG_WIDTH = 300; @@ -29,10 +23,6 @@ static constexpr uint32_t STOPWATCH_ITEM_FONT_COLOR = 0xffff8530; StopwatchItemView::StopwatchItemView() { - SetPosition(0, 0, STOPWATCH_ITEM_WIDTH, STOPWATCH_ITEM_HEIGHT); - SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - SetTouchable(true); - itemBg_.SetPosition(STOPWATCH_ITEM_BG_XPOS, STOPWATCH_ITEM_BG_YPOS); itemBg_.Resize(STOPWATCH_ITEM_BG_WIDTH, STOPWATCH_ITEM_BG_HEIGHT); itemBg_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); @@ -65,9 +55,9 @@ StopwatchItemView::~StopwatchItemView() Remove(&itemBg_); } -void StopwatchItemView::SetItemInfo(int16_t index, const StopwatchItem &itemInfo) +void StopwatchItemView::SetItemInfo(const StopwatchItem &itemInfo) { - nameLabel_.SetText(("分段" + std::to_string(index)).c_str()); + nameLabel_.SetText(("分段" + std::to_string(itemInfo.index)).c_str()); recordLabel_.SetText(itemInfo.record.c_str()); if (itemInfo.isLatest) { nameLabel_.SetStyle(STYLE_TEXT_COLOR, STOPWATCH_ITEM_FONT_COLOR); diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp index d73b785bc..36dde071c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp @@ -1,11 +1,12 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: StopwatchModel * Create: 2025-06-06 */ + #include -#include "stopwatch/StopwatchModel.h" #include "wearable_log.h" +#include "stopwatch/StopwatchModel.h" namespace OHOS { static constexpr uint16_t UNIT_SEC_TO_MSEC = 1000; @@ -36,13 +37,13 @@ void StopwatchModel::SetStartTime() void StopwatchModel::SaveElapsedTime() { - uiSavedElapsedTime_ += uiElapsedTime_; - uiElapsedTime_ = 0; + savedElapsedTime_ += elapsedTime_; + elapsedTime_ = 0; } uint64_t StopwatchModel::GetElapsedTime() { - return uiSavedElapsedTime_ + uiElapsedTime_; + return savedElapsedTime_ + elapsedTime_; } uint64_t StopwatchModel::UpdateElapsedTime() @@ -54,31 +55,26 @@ uint64_t StopwatchModel::UpdateElapsedTime() struct timeval64 currTime = {0}; gettimeofday64(&currTime, NULL); #endif - uiElapsedTime_ = (currTime.tv_sec * UNIT_SEC_TO_MSEC + currTime.tv_usec / UNIT_SEC_TO_MSEC) - - (startTime_.tv_sec * UNIT_SEC_TO_MSEC + startTime_.tv_usec / UNIT_SEC_TO_MSEC); - return uiSavedElapsedTime_ + uiElapsedTime_; + elapsedTime_ = (currTime.tv_sec * UNIT_SEC_TO_MSEC + currTime.tv_usec / UNIT_SEC_TO_MSEC) - + (startTime_.tv_sec * UNIT_SEC_TO_MSEC + startTime_.tv_usec / UNIT_SEC_TO_MSEC); + return savedElapsedTime_ + elapsedTime_; } void StopwatchModel::ResetCounter() { - uiElapsedTime_ = 0; - uiSavedElapsedTime_ = 0; + elapsedTime_ = 0; + savedElapsedTime_ = 0; records_.Clear(); } -bool StopwatchModel::GetActiveState() -{ - return bIsActive_; -} - -void StopwatchModel::SetActiveState() +bool StopwatchModel::GetRunningState() { - bIsActive_ = true; + return isRunning_; } -void StopwatchModel::SetInactiveState() +void StopwatchModel::SetRunningState(bool isRunning) { - bIsActive_ = false; + isRunning_ = isRunning; } List &StopwatchModel::GetRecordsList() @@ -97,24 +93,23 @@ void StopwatchModel::AddRecordToList(const StopwatchItem &record) records_.PushFront(record); } -bool StopwatchModel::IsInRecordView() +bool StopwatchModel::GetRecordListVisible() { - return bIsRecordView_; + return isRecordListVisible_; } -void StopwatchModel::SetRecordViewState(bool state) +void StopwatchModel::SetRecordListVisible(bool isVisible) { - bIsRecordView_ = state; + isRecordListVisible_ = isVisible; } -void StopwatchModel::ClearData() +bool StopwatchModel::GetTimeOverRangeState() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchModel::ClearData start"); - uiElapsedTime_ = 0; - uiSavedElapsedTime_ = 0; - bIsActive_ = false; - bIsRecordView_ = false; - startTime_ = {0}; - records_.Clear(); + return isTimeOverRange_; +} + +void StopwatchModel::SetTimeOverRangeState(bool isTimeOverRange) +{ + isTimeOverRange_ = isTimeOverRange; } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp index 0652df389..f7194f8a1 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp @@ -1,43 +1,44 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: StopwatchPage * Create: 2025-06-06 */ #include #include -#include "stopwatch/StopwatchPage.h" -#include "stopwatch/StopwatchView.h" -#include "stopwatch/StopwatchPresenter.h" -#include "stopwatch/StopwatchModel.h" #include "NativeAbility.h" #include "SlicePageFactory.h" #include "NativeRegisterManager.h" #include "UiConfig.h" #include "common/image_cache_manager.h" -#include "ui_stopwatch_resource.h" +#include "ui_resource_stopwatch.h" #include "main/LoadImg.h" #ifdef BUILD_IN_LINUX #include "localtime.h" #endif +#include "stopwatch/StopwatchView.h" +#include "stopwatch/StopwatchPresenter.h" +#include "stopwatch/StopwatchModel.h" +#include "stopwatch/StopwatchPage.h" namespace OHOS { -static constexpr char *STOPWATCH_START = "stopwatch_start"; -static constexpr char *STOPWATCH_RESET = "stopwatch_reset"; -static constexpr uint16_t OFFSET = 4; +static const char *STOPWATCH_APP_NAME = "秒表"; +static const char *STOPWATCH_START_PAUSE = "stopwatch_start_pause"; // 开始/暂停按钮 +static const char *STOPWATCH_RESET_RECORD = "stopwatch_reset_record"; // 重置/分段按钮 +static const char *STOPWATCH_RECORD_LIST = "stopwatch_record_list"; static constexpr uint16_t NUM_TEN = 10; static constexpr uint16_t UNIT_SEC_TO_MSEC = 1000; static constexpr uint16_t UNIT_SECS_PER_MIN = 60; static constexpr uint16_t UNIT_SECS_PER_HOUR = 3600; static constexpr uint16_t MAX_RECORD_SIZE = 20; -static constexpr uint16_t STOPWATCH_CONTAINER_XPOS = 0; -static constexpr uint16_t STOPWATCH_CONTAINER_YPOS = 0; static constexpr uint16_t STOPWATCH_HAND_POSITION_XPOS = 224; static constexpr uint16_t STOPWATCH_HAND_POSITION_YPOS = 4; static constexpr uint16_t STOPWATCH_HAND_CENTER_XPOS = 3; static constexpr uint16_t STOPWATCH_HAND_CENTER_YPOS = 223; static constexpr uint16_t STOPWATCH_HAND_WIDTH = 2; static constexpr uint16_t STOPWATCH_HAND_HEIGHT = 5; +static constexpr uint16_t STOPWATCH_IMAGE_SCALE_XPOS = 4; +static constexpr uint16_t STOPWATCH_IMAGE_SCALE_YPOS = 4; static constexpr uint16_t STOPWATCH_LABEL_CURTIME_XPOS = 199; static constexpr uint16_t STOPWATCH_LABEL_CURTIME_YPOS = 54; static constexpr uint16_t STOPWATCH_LABEL_CURTIME_WIDTH = 67; @@ -48,12 +49,13 @@ static constexpr uint16_t STOPWATCH_LABEL_APPNAME_YPOS = 82; static constexpr uint16_t STOPWATCH_LABEL_APPNAME_WIDTH = 64; static constexpr uint16_t STOPWATCH_LABEL_APPNAME_HEIGHT = 38; static constexpr uint16_t STOPWATCH_LABEL_APPNAME_FONT_SIZE = 32; -static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_XPOS = 87; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_XPOS = 78; static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_YPOS1 = 176; static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_YPOS2 = 82; static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_WIDTH = 302; static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_HEIGHT = 90; static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_FONT_SIZE = 72; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_FONT_OPA = 76; static constexpr uint16_t STOPWATCH_BUTTON_SRART_XPOS = 250; static constexpr uint16_t STOPWATCH_BUTTON_SRART_YPOS = 302; static constexpr uint16_t STOPWATCH_BUTTON_PAUSE_XPOS = 110; @@ -64,7 +66,9 @@ static constexpr uint16_t STOPWATCH_LIST_RECORD_XPOS = 73; static constexpr uint16_t STOPWATCH_LIST_RECORD_YPOS = 170; static constexpr uint16_t STOPWATCH_LIST_RECORD_WIDTH = 312; static constexpr uint16_t STOPWATCH_LIST_RECORD_HEIGHT = 122; -static constexpr uint16_t STOPWATCH_LABEL_REBOUND_SIZE = 60; +static constexpr uint16_t STOPWATCH_LIST_REBOUND_SIZE = 60; +static constexpr uint16_t STOPWATCH_LIST_ITEM_WIDTH = 312; +static constexpr uint16_t STOPWATCH_LIST_ITEM_HEIGHT = 60; REGIST_SLICE_PAGE(VIEW_STOPWATCH, STOPWATCH_PAGES::STOPWATCH_MAIN_PAGE, StopwatchPage, true); @@ -128,17 +132,42 @@ static std::string FormatElapsedTime(uint64_t uiElapsedTime) return strElapsedTime; } +static UIView *CreateViewCb(uint8_t type) +{ + StopwatchItemView *item = new StopwatchItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, STOPWATCH_LIST_ITEM_WIDTH, STOPWATCH_LIST_ITEM_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + StopwatchItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + StopwatchItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + void StopwatchPage::StopwatchAnimatorCallback::Callback(UIView *view) { UNUSED(view); uint64_t uiElapsedTime = StopwatchModel::GetInstance().UpdateElapsedTime(); uint64_t millisecs = GetMilliSeconds(uiElapsedTime); - stopwatchPage->GetSweepClock()->SetSweepTime24Hour(0, 0, millisecs); - stopwatchPage->GetSweepClock()->Invalidate(); + page_->sweepClock_->SetSweepTime24Hour(0, 0, millisecs); + page_->sweepClock_->Invalidate(); std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); - stopwatchPage->GetElapsedTimeLabel()->SetText(strElapsedTime.c_str()); + page_->elapsedTime_->SetText(strElapsedTime.c_str()); if (uiElapsedTime >= UNIT_SECS_PER_HOUR * UNIT_SEC_TO_MSEC) { - stopwatchPage->Overflowing(); + page_->TimeOverRange(); } } @@ -160,10 +189,9 @@ StopwatchPage::StopwatchPage() StopwatchPage::~StopwatchPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::~StopwatchPage"); - bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(PNG_APPLIST_STOPWATCH_IMAGE); + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(STOPWATCH_IMAGE); if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadStopwatchImage fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage UnloadStopwatchImage fail"); } if (sweepClock_ != nullptr) { sweepClock_->RemoveAll(); @@ -194,10 +222,6 @@ StopwatchPage::~StopwatchPage() delete recordsList_; recordsList_ = nullptr; } - if (listAdapter_ != nullptr) { - delete listAdapter_; - listAdapter_ = nullptr; - } if (backGround_ != nullptr) { delete backGround_; backGround_ = nullptr; @@ -210,13 +234,13 @@ StopwatchPage::~StopwatchPage() delete secondHand_; secondHand_ = nullptr; } - if (animator_ != nullptr) { - delete animator_; - animator_ = nullptr; + if (stopwatchAnimator_ != nullptr) { + delete stopwatchAnimator_; + stopwatchAnimator_ = nullptr; } - if (animatorCallback_ != nullptr) { - delete animatorCallback_; - animatorCallback_ = nullptr; + if (stopwatchAnimatorCallback_ != nullptr) { + delete stopwatchAnimatorCallback_; + stopwatchAnimatorCallback_ = nullptr; } if (timeAnimator_ != nullptr) { delete timeAnimator_; @@ -226,39 +250,34 @@ StopwatchPage::~StopwatchPage() delete timeCallback_; timeCallback_ = nullptr; } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::~StopwatchPage"); } void StopwatchPage::OnStart(void *data) { - bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(PNG_APPLIST_STOPWATCH_IMAGE); + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(STOPWATCH_IMAGE); if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadStopwatchImage fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage LoadStopwatchImage fail"); return; } sweepClock_ = new UISweepClock(); if (sweepClock_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UISweepClock new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage sweepClock_ new fail"); return; } - sweepClock_->SetPosition(STOPWATCH_CONTAINER_XPOS, STOPWATCH_CONTAINER_YPOS); + sweepClock_->SetPosition(0, 0); sweepClock_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); sweepClock_->SetDraggable(true); sweepClock_->SetTouchable(true); + sweepClock_->SetOnDragListener(this); secondHand_ = new Image(); if (secondHand_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage secondHand_ new fail"); return; } - ImageInfo *second = - ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_STOPWATCH_STOPWATCH02, PNG_APPLIST_STOPWATCH_IMAGE); - - if (second == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::OnStart source fail"); - return; - } - secondHand_->SetSrc(second); + LOADIMG::LoadImageImg(secondHand_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_HAND); sweepClock_->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand_, {STOPWATCH_HAND_POSITION_XPOS, STOPWATCH_HAND_POSITION_YPOS}, {STOPWATCH_HAND_CENTER_XPOS, STOPWATCH_HAND_CENTER_YPOS}); @@ -270,7 +289,6 @@ void StopwatchPage::OnStart(void *data) {STOPWATCH_HAND_POSITION_XPOS, STOPWATCH_HAND_POSITION_YPOS}, {STOPWATCH_HAND_CENTER_XPOS, STOPWATCH_HAND_CENTER_YPOS}, Color::White(), STOPWATCH_HAND_WIDTH, STOPWATCH_HAND_HEIGHT, OPA_TRANSPARENT); - sweepClock_->SetWorkMode(UISweepClock::WorkMode::NORMAL); uint64_t uiElapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); uint64_t millisecs = GetMilliSeconds(uiElapsedTime); @@ -278,25 +296,25 @@ void StopwatchPage::OnStart(void *data) backGround_ = new UIImageView(); if (backGround_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage backGround_ new fail"); return; } backGround_->SetPosition(0, 0); - LOADIMG::LoadImageViewImg(backGround_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH06); + LOADIMG::LoadImageViewImg(backGround_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_BG); sweepClock_->Add(backGround_); imgScale_ = new UIImageView(); if (imgScale_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage imgScale_ new fail"); return; } - imgScale_->SetPosition(OFFSET, OFFSET); - LOADIMG::LoadImageViewImg(imgScale_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH04); + imgScale_->SetPosition(STOPWATCH_IMAGE_SCALE_XPOS, STOPWATCH_IMAGE_SCALE_YPOS); + LOADIMG::LoadImageViewImg(imgScale_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_SCALE); sweepClock_->Add(imgScale_); currentTime_ = new UILabel(); if (currentTime_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupCurrentTime new Label currentTime_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage currentTime_ new fail"); return; } currentTime_->SetPosition(STOPWATCH_LABEL_CURTIME_XPOS, STOPWATCH_LABEL_CURTIME_YPOS); @@ -304,12 +322,11 @@ void StopwatchPage::OnStart(void *data) currentTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_CURTIME_FONT_SIZE); currentTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); currentTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - currentTime_->SetVisible(true); sweepClock_->Add(currentTime_); appName_ = new UILabel(); if (appName_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupAppName new Label appName_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage appName_ new fail"); return; } appName_->SetPosition(STOPWATCH_LABEL_APPNAME_XPOS, STOPWATCH_LABEL_APPNAME_YPOS); @@ -317,34 +334,33 @@ void StopwatchPage::OnStart(void *data) appName_->SetText(STOPWATCH_APP_NAME); appName_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); appName_->SetTextColor(Color::White()); - appName_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_APPNAME_FONT_SIZE); + appName_->SetFont(BOLD_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_APPNAME_FONT_SIZE); appName_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); appName_->SetVisible(true); sweepClock_->Add(appName_); elapsedTime_ = new UILabel(); if (elapsedTime_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupElapsedTime new Label elapsedTime_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage elapsedTime_ new fail"); return; } elapsedTime_->SetPosition(STOPWATCH_LABEL_ELSTIME_XPOS, STOPWATCH_LABEL_ELSTIME_YPOS1); elapsedTime_->Resize(STOPWATCH_LABEL_ELSTIME_WIDTH, STOPWATCH_LABEL_ELSTIME_HEIGHT); elapsedTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - elapsedTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_ELSTIME_FONT_SIZE); + elapsedTime_->SetFont(BOLD_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_ELSTIME_FONT_SIZE); elapsedTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - elapsedTime_->SetVisible(true); std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); elapsedTime_->SetText(strElapsedTime.c_str()); sweepClock_->Add(elapsedTime_); startButton_ = new UILabelButton(); if (startButton_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupButton new UILabelButton startButton_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage startButton_ new fail"); return; } startButton_->SetPosition(STOPWATCH_BUTTON_SRART_XPOS, STOPWATCH_BUTTON_SRART_YPOS); startButton_->Resize(STOPWATCH_BUTTON_WIDTH, STOPWATCH_BUTTON_HEIGHT); - startButton_->SetViewId(STOPWATCH_START); + startButton_->SetViewId(STOPWATCH_START_PAUSE); startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); @@ -353,85 +369,78 @@ void StopwatchPage::OnStart(void *data) resetButton_ = new UILabelButton(); if (resetButton_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupButton new UILabelButton resetButton_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage resetButton_ new fail"); return; } resetButton_->SetPosition(STOPWATCH_BUTTON_PAUSE_XPOS, STOPWATCH_BUTTON_PAUSE_YPOS); resetButton_->Resize(STOPWATCH_BUTTON_WIDTH, STOPWATCH_BUTTON_HEIGHT); - resetButton_->SetViewId(STOPWATCH_RESET); + resetButton_->SetViewId(STOPWATCH_RESET_RECORD); resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); resetButton_->SetOnClickListener(this); sweepClock_->Add(resetButton_); - listAdapter_ = new StopwatchAdapter(); - if (listAdapter_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "StopwatchPage::SetupRecordsList new StopwatchAdapter listAdapter_ fail"); - return; - } - recordsList_ = new UIList(); + recordsList_ = new UISimpleList(); if (recordsList_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupRecordsList new UIList recordsList_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage recordsList_ new fail"); return; } recordsList_->SetPosition(STOPWATCH_LIST_RECORD_XPOS, STOPWATCH_LIST_RECORD_YPOS); recordsList_->Resize(STOPWATCH_LIST_RECORD_WIDTH, STOPWATCH_LIST_RECORD_HEIGHT); + recordsList_->SetViewId(STOPWATCH_RECORD_LIST); recordsList_->SetThrowDrag(true); recordsList_->SetDraggable(true); - recordsList_->SetReboundSize(STOPWATCH_LABEL_REBOUND_SIZE); + recordsList_->SetReboundSize(STOPWATCH_LIST_REBOUND_SIZE); recordsList_->EnableAutoAlign(true); recordsList_->SetElastic(true); recordsList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - recordsList_->SetAdapter(listAdapter_); + recordsList_->SetOnClickListener(this); recordsList_->SetVisible(false); sweepClock_->Add(recordsList_); - animatorCallback_ = new StopwatchAnimatorCallback(this); - if (animatorCallback_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail\n"); + AddViewToPageContainer(sweepClock_); + + stopwatchAnimatorCallback_ = new StopwatchAnimatorCallback(this); + if (stopwatchAnimatorCallback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage stopwatchAnimatorCallback_ new fail"); return; } - animator_ = new Animator(animatorCallback_, nullptr, 0, true); - if (animator_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::InitView new Animator animator_ fail"); + stopwatchAnimator_ = new Animator(stopwatchAnimatorCallback_, nullptr, 0, true); + if (stopwatchAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage stopwatchAnimator_ new fail"); return; } timeCallback_ = new TimeAnimatorCallback(); if (timeCallback_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage timeCallback_ new fail"); return; } timeAnimator_ = new Animator(timeCallback_, currentTime_, 0, true); if (timeAnimator_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::InitView new Animator timeAnimator_ fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage timeAnimator_ new fail"); return; } - timeAnimator_->Start(); - sweepClock_->SetOnDragListener(this); - AddViewToPageContainer(sweepClock_); - - bool isActive = StopwatchModel::GetInstance().GetActiveState(); - DrawButtonStatusView(isActive); - bool state = StopwatchModel::GetInstance().IsInRecordView(); - if (StopwatchModel::GetInstance().GetOverflowState()) { - state = false; + bool isRunning = StopwatchModel::GetInstance().GetRunningState(); + DrawButtonStatusView(isRunning); + bool isVisible = StopwatchModel::GetInstance().GetRecordListVisible(); + if (StopwatchModel::GetInstance().GetTimeOverRangeState()) { + isVisible = false; } - DrawContainRecordListView(state); + DrawRecordListVisibleView(isVisible); } void StopwatchPage::OnStop() {} void StopwatchPage::OnPause() { - if (animator_ != nullptr) { - if (animator_->GetState() != Animator::STOP) { - animator_->Stop(); + if (stopwatchAnimator_ != nullptr) { + if (stopwatchAnimator_->GetState() != Animator::STOP) { + stopwatchAnimator_->Stop(); } } if (timeAnimator_ != nullptr) { @@ -443,10 +452,10 @@ void StopwatchPage::OnPause() void StopwatchPage::OnResume() { - if (animator_ != nullptr) { - bool isActive = StopwatchModel::GetInstance().GetActiveState(); - if (isActive && animator_->GetState() == Animator::STOP) { - animator_->Start(); + if (stopwatchAnimator_ != nullptr) { + bool isRunning = StopwatchModel::GetInstance().GetRunningState(); + if (isRunning && stopwatchAnimator_->GetState() == Animator::STOP) { + stopwatchAnimator_->Start(); } } if (timeAnimator_ != nullptr) { @@ -456,45 +465,42 @@ void StopwatchPage::OnResume() } } -void StopwatchPage::DrawButtonStatusView(bool isActive) +void StopwatchPage::DrawButtonStatusView(bool isRunning) { - if (isActive) { - LOADIMG::LoadBtnImage(startButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH08, - IMAGE_STOPWATCH_STOPWATCH08); + elapsedTime_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + if (isRunning) { + LOADIMG::LoadBtnImage(startButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_PAUSE, IMAGE_STOPWATCH_PAUSE); startButton_->Invalidate(); resetButton_->Enable(); - LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH14, - IMAGE_STOPWATCH_STOPWATCH14); + LOADIMG::LoadBtnImage(resetButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_RECORD, IMAGE_STOPWATCH_RECORD); auto &recordList = StopwatchModel::GetInstance().GetRecordsList(); if (recordList.Size() >= MAX_RECORD_SIZE) { resetButton_->Disable(); - LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH20, - IMAGE_STOPWATCH_STOPWATCH20); + LOADIMG::LoadBtnImage(resetButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_RECORD_DISABLE, + IMAGE_STOPWATCH_RECORD_DISABLE); } resetButton_->Invalidate(); } else { - LOADIMG::LoadBtnImage(startButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH12, - IMAGE_STOPWATCH_STOPWATCH12); + LOADIMG::LoadBtnImage(startButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_START, IMAGE_STOPWATCH_START); startButton_->Invalidate(); resetButton_->Enable(); - // 复位 - LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH19, - IMAGE_STOPWATCH_STOPWATCH19); + LOADIMG::LoadBtnImage(resetButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_RESET, IMAGE_STOPWATCH_RESET); uint64_t elapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); if (elapsedTime == 0) { resetButton_->Disable(); - LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH10, - IMAGE_STOPWATCH_STOPWATCH10); + LOADIMG::LoadBtnImage(resetButton_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_RESET_DISABLE, + IMAGE_STOPWATCH_RESET_DISABLE); + elapsedTime_->SetStyle(STYLE_TEXT_OPA, STOPWATCH_LABEL_ELSTIME_FONT_OPA); } resetButton_->Invalidate(); } } -void StopwatchPage::DrawContainRecordListView(bool isContainRecordList) +void StopwatchPage::DrawRecordListVisibleView(bool isRecordListVisible) { - if (isContainRecordList) { + if (isRecordListVisible) { appName_->SetVisible(false); recordsList_->SetVisible(true); elapsedTime_->SetPosition(STOPWATCH_LABEL_ELSTIME_XPOS, STOPWATCH_LABEL_ELSTIME_YPOS2); @@ -509,80 +515,87 @@ void StopwatchPage::DrawContainRecordListView(bool isContainRecordList) void StopwatchPage::RefreshRecordsList() { auto &records = StopwatchModel::GetInstance().GetRecordsList(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::RefreshRecordsList"); - listAdapter_->SetData(records); + recordsList_->ClearAll(); + ListNode *node = records.Head(); + while (node != records.End()) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + StopwatchItem &itemData = node->data_; + content.data = reinterpret_cast(&itemData); + recordsList_->AddContent(content); + node = node->next_; + } recordsList_->RefreshList(); } bool StopwatchPage::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - bool isActive = StopwatchModel::GetInstance().GetActiveState(); - if (strcmp(view.GetViewId(), STOPWATCH_START) == 0) { - if (isActive) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick activeState = %d, pause counting click", - isActive); - StopwatchModel::GetInstance().SetInactiveState(); + bool isRunning = StopwatchModel::GetInstance().GetRunningState(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::OnClick RunningState = %d", isRunning); + if (strcmp(view.GetViewId(), STOPWATCH_START_PAUSE) == 0) { + if (isRunning) { + StopwatchModel::GetInstance().SetRunningState(false); DrawButtonStatusView(false); - animator_->Stop(); + stopwatchAnimator_->Stop(); StopwatchModel::GetInstance().SaveElapsedTime(); } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick activeState = %d, start counting click", - isActive); - StopwatchModel::GetInstance().SetActiveState(); - if (StopwatchModel::GetInstance().GetOverflowState()) { - DrawContainRecordListView(false); - StopwatchModel::GetInstance().SetOverflowState(false); + StopwatchModel::GetInstance().SetRunningState(true); + if (StopwatchModel::GetInstance().GetTimeOverRangeState()) { + DrawRecordListVisibleView(false); + StopwatchModel::GetInstance().SetTimeOverRangeState(false); } DrawButtonStatusView(true); StopwatchModel::GetInstance().SetStartTime(); - animator_->Start(); + stopwatchAnimator_->Start(); } - } else if (strcmp(view.GetViewId(), STOPWATCH_RESET) == 0) { - if (isActive) { - StopwatchModel::GetInstance().SetRecordViewState(true); + } else if (strcmp(view.GetViewId(), STOPWATCH_RESET_RECORD) == 0) { + if (isRunning) { + StopwatchModel::GetInstance().SetRecordListVisible(true); uint64_t uiElapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); - StopwatchItem item = {strElapsedTime, true}; + auto &recordList = StopwatchModel::GetInstance().GetRecordsList(); + StopwatchItem item = {recordList.Size() + 1, strElapsedTime, true}; StopwatchModel::GetInstance().AddRecordToList(item); - DrawContainRecordListView(true); + DrawRecordListVisibleView(true); DrawButtonStatusView(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick save a record"); } else { - StopwatchModel::GetInstance().SetRecordViewState(false); + StopwatchModel::GetInstance().SetRecordListVisible(false); StopwatchModel::GetInstance().ResetCounter(); elapsedTime_->SetText("00:00.00"); sweepClock_->SetInitTime24Hour(0, 0, 0); sweepClock_->Invalidate(); - DrawContainRecordListView(false); + DrawRecordListVisibleView(false); DrawButtonStatusView(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick reset a record"); } + } else if (strcmp(view.GetViewId(), STOPWATCH_RECORD_LIST) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(STOPWATCH_PAGES::STOPWATCH_RECORD_PAGE, + TransitionType::TRANSITION_INVALID, false); } return true; } bool StopwatchPage::OnDrag(UIView &view, const DragEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchOnDragListener::OnDrag"); UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSliceToApplist(); } return true; } -void StopwatchPage::Overflowing() +void StopwatchPage::TimeOverRange() { - animator_->Stop(); + stopwatchAnimator_->Stop(); elapsedTime_->SetText("59:59.99"); sweepClock_->SetSweepTime24Hour(0, 0, 0); sweepClock_->Invalidate(); - StopwatchModel::GetInstance().SetInactiveState(); + StopwatchModel::GetInstance().SetRunningState(false); DrawButtonStatusView(false); StopwatchModel::GetInstance().ResetCounter(); - StopwatchModel::GetInstance().SetOverflowState(true); + StopwatchModel::GetInstance().SetTimeOverRangeState(true); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp index 90fcfe210..b2a30dec4 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp @@ -1,14 +1,14 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: StopwatchPresenter * Create: 2025-06-06 */ + +#include "NativeRegisterManager.h" #include "stopwatch/StopwatchView.h" #include "stopwatch/StopwatchPresenter.h" -#include "NativeRegisterManager.h" namespace OHOS { -REGIST_MENU(VIEW_STOPWATCH, StopwatchView, StopwatchPresenter, PNG_APPLIST_STOPWATCH_LOGO, PNG_APPLIST_DEFAULT_IMG, - "秒表"); +REGIST_MENU(VIEW_STOPWATCH, StopwatchView, StopwatchPresenter, STOPWATCH_ICON, STOPWATCH_ICON, "秒表"); } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchRecordPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchRecordPage.cpp new file mode 100644 index 000000000..1a4d428a2 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/stopwatch/src/StopwatchRecordPage.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchRecordPage + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "stopwatch/StopwatchView.h" +#include "stopwatch/StopwatchRecordPage.h" + +namespace OHOS { +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 38; +static constexpr uint16_t LABEL_W = 253; +static constexpr uint16_t LABEL_H = 53; +static constexpr uint16_t LABEL_FONT = 38; +static constexpr uint16_t LIST_X = 73; +static constexpr uint16_t LIST_Y = 100; +static constexpr uint16_t LIST_W = 312; +static constexpr uint16_t LIST_H = 364; +static constexpr uint16_t LIST_ITEM_WIDTH = 312; +static constexpr uint16_t LIST_ITEM_HEIGHT = 60; +static constexpr uint16_t LIST_REBOUND_SIZE = 60; +static constexpr uint16_t LIST_BLANK_SIZE = 80; + +REGIST_SLICE_PAGE(VIEW_STOPWATCH, STOPWATCH_PAGES::STOPWATCH_RECORD_PAGE, StopwatchRecordPage, false); + +static UIView *CreateViewCb(uint8_t type) +{ + StopwatchItemView *item = new StopwatchItemView(); + if (item == nullptr) { + return nullptr; + } + item->SetPosition(0, 0, LIST_ITEM_WIDTH, LIST_ITEM_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + return item; +} + +static void UpdateViewCb(UIView *view, void *data, uint8_t type) +{ + if (view == nullptr || data == nullptr) { + return; + } + StopwatchItemView *item = dynamic_cast(view); + if (item == nullptr) { + return; + } + StopwatchItem *itemInfo = static_cast(data); + item->SetItemInfo(*itemInfo); +} + +StopwatchRecordPage::~StopwatchRecordPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (background_ != nullptr) { + delete background_; + background_ = nullptr; + } + if (titleLabel_ != nullptr) { + delete titleLabel_; + titleLabel_ = nullptr; + } + if (recordList_ != nullptr) { + delete recordList_; + recordList_ = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchRecordPage::~StopwatchRecordPage"); +} + +void StopwatchRecordPage::InitBackgroundView() +{ + background_ = new UIImageView(); + if (background_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchRecordPage background_ new fail"); + return; + } + background_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(background_, STOPWATCH_IMAGE, IMAGE_STOPWATCH_BG); + group_->Add(background_); +} + +void StopwatchRecordPage::CreateUILabel() +{ + titleLabel_ = new UILabel(); + if (titleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchRecordPage titleLabel_ new fail"); + return; + } + titleLabel_->SetPosition(LABEL_X, LABEL_Y, LABEL_W, LABEL_H); + titleLabel_->SetText("分段详情"); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, LABEL_FONT); + group_->Add(titleLabel_); +} + +void StopwatchRecordPage::CreateUIList() +{ + recordList_ = new UISimpleList(); + if (recordList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchRecordPage recordList_ new fail"); + return; + } + recordList_->SetPosition(LIST_X, LIST_Y, LIST_W, LIST_H); + recordList_->SetThrowDrag(true); + recordList_->SetDraggable(true); + recordList_->SetReboundSize(LIST_REBOUND_SIZE); + recordList_->EnableAutoAlign(true); + recordList_->SetElastic(true); + recordList_->SetScrollBlankSize(LIST_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + recordList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + auto &records = StopwatchModel::GetInstance().GetRecordsList(); + ListNode *node = records.Head(); + while (node != records.End()) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 0; + StopwatchItem &itemData = node->data_; + content.data = reinterpret_cast(&itemData); + recordList_->AddContent(content); + node = node->next_; + } + recordList_->RefreshList(); + group_->Add(recordList_); +} + +void StopwatchRecordPage::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchRecordPage group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + + InitBackgroundView(); + CreateUILabel(); + CreateUIList(); + AddViewToPageContainer(group_); +} + +bool StopwatchRecordPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(STOPWATCH_PAGES::STOPWATCH_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool StopwatchRecordPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerCountDown.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerCountDown.cpp new file mode 100644 index 000000000..d15262965 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerCountDown.cpp @@ -0,0 +1,479 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerCountDown + * Create: 2025-06-09 + */ + +#include +#include +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "pwm.h" +#include "main/LoadImg.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif +#include "timers/TimerView.h" +#include "timers/TimerPresenter.h" +#include "timers/TimerMainPage.h" +#include "timers/TimerCountDown.h" + +namespace OHOS { +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t TIMING_TITLE_POSITION_X = 170; +static constexpr uint16_t TIMING_TITLE_POSITION_Y = 110; +static constexpr uint16_t TIMING_TITLE_SIZE_WIDTH = 114; +static constexpr uint16_t TIMING_TITLE_SIZE_HEIGHT = 38; +static constexpr uint16_t TIMING_TITLE_FONT = 38; +static constexpr uint16_t TIMING_LABEL_CURTIME_XPOS = 177; +static constexpr uint16_t TIMING_LABEL_CURTIME_YPOS = 54; +static constexpr uint16_t TIMING_LABEL_CURTIME_WIDTH = 100; +static constexpr uint16_t TIMING_LABEL_CURTIME_HEIGHT = 30; +static constexpr uint16_t TIMING_LABEL_CURTIME_FONT_SIZE = 28; +static constexpr uint16_t TIMING_START_IMAGE_XPOS = 251; +static constexpr uint16_t TIMING_START_IMAGE_YPOS = 306; +static constexpr uint16_t TIMING_START_IMAGE_SIZE = 96; +static constexpr uint16_t TIMING_RESET_IMAGE_XPOS = 107; +static constexpr uint16_t TIMING_RESET_IMAGE_YPOS = 306; +static constexpr uint16_t TIMING_RESET_IMAGE_SIZE = 96; +static constexpr uint16_t TIMING_TIMER_TIME_XPOS = 85; +static constexpr uint16_t TIMING_TIMER_TIME_YPOS = 182; +static constexpr uint16_t TIMING_TIMER_TIME_WIDTH = 322; +static constexpr uint16_t TIMING_TIMER_TIME_HEIGHT = 90; +static constexpr uint16_t TIMING_TIMER_TIME_FONT_SIZE = 72; +static constexpr uint16_t HOUR_TIME = 3600; +static constexpr uint16_t MIN_TIME = 60; +static constexpr uint16_t TIMING_CIRCLE_LINE_WIDTH = 10; +static constexpr uint16_t TIMING_CIRCLE = 227; +static constexpr uint16_t CIRCLE_RADIUS = 222; +static constexpr uint16_t TIMING_CIRCLE_END = 360; +static constexpr uint32_t TIMING_CIRCLE_RANGE = 100000; +static constexpr uint16_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t REMIND_MIN_MS = 16; +static constexpr char *RESET_OR_EXIT_BUTTON = "resetOrExitButton"; +static constexpr char *START_OR_PAUSE_BUTTON = "startOrPauseButton"; + +static std::string GetCurrentTimeStr() +{ + struct tm localTime; + time_t seconds = time(nullptr); + localtime_r(&seconds, &localTime); + std::string currTime; + if (localTime.tm_hour < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_hour) + ":"; + if (localTime.tm_min < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_min); + return currTime; +} + +void TimerCountDown::OnCreateView(void *data) +{ + fragmentView_.SetTouchable(true); + fragmentView_.SetDraggable(true); + fragmentView_.SetOnDragListener(this); + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ fail"); + return; + } + LOADIMG::LoadImageViewImg(bgImg_, TIMER_IMAGE, IMAGE_TIMER_BG); + bgImg_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + // 标题 + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(TIMING_TITLE_POSITION_X, TIMING_TITLE_POSITION_Y); + labelTitle_->Resize(TIMING_TITLE_SIZE_WIDTH, TIMING_TITLE_SIZE_HEIGHT); + labelTitle_->SetText("计时器"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, TIMING_TITLE_FONT); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + currentTime_ = new UILabel(); + if (currentTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentTime_ fail"); + return; + } + currentTime_->SetPosition(TIMING_LABEL_CURTIME_XPOS, TIMING_LABEL_CURTIME_YPOS); + currentTime_->Resize(TIMING_LABEL_CURTIME_WIDTH, TIMING_LABEL_CURTIME_HEIGHT); + currentTime_->SetFont(BOLD_VECTOR_FONT_FILENAME, TIMING_LABEL_CURTIME_FONT_SIZE); + currentTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + currentTime_->SetVisible(true); + + fragmentView_.Add(bgImg_); + fragmentView_.Add(labelTitle_); + fragmentView_.Add(currentTime_); + + CircleProgress(); + CreateButton(); + CreateTimerTime(); + InitAnimator(); + + currentTimeCallback_ = new TimeAnimatorCallback(); + if (currentTimeCallback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentTimeCallback_ fail"); + return; + } + currentTimeAnimator_ = new Animator(currentTimeCallback_, currentTime_, 0, true); + if (currentTimeAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentTimeAnimator_ fail"); + return; + } + currentTimeAnimator_->Start(); +} + +void TimerCountDown::OnDestroyView() +{ + fragmentView_.RemoveAll(); + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (timerClock_ != nullptr) { + delete timerClock_; + timerClock_ = nullptr; + } + + if (resetOrExitImg_ != nullptr) { + delete resetOrExitImg_; + resetOrExitImg_ = nullptr; + } + + if (startOrPauseImg_ != nullptr) { + delete startOrPauseImg_; + startOrPauseImg_ = nullptr; + } + + if (circleProgress_ != nullptr) { + delete circleProgress_; + circleProgress_ = nullptr; + } + + if (currentTime_ != nullptr) { + delete currentTime_; + currentTime_ = nullptr; + } + + if (currentTimeCallback_ != nullptr) { + delete currentTimeCallback_; + currentTimeCallback_ = nullptr; + } + + if (currentTimeAnimator_ != nullptr) { + delete currentTimeAnimator_; + currentTimeAnimator_ = nullptr; + } + + if (countDownTimecallBack_ != nullptr) { + delete countDownTimecallBack_; + countDownTimecallBack_ = nullptr; + } + + if (countDownTimeanimator_ != nullptr) { + delete countDownTimeanimator_; + countDownTimeanimator_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); +} + +void TimerCountDown::OnResume() +{ + if (TimerModel::GetInstance().GetExistTimer()) { + SetAnimatorStatus(true); + TimerModel::GetInstance().SetExistTimer(false); + } + if (currentTimeAnimator_ != nullptr) { + if (currentTimeAnimator_->GetState() == Animator::STOP) { + currentTimeAnimator_->Start(); + } + } + if (!startOrPauseImg_->IsTouchable()) { + LOADIMG::LoadImageViewImg(startOrPauseImg_, TIMER_IMAGE, IMAGE_TIMER_PAUSE); + } +} + +void TimerCountDown::OnPause() +{ + if (TimerModel::GetInstance().GetIsCountDown()) { + TimerModel::GetInstance().SetExistTimer(true); + } + if (currentTimeAnimator_ != nullptr) { + if (currentTimeAnimator_->GetState() != Animator::STOP) { + currentTimeAnimator_->Stop(); + } + } + SetAnimatorStatus(false); +} + +void TimerCountDown::CreateButton() +{ + // 开始/暂停按钮 + startOrPauseImg_ = new UIImageView(); + if (startOrPauseImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startOrPauseImg_ fail"); + return; + } + startOrPauseImg_->SetPosition(TIMING_START_IMAGE_XPOS, TIMING_START_IMAGE_YPOS); + startOrPauseImg_->Resize(TIMING_START_IMAGE_SIZE, TIMING_START_IMAGE_SIZE); + startOrPauseImg_->SetViewId(START_OR_PAUSE_BUTTON); + startOrPauseImg_->SetTouchable(true); + startOrPauseImg_->SetOnClickListener(this); + LOADIMG::LoadImageViewImg(startOrPauseImg_, TIMER_IMAGE, IMAGE_TIMER_PLAY); + + fragmentView_.Add(startOrPauseImg_); + + // 复位/退出按钮 + ImageInfo *image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_TIMER_EXIT, TIMER_IMAGE); + resetOrExitImg_ = new UIImageView(); + if (resetOrExitImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "resetOrExitImg_ fail"); + return; + } + resetOrExitImg_->SetPosition(TIMING_RESET_IMAGE_XPOS, TIMING_RESET_IMAGE_YPOS); + resetOrExitImg_->Resize(TIMING_RESET_IMAGE_SIZE, TIMING_RESET_IMAGE_SIZE); + resetOrExitImg_->SetViewId(RESET_OR_EXIT_BUTTON); + resetOrExitImg_->SetTouchable(true); + resetOrExitImg_->SetOnClickListener(this); + resetOrExitImg_->SetSrc(image2); + fragmentView_.Add(resetOrExitImg_); +} + +void TimerCountDown::CreateTimerTime() +{ + timerClock_ = new UIDigitalClock(); + if (timerClock_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timerClock_ fail"); + return; + } + timerClock_->SetPosition(TIMING_TIMER_TIME_XPOS, TIMING_TIMER_TIME_YPOS); + timerClock_->Resize(TIMING_TIMER_TIME_WIDTH, TIMING_TIMER_TIME_HEIGHT); + timerClock_->SetFont(BOLD_VECTOR_FONT_FILENAME, TIMING_TIMER_TIME_FONT_SIZE); + timerClock_->SetDisplayMode(UIDigitalClock::DISPLAY_24_HOUR); + timerClock_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + + fragmentView_.Add(timerClock_); +} + +void TimerCountDown::RefreshFragment() +{ + uint64_t totalTime = TimerModel::GetInstance().GetTotalTime(); + uint8_t hour = totalTime / HOUR_TIME; + uint8_t minute = totalTime % HOUR_TIME / MIN_TIME; + uint8_t second = totalTime % MIN_TIME; + timerClock_->SetTime24Hour(hour, minute, second); + TimerModel::GetInstance().SetEclipseTime(true, 0); + LOADIMG::LoadImageViewImg(resetOrExitImg_, TIMER_IMAGE, IMAGE_TIMER_EXIT); + circleProgress_->SetValue(TIMING_CIRCLE_RANGE); + +} + +void TimerCountDown::CircleProgress() +{ + circleProgress_ = new UICircleProgress(); + if (circleProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgress_ fail"); + return; + } + circleProgress_->SetPosition(0, 0); + circleProgress_->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + circleProgress_->EnableBackground(true); + circleProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0XFFFFBF00); + circleProgress_->SetBackgroundStyle(STYLE_LINE_COLOR, 0XFF473D20); + circleProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, TIMING_CIRCLE_LINE_WIDTH); + circleProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, TIMING_CIRCLE_LINE_WIDTH); + circleProgress_->EnableBackground(true); + circleProgress_->SetCenterPosition(TIMING_CIRCLE, TIMING_CIRCLE); + circleProgress_->SetRadius(CIRCLE_RADIUS); + circleProgress_->SetStartAngle(0); + circleProgress_->SetEndAngle(TIMING_CIRCLE_END); + circleProgress_->SetRange(TIMING_CIRCLE_RANGE, 0); + circleProgress_->SetValue(TIMING_CIRCLE_RANGE); + fragmentView_.Add(circleProgress_); +} + +// 单位为毫秒计算 +void TimerCountDown::SetTimerTime(int64_t onTime) +{ + uint64_t time = onTime / MS_ONE_SECONDS; + uint16_t reminMs = onTime % MS_ONE_SECONDS; + if (reminMs > REMIND_MIN_MS) { + time++; + } + uint8_t hour = time / HOUR_TIME; + uint8_t minute = time % HOUR_TIME / MIN_TIME; + uint8_t second = time % MIN_TIME; + timerClock_->SetTime24Hour(hour, minute, second); + uint64_t totalTime = TimerModel::GetInstance().GetTotalTime(); + double percentage = static_cast(onTime) / ((uint64_t)totalTime * MS_ONE_SECONDS); + double value = round(percentage * TIMING_CIRCLE_RANGE); + circleProgress_->SetValue(static_cast(value)); + circleProgress_->Invalidate(); + timerClock_->Invalidate(); +} + +void TimerCountDown::InitAnimator() +{ + countDownTimecallBack_ = new TimerCountDownCallback(this); + if (countDownTimecallBack_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "countDownTimecallBack_ fail"); + return; + } + countDownTimeanimator_ = new Animator(countDownTimecallBack_, nullptr, 0, true); + if (countDownTimeanimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "countDownTimeanimator_ fail"); + return; + } +} + +void TimerCountDown::TimerCountDownCallback::Callback(UIView *view) +{ + (void)view; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + + uint64_t totalTime = TimerModel::GetInstance().GetTotalTime(); + uint64_t eclipseTime = TimerModel::GetInstance().GetEclipseTime(); + uint64_t s_time = TimerModel::GetInstance().GetStartTime(); + uint64_t c_time = (uint64_t)current_time.tv_sec * MS_ONE_SECONDS + current_time.tv_usec / MS_ONE_SECONDS; + int64_t remainTime = (uint64_t)totalTime * MS_ONE_SECONDS - eclipseTime - (c_time - s_time); + if (remainTime < 0) { + // 计时到设定时间,复位图标修改为退出图标,暂停图标修改为播放图标,并设置成不可点击态 + page_->startOrPauseImg_->SetTouchable(false); + LOADIMG::LoadImageViewImg(page_->startOrPauseImg_, TIMER_IMAGE, IMAGE_TIMER_PAUSE); + LOADIMG::LoadImageViewImg(page_->resetOrExitImg_, TIMER_IMAGE, IMAGE_TIMER_EXIT); + TimerModel::GetInstance().SetIsPause(false); + TimerModel::GetInstance().SetIsCountDown(false); + page_->startOrPauseImg_->Invalidate(); + page_->resetOrExitImg_->Invalidate(); + page_->countDownTimeanimator_->Stop(); + page_->SetTimerTime(0); + // 调用pwm接口实现马达震动,客户自实现 + } else { + page_->SetTimerTime(remainTime); + } +} + +void TimerCountDown::SetAnimatorStatus(bool status) +{ + if (status) { + LOADIMG::LoadImageViewImg(startOrPauseImg_, TIMER_IMAGE, IMAGE_TIMER_PAUSE_ORANGE); + LOADIMG::LoadImageViewImg(resetOrExitImg_, TIMER_IMAGE, IMAGE_TIMER_RESTART); + countDownTimeanimator_->Start(); + TimerModel::GetInstance().InitTimer(); + } else { + countDownTimeanimator_->Stop(); + LOADIMG::LoadImageViewImg(startOrPauseImg_, TIMER_IMAGE, IMAGE_TIMER_PLAY); + TimerModel::GetInstance().DisableTimer(); + } +} + +bool TimerCountDown::OnDragStart(UIView& view, const DragEvent& event) +{ + return true; +} + +bool TimerCountDown::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + if (TimerModel::GetInstance().GetIsCountDown()) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } else { + fragmentView_.SetVisible(false); + TimerMainPage::GetInstance()->ShowMainPage(); + } + } + return true; +} + +bool TimerCountDown::OnDragEnd(UIView& view, const DragEvent& event) +{ + return true; +} + +bool TimerCountDown::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), RESET_OR_EXIT_BUTTON) == 0) { + if (TimerModel::GetInstance().GetIsCountDown()) { + // 此时计时器处于计时状态,点击按钮,重置timerClock_时间为倒计时初始选择时间,修改复位图标为退出图标,暂停图标变为开始图标, + SetAnimatorStatus(false); + TimerModel::GetInstance().SetIsCountDown(false); + uint64_t totalTime = TimerModel::GetInstance().GetTotalTime(); + uint8_t hour = totalTime / HOUR_TIME; + uint8_t minute = totalTime % HOUR_TIME / MIN_TIME; + uint8_t second = totalTime % MIN_TIME; + timerClock_->SetTime24Hour(hour, minute, second); + TimerModel::GetInstance().SetEclipseTime(true, 0); + LOADIMG::LoadImageViewImg(resetOrExitImg_, TIMER_IMAGE, IMAGE_TIMER_EXIT); + circleProgress_->SetValue(TIMING_CIRCLE_RANGE); + } else if (!TimerModel::GetInstance().GetIsCountDown() && TimerModel::GetInstance().GetIsPause()) { + // 此时计时器处于暂停状态,点击复位按钮,重置timerClock_时间为倒计时初始选择时间,将复位图标变为退出图标, + TimerModel::GetInstance().SetIsCountDown(false); + uint64_t totalTime = TimerModel::GetInstance().GetTotalTime(); + uint8_t hour = totalTime / HOUR_TIME; + uint8_t minute = totalTime % HOUR_TIME / MIN_TIME; + uint8_t second = totalTime % MIN_TIME; + timerClock_->SetTime24Hour(hour, minute, second); + TimerModel::GetInstance().SetEclipseTime(true, 0); + LOADIMG::LoadImageViewImg(resetOrExitImg_, TIMER_IMAGE, IMAGE_TIMER_EXIT); + circleProgress_->SetValue(TIMING_CIRCLE_RANGE); + TimerModel::GetInstance().SetIsPause(false); + } else { + NativeAbility::GetInstance().SwitchPageInSlice(TIMER_PAGES::TIMER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + } else if (strcmp(view.GetViewId(), START_OR_PAUSE_BUTTON) == 0) { + if (TimerModel::GetInstance().GetIsCountDown()) { + // 计时器此时处于运行状态,点击暂停按钮,暂停图标变为开始图标 + SetAnimatorStatus(false); + TimerModel::GetInstance().SetIsCountDown(false); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint64_t time = ((uint64_t)current_time.tv_sec * MS_ONE_SECONDS + current_time.tv_usec / MS_ONE_SECONDS) - + TimerModel::GetInstance().GetStartTime(); + TimerModel::GetInstance().SetEclipseTime(false, time); + TimerModel::GetInstance().SetIsPause(true); + } else { + // 计时器此时处于停止/暂停状态,点击开始按钮,开始图标变为暂停图标,并获取点击时的时间,用作开始时间 + SetAnimatorStatus(true); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint64_t s_time = + (uint64_t)current_time.tv_sec * MS_ONE_SECONDS + current_time.tv_usec / MS_ONE_SECONDS; // 转换成ms + TimerModel::GetInstance().SetStartTime(s_time); + TimerModel::GetInstance().SetIsCountDown(true); + TimerModel::GetInstance().SetIsPause(false); + } + } + return true; +} + +void TimerCountDown::TimeAnimatorCallback::Callback(UIView *view) +{ + UILabel *timeLabel = dynamic_cast(view); + if (timeLabel == nullptr) { + return; + } + std::string currTime = GetCurrentTimeStr(); + timeLabel->SetText(currTime.c_str()); + timeLabel->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerMainPage.cpp index 35f8c4b99..812947111 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerMainPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerMainPage.cpp @@ -1,25 +1,24 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: TimerMainPage * Create: 2025-06-09 */ #include -#include "timers/TimerMainPage.h" -#include "timers/TimerSettingPage.h" -#include "timers/TimerTimingPage.h" -#include "timers/TimerPresenter.h" #include "SlicePageFactory.h" -#include "timers/TimerView.h" #include "components/ui_scroll_view_nested.h" #include "components/ui_arc_label.h" #include "graphic_timer.h" #include "ohos_timer.h" #include "wearable_log.h" #include "main/LoadImg.h" +#include "timers/TimerView.h" +#include "timers/TimerSettingPage.h" +#include "timers/TimerCountDown.h" +#include "timers/TimerPresenter.h" +#include "timers/TimerMainPage.h" namespace OHOS { -static constexpr int16_t ADDBUTTON_MAX = 4; static constexpr uint8_t MAIN_TITLE_FONT_SIZE = 40; static constexpr int16_t MAIN_TITLE_SIZE_WIDTH = 160; static constexpr int16_t MAIN_TITLE_SIZE_HEIGHT = 50; @@ -34,165 +33,219 @@ static constexpr int16_t SELECTMIN_POXS = 252; static constexpr int16_t SELECTMIN_POY = 89; static constexpr int16_t SELECTMIN_POYS = 220; static constexpr int16_t SELECTMIN_SIZE = 100; -static constexpr int16_t MAX_SCR_DIS = 1000; +static constexpr uint16_t MS_ONE_SECONDS = 1000; static constexpr uint8_t MIN = 60; +static constexpr char *SET_TIME_BUTTON = "setTimeButton"; +static constexpr char *ONE_MINUTE = "1"; +static constexpr char *THREE_MINUTE = "3"; +static constexpr char *FIFTEEN_MINUTE = "15"; +static constexpr char *THIRTY_MINUTE = "30"; +static TimerMainPage *g_pTimerMainPage{nullptr}; REGIST_SLICE_PAGE(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE, TimerMainPage, true); +TimerMainPage::TimerMainPage() +{ + g_pTimerMainPage = this; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::TimerMainPage()"); +} + TimerMainPage::~TimerMainPage() { - bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); - if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadTimerImage fail"); + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; } - if (group != nullptr) { - group->RemoveAll(); - delete group; - group = nullptr; + if (countDownFragment_ != nullptr) { + countDownFragment_->DestroyView(); + delete countDownFragment_; + countDownFragment_ = nullptr; } - if (title != nullptr) { - delete title; - title = nullptr; + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; } - if (addButton != nullptr) { - delete addButton; - addButton = nullptr; + if (addButton_ != nullptr) { + delete addButton_; + addButton_ = nullptr; } - for (int i = 0; i < ADDBUTTON_MAX; i++) { - if (selectMin[i] != nullptr) { - delete selectMin[i]; - selectMin[i] = nullptr; + for (int i = 0; i < SELECT_IMAGE_COUNT; i++) { + if (selectMin_[i] != nullptr) { + delete selectMin_[i]; + selectMin_[i] = nullptr; } } - if (backround != nullptr) { - delete backround; - backround = nullptr; + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); + TimerModel::GetInstance().SetIsShowFragment(false); + g_pTimerMainPage = nullptr; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::~TimerMainPage()"); } -void TimerMainPage::OnStart(void* data) +void TimerMainPage::OnResume() +{ + if (countDownFragment_->GetFragmentView()->IsVisible()) { + countDownFragment_->OnResume(); + } +} + +void TimerMainPage::OnPause() +{ + if (countDownFragment_->GetFragmentView()->IsVisible()) { + countDownFragment_->OnPause(); + } +} + +TimerMainPage* TimerMainPage::GetInstance() { - bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(TIMER_IMAGE); - if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage fail"); + return g_pTimerMainPage; +} + +void TimerMainPage::OnStart(void *data) +{ + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ fail"); return; } - // 主界面 - if (group == nullptr) { - group = new UIScrollView(); - group->SetPosition(0, 0, VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - group->SetViewId("mainview"); + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetVisible(false); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ fail"); + return; } - if (backround == nullptr) { - backround = new UIImageView(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnStart new backround"); + LOADIMG::LoadImageViewImg(bgImg_, TIMER_IMAGE, IMAGE_TIMER_BG); + bgImg_->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_WIDTH); + group_->Add(bgImg_); + + countDownFragment_ = new TimerCountDown(); + if (countDownFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "countDownFragment_ fail"); + return; } - LOADIMG::LoadImageViewImg(backround, TIMER_IMAGE, IMAGE_CONVERTER_TOOL_TIMER_BG); - backround->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_WIDTH); - group->Add(backround); + countDownFragment_->GetFragmentView()->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + countDownFragment_->CreateView(); + countDownFragment_->GetFragmentView()->SetVisible(false); + InitView(); LabelTitle(); - group->SetOnDragListener(this); - group->SetVisible(false); - AddViewToPageContainer(group); + + AddViewToPageContainer(group_); + AddViewToPageContainer(countDownFragment_->GetFragmentView()); + // 定时器存在,不展示主页面,直接进入计时页面 if (TimerModel::GetInstance().GetExistTimer()) { - // 定时器存在,进入计时页面 - NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + countDownFragment_->GetFragmentView()->SetVisible(true); + } else if (TimerModel::GetInstance().GetIsShowFragment()) { + TimerModel::GetInstance().SetIsShowFragment(false); + countDownFragment_->RefreshFragment(); + countDownFragment_->GetFragmentView()->SetVisible(true); } else { - group->SetVisible(true); + group_->SetVisible(true); } } void TimerMainPage::LabelTitle() { - // 标题 - if (title == nullptr) { - title = new UILabel(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::LabelTitle new title"); - } - title->SetPosition(MAIN_TITLE_POSITION_X, MAIN_TITLE_POSITION_Y); - title->SetText("计时器"); - title->Resize(MAIN_TITLE_SIZE_WIDTH, MAIN_TITLE_SIZE_HEIGHT); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MAIN_TITLE_FONT_SIZE); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - title->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - title->SetVisible(true); - group->Add(title); + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ fail"); + return; + } + labelTitle_->SetPosition(MAIN_TITLE_POSITION_X, MAIN_TITLE_POSITION_Y); + labelTitle_->SetText("计时器"); + labelTitle_->Resize(MAIN_TITLE_SIZE_WIDTH, MAIN_TITLE_SIZE_HEIGHT); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, MAIN_TITLE_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelTitle_->SetVisible(true); + group_->Add(labelTitle_); } void TimerMainPage::InitView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::InitView() Start!"); - if (addButton == nullptr) { - addButton = new UIImageView(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::InitView new addButton"); - } - LOADIMG::LoadImageViewImg(addButton, TIMER_IMAGE, IMAGE_CONVERTER_TOOL_TIMER_USER); - addButton->SetPosition(MAIN_ADDBUTTON_POSITION_X, MAIN_ADDBUTTON_POSITION_Y); - addButton->Resize(MAIN_ADDBUTTON_SIZE_WIDTH, MAIN_ADDBUTTON_SIZE_HEIGHT); - addButton->SetViewId(SETTING_TIMER); - addButton->SetTouchable(true); - addButton->SetOnClickListener(this); - group->Add(addButton); - - int posX[ADDBUTTON_MAX] = {SELECTMIN_POX, SELECTMIN_POXS, SELECTMIN_POX, SELECTMIN_POXS}; - int posY[ADDBUTTON_MAX] = {SELECTMIN_POY, SELECTMIN_POY, SELECTMIN_POYS, SELECTMIN_POYS}; - const char* buttonViewId[ADDBUTTON_MAX] = {"1", "3", "15", "30"}; - ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_1, TIMER_IMAGE); - ImageInfo *image3 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_3, TIMER_IMAGE); - ImageInfo *image15 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_15, TIMER_IMAGE); - ImageInfo *image30 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_30, TIMER_IMAGE); - ImageInfo* buttonSrc[ADDBUTTON_MAX] = {image1, image3, image15, image30}; - // 一分钟按钮 - for (int i = 0;i < ADDBUTTON_MAX;i++) { - if (selectMin[i] == nullptr) { - selectMin[i] = new UIImageView(); + addButton_ = new UIImageView(); + if (addButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addButton_ fail"); + return; + } + LOADIMG::LoadImageViewImg(addButton_, TIMER_IMAGE, IMAGE_TIMER_USER); + addButton_->SetPosition(MAIN_ADDBUTTON_POSITION_X, MAIN_ADDBUTTON_POSITION_Y); + addButton_->Resize(MAIN_ADDBUTTON_SIZE_WIDTH, MAIN_ADDBUTTON_SIZE_HEIGHT); + addButton_->SetViewId(SET_TIME_BUTTON); + addButton_->SetTouchable(true); + addButton_->SetOnClickListener(this); + group_->Add(addButton_); + + int posX[SELECT_IMAGE_COUNT] = {SELECTMIN_POX, SELECTMIN_POXS, SELECTMIN_POX, SELECTMIN_POXS}; + int posY[SELECT_IMAGE_COUNT] = {SELECTMIN_POY, SELECTMIN_POY, SELECTMIN_POYS, SELECTMIN_POYS}; + const char *buttonViewId[SELECT_IMAGE_COUNT] = {ONE_MINUTE, THREE_MINUTE, FIFTEEN_MINUTE, THIRTY_MINUTE}; + int buttonImg[SELECT_IMAGE_COUNT] = {IMAGE_TIMER_1, IMAGE_TIMER_3, IMAGE_TIMER_15, IMAGE_TIMER_30}; + // 计时选择时间按钮 + for (int i = 0; i < SELECT_IMAGE_COUNT; i++) { + selectMin_[i] = new UIImageView(); + if (selectMin_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "selectMin_[%d] fail", i); + return; } - selectMin[i]->SetPosition(posX[i], posY[i]); - selectMin[i]->Resize(SELECTMIN_SIZE, SELECTMIN_SIZE); - selectMin[i]->SetTouchable(true); - selectMin[i]->SetOnClickListener(this); - selectMin[i]->SetViewId(buttonViewId[i]); - selectMin[i]->SetSrc(buttonSrc[i]); - group->Add(selectMin[i]); + selectMin_[i]->SetPosition(posX[i], posY[i]); + selectMin_[i]->Resize(SELECTMIN_SIZE, SELECTMIN_SIZE); + selectMin_[i]->SetTouchable(true); + selectMin_[i]->SetOnClickListener(this); + selectMin_[i]->SetViewId(buttonViewId[i]); + LOADIMG::LoadImageViewImg(selectMin_[i], TIMER_IMAGE, buttonImg[i]); + group_->Add(selectMin_[i]); } } +void TimerMainPage::ShowMainPage() +{ + group_->SetVisible(true); +} + bool TimerMainPage::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - std::string viewId = view.GetViewId(); - if (viewId == SETTING_TIMER) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnClick viewId == SETTING_TIMER"); - NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_SETTING_PAGE); - } else if (viewId == "1"|| viewId == "3" || viewId == "15" || viewId == "30") { - int num = std::stoi(viewId); + if (strcmp(view.GetViewId(), SET_TIME_BUTTON) == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(TIMER_PAGES::TIMER_SETTING_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if ((strcmp(view.GetViewId(), ONE_MINUTE) == 0) || + (strcmp(view.GetViewId(), THREE_MINUTE) == 0) || + (strcmp(view.GetViewId(), FIFTEEN_MINUTE) == 0) || + (strcmp(view.GetViewId(), THIRTY_MINUTE) == 0)) { + int num = std::stoi(std::string(view.GetViewId())); struct timeval start_time; gettimeofday(&start_time, nullptr); - uint32_t s_time = start_time.tv_sec * MAX_SCR_DIS + start_time.tv_usec / MAX_SCR_DIS; // 转换成ms + uint64_t s_time = + (uint64_t)start_time.tv_sec * MS_ONE_SECONDS + start_time.tv_usec / MS_ONE_SECONDS; // 转换成ms TimerModel::GetInstance().SetStartTime(s_time); - TimerModel::GetInstance().SetSaveTime(true, 0); - TimerModel::GetInstance().SetDurationTime(num * MIN); - NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + TimerModel::GetInstance().SetEclipseTime(true, 0); + TimerModel::GetInstance().SetTotalTime(num * MIN); + countDownFragment_->RefreshFragment(); + countDownFragment_->GetFragmentView()->SetVisible(true); } return true; } -bool TimerMainPage::OnDrag(UIView& view, const DragEvent& event) +bool TimerMainPage::OnDrag(UIView &view, const DragEvent &event) { UNUSED(view); - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && - (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); } return true; } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerModel.cpp index 83c3b843c..ea4bf93ff 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerModel.cpp @@ -1,24 +1,17 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: TimerModel * Create: 2025-06-09 */ -#include "timers/TimerModel.h" -#include "main/HealthModel.h" -#include "uiservice/ui_service.h" #include "wearable_log.h" +#include "timers/TimerModel.h" namespace OHOS { -static int g_motionTimes{0}; -static constexpr uint64_t MS_ONE_SECONDS = 1000; -TimerModel::TimerModel() -{ -} +static constexpr uint16_t MS_ONE_SECONDS = 1000; +TimerModel::TimerModel() {} -TimerModel::~TimerModel() -{ -} +TimerModel::~TimerModel() {} TimerModel &TimerModel::GetInstance() { @@ -26,42 +19,42 @@ TimerModel &TimerModel::GetInstance() return instance; } -uint32_t TimerModel::GetSaveTime() +uint64_t TimerModel::GetEclipseTime() { - return save_time; + return eclipseTime_; } -void TimerModel::SetSaveTime(bool falg, uint32_t value) +void TimerModel::SetEclipseTime(bool flag, uint64_t value) { - if (falg) { - save_time = 0; + if (flag) { + eclipseTime_ = 0; } else { - save_time += value; + eclipseTime_ += value; } } -void TimerModel::SetDurationTime(uint32_t time) +void TimerModel::SetTotalTime(uint64_t time) { - durationTime = time; + totalTime_ = time; } -uint32_t TimerModel::GetDurationTime() +uint64_t TimerModel::GetTotalTime() { - return durationTime; + return totalTime_; } /* 定时器回调函数 */ void TimerTimerCallback(void *data) { (void)data; - uint32_t dura_time = TimerModel::GetInstance().GetDurationTime(); - uint32_t start_time = TimerModel::GetInstance().GetStartTime(); - uint32_t save_time = TimerModel::GetInstance().GetSaveTime(); + uint64_t total_time = TimerModel::GetInstance().GetTotalTime(); + uint64_t start_time = TimerModel::GetInstance().GetStartTime(); + uint64_t eclipse_time = TimerModel::GetInstance().GetEclipseTime(); struct timeval current_time; gettimeofday(¤t_time, nullptr); - uint32_t remTime = dura_time * 1000 - (current_time.tv_usec - start_time) - save_time; - if (remTime == 0) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TimerTimerCallback: end :%d", time); + uint64_t curr_time_ms = (uint64_t)current_time.tv_sec * MS_ONE_SECONDS + current_time.tv_usec / MS_ONE_SECONDS; + int64_t remTime = (uint64_t)total_time * MS_ONE_SECONDS - (curr_time_ms - start_time) - eclipse_time; + if (remTime <= 0) { TimerModel::GetInstance().SetExistTimer(false); TimerModel::GetInstance().DisableTimer(); } @@ -70,22 +63,22 @@ void TimerTimerCallback(void *data) /* 开启定时器 */ void TimerModel::InitTimer() { - if (g_startCounting != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer g_startCounting != nullptr!!"); + if (startCounting_ != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitTimer startCounting_ != nullptr!!"); return; } uint32_t tick = GetOSTick(MS_ONE_SECONDS); - g_startCounting = new GraphicTimer(tick, TimerTimerCallback, nullptr, true); - if (g_startCounting == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer new GraphicTimer failed!!"); + startCounting_ = new GraphicTimer(tick, TimerTimerCallback, nullptr, true); + if (startCounting_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitTimer new GraphicTimer failed!!"); return; } - bool retTimer = g_startCounting->Start(); + bool retTimer = startCounting_->Start(); if (!retTimer) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer Start failed!!"); - if (g_startCounting != nullptr) { - delete g_startCounting; - g_startCounting = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitTimer Start failed!!"); + if (startCounting_ != nullptr) { + delete startCounting_; + startCounting_ = nullptr; } return; } @@ -94,10 +87,10 @@ void TimerModel::InitTimer() /* 关闭定时器 */ void TimerModel::DisableTimer() { - if (g_startCounting != nullptr) { - delete g_startCounting; - g_startCounting = nullptr; - g_motionTimes = 0; + if (startCounting_ != nullptr) { + startCounting_->Stop(); + delete startCounting_; + startCounting_ = nullptr; } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerPresenter.cpp index b7390642f..2498e3c62 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerPresenter.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: TimerPresenter * Create: 2025-06-09 */ +#include "ohos_timer.h" +#include "NativeRegisterManager.h" #include "timers/TimerView.h" #include "timers/TimerModel.h" #include "timers/TimerPresenter.h" -#include "NativeRegisterManager.h" -#include "ohos_timer.h" namespace OHOS { - REGIST_MENU(VIEW_TIMER, TimerView, TimerPresenter, TIMER_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, "计时器"); +REGIST_MENU(VIEW_TIMER, TimerView, TimerPresenter, TIMER_ICON, TIMER_ICON, "计时器"); } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerSettingPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerSettingPage.cpp index 0f01e9354..2ab02db7c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerSettingPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/timers/src/TimerSettingPage.cpp @@ -1,23 +1,22 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: TimerSettingPage * Create: 2025-06-09 */ #include #include -#include "timers/TimerSettingPage.h" -#include "timers/TimerPresenter.h" #include "components/ui_arc_label.h" #include "wearable_log.h" -#include "timers/TimerView.h" #include "SlicePageFactory.h" #include "common/image_cache_manager.h" +#include "timers/TimerView.h" +#include "timers/TimerPresenter.h" +#include "timers/TimerSettingPage.h" namespace OHOS { static constexpr uint8_t BACKGROUND_FONT = 40; static constexpr uint8_t HIGHTLIGHT_FONT = 50; -static constexpr uint8_t TIMERPICKER_MAX = 3; static constexpr uint16_t PADDING = 3; static constexpr uint16_t BORDER_RADIUS = 5; static constexpr uint16_t TEXT_FONT = 24; @@ -35,352 +34,324 @@ static constexpr uint16_t SETTING_START_POSITION_X = 112; static constexpr uint16_t SETTING_START_POSITION_Y = 347; static constexpr uint16_t SETTING_START_SIZE_WIDTH = 232; static constexpr uint16_t SETTING_START_SIZE_HEIGHT = 76; -static constexpr uint16_t SETTING_START_FONT = 40; static constexpr uint16_t TIMERPICKER_POSX1 = 61; static constexpr uint16_t TIMERPICKER_POSX2 = 183; static constexpr uint16_t TIMERPICKER_POSX3 = 305; static constexpr uint16_t TIMERPICKER_POSY = 119; -static constexpr uint16_t SETTING_TIMERPICKER_SIZE_WIDTH = 88; -static constexpr uint16_t SETTING_TIMERPICKER_SIZE_HEIGHT = 189; +static constexpr uint16_t SETTING_TIMERPICKER_WIDTH = 88; +static constexpr uint16_t SETTING_TIMERPICKER_HEIGHT = 189; static constexpr uint16_t TIMERPICKER_RADIUS = 11; static constexpr uint16_t SETTING_TIMERPICKER_ITEM_HEIGHT = 70; static constexpr uint16_t SETTING_TIMERPICKER_HOUR = 24; -static constexpr uint16_t SETTING_TIMERPICKER_HOURS = 23; +static constexpr uint16_t SETTING_TIMERPICKER_HOUR_END = 23; static constexpr uint16_t SETTING_TIMERPICKER_MIN = 60; -static constexpr uint16_t SETTING_TIMERPICKER_MINS = 59; -static constexpr uint16_t SETTING_PICKERGROUP_POSX = 70; -static constexpr uint16_t SETTING_PICKERGROUP_POSY = 132; -static constexpr uint16_t SETTING_PICKERGROUP_SIZE_WIDTH = 80; -static constexpr uint16_t SETTING_PICKERGROUP_SIZE_HEIGHT = 208; +static constexpr uint16_t SETTING_TIMERPICKER_MIN_END = 59; static constexpr uint16_t HOUR_TIME = 3600; static constexpr uint16_t MIN_TIME = 60; static constexpr uint16_t POX1_MIN = 86; -static constexpr uint16_t POX1_MAX = 174; static constexpr uint16_t POX2_MIN = 206; -static constexpr uint16_t POX2_MAX = 294; static constexpr uint16_t POX3_MIN = 332; -static constexpr uint16_t POX3_MAX = 420; -static constexpr uint16_t POY_MIN = 119; -static constexpr uint16_t POY_MAX = 308; -static constexpr uint16_t SLEEP = 500; -static constexpr uint16_t SUM_2 = 2; +static constexpr uint16_t INDEX_2 = 2; +static constexpr char *START_TIMING_BUTTON = "startCountDownButton"; +static constexpr char *HOUR_PICKER = "hourPicker"; +static constexpr char *MIN_PICKER = "minPicker"; +static constexpr char *SEC_PICKER = "secPicker"; +// 时间选择器分钟与秒钟列 +static const char *g_uiPickerMinAndSecData[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", + "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", + "51", "52", "53", "54", "55", "56", "57", "58", "59", "00"}; + +// 时间选择器小时列 +static const char *g_uiPickerHourData[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", + "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "00"}; REGIST_SLICE_PAGE(VIEW_TIMER, TIMER_PAGES::TIMER_SETTING_PAGE, TimerSettingPage, false); -TimerSettingPage::~TimerSettingPage() +TimerSettingPage::TimerSettingPage() { - bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); - if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadTimerImage fail"); - } - - if (group != nullptr) { - group->RemoveAll(); - delete group; - group = nullptr; - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::TimerSettingPage"); +} - if (title != nullptr) { - delete title; - title = nullptr; +TimerSettingPage::~TimerSettingPage() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; } - if (back != nullptr) { - delete back; - back = nullptr; + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; } - for (int i = 0; i < TIMERPICKER_MAX; i++) { - if (timerPicker[i] != nullptr) { - delete timerPicker[i]; - timerPicker[i] = nullptr; + for (int i = 0; i < PICKER_COUNT; i++) { + if (timerPicker_[i] != nullptr) { + delete timerPicker_[i]; + timerPicker_[i] = nullptr; } } - if (start != nullptr) { - delete start; - start = nullptr; + if (startImg_ != nullptr) { + delete startImg_; + startImg_ = nullptr; } - if (timerLabel != nullptr) { - delete timerLabel; - timerLabel = nullptr; + if (labelUnit_ != nullptr) { + delete labelUnit_; + labelUnit_ = nullptr; } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::~TimerSettingPage"); } void TimerSettingPage::OnStart(void *data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnStart() Start"); - bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(TIMER_IMAGE); - if (ret == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage fail"); + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelTitle_ fail"); return; } - image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( - IMAGE_CONVERTER_TOOL_TIMER_BEGIN_GRAY, TIMER_IMAGE); - if (image1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage image1 fail"); - return; + labelTitle_->SetPosition(SETTING_TITLE_POSITION_X, SETTING_TITLE_POSITION_Y); + labelTitle_->Resize(SETTING_TITLE_SIZE_WIDTH, SETTING_TITLE_SIZE_HEIGHT); + labelTitle_->SetText("设置时间"); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, SETTING_TITLE_TEXT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + if (group_ == nullptr) { } - image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes( - IMAGE_CONVERTER_TOOL_TIMER_BEGIN_ORANGE, TIMER_IMAGE); - if (image2 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage image2 fail"); + group_ = new UIScrollView(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new group_ fail"); return; } - // 标题 - if (title == nullptr) { - title = new UILabel(); - } - title->SetPosition(SETTING_TITLE_POSITION_X, SETTING_TITLE_POSITION_Y); - title->Resize(SETTING_TITLE_SIZE_WIDTH, SETTING_TITLE_SIZE_HEIGHT); - title->SetText("设置时间"); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_TITLE_TEXT_SIZE); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - title->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - title->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - if (group == nullptr) { - group = new UIScrollView(); - } - group->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - group->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - group->SetThrowDrag(true); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + group_->SetThrowDrag(true); CreateLabel(); CreateStartButton(); CreatePicker(); - group->Add(title); - group->SetOnDragListener(this); - AddViewToPageContainer(group); + group_->Add(labelTitle_); + group_->SetOnDragListener(this); + AddViewToPageContainer(group_); } void TimerSettingPage::CreateLabel(void) { - // Add Label to App - if (timerLabel == nullptr) { - timerLabel = new UILabel(); + // 用来显示picker的类型单位:小时、分、秒 同一时间只显示一个picker的类型单位 + labelUnit_ = new UILabel(); + if (labelUnit_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new labelUnit_ fail"); + return; } - timerLabel->SetPosition(SETTING_TIMERLABEL_POSITION_X, - SETTING_TIMERLABEL_POSITION_Y); // widget's left position and top position - timerLabel->Resize(SETTING_TIMERLABEL_SIZE_WIDTH, - SETTING_TIMERLABEL_SIZE_HEIGHT); // widget's width and height - timerLabel->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFFBF00); - timerLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xef); - timerLabel->SetStyle(STYLE_BORDER_RADIUS, BORDER_RADIUS); - timerLabel->SetStyle(STYLE_PADDING_TOP, PADDING); - timerLabel->SetStyle(STYLE_PADDING_BOTTOM, PADDING); - timerLabel->SetStyle(STYLE_TEXT_FONT, TEXT_FONT); - - // Set additional property - timerLabel->SetText("小时"); - timerLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); - timerLabel->SetTextColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff)); - timerLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - timerLabel->SetDirect(TEXT_DIRECT_MIXED); - timerLabel->SetRollSpeed(0); - timerLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_TIMERLABEL_FONT); - timerLabel->SetVisible(false); - // Add to rootView - group->Add(timerLabel); + labelUnit_->SetPosition(SETTING_TIMERLABEL_POSITION_X, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->Resize(SETTING_TIMERLABEL_SIZE_WIDTH, SETTING_TIMERLABEL_SIZE_HEIGHT); + labelUnit_->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFFBF00); + labelUnit_->SetStyle(STYLE_BACKGROUND_OPA, 0xef); + labelUnit_->SetStyle(STYLE_BORDER_RADIUS, BORDER_RADIUS); + labelUnit_->SetStyle(STYLE_PADDING_TOP, PADDING); + labelUnit_->SetStyle(STYLE_PADDING_BOTTOM, PADDING); + labelUnit_->SetStyle(STYLE_TEXT_FONT, TEXT_FONT); + labelUnit_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelUnit_->SetTextColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff)); + labelUnit_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelUnit_->SetDirect(TEXT_DIRECT_MIXED); + labelUnit_->SetRollSpeed(0); + labelUnit_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_TIMERLABEL_FONT); + labelUnit_->SetVisible(false); + group_->Add(labelUnit_); } void TimerSettingPage::CreateStartButton(void) { // 开始按钮 - if (start == nullptr) { - start = new UIImageView(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage:: new start UIImageView"); + startImg_ = new UIImageView(); + if (startImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new startImg_ fail"); + return; } - start->SetPosition(SETTING_START_POSITION_X, SETTING_START_POSITION_Y); - start->Resize(SETTING_START_SIZE_WIDTH, SETTING_START_SIZE_HEIGHT); - start->SetViewId(START_TIMING); - start->SetTouchable(false); - start->SetOnClickListener(this); - start->SetSrc(image1); - group->Add(start); + startImg_->SetPosition(SETTING_START_POSITION_X, SETTING_START_POSITION_Y); + startImg_->Resize(SETTING_START_SIZE_WIDTH, SETTING_START_SIZE_HEIGHT); + startImg_->SetViewId(START_TIMING_BUTTON); + startImg_->SetTouchable(false); + startImg_->SetOnClickListener(this); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_GRAY); + group_->Add(startImg_); } -// 时间选择器分钟与秒钟列 -const char *uiPickerData[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", - "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", - "51", "52", "53", "54", "55", "56", "57", "58", "59", "00"}; - -// 时间选择器小时列 -const char *uiPicker5Data[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", - "15", "16", "17", "18", "19", "20", "21", "22", "23", "00"}; - void TimerSettingPage::CreatePicker() { - // Add Picker to App - int posX[TIMERPICKER_MAX] = {TIMERPICKER_POSX1, TIMERPICKER_POSX2, TIMERPICKER_POSX3}; + int posX[PICKER_COUNT] = {TIMERPICKER_POSX1, TIMERPICKER_POSX2, TIMERPICKER_POSX3}; int posY = TIMERPICKER_POSY; - for (int i = 0; i < TIMERPICKER_MAX; i++) { - if (timerPicker[i] == nullptr) { - timerPicker[i] = new UIPicker(); + for (int i = 0; i < PICKER_COUNT; i++) { + timerPicker_[i] = new UIPicker(); + if (timerPicker_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new timerPicker_[%d] fail", i); + return; } - timerPicker[i]->SetPosition(posX[i], posY); // widget's left position and top position - timerPicker[i]->Resize(SETTING_TIMERPICKER_SIZE_WIDTH, SETTING_TIMERPICKER_SIZE_HEIGHT); - timerPicker[i]->SetViewId("hourPicker"); // Set style - timerPicker[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - timerPicker[i]->SetStyle(STYLE_BORDER_WIDTH, TIMERPICKER_MAX); - timerPicker[i]->SetStyle(STYLE_BORDER_RADIUS, TIMERPICKER_RADIUS); - timerPicker[i]->SetStyle(STYLE_BORDER_COLOR, 0xffb9b9b9); - timerPicker[i]->SetItemHeight(SETTING_TIMERPICKER_ITEM_HEIGHT); - timerPicker[i]->SetLoopState(true); - timerPicker[i]->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); - timerPicker[i]->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); - timerPicker[i]->SetTextColor(Color::GetColorFromRGBA(0x64, 0x69, 0x6e, 0xff), - Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + timerPicker_[i]->SetPosition(posX[i], posY); + timerPicker_[i]->Resize(SETTING_TIMERPICKER_WIDTH, SETTING_TIMERPICKER_HEIGHT); + timerPicker_[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timerPicker_[i]->SetStyle(STYLE_BORDER_WIDTH, PADDING); + timerPicker_[i]->SetStyle(STYLE_BORDER_RADIUS, TIMERPICKER_RADIUS); + timerPicker_[i]->SetStyle(STYLE_BORDER_COLOR, 0xffb9b9b9); + timerPicker_[i]->SetItemHeight(SETTING_TIMERPICKER_ITEM_HEIGHT); + timerPicker_[i]->SetLoopState(true); + timerPicker_[i]->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + timerPicker_[i]->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + timerPicker_[i]->SetTextColor(Color::GetColorFromRGBA(0x64, 0x69, 0x6e, 0xff), + Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); if (i == 0) { - timerPicker[i]->SetValues(uiPicker5Data, SETTING_TIMERPICKER_HOUR); - timerPicker[i]->SetSelected(SETTING_TIMERPICKER_HOURS); + timerPicker_[i]->SetValues(g_uiPickerHourData, SETTING_TIMERPICKER_HOUR); + timerPicker_[i]->SetSelected(SETTING_TIMERPICKER_HOUR_END); } else { - timerPicker[i]->SetValues(uiPickerData, SETTING_TIMERPICKER_MIN); - timerPicker[i]->SetSelected(SETTING_TIMERPICKER_MINS); + timerPicker_[i]->SetValues(g_uiPickerMinAndSecData, SETTING_TIMERPICKER_MIN); + timerPicker_[i]->SetSelected(SETTING_TIMERPICKER_MIN_END); } - timerPicker[i]->SetOnClickListener(this); - timerPicker[i]->SetDraggable(true); - timerPicker[i]->SetOnDragListener(this); - timerPicker[i]->RegisterSelectedListener(this); - group->Add(timerPicker[i]); + timerPicker_[i]->SetOnClickListener(this); + timerPicker_[i]->SetDraggable(true); + timerPicker_[i]->SetOnDragListener(this); + timerPicker_[i]->RegisterSelectedListener(this); + group_->Add(timerPicker_[i]); } - timerPicker[0]->SetViewId("hourPicker"); // Set style - timerPicker[1]->SetViewId("minPicker"); // Set style - timerPicker[SUM_2]->SetViewId("secPicker"); // Set style + timerPicker_[0]->SetViewId(HOUR_PICKER); + timerPicker_[1]->SetViewId(MIN_PICKER); + timerPicker_[INDEX_2]->SetViewId(SEC_PICKER); } bool TimerSettingPage::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - std::string viewId = view.GetViewId(); - if (viewId == START_TIMING) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnClick viewId == START_TIMING"); - TimerModel::GetInstance().SetSaveTime(true, 0); - uint8_t hour = std::stoi(uiPicker5Data[timerPicker[0]->GetSelected()]); - uint8_t minute = std::stoi(uiPickerData[timerPicker[1]->GetSelected()]); - uint8_t second = std::stoi(uiPickerData[timerPicker[SUM_2]->GetSelected()]); - uint32_t durationTime = (hour * HOUR_TIME) + (minute * MIN_TIME) + (second); - TimerModel::GetInstance().SetDurationTime(durationTime); - NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + if (strcmp(view.GetViewId(), START_TIMING_BUTTON) == 0) { + TimerModel::GetInstance().SetEclipseTime(true, 0); + uint8_t hour = std::stoi(g_uiPickerHourData[timerPicker_[0]->GetSelected()]); + uint8_t minute = std::stoi(g_uiPickerMinAndSecData[timerPicker_[1]->GetSelected()]); + uint8_t second = std::stoi(g_uiPickerMinAndSecData[timerPicker_[INDEX_2]->GetSelected()]); + uint64_t totalTime = (hour * HOUR_TIME) + (minute * MIN_TIME) + (second); + TimerModel::GetInstance().SetTotalTime(totalTime); + TimerModel::GetInstance().SetIsShowFragment(true); + NativeAbility::GetInstance().SwitchPageInSlice(TIMER_PAGES::TIMER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); } - timerLabel->Invalidate(); + labelUnit_->Invalidate(); return true; } bool TimerSettingPage::OnDrag(UIView &view, const DragEvent &event) { - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && - (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnDrag SwitchSlice(TIMER_MAIN_PAGE)"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(TIMER_PAGES::TIMER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); } - if (view.GetViewId() == "hourPicker") { - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("小时"); - timerLabel->Invalidate(); - } else if (view.GetViewId() == "minPicker") { - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("分钟"); - timerLabel->Invalidate(); - } else if (view.GetViewId() == "secPicker") { - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("秒"); - timerLabel->Invalidate(); + if (strcmp(view.GetViewId(), HOUR_PICKER) == 0) { + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("小时"); + labelUnit_->Invalidate(); + } else if (strcmp(view.GetViewId(), MIN_PICKER) == 0) { + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("分钟"); + labelUnit_->Invalidate(); + } else if (strcmp(view.GetViewId(), SEC_PICKER) == 0) { + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("秒"); + labelUnit_->Invalidate(); } return true; } -void TimerSettingPage::OnPickerStoped(UIPicker& picker) +void TimerSettingPage::OnPickerStoped(UIPicker &picker) { - if (picker.GetViewId() == "hourPicker") { + if (strcmp(picker.GetViewId(), HOUR_PICKER) == 0) { uint16_t hour = picker.GetSelected(); - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - if ((hour == SETTING_TIMERPICKER_HOURS) && (timerPicker[1]->GetSelected() == SETTING_TIMERPICKER_MINS) && - (timerPicker[SUM_2]->GetSelected() == SETTING_TIMERPICKER_MINS)) { - start->SetTouchable(false); - start->SetSrc(image1); + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + if ((hour == SETTING_TIMERPICKER_HOUR_END) && (timerPicker_[1]->GetSelected() == SETTING_TIMERPICKER_MIN_END) && + (timerPicker_[INDEX_2]->GetSelected() == SETTING_TIMERPICKER_MIN_END)) { + startImg_->SetTouchable(false); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_GRAY); } else { - start->SetTouchable(true); - start->SetSrc(image2); + startImg_->SetTouchable(true); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_ORANGE); } - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("小时"); - timerLabel->Invalidate(); - } else if (picker.GetViewId() == "minPicker") { + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("小时"); + labelUnit_->Invalidate(); + } else if (strcmp(picker.GetViewId(), MIN_PICKER) == 0) { uint16_t minute = picker.GetSelected(); - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - if ((timerPicker[0]->GetSelected() == SETTING_TIMERPICKER_HOURS) && (minute == SETTING_TIMERPICKER_MINS) && - (timerPicker[SUM_2]->GetSelected() == SETTING_TIMERPICKER_MINS)) { - start->SetTouchable(false); - start->SetSrc(image1); + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + if ((timerPicker_[0]->GetSelected() == SETTING_TIMERPICKER_HOUR_END) && (minute == SETTING_TIMERPICKER_MIN_END) && + (timerPicker_[INDEX_2]->GetSelected() == SETTING_TIMERPICKER_MIN_END)) { + startImg_->SetTouchable(false); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_GRAY); } else { - start->SetTouchable(true); - start->SetSrc(image2); + startImg_->SetTouchable(true); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_ORANGE); } - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("分钟"); - timerLabel->Invalidate(); - } else { + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("分钟"); + labelUnit_->Invalidate(); + } else if (strcmp(picker.GetViewId(), SEC_PICKER) == 0) { uint16_t sec = picker.GetSelected(); - timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); - timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); - timerPicker[0]->Invalidate(); - timerPicker[1]->Invalidate(); - timerPicker[SUM_2]->Invalidate(); - if ((timerPicker[0]->GetSelected() == SETTING_TIMERPICKER_HOURS) && - (timerPicker[1]->GetSelected() == SETTING_TIMERPICKER_MINS) && (sec == SETTING_TIMERPICKER_MINS)) { - start->SetTouchable(false); - start->SetSrc(image1); + timerPicker_[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker_[INDEX_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker_[0]->Invalidate(); + timerPicker_[1]->Invalidate(); + timerPicker_[INDEX_2]->Invalidate(); + if ((timerPicker_[0]->GetSelected() == SETTING_TIMERPICKER_HOUR_END) && + (timerPicker_[1]->GetSelected() == SETTING_TIMERPICKER_MIN_END) && (sec == SETTING_TIMERPICKER_MIN_END)) { + startImg_->SetTouchable(false); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_GRAY); } else { - start->SetTouchable(true); - start->SetSrc(image2); + startImg_->SetTouchable(true); + LOADIMG::LoadImageViewImg(startImg_, TIMER_IMAGE, IMAGE_TIMER_BEGIN_ORANGE); } - timerLabel->SetVisible(true); - timerLabel->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); - timerLabel->SetText("秒"); - timerLabel->Invalidate(); + labelUnit_->SetVisible(true); + labelUnit_->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); + labelUnit_->SetText("秒"); + labelUnit_->Invalidate(); } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleMainPage.cpp new file mode 100644 index 000000000..bda8d0153 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleMainPage.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#include "uisample/UISampleMainPage.h" +#include "uisample/UISampleModel.h" +#include "uisample/UISampleView.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "main/LoadImg.h" +#include "components/ui_label_button.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_test.h" + +namespace OHOS { +namespace { +const uint16_t TESTCASE_BUTTON_HEIGHT = 100; +const uint16_t STYLE_BORDER_WIDTH_VALUE = 4; +static int16_t SAMPLE_TITLE_TEXT_SIZE = 38; +} // namespace +REGIST_SLICE_PAGE(VIEW_UISAMPLE, SAMPLE_PAGES::SAMPLE_MAIN_PAGE, UISampleMainPage, true); +static UISampleMainPage* g_instance = nullptr; + +UISampleMainPage::UISampleMainPage() +{ + g_instance = this; +} + +UISampleMainPage* UISampleMainPage::GetInstance() +{ + return g_instance; +} + +UISampleMainPage::~UISampleMainPage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + + if (mainList_ != nullptr) { + delete mainList_; + mainList_ = nullptr; + } + g_instance = nullptr; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + UILabelButton* item = dynamic_cast(view); + if (item != nullptr) { + TestCaseInfo* info = static_cast(data); + if (info != nullptr) { + item->SetText(info->sliceId); + item->SetViewId(info->sliceId); + } + } +} + +static UIView* CreateViewCb(uint8_t type) +{ + UILabelButton* item = new UILabelButton(); + if (item == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create item faild!"); + return nullptr; + } + + item->SetPosition(0, 0); + item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::RELEASED); + item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::PRESSED); + item->SetStyleForState(STYLE_BORDER_WIDTH, STYLE_BORDER_WIDTH_VALUE, UIButton::INACTIVE); + item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::RELEASED); + item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::PRESSED); + item->SetStyleForState(STYLE_BORDER_OPA, 0, UIButton::INACTIVE); + item->SetStyleForState(STYLE_BORDER_RADIUS, 0, UIButton::RELEASED); + item->SetStyleForState(STYLE_BORDER_RADIUS, 0, UIButton::PRESSED); + item->SetStyleForState(STYLE_BORDER_RADIUS, 0, UIButton::INACTIVE); + item->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + item->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + item->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + item->Resize(HORIZONTAL_RESOLUTION - TEXT_DISTANCE_TO_LEFT_SIDE, TESTCASE_BUTTON_HEIGHT); + item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40: means font size + item->SetAlign(TEXT_ALIGNMENT_LEFT); + item->SetLabelPosition(150, 0); // 150: label x-coordinate + item->SetOnClickListener(UISampleMainPage::GetInstance()); + return item; +} + +void UISampleMainPage::OnStart(void *data) +{ + if (container_ == nullptr) { + container_ = new UIScrollViewNested(); + if (container_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleMainPage::OnStart::container_ is nullptr"); + return; + } + } + container_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + container_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + container_->SetVisible(true); + + CreateTitle(); + CreateMainList(); + AddViewToPageContainer(container_); + container_->Invalidate(); +} + +void UISampleMainPage::CreateTitle() +{ + if (title_ == nullptr) { + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleMainPage::OnStart::title_ is nullptr"); + return; + } + } + + title_->SetPosition(130, 0, 185, 80); // tile position x:130 size w: 185 h: 80 + title_->SetText("用例"); + title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SAMPLE_TITLE_TEXT_SIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + title_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + container_->Add(title_); +} + +void UISampleMainPage::CreateMainList() +{ + if (mainList_ == nullptr) { + mainList_ = new UISimpleList(); + if (mainList_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleMainPage::OnStart::mainList_ is nullptr"); + return; + } + } + mainList_->SetPosition(0, 100, 600, 600); // position: y: 100 w: 600 h:600 + mainList_->SetThrowDrag(true); + mainList_->SetReboundSize(100); // 100: reboind size + mainList_->SetElastic(true); + container_->Add(mainList_); + + if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { + mainList_->SetOnDragListener(this); + } + UITestGroup::GetInstance()->SetUpTestCase(); + List* testCaseList = UITestGroup::GetInstance()->GetTestCase(); + Contents content = {}; + for (auto node = testCaseList->Begin(); node != testCaseList->End(); node = node->next_) { + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 1; + content.data = reinterpret_cast(&(node->data_)); + mainList_->AddContent(content); + } + mainList_->RefreshList(); +} + +bool UISampleMainPage::OnClick(UIView& view, const ClickEvent& event) +{ + if (strcmp(view.GetViewId(), "自研用例") == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SAMPLE_PAGES::SAMPLE_PROPRIETARY_TESTCASE_PAGE); + } else if (strcmp(view.GetViewId(), "开源用例") == 0) { + NativeAbility::GetInstance().SwitchPageInSlice(SAMPLE_PAGES::SAMPLE_NATIVE_TESTCASE_PAGE); + } + return true; +} + +bool UISampleMainPage::OnDrag(UIView& view, const DragEvent& event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } + return true; +} +} + diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleModel.cpp index 68a75729e..142ee4889 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleModel.cpp @@ -1,21 +1,21 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.cpp - * Author: - * Create: 2021-11-23 - */ - -#include "uisample/UISampleModel.h" - -namespace OHOS { - UISampleModel::UISampleModel() {} - - UISampleModel::~UISampleModel() {} - - UISampleModel &UISampleModel::GetInstance() - { - static UISampleModel instance; - return instance; - } - -} +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#include "uisample/UISampleModel.h" + +namespace OHOS { + UISampleModel::UISampleModel() {} + + UISampleModel::~UISampleModel() {} + + UISampleModel &UISampleModel::GetInstance() + { + static UISampleModel instance; + return instance; + } + +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleNativeTestCasePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleNativeTestCasePage.cpp new file mode 100644 index 000000000..d97841358 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleNativeTestCasePage.cpp @@ -0,0 +1,254 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ +#include "uisample/UISampleNativeTestCasePage.h" +#include "uisample/UISampleModel.h" +#include "uisample/UISampleView.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "main/LoadImg.h" +#include "components/root_view.h" +#include "components/ui_label.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "View.h" +#include "ui_test.h" + +namespace OHOS { +namespace { +const uint16_t TESTCASE_BUTTON_HEIGHT = 100; +static int16_t SAMPLE_TITLE_TEXT_SIZE = 38; +} // namespace + +REGIST_SLICE_PAGE(VIEW_UISAMPLE, SAMPLE_PAGES::SAMPLE_NATIVE_TESTCASE_PAGE, UISampleNativeTestCasePage, false); +static UISampleNativeTestCasePage* g_instance = nullptr; +static RootView::OnKeyActListener *g_keyListener = nullptr; + +UISampleNativeTestCasePage::UISampleNativeTestCasePage() +{ + g_instance = this; +} + +UISampleNativeTestCasePage* UISampleNativeTestCasePage::GetInstance() +{ + return g_instance; +} + +UISampleNativeTestCasePage::~UISampleNativeTestCasePage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + + if (mainList_ != nullptr) { + delete mainList_; + mainList_ = nullptr; + } + + if (backBtn_ != nullptr) { + delete backBtn_; + backBtn_ = nullptr; + } + g_instance = nullptr; + isInTestCase_ = false; +} + +static UIView* CreateViewCb(uint8_t type) +{ + UILabel* item = new UILabel(); + if (item == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create item faild!"); + return nullptr; + } + + item->SetPosition(0, 0, Screen::GetInstance().GetWidth(), TESTCASE_BUTTON_HEIGHT); + item->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40: means font size + item->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + item->SetTouchable(true); + item->SetOnClickListener(UISampleNativeTestCasePage::GetInstance()); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + UILabel* item = dynamic_cast(view); + if (item != nullptr) { + TestCaseInfo* info = static_cast(data); + if (info != nullptr) { + item->SetText(info->sliceId); + item->SetViewId(info->sliceId); + } + } +} + +bool UISampleNativeTestCasePage::BackMenuPage(UIView& view) +{ + if (container_ != nullptr) { + container_->RemoveAll(); + + UITest* uiTest = UITestGroup::GetInstance()->GetTestCase(view.GetViewId()); + if (uiTest != nullptr) { + uiTest->TearDown(); + } + + RootView::GetInstance()->SetOnKeyActListener(g_keyListener); + g_keyListener = nullptr; + isInTestCase_ = false; + + container_->Add(title_); + container_->Add(mainList_); + container_->Invalidate(); + } + return true; +} + +void UISampleNativeTestCasePage::OnStart(void *data) +{ + if (container_ == nullptr) { + container_ = new UIScrollViewNested(); + if (container_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleNativeTestCasePage::OnStart::container_ is nullptr"); + return; + } + } + container_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + container_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + container_->SetVisible(true); + + CreateTitle(); + CreateMainList(); + CreateBackButton(); + AddViewToPageContainer(container_); + container_->Invalidate(); +} + +void UISampleNativeTestCasePage::CreateTitle() +{ + if (title_ == nullptr) { + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleNativeTestCasePage::OnStart::title_ is nullptr"); + return; + } + } + title_->SetPosition(130, 0, 185, 80); // tile position x:130 size w: 185 h: 80 + title_->SetText("开源用例"); + title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SAMPLE_TITLE_TEXT_SIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + title_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + container_->Add(title_); +} + +void UISampleNativeTestCasePage::CreateMainList() +{ + if (mainList_ == nullptr) { + mainList_ = new UISimpleList(); + } + if (mainList_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleNativeTestCasePage::OnStart::mainList_ is nullptr"); + return; + } + mainList_->SetPosition(0, 100, Screen::GetInstance().GetWidth(), 366); // position: y: 100 w: 600 h:600 + mainList_->SetViewId("sample"); + mainList_->SetThrowDrag(true); + mainList_->SetReboundSize(100); // 100: reboind size + mainList_->SetElastic(true); + container_->Add(mainList_); + mainList_->SetOnDragListener(this); + + UITestGroup::GetInstance()->SetUpOHTestCase(); + mainList_->ClearAll(); + List* testCaseList = UITestGroup::GetInstance()->GetTestCase(); + Contents content = {}; + for (auto node = testCaseList->Begin(); node != testCaseList->End(); node = node->next_) { + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 1; + content.data = reinterpret_cast(&(node->data_)); + mainList_->AddContent(content); + } + mainList_->RefreshList(); +} + +void UISampleNativeTestCasePage::CreateBackButton() +{ + if (backBtn_ == nullptr) { + backBtn_ = new UIButton(); + } + if (backBtn_ != nullptr) { + backBtn_->SetPosition(0, 202, 50, 50); // 0: x position, 202: y position, 50: width and height + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + backBtn_->SetOnClickListener(this); + } +} + +bool UISampleNativeTestCasePage::OnClick(UIView& view, const ClickEvent& event) +{ + if (isInTestCase_) { + return BackMenuPage(view); + } + + if (container_ == nullptr) { + return false; + } + + UITest* uiTest = UITestGroup::GetInstance()->GetTestCase(view.GetViewId()); + if (uiTest == nullptr) { + return false; + } + uiTest->SetUp(); + container_->RemoveAll(); + + UIView* tempView = const_cast(uiTest->GetTestView()); + if (tempView != nullptr) { + tempView->SetTouchable(true); + tempView->SetViewId(view.GetViewId()); + tempView->SetPosition(tempView->GetX(), tempView->GetY()); + container_->Add(tempView); + + g_keyListener = RootView::GetInstance()->GetOnKeyActListener(); + RootView::GetInstance()->SetOnKeyActListener(nullptr); + } + + if (backBtn_ != nullptr) { + backBtn_->SetViewId(view.GetViewId()); + container_->Add(backBtn_); + } + + isInTestCase_ = true; + container_->Invalidate(); + return true; +} + +bool UISampleNativeTestCasePage::OnDrag(UIView& view, const DragEvent& event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SAMPLE_MAIN_PAGE); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp index 7d42911b9..26d5026fd 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp @@ -1,36 +1,36 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.cpp - * Author: - * Create: 2021-11-23 - */ - -#include "uisample/UISampleView.h" -#include "uisample/UISampleModel.h" -#include "uisample/UISamplePresenter.h" -#include "uiservice/ui_service.h" -#include "NativeRegisterManager.h" - -namespace OHOS { - -REGIST_MENU(VIEW_UISAMPLE, UISampleView, UISamplePresenter, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_DEFAULT_IMG, "示例"); - - UISamplePresenter::UISamplePresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UISamplePresenter::UISamplePresenter"); - uisampleModel = &UISampleModel::GetInstance(); - } - - UISamplePresenter::~UISamplePresenter() {} - - void UISamplePresenter::OnResume(void) - { - SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); - } - - void UISamplePresenter::OnPause(void) - { - SendMsgToUIService(UI_RM_SLEEP_VETO, 0, nullptr, 0); - return; - } -} +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#include "uisample/UISamplePresenter.h" +#include "uisample/UISampleView.h" +#include "uisample/UISampleModel.h" +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" + +namespace OHOS { + +REGIST_MENU(VIEW_UISAMPLE, UISampleView, UISamplePresenter, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_DEFAULT_IMG, "示例"); + + UISamplePresenter::UISamplePresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UISamplePresenter::UISamplePresenter"); + uisampleModel_ = &UISampleModel::GetInstance(); + } + + UISamplePresenter::~UISamplePresenter() {} + + void UISamplePresenter::OnResume(void) + { + SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); + } + + void UISamplePresenter::OnPause(void) + { + SendMsgToUIService(UI_RM_SLEEP_VETO, 0, nullptr, 0); + return; + } +} diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleProprietaryTestCasePage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleProprietaryTestCasePage.cpp new file mode 100644 index 000000000..139af11b9 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/src/UISampleProprietaryTestCasePage.cpp @@ -0,0 +1,256 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025. All rights reserved. + * Description: TestCase + * Author: Hisi Graphic Team + * Created: 2025-7 + */ + +#include "uisample/UISampleModel.h" +#include "uisample/UISampleProprietaryTestCasePage.h" +#include "uisample/UISampleView.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "main/LoadImg.h" +#include "components/root_view.h" +#include "components/ui_label.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "View.h" +#include "ui_test.h" + +namespace OHOS { +namespace { +const uint16_t TESTCASE_BUTTON_HEIGHT = 100; +static int16_t SAMPLE_TITLE_TEXT_SIZE = 38; +} // namespace + +REGIST_SLICE_PAGE(VIEW_UISAMPLE, SAMPLE_PAGES::SAMPLE_PROPRIETARY_TESTCASE_PAGE, + UISampleProprietaryTestCasePage, false); +static UISampleProprietaryTestCasePage* g_instance = nullptr; +static RootView::OnKeyActListener *g_keyListener = nullptr; + +UISampleProprietaryTestCasePage::UISampleProprietaryTestCasePage() +{ + g_instance = this; +} + +UISampleProprietaryTestCasePage* UISampleProprietaryTestCasePage::GetInstance() +{ + return g_instance; +} + +UISampleProprietaryTestCasePage::~UISampleProprietaryTestCasePage() +{ + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + + if (mainList_ != nullptr) { + delete mainList_; + mainList_ = nullptr; + } + + if (backBtn_ != nullptr) { + delete backBtn_; + backBtn_ = nullptr; + } + g_instance = nullptr; + isInTestCase_ = false; +} + +static UIView* CreateViewCb(uint8_t type) +{ + UILabel* item = new UILabel(); + if (item == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create item faild!"); + return nullptr; + } + + item->SetPosition(0, 0, Screen::GetInstance().GetWidth(), TESTCASE_BUTTON_HEIGHT); + item->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40: means font size + item->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + item->SetTouchable(true); + item->SetOnClickListener(UISampleProprietaryTestCasePage::GetInstance()); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + UNUSED(type); + UILabel* item = dynamic_cast(view); + if (item != nullptr) { + TestCaseInfo* info = static_cast(data); + if (info != nullptr) { + item->SetText(info->sliceId); + item->SetViewId(info->sliceId); + } + } +} + +bool UISampleProprietaryTestCasePage::BackMenuPage(UIView& view) +{ + if (container_ != nullptr) { + container_->RemoveAll(); + UITest* uiTest = UITestGroup::GetInstance()->GetTestCase(view.GetViewId()); + if (uiTest != nullptr) { + uiTest->TearDown(); + } + RootView::GetInstance()->SetOnKeyActListener(g_keyListener); + g_keyListener = nullptr; + isInTestCase_ = false; + + container_->Add(title_); + container_->Add(mainList_); + container_->Invalidate(); + } + return true; +} + +void UISampleProprietaryTestCasePage::OnStart(void *data) +{ + if (container_ == nullptr) { + container_ = new UIScrollViewNested(); + if (container_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleProprietaryTestCasePage::OnStart::container_ is nullptr"); + return; + } + } + container_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + container_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + container_->SetVisible(true); + + CreateTitle(); + CreateMainList(); + CreateBackButton(); + AddViewToPageContainer(container_); + container_->Invalidate(); +} + +void UISampleProprietaryTestCasePage::CreateTitle() +{ + if (title_ == nullptr) { + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleProprietaryTestCasePage::OnStart::title_ is nullptr"); + return; + } + } + + title_->SetPosition(130, 0, 185, 80); // tile position x:130 size w: 185 h: 80 + title_->SetText("自研用例"); + title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SAMPLE_TITLE_TEXT_SIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + title_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + container_->Add(title_); +} + +void UISampleProprietaryTestCasePage::CreateMainList() +{ + if (mainList_ == nullptr) { + mainList_ = new UISimpleList(); + if (mainList_ == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " UISampleProprietaryTestCasePage::OnStart::mainList_ is nullptr"); + return; + } + } + mainList_->SetPosition(0, 100, Screen::GetInstance().GetWidth(), 366); // position: y: 100 w: 600 h:600 + mainList_->SetViewId("sample"); + mainList_->SetThrowDrag(true); + mainList_->SetReboundSize(100); // 100: reboind size + mainList_->SetElastic(true); + mainList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + container_->Add(mainList_); + mainList_->SetOnDragListener(this); + + UITestGroup::GetInstance()->SetUpHSTestCase(); + mainList_->ClearAll(); + List* testCaseList = UITestGroup::GetInstance()->GetTestCase(); + Contents content = {}; + for (auto node = testCaseList->Begin(); node != testCaseList->End(); node = node->next_) { + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.type = 1; + content.data = reinterpret_cast(&(node->data_)); + mainList_->AddContent(content); + } + mainList_->RefreshList(); +} + +void UISampleProprietaryTestCasePage::CreateBackButton() +{ + if (backBtn_ == nullptr) { + backBtn_ = new UIButton(); + } + if (backBtn_ != nullptr) { + backBtn_->SetPosition(0, 202, 50, 50); // 0: x position, 202: y position, 50: width and height + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + backBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + backBtn_->SetOnClickListener(this); + } +} + +bool UISampleProprietaryTestCasePage::OnClick(UIView& view, const ClickEvent& event) +{ + if (isInTestCase_) { + return BackMenuPage(view); + } + + if (container_ == nullptr) { + return false; + } + + UITest* uiTest = UITestGroup::GetInstance()->GetTestCase(view.GetViewId()); + if (uiTest == nullptr) { + return false; + } + uiTest->SetUp(); + container_->RemoveAll(); + + UIView* tempView = const_cast(uiTest->GetTestView()); + if (tempView != nullptr) { + tempView->SetTouchable(true); + tempView->SetViewId(view.GetViewId()); + tempView->SetPosition(tempView->GetX(), tempView->GetY()); + container_->Add(tempView); + + g_keyListener = RootView::GetInstance()->GetOnKeyActListener(); + RootView::GetInstance()->SetOnKeyActListener(nullptr); + } + + if (backBtn_ != nullptr) { + backBtn_->SetViewId(view.GetViewId()); + container_->Add(backBtn_); + } + + isInTestCase_ =true; + container_->Invalidate(); + return true; +} + +bool UISampleProprietaryTestCasePage::OnDrag(UIView& view, const DragEvent& event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(SAMPLE_MAIN_PAGE); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/test_case_list_adapter.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/test_case_list_adapter.h index eeaddcb05..22f65f626 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/test_case_list_adapter.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/test_case_list_adapter.h @@ -12,32 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #ifndef TEST_CASE_LIST_ADAPTER_H #define TEST_CASE_LIST_ADAPTER_H -#include "components/abstract_adapter.h" -#include "components/root_view.h" -#include "components/ui_label.h" #include "components/ui_label_button.h" -namespace OHOS { -class TestCaseListAdapter : public AbstractAdapter { -public: - TestCaseListAdapter() {} - ~TestCaseListAdapter() - { - if (listener_ != nullptr) { - delete listener_; - listener_ = nullptr; - } - } - UIView* GetView(UIView* inView, int16_t index) override; - int16_t GetItemWidthWithMargin(int16_t index) override; - int16_t GetItemHeightWithMargin(int16_t index) override; - uint16_t GetCount() override; -private: - UIView::OnClickListener* listener_{nullptr}; -}; -} // namespace OHOS #endif // TEST_CASE_LIST_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/ui_test_group.h b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/ui_test_group.h index bcebab041..69b14faee 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/ui_test_group.h +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/include/ui_test_group.h @@ -26,20 +26,25 @@ struct TestCaseInfo { UITest* testObj; }; -class UITestGroup { +class UITestGroup : public HeapBase { public: static UITestGroup* GetInstance() { static UITestGroup instance; return &instance; } + void SetUpTestCase(); - List& GetTestCase(); - UITest* GetTestCase(const char* id); - void TearDownTestCase(); - void AddTestCase(TestCaseInfo testCaseInfo); + void SetUpHSTestCase(); + void SetUpOHTestCase(); + List*& GetTestCase(); + UITest* GetTestCase(const char* id); private: + UITestGroup() {} + ~UITestGroup(); + void UpdataContents(); + void TearDownTestCase(); List *testCaseList_ = nullptr; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp index c2188a499..1d968702a 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp @@ -15,89 +15,283 @@ #include "ui_test_group.h" #include "graphic_config.h" +#include "ui_test_analog_clock/ui_test_analog_clock.h" +#include "ui_test_animator/ui_test_animator.h" #include "ui_test_breath/ui_test_breath.h" +#include "ui_test_border_margin_padding/ui_test_border_margin_padding.h" +#include "ui_test_button/ui_test_button.h" +#include "ui_test_capture/ui_test_capture.h" +#include "ui_test_canvas/ui_test_canvas.h" #include "ui_test_card_switch/ui_test_card_switch.h" +#include "ui_test_clock_dial/ui_test_clock_dial.h" +#include "ui_test_chart/ui_test_chart_polyline.h" +#include "ui_test_chart/ui_test_chart_pillar.h" +#include "ui_test_countdown/ui_test_countdown.h" +#include "ui_test_coverflow/ui_test_coverflow.h" +#include "ui_test_coverflow/ui_test_coverflow2.h" +#include "ui_test_cross/ui_test_cross.h" #include "ui_test_cube_rotate/ui_test_cube_rotate.h" +#include "ui_test_digital_clock/ui_test_digital_clock.h" +#include "ui_test_draw/ui_test_canvas_ext.h" +#include "ui_test_draw/ui_test_draw.h" +#include "ui_test_draw_rect/ui_test_draw_rect.h" +#include "ui_test_draw_line/ui_test_draw_line.h" +#include "ui_test_emoji/ui_test_emoji.h" +#include "ui_test_event_injector/ui_test_event_injector.h" +#include "ui_test_focus_manager/ui_test_focus_manager.h" +#if ENABLE_VECTOR_FONT +#include "ui_test_font/ui_test_font.h" +#endif +#if (ENABLE_FONT_VECTOR_GLOBAL && ENABLE_FONT_GLOBAL_TEST) +#include "ui_test_font/ui_test_font_global.h" +#endif +#if ENABLE_ICU && ENABLE_MULTI_FONT && ENABLE_SHAPING +#include "ui_test_font/ui_test_multi_font.h" +#endif +#include "ui_test_hexagons_list/ui_test_hexagons_list.h" +#include "ui_test_icosahedron/ui_test_icosahedron.h" +#include "ui_test_image/ui_test_image.h" +#if CAPABILITY_HW_JPEG_DECODE +#include "ui_test_image/ui_test_jpeg.h" +#endif +#if ENABLE_JPEG_AND_PNG +#include "ui_test_image/ui_test_png.h" +#endif +#if (ENABLE_IMAGE_PACKER && ENABLE_IMAGE_PACKER_TEST) +#include "ui_test_image/ui_test_image_packer.h" +#endif +#include "ui_test_image_animator/ui_test_image_animator.h" +#include "ui_test_image_fps/ui_test_image_fps.h" +#include "ui_test_input_event/ui_test_input_event.h" +#include "ui_test_kaleidoscope/ui_test_kaleidoscope.h" +#include "ui_test_key/ui_test_key.h" +#if ENABLE_SOFT_KEYBOARD +#include "ui_test_keyboard/ui_test_keyboard.h" +#endif +#include "ui_test_label/ui_test_arc_label.h" +#include "ui_test_list_fps/ui_test_list_fps.h" #include "ui_test_list_fps/ui_test_list_fps.h" +#include "ui_test_list/ui_test_list.h" +#include "ui_test_list_ext/ui_test_list_ext.h" +#include "ui_test_lottie/ui_test_lottie.h" +#include "ui_test_lottie/ui_test_trim_path.h" +#include "ui_test_map/ui_test_map.h" +#include "ui_test_message/ui_test_message.h" #include "ui_test_message/ui_test_message.h" +#include "ui_test_nested/ui_test_nested.h" +#include "ui_test_opacity/ui_test_opacity.h" +#include "ui_test_particle/ui_test_particle.h" +#include "ui_test_particle/ui_test_particle.h" +#include "ui_test_picker/ui_test_ui_picker.h" +#include "ui_test_progress_bar/ui_test_box_progress.h" +#include "ui_test_progress_bar/ui_test_circle_progress.h" +#include "ui_test_qrcode/ui_test_qrcode.h" #if ENABLE_VGU_ENGINE && CAPABILITY_HWDRAW_PATH -#include "ui_test_countdown/ui_test_countdown.h" #include "ui_test_running_ball/ui_test_running_ball.h" #endif -#if ENABLE_SOFT_KEYBOARD -#include "ui_test_keyboard/ui_test_keyboard.h" +#include "ui_test_roller_view/ui_test_roller_view.h" +#if ENABLE_DEBUG && ENABLE_ROTATE_INPUT +#include "ui_test_rotate_injector/ui_test_rotate_injector.h" #endif -#include "ui_test_icosahedron/ui_test_icosahedron.h" -#include "ui_test_tiger/ui_test_tiger.h" -#include "ui_test_hexagons_list/ui_test_hexagons_list.h" -#include "ui_test_waterfall_list/ui_test_waterfall_list.h" -#include "ui_test_video_play/ui_test_video_play.h" -#include "ui_test_coverflow/ui_test_coverflow.h" +#include "ui_test_render/ui_test_render.h" +#include "ui_test_rotate_input/ui_test_rotate_input.h" #include "ui_test_slipflow/ui_test_slipflow.h" -#include "ui_test_kaleidoscope/ui_test_kaleidoscope.h" -#include "ui_test_roller_view/ui_test_roller_view.h" -#include "ui_test_emoji/ui_test_emoji.h" +#include "ui_test_foldable/ui_test_foldable.h" #include "ui_test_sphere_view/ui_test_sphere_view.h" -#include "ui_test_nested/ui_test_nested.h" -#include "ui_test_particle/ui_test_particle.h" -#include "ui_test_lottie/ui_test_lottie.h" +#include "ui_test_scroll_bar/ui_test_scroll_bar.h" +#include "ui_test_slider/ui_test_slider.h" +#include "ui_test_simple_list/ui_test_simple_list.h" +#include "ui_test_simple_list/ui_test_simple_transform_list.h" +#include "ui_test_svg/ui_test_svg.h" +#include "ui_test_text_fps/ui_test_text_fps.h" +#include "ui_test_texture_mapper/ui_test_texture_mapper.h" +#include "ui_test_tiger/ui_test_tiger.h" +#include "ui_test_transition/ui_test_transition_view.h" +#include "ui_test_ui_list/ui_test_ui_list.h" +#include "ui_test_ui_list_view/ui_test_list_layout.h" +#include "ui_test_ui_scroll_view/ui_test_ui_scroll_view.h" +#include "ui_test_ui_swipe_view/ui_test_ui_swipe_view.h" +#if ENABLE_VECTOR_FONT +#include "ui_test_vector_font/ui_test_vector_font.h" +#endif +#include "ui_test_video_play/ui_test_video_play.h" +#include "ui_test_view_group/ui_test_view_group.h" +#include "ui_test_view_bounds/ui_test_view_bounds.h" +#include "ui_test_view_percent/ui_test_view_percent.h" +#include "ui_test_view_scale_rotate/ui_test_view_scale_rotate.h" +#include "ui_test_view_bitmap/ui_test_view_bitmap.h" +#include "ui_test_view_alignment/ui_test_alignment_external.h" +#include "ui_test_view_alignment/ui_test_alignment_internal.h" +#include "ui_test_view_alignment/ui_test_alignment_dynamic.h" +#include "ui_test_waterfall_list/ui_test_waterfall_list.h" +#include "ui_test_float_box/ui_test_float_box.h" +#include "ui_test_chart/ui_test_scatter_plot.h" + namespace OHOS { -void UITestGroup::AddTestCase(TestCaseInfo testCaseInfo) +UITestGroup::~UITestGroup() +{ + TearDownTestCase(); + if (testCaseList_ != nullptr) { + delete testCaseList_; + testCaseList_ = nullptr; + } +} + +void UITestGroup::SetUpTestCase() { + if (testCaseList_ == nullptr) { + testCaseList_ = new List(); + } if (testCaseList_ == nullptr) { return; } - testCaseList_->PushBack(testCaseInfo); + + TearDownTestCase(); + testCaseList_->PushBack(TestCaseInfo{"自研用例", nullptr}); + testCaseList_->PushBack(TestCaseInfo{"开源用例", nullptr}); } -void UITestGroup::SetUpTestCase() +void UITestGroup::SetUpHSTestCase() { - testCaseList_ = new List(); + if (testCaseList_ == nullptr) { + testCaseList_ = new List(); + } + if (testCaseList_ == nullptr) { return; } - testCaseList_->Clear(); + TearDownTestCase(); testCaseList_->PushBack(TestCaseInfo{"老虎头", new UITestTiger()}); testCaseList_->PushBack(TestCaseInfo{"蜂窝表盘", new UITestHexagonsList()}); + testCaseList_->PushBack(TestCaseInfo{"无变换滑动列表", new UITestListFPS()}); + testCaseList_->PushBack(TestCaseInfo{"带缩放滑动列表", new UITestListExt()}); + testCaseList_->PushBack(TestCaseInfo{"简易列表", new UITestSimpleList()}); + testCaseList_->PushBack(TestCaseInfo{"简易变换列表", new UITestSimpleTransformList()}); + testCaseList_->PushBack(TestCaseInfo{"全屏文字", new UITestTextFPS()}); testCaseList_->PushBack(TestCaseInfo{"瀑布列表", new UITestWaterfallList()}); testCaseList_->PushBack(TestCaseInfo{"滑动列表", new UITestListFPS()}); testCaseList_->PushBack(TestCaseInfo{"卡片切换", new UITestCardSwitch()}); testCaseList_->PushBack(TestCaseInfo{"立方体旋转", new UITestCubeRotate()}); testCaseList_->PushBack(TestCaseInfo{"消息", new UITestMessage()}); testCaseList_->PushBack(TestCaseInfo{"呼吸效果", new UITestBreath()}); + testCaseList_->PushBack(TestCaseInfo{"折叠控件", new UITestFoldable()}); testCaseList_->PushBack(TestCaseInfo{"覆盖流", new UITestCoverflow()}); testCaseList_->PushBack(TestCaseInfo{"滑动流", new UITestSlipflow()}); testCaseList_->PushBack(TestCaseInfo{"万花筒", new UITestKaleidoscope()}); testCaseList_->PushBack(TestCaseInfo{"滚筒", new UITestRollerView()}); - + testCaseList_->PushBack(TestCaseInfo{"地图", new UITestMap()}); #if ENABLE_VGU_ENGINE && CAPABILITY_HWDRAW_PATH testCaseList_->PushBack(TestCaseInfo{"倒计时", new UITestCountdown()}); testCaseList_->PushBack(TestCaseInfo{"动画曲线", new UITestRunningBall()}); + testCaseList_->PushBack(TestCaseInfo{"扩展画布", new UITestCanvasExt()}); #endif #if ENABLE_SOFT_KEYBOARD testCaseList_->PushBack(TestCaseInfo{"软键盘", new UITestKeyboard()}); #endif + testCaseList_->PushBack(TestCaseInfo{"绘制SVG", new UITestSVG()}); + testCaseList_->PushBack(TestCaseInfo{"容器覆盖流", new UITestCoverflow2()}); + testCaseList_->PushBack(TestCaseInfo{"覆盖流", new UITestCoverflow()}); testCaseList_->PushBack(TestCaseInfo{"视频播放", new UITestVideoPlay()}); testCaseList_->PushBack(TestCaseInfo{"球型菜单", new UITestSphereView()}); testCaseList_->PushBack(TestCaseInfo{"足球效果", new UITestIcosahedron()}); +#if CAPABILITY_HW_JPEG_DECODE + testCaseList_->PushBack(TestCaseInfo{"JPEG显示", new UITestJPEG()}); +#endif +#if ENABLE_JPEG_AND_PNG + testCaseList_->PushBack(TestCaseInfo{"PNG显示", new UITestPNG()}); +#endif + testCaseList_->PushBack(TestCaseInfo{"图片旋转缩放动画", new UITestTextureMapper()}); +#if ENABLE_DEBUG && ENABLE_ROTATE_INPUT + testCaseList_->PushBack(TestCaseInfo{"模拟表冠", new UITestRotateInjector()}); +#endif + testCaseList_->PushBack(TestCaseInfo{"二维码", new UITestQrcode()}); + testCaseList_->PushBack(TestCaseInfo{"折线图", new UITestChartPolyline()}); + testCaseList_->PushBack(TestCaseInfo{"柱状图", new UITestChartPillar()}); + testCaseList_->PushBack(TestCaseInfo{"弧形文字", new UITestArcLabel()}); +#if ENABLE_ICU && ENABLE_MULTI_FONT && ENABLE_SHAPING + testCaseList_->PushBack(TestCaseInfo{"多语言混排", new UITestMultiFont()}); +#endif +#if ENABLE_VECTOR_FONT + testCaseList_->PushBack(TestCaseInfo{"矢量文字", new UITestFont()}); +#endif +#if (ENABLE_FONT_VECTOR_GLOBAL && ENABLE_FONT_GLOBAL_TEST) + testCaseList_->PushBack(TestCaseInfo{"多语言切换", new UITestFontGlobal()}); +#endif + testCaseList_->PushBack(TestCaseInfo{"全屏高斯模糊", new UITestKey()}); + testCaseList_->PushBack(TestCaseInfo{"截图", new UITestCapture()}); testCaseList_->PushBack(TestCaseInfo{"滑动冲突", new UITestNested()}); - testCaseList_->PushBack(TestCaseInfo{"粒子效果", new UITestParticle()}); + testCaseList_->PushBack(TestCaseInfo{"悬浮框", new UITestFloatBox()}); + testCaseList_->PushBack(TestCaseInfo{"散点图", new UITestScatterPlot()}); testCaseList_->PushBack(TestCaseInfo{"Lottie", new UITestLottie()}); + testCaseList_->PushBack(TestCaseInfo{"路径裁剪", new UITestTrimPath()}); + testCaseList_->PushBack(TestCaseInfo{"粒子效果", new UITestParticle()}); + testCaseList_->PushBack(TestCaseInfo{"页面动效", new UITestTransitionView()}); + testCaseList_->PushBack(TestCaseInfo{"画布", new UITestDraw()}); + testCaseList_->PushBack(TestCaseInfo{"图片显示", new UITestImage()}); + testCaseList_->PushBack(TestCaseInfo{"矩形绘制", new UITestDrawRect()}); +#if (ENABLE_IMAGE_PACKER && ENABLE_IMAGE_PACKER_TEST) + testCaseList_->PushBack(TestCaseInfo{"图片打包", new UITestImageBin()}); +#endif +} + +void UITestGroup::SetUpOHTestCase() +{ + if (testCaseList_ == nullptr) { + testCaseList_ = new List(); + } + + if (testCaseList_ == nullptr) { + return; + } + TearDownTestCase(); + testCaseList_->PushBack(TestCaseInfo{"滑动条", new UITestSlider()}); + testCaseList_->PushBack(TestCaseInfo{"图片动画", new UITestImageFPS()}); + testCaseList_->PushBack(TestCaseInfo{"透明度", new UITestOpacity()}); + testCaseList_->PushBack(TestCaseInfo{"播放图片动画", new UITestImageAnimator()}); + testCaseList_->PushBack(TestCaseInfo{"焦点管理", new UITestFocusManager()}); + testCaseList_->PushBack(TestCaseInfo{"绘制线条", new UITestDrawLine()}); + testCaseList_->PushBack(TestCaseInfo{"数字时钟", new UITestDigitalClock()}); + testCaseList_->PushBack(TestCaseInfo{"边界间隔", new UITestBorderMarginPadding()}); + testCaseList_->PushBack(TestCaseInfo{"动效", new UITestAnimator()}); + testCaseList_->PushBack(TestCaseInfo{"视图组", new UITestViewGroup()}); + testCaseList_->PushBack(TestCaseInfo{"事件测试", new UITestInputEvent()}); + testCaseList_->PushBack(TestCaseInfo{"滚动条", new UITestScrollBar()}); + testCaseList_->PushBack(TestCaseInfo{"画布", new UITestCanvas()}); + testCaseList_->PushBack(TestCaseInfo{"Swipe视图", new UITestUISwipeView()}); + testCaseList_->PushBack(TestCaseInfo{"滑动视图", new UITestUIScrollView()}); + testCaseList_->PushBack(TestCaseInfo{"列表布局", new UITestListLayout()}); + testCaseList_->PushBack(TestCaseInfo{"列表", new UITestUIList()}); + testCaseList_->PushBack(TestCaseInfo{"按钮", new UITestButton()}); + testCaseList_->PushBack(TestCaseInfo{"选择", new UITestUIPicker()}); + testCaseList_->PushBack(TestCaseInfo{"圆形进度条", new UITestCircleProgress()}); + testCaseList_->PushBack(TestCaseInfo{"盒状进度条", new UITestBoxProgress()}); + testCaseList_->PushBack(TestCaseInfo{"事件模拟", new UITestEventInjector()}); + testCaseList_->PushBack(TestCaseInfo{"位图", new UITestViewBitmap()}); + testCaseList_->PushBack(TestCaseInfo{"旋转", new UITestViewScaleRotate()}); + testCaseList_->PushBack(TestCaseInfo{"视图比例", new UITestViewPercent()}); + testCaseList_->PushBack(TestCaseInfo{"视图边界", new UITestViewBounds()}); +#if ENABLE_VECTOR_FONT + testCaseList_->PushBack(TestCaseInfo{"矢量文字", new UITestVectorFont()}); +#endif + testCaseList_->PushBack(TestCaseInfo{"模拟时钟", new UITestAnalogClock()}); + testCaseList_->PushBack(TestCaseInfo{"旋转输入", new UITestRotateInput()}); + testCaseList_->PushBack(TestCaseInfo{"渲染", new UITestRender()}); } -List& UITestGroup::GetTestCase() +List*& UITestGroup::GetTestCase() { - return *testCaseList_; + return testCaseList_; } UITest* UITestGroup::GetTestCase(const char* id) { - if (id == nullptr) { + if (id == nullptr || testCaseList_ == nullptr) { return nullptr; } + ListNode* node = testCaseList_->Begin(); while (node != testCaseList_->End()) { - if (!strcmp(id, node->data_.sliceId)) { + if (strcmp(id, node->data_.sliceId) == 0) { return node->data_.testObj; } node = node->next_; @@ -107,11 +301,17 @@ UITest* UITestGroup::GetTestCase(const char* id) void UITestGroup::TearDownTestCase() { + if (testCaseList_ == nullptr) { + return; + } + ListNode* node = testCaseList_->Begin(); while (node != testCaseList_->End()) { - delete node->data_.testObj; - node->data_.testObj = nullptr; - node = node->next_; + if (node->data_.testObj != nullptr) { + delete node->data_.testObj; + node->data_.testObj = nullptr; + } + node = testCaseList_->Remove(node); } testCaseList_->Clear(); } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/uiservice/src/ui_service.cpp index ef81ce75d..5ed907839 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -16,7 +16,7 @@ #include "uiservice/ui_service.h" #include "wearable_log.h" #include "samgr_lite.h" -#include "settings/SettingModel.h" +#include "settings/model/SettingBluetoothModel.h" #include "main/UiServersMsg.h" #include "ohos_init.h" #include "memory_adapter.h" @@ -40,6 +40,10 @@ #include "NativeAbility.h" #include "TransitionType.h" +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) +#include "lwip_driver_adapter.h" +#endif + extern "C" errcode_t uapi_pm_add_sleep_veto(pm_id_t veto_id); extern "C" errcode_t uapi_pm_remove_sleep_veto(pm_id_t veto_id); @@ -113,8 +117,10 @@ void ScreenOffEnable(int32_t enable) void ConnectNewPhone(void) { +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) + lwip_close_bt_pan(); +#endif unsigned int connedDevicesNum = 0; - bool ret = gap_get_paired_devices_num(&connedDevicesNum); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setup GapGetPariedDevicesNum ret = %d, num = %d", ret, connedDevicesNum); @@ -184,11 +190,13 @@ void ServiceMsgProcess(Request *request) break; case BT_CONNECTED_TO_UI: GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::SettingModel::UpdateBlueToothConnectStatus, &OHOS::SettingModel::GetInstance(), true)); + std::bind(&OHOS::SettingBluetoothModel::UpdateAclConnectStatus, + OHOS::SettingBluetoothModel::GetInstance(), true)); break; case BT_DISCONNECTED_TO_UI: GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::SettingModel::UpdateBlueToothConnectStatus, &OHOS::SettingModel::GetInstance(), false)); + std::bind(&OHOS::SettingBluetoothModel::UpdateAclConnectStatus, + OHOS::SettingBluetoothModel::GetInstance(), false)); break; case UI_ADD_SLEEP_VETO: uapi_pm_add_sleep_veto(PM_ID_SCREEN); @@ -204,8 +212,8 @@ void ServiceMsgProcess(Request *request) break; case UI_OTA_UPDATE: power_display_svr_get_api()->turn_on_screen(); - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_SET_OTA, - OHOS::TransitionType::TRANSITION_INVALID, OHOS::gSliceDefaultPriority, true); + OHOS::NativeAbility::GetInstance().SwitchSlice(VIEW_SETTING, OHOS::SettingPageId::SYSTEM_OTA_PAGE, + OHOS::TransitionType::TRANSITION_INVALID, true); break; } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherItemView.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherItemView.cpp index e417f9f1f..785037f6c 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherItemView.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherItemView.cpp @@ -1,12 +1,12 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: WeatherItemView * Create: 2025-03-23 */ #include "wearable_log.h" -#include "weather/WeatherItemView.h" #include "weather/WeatherModel.h" +#include "weather/WeatherItemView.h" namespace OHOS { static constexpr int16_t WEATHER_ICON_X = 155; @@ -16,8 +16,6 @@ static constexpr int16_t WEATHER_CHARTLINE_X = 20; static constexpr int16_t WEATHER_CHARTLINE_Y = 78; static constexpr int16_t WEATHER_CHARTLINE_WIDTH = 450; static constexpr int16_t WEATHER_CHARTLINE_HEIGHT = 2; -static constexpr int16_t WEATHER_ITEM_BUTTON_WIDTH = 390; -static constexpr int16_t WEATHER_ITEM_BUTTON_HEIGHT = 83; static constexpr int16_t WEATHER_ITEM_LABEL_WIDTH = 155; static constexpr int16_t WEATHER_ITEM_LABEL_HEIGHT = 80; static constexpr int16_t WEATHER_ITEM_FONT_SIZE = 35; @@ -27,72 +25,52 @@ static constexpr int16_t NUMS_50 = 50; WeatherItemView::WeatherItemView() { - SetPosition(0, 0, WEATHER_ITEM_BUTTON_WIDTH, WEATHER_ITEM_BUTTON_HEIGHT); - SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - SetTouchable(true); - SetUpChild(); + bgImg_.SetPosition(0, 0); + bgImg_.Resize(WEATHER_IMAGE_SIZE, WEATHER_IMAGE_SIZE); + WeatherModel::GetInstance().LoadImageOfDayNight(&bgImg_, IMAGE_WEATHER_ITEM1, IMAGE_WEATHER_ITEM2); + labelDay_.SetPosition(WEATHER_LABEL_X, 0); + labelDay_.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); + labelDay_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelDay_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelDay_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelDay_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelDay_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + icon_.SetPosition(WEATHER_ICON_X, WEATHER_ICON_Y); + icon_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - Add(&sNextImage); - Add(&sLabel_1); - Add(&sIcon); - Add(&sLabel_2); - Add(&chartLine); + labelTmp_.SetPosition(WEATHER_LABEL2_X, 0); + labelTmp_.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); + labelTmp_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelTmp_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTmp_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTmp_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTmp_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + chartLine_.SetPosition(WEATHER_CHARTLINE_X, WEATHER_CHARTLINE_Y, WEATHER_CHARTLINE_WIDTH, WEATHER_CHARTLINE_HEIGHT); + chartLine_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + Add(&bgImg_); + Add(&labelDay_); + Add(&icon_); + Add(&labelTmp_); + Add(&chartLine_); } WeatherItemView::~WeatherItemView() { - Remove(&sIcon); - Remove(&sLabel_1); - Remove(&sLabel_2); - Remove(&chartLine); + Remove(&bgImg_); + Remove(&icon_); + Remove(&labelDay_); + Remove(&labelTmp_); + Remove(&chartLine_); } void WeatherItemView::SetItemInfo(const WeatherItem itemInfo) { - sItemInfo = itemInfo; - sLabel_1.SetText(itemInfo.label_1); - sIcon.SetSrc(itemInfo.icon); - sLabel_2.SetText(itemInfo.label_2); - chartLine.SetVisible(itemInfo.hasSecondMenu); + labelDay_.SetText(itemInfo.weatherWeek); + LOADIMG::LoadImageViewImg(&icon_, WEATHER_IMAGE, itemInfo.image); + labelTmp_.SetText(itemInfo.weatherTemp); + chartLine_.SetVisible(itemInfo.hasSecondMenu); } - -void WeatherItemView::SetUpChild() -{ - sNextImage.SetPosition(0, 0); - sNextImage.Resize(WEATHER_IMAGE_SIZE, WEATHER_IMAGE_SIZE); - bool index = WeatherModel::GetInstance().GetDayStatus(); - ImageInfo *img = nullptr; - if (index) { - img = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER71, WEATHER_IMAGE); - } else { - img = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER72, WEATHER_IMAGE); - } - if (img == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::LoadOneInMultiRes fail"); - } - sNextImage.SetSrc(img); - - sLabel_1.SetPosition(WEATHER_LABEL_X, 0); - sLabel_1.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); - sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); - sLabel_1.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel_1.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - sLabel_1.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - sIcon.SetPosition(WEATHER_ICON_X, WEATHER_ICON_Y); - sIcon.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - - sLabel_2.SetPosition(WEATHER_LABEL2_X, 0); - sLabel_2.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); - sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); - sLabel_2.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel_2.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel_2.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - - chartLine.SetPosition(WEATHER_CHARTLINE_X, WEATHER_CHARTLINE_Y, WEATHER_CHARTLINE_WIDTH, WEATHER_CHARTLINE_HEIGHT); - chartLine.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); } - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherMainPage.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherMainPage.cpp index e1d963039..44c892912 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherMainPage.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherMainPage.cpp @@ -1,22 +1,25 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: WeatherMainPage * Create: 2025-03-23 */ +#include +#include #include -#include "weather/WeatherMainPage.h" -#include "components/ui_list_nested.h" -#include "components/ui_scroll_view_nested.h" #include "NativeAbility.h" #include "SlicePageFactory.h" -#include "weather/WeatherPresenter.h" -#include "weather/WeatherModel.h" -#include "ui_resource_weather.h" #include "common/image_cache_manager.h" +#include "bts_br_gap.h" +#include "bts_spp.h" +#include "msg_center_device.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" #include "wearable_log.h" -#include -#include +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherMainPage.h" static constexpr int16_t WEATHER_LABEL_SIZE_WIDTH_ONE = 250; static constexpr int16_t WEATHER_LABEL_SIZE_HEIGHT_ONE = 60; @@ -31,7 +34,7 @@ static constexpr int16_t WEATHER_LABEL_FRONT_TWO = 24; static constexpr int16_t WEATHER_LABEL_FRONT_THREE = 36; static constexpr int16_t WEATHER_LABEL_FRONT_FOUR = 120; static constexpr int16_t WEATHER_LABEL_FRONT = 22; -static constexpr int16_t WEATHER_AROUND_X = 74; +static constexpr int16_t WEATHER_AROUND_X = 49; static constexpr int16_t WEATHER_AROUND_Y = 323; static constexpr int16_t WEATHER_AROUND_WIDTH = 198; static constexpr int16_t WEATHER_AROUND_HEIGHT = 40; @@ -45,11 +48,11 @@ static constexpr int16_t WEATHER_TEMP_WIDTH = 190; static constexpr int16_t WEATHER_TEMP_HEIGHT = 120; static constexpr int16_t WEATHER_IMAGE_WIDTH = 78; static constexpr int16_t WEATHER_IMAGE_HEIGHT = 115; -static constexpr int16_t WEATHER_IMAGEAIR_X = 78; -static constexpr int16_t WEATHER_IMAGEAIR_Y = 327; +static constexpr int16_t WEATHER_IMAGEAIR_X = 49; +static constexpr int16_t WEATHER_IMAGEAIR_Y = 323; static constexpr int16_t WEATHER_IMAGEAIR_DATA = 40; -static constexpr int16_t WEATHER_IMAGEHUMIDITY_X = 336; -static constexpr int16_t WEATHER_IMAGEHUMIDITY_Y = 327; +static constexpr int16_t WEATHER_IMAGEHUMIDITY_X = 357; +static constexpr int16_t WEATHER_IMAGEHUMIDITY_Y = 323; static constexpr int16_t WEATHER_LABLEAIR_DATA = 79; static constexpr int16_t WEATHER_LABLEAIR_HEIGHT = 30; static constexpr int16_t WEATHER_IMAGEHUMIDITY_DATA = 120; @@ -63,238 +66,349 @@ static constexpr int16_t WEATHER_LABELTITLE_POSITION_Y = 100; static constexpr int16_t WEATHER_LABELTITLE_WIDTH = 400; static constexpr int16_t WEATHER_ADDRESS_X = 143; static constexpr int16_t WEATHER_ADDRESS_Y = 49; +static constexpr int16_t WEATHER_TYPE = 32; +static constexpr int16_t BUFFER_SIZE = 6; -const char *weatherNames[] = {"晴", "多云", "阴", "阵雨", "雷阵雨", "雷阵雨伴有冰雹", "雨夹雪", - "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨", "阵雪", - "小雪", "中雪", "大雪", "暴雪", "雾", "冻雨", "沙尘暴", - "小到中雨", "中到大雨", "大到暴雨", "小到中雪", "中到大雪", "大到暴雪", "浮尘", - "扬沙", "强沙尘暴", "霾", "无天气数据"}; +const char *g_weatherNames[] = {"晴", "多云", "阴", "阵雨", "雷阵雨", "雷阵雨伴有冰雹", "雨夹雪", + "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨", "阵雪", + "小雪", "中雪", "大雪", "暴雪", "雾", "冻雨", "沙尘暴", + "小到中雨", "中到大雨", "大到暴雨", "小到中雪", "中到大雪", + "大到暴雪", "浮尘", "扬沙", "强沙尘暴", "霾", "无天气数据"}; namespace OHOS { REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_MAIN_PAGE, WeatherMainPage, true); +static WeatherMainPage *g_pWeatherMainPage = nullptr; WeatherMainPage::WeatherMainPage() { - weatherModel = &WeatherModel::GetInstance(); + g_pWeatherMainPage = this; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::WeatherMainPage"); } WeatherMainPage::~WeatherMainPage() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::~WeatherMainPage"); - if (group != nullptr) { - group->RemoveAll(); - delete group; - group = nullptr; + g_pWeatherMainPage = nullptr; + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + for (int i = 0; i < LABEL_COUNT; i++) { + if (title_[i] != nullptr) { + delete title_[i]; + title_[i] = nullptr; + } } - if (weatherImg != nullptr) { - delete weatherImg; - weatherImg = nullptr; + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; } - if (mainImg != nullptr) { - delete mainImg; - mainImg = nullptr; + if (addressImg_ != nullptr) { + delete addressImg_; + addressImg_ = nullptr; } - if (aroundImg != nullptr) { - delete aroundImg; - aroundImg = nullptr; + if (weatherImg_ != nullptr) { + delete weatherImg_; + weatherImg_ = nullptr; } - if (ImageAir != nullptr) { - delete ImageAir; - ImageAir = nullptr; + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; } - if (ImageHumidity != nullptr) { - delete ImageHumidity; - ImageHumidity = nullptr; + if (airQualityAndHumidityBgImg_ != nullptr) { + delete airQualityAndHumidityBgImg_; + airQualityAndHumidityBgImg_ = nullptr; } - if (ImagePageKey != nullptr) { - delete ImagePageKey; - ImagePageKey = nullptr; + if (airQulityImgIcon_ != nullptr) { + delete airQulityImgIcon_; + airQulityImgIcon_ = nullptr; + } + + if (humidityImgIcon_ != nullptr) { + delete humidityImgIcon_; + humidityImgIcon_ = nullptr; + } + + if (pageIdxImg_ != nullptr) { + delete pageIdxImg_; + pageIdxImg_ = nullptr; } ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); } +WeatherMainPage *WeatherMainPage::GetInstance() +{ + return g_pWeatherMainPage; +} + void WeatherMainPage::OnStart(void *data) { - group = new UIViewGroup(); - if (group == nullptr) { + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::group_ fail"); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitPageFirst successful"); - group->SetPosition(0, 0); - group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - group->SetOnDragListener(this); - group->SetViewId("weather"); - group->SetDraggable(true); - group->SetTouchable(true); - flag = weatherModel->InitWeatherItem(); - cur = weatherModel->GetCurWeather(); - mainImg = new UIImageView(); - if (mainImg == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::mainImg new image fail"); + group_->SetPosition(0, 0); + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetOnDragListener(this); + group_->SetViewId("weather"); + group_->SetDraggable(true); + group_->SetTouchable(true); + flag_ = WeatherModel::GetInstance().InitWeatherItem(); + cur_ = WeatherModel::GetInstance().GetCurWeather(); + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::bgImg_ new image fail"); return; } - mainImg->SetPosition(0, 0); - mainImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - group->Add(mainImg); - InitWeatherImage(); - InitImage(); - InitLabel(); - if (!flag) { - labelTitle = new UILabel(); - if (labelTitle == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::labelTitle new label fail"); - return; - } - labelTitle->SetText("天气未更新,请连接手机更新数据"); - labelTitle->SetPosition(WEATHER_LABELTITLE_POSITION_X, WEATHER_LABELTITLE_POSITION_Y, WEATHER_LABELTITLE_WIDTH, - WEATHER_LABEL_SIZE_HEIGHT_ONE); - labelTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT); - group->Add(labelTitle); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitWeatherItem fail"); + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + + group_->Add(bgImg_); + InitWeatherImage1(); + InitWeatherImage2(); + InitWeatherLabel1(); + InitWeatherLabel2(); + + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::labelTitle_ new label fail"); + return; + } + if (!flag_) { + labelTitle_->SetPosition(WEATHER_LABELTITLE_POSITION_X, WEATHER_LABELTITLE_POSITION_Y, WEATHER_LABELTITLE_WIDTH, + WEATHER_LABEL_SIZE_HEIGHT_ONE); + labelTitle_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT); + labelTitle_->SetText("天气未更新,请连接手机更新数据"); + labelTitle_->SetVisible(true); + group_->Add(labelTitle_); + } + AddViewToPageContainer(group_); + if (GetConnectStatus()) { + errcode_t result; + uint8_t value = 1; // 更新数据实际不需要使用value 手机侧不关心该字段 +#ifdef _WIN32 + result = 0; +#else + result = msg_center_send_data(MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SYNC_WEATHER_REQ, &value, sizeof(value)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage msg_center_send_data result:%d ", result); +#endif } - AddViewToPageContainer(group); } -void WeatherMainPage::InitImage() +void WeatherMainPage::ReloadPage() { - aroundImg = new UIImageView(); - if (aroundImg == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::aroundImage new image fail"); - return; - } - aroundImg->SetPosition(WEATHER_AROUND_X, WEATHER_AROUND_Y); - if (weatherModel->GetDayStatus()) { - LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER64); - LOADIMG::LoadImageViewImg(aroundImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER75); + flag_ = WeatherModel::GetInstance().InitWeatherItem(); + cur_ = WeatherModel::GetInstance().GetCurWeather(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::flag_:%d", flag_); + if (!flag_) { + labelTitle_->SetVisible(true); } else { - LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER65); - LOADIMG::LoadImageViewImg(aroundImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER76); + labelTitle_->SetVisible(false); } - ImageAir = new UIImageView(); - if (ImageAir == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImageAir new image fail"); - return; + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + WeatherModel::GetInstance().LoadImageOfDayNight(airQualityAndHumidityBgImg_, + IMAGE_WEATHER_ITEM5, IMAGE_WEATHER_ITEM6); + + curWeatherCode_ = std::atoi(cur_.weather_code); + LOADIMG::LoadImageViewImg(weatherImg_, WEATHER_IMAGE, bigWeatherImage[curWeatherCode_]); + + for (int i = 0; i < LABEL_COUNT; i++) { + std::ostringstream oss; + if (i == LABEL_ADDRESS) { + title_[i]->SetText(cur_.address); + int controlOffset = 10; + int cut = 2; + int posX = (VERTICAL_RESOLUTION - addressImg_->GetWidth() - + title_[i]->GetTextWidth() - controlOffset) / cut; + addressImg_->SetX(posX); + posX = posX + addressImg_->GetWidth() + controlOffset; + title_[i]->SetX(posX); + } else if (i == LABEL_TEMP) { + oss << cur_.max_temp << "° / " << cur_.min_temp << "° " << g_weatherNames[curWeatherCode_]; + std::string weatherTemp = oss.str(); + title_[i]->SetText(weatherTemp.c_str()); + } else if (i == LABEL_AIR) { + oss << "空气 --"; + std::string weatherAir = oss.str(); + title_[i]->SetText(weatherAir.c_str()); + } else if (i == LABEL_HUMIDITY) { + oss << "湿度 " << cur_.humidity << "%"; + std::string weatherHumidity = oss.str(); + title_[i]->SetText(weatherHumidity.c_str()); + } else if (i == LABEL_UPDATETIME) { + std::string updateTime = FormatTime(cur_.updateTime); + oss << "上次更新时间 " << updateTime; + updateTime = oss.str(); + title_[i]->SetText(updateTime.c_str()); + } else if (i == LABEL_CURRENT_TEMP) { + oss << cur_.temp << "°"; + std::string weatherTemp = oss.str(); + title_[i]->SetText(weatherTemp.c_str()); + } } - ImageAir->SetPosition(WEATHER_IMAGEAIR_X, WEATHER_IMAGEAIR_Y); - ImageAir->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - LOADIMG::LoadImageViewImg(ImageAir, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER69); - ImageHumidity = new UIImageView(); - if (ImageHumidity == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImageHumidity new image fail"); +} + +void WeatherMainPage::InitWeatherImage1() +{ + addressImg_ = new UIImageView(); + if (addressImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::addressImg_ new image fail"); return; } - ImageHumidity->SetPosition(WEATHER_IMAGEHUMIDITY_X, WEATHER_IMAGEHUMIDITY_Y); - ImageHumidity->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - LOADIMG::LoadImageViewImg(ImageHumidity, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER70); - ImagePageKey = new UIImageView(); - if (ImagePageKey == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImagePageKey new image fail"); + addressImg_->SetPosition(WEATHER_ADDRESS_X, WEATHER_ADDRESS_Y); + addressImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + curWeatherCode_ = std::atoi(cur_.weather_code); + LOADIMG::LoadImageViewImg(addressImg_, WEATHER_IMAGE, IMAGE_WEATHER_LOCATE); + + weatherImg_ = new UIImageView(); + if (weatherImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::weatherImg_ new image fail"); return; } - ImagePageKey->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y); - ImagePageKey->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - LOADIMG::LoadImageViewImg(ImagePageKey, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER66); - group->Add(aroundImg); - group->Add(ImageAir); - group->Add(ImageHumidity); - group->Add(ImagePageKey); + weatherImg_->SetPosition(WEATHER_IMG_X, WEATHER_TEMP_POSITION_Y); + weatherImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + curWeatherCode_ = std::atoi(cur_.weather_code); + if (curWeatherCode_ < 0 || curWeatherCode_ > WEATHER_TYPE) { + curWeatherCode_ = 0; + } + LOADIMG::LoadImageViewImg(weatherImg_, WEATHER_IMAGE, bigWeatherImage[curWeatherCode_]); + group_->Add(addressImg_); + group_->Add(weatherImg_); } -void WeatherMainPage::InitWeatherImage() +void WeatherMainPage::InitWeatherImage2() { - addressImg = new UIImageView(); - if (addressImg == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::img new image fail"); + airQualityAndHumidityBgImg_ = new UIImageView(); + if (airQualityAndHumidityBgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::aroundImage new image fail"); return; } - addressImg->SetPosition(WEATHER_ADDRESS_X, WEATHER_ADDRESS_Y); - addressImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - curWeather_code = std::atoi(cur.weather_code); - LOADIMG::LoadImageViewImg(addressImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER77); - - weatherImg = new UIImageView(); - if (weatherImg == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::img new image fail"); + airQualityAndHumidityBgImg_->SetPosition(WEATHER_AROUND_X, WEATHER_AROUND_Y); + WeatherModel::GetInstance().LoadImageOfDayNight(airQualityAndHumidityBgImg_, + IMAGE_WEATHER_ITEM5, IMAGE_WEATHER_ITEM6); + airQulityImgIcon_ = new UIImageView(); + if (airQulityImgIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::airQulityImgIcon_ new image fail"); + return; + } + airQulityImgIcon_->SetPosition(WEATHER_IMAGEAIR_X, WEATHER_IMAGEAIR_Y); + airQulityImgIcon_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(airQulityImgIcon_, WEATHER_IMAGE, IMAGE_WEATHER_AIR); + humidityImgIcon_ = new UIImageView(); // humidityImgIcon_->humidityImgIconIcon + if (humidityImgIcon_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::humidityImgIcon_ new image fail"); return; } - weatherImg->SetPosition(WEATHER_IMG_X, WEATHER_TEMP_POSITION_Y); - weatherImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - curWeather_code = std::atoi(cur.weather_code); - LOADIMG::LoadImageViewImg(weatherImg, WEATHER_IMAGE, bigWeatherImage[curWeather_code]); - group->Add(addressImg); - group->Add(weatherImg); + humidityImgIcon_->SetPosition(WEATHER_IMAGEHUMIDITY_X, WEATHER_IMAGEHUMIDITY_Y); + humidityImgIcon_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(humidityImgIcon_, WEATHER_IMAGE, IMAGE_WEATHER_WET); + pageIdxImg_ = new UIImageView(); + if (pageIdxImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::pageIdxImg_ new image fail"); + return; + } + pageIdxImg_->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y); + pageIdxImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(pageIdxImg_, WEATHER_IMAGE, IMAGE_WEATHER_PAGE1); + group_->Add(airQualityAndHumidityBgImg_); + group_->Add(airQulityImgIcon_); + group_->Add(humidityImgIcon_); + group_->Add(pageIdxImg_); } - -void WeatherMainPage::InitLabel() +void WeatherMainPage::InitWeatherLabel1() { - int posX[LABEL_COUNT] = {140, 113, 120, 222, 100, 210}; + int posX[LABEL_COUNT] = {140, 113, 119, 232, 100, 210}; int posY[LABEL_COUNT] = {34, 274, 332, 332, 376, 130}; - for (int i = 0; i < LABEL_COUNT; i++) { - title[i] = new UILabel(); - if (title[i] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitPageFirst new label:%d fail", i); + for (int i = 0; i < LABEL_HUMIDITY; i++) { // 从adress控件加载到humidity控件 + std::ostringstream oss; + title_[i] = new UILabel(); + if (title_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage new label:%d fail", i); return; } - if (i == SET_ZERO) { - title[i]->SetText(cur.address); - title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_ONE); - title[i]->SetAlign(TEXT_ALIGNMENT_LEFT); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_ONE); - } else if (i == SET_ONE) { - std::ostringstream oss; - oss << cur.max_degree << "° / " << cur.min_degree << "° " << weatherNames[curWeather_code]; + if (i == LABEL_ADDRESS) { + title_[i]->SetText(cur_.address); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_ONE); + title_[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + title_[i]->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_ONE); + int controlOffset = 10; + int cut = 2; + int posX = (VERTICAL_RESOLUTION - addressImg_->GetWidth() - title_[i]->GetTextWidth() + - controlOffset) / cut; + addressImg_->SetX(posX); + posX = posX + addressImg_->GetWidth() + controlOffset; + title_[i]->SetX(posX); + } else if (i == LABEL_TEMP) { + oss << cur_.max_temp << "° / " << cur_.min_temp << "° " << g_weatherNames[curWeatherCode_]; std::string weatherTemp = oss.str(); - title[i]->SetText(weatherTemp.c_str()); - title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_FIVE, WEATHER_LABEL_SIZE_HEIGHT_FIVE); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_THREE); - } else if (i == SET_TWO) { - std::ostringstream oss; - oss << "空气 -"; - std::string weatherHumidity = oss.str(); - title[i]->SetText(weatherHumidity.c_str()); - title[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title[i]->SetPosition(posX[i], posY[i], WEATHER_LABLEAIR_DATA, WEATHER_LABLEAIR_HEIGHT); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); - } else if (i == SET_THREE) { - std::ostringstream oss; - oss << "湿度" << cur.humidity <<"%"; + title_[i]->SetText(weatherTemp.c_str()); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_FIVE, WEATHER_LABEL_SIZE_HEIGHT_FIVE); + title_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_THREE); + } else if (i == LABEL_AIR) { + oss << "空气 --"; + std::string weatherAir = oss.str(); + title_[i]->SetText(weatherAir.c_str()); + title_[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + title_[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_LABLEAIR_DATA, WEATHER_LABLEAIR_HEIGHT); + title_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + } + title_[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(title_[i]); + } +} + +void WeatherMainPage::InitWeatherLabel2() +{ + int posX[LABEL_COUNT] = {140, 113, 119, 232, 100, 210}; + int posY[LABEL_COUNT] = {34, 274, 332, 332, 376, 130}; + for (int i = LABEL_HUMIDITY; i < LABEL_COUNT; i++) { // 从HUMIDITY控件开始到加载剩余label + std::ostringstream oss; + title_[i] = new UILabel(); + if (title_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage new label:%d fail", i); + return; + } + if (i == LABEL_HUMIDITY) { + title_[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_IMAGEHUMIDITY_DATA, WEATHER_LABLEAIR_HEIGHT); + title_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + oss << "湿度 " << cur_.humidity << "%"; std::string weatherHumidity = oss.str(); - title[i]->SetText(weatherHumidity.c_str()); - title[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title[i]->SetPosition(posX[i], posY[i], WEATHER_IMAGEHUMIDITY_DATA, WEATHER_LABLEAIR_HEIGHT); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); - } else if (i == SET_FOUR) { - std::ostringstream oss; - std::string updateTime = FormatTime(flag, cur.updateTime); + title_[i]->SetText(weatherHumidity.c_str()); + } else if (i == LABEL_UPDATETIME) { + std::string updateTime = FormatTime(cur_.updateTime); oss << "上次更新时间 " << updateTime; updateTime = oss.str(); - title[i]->SetText(updateTime.c_str()); - title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_FOUR); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); - } else if (i == SET_FIVE) { - std::ostringstream oss; - oss << cur.degree << "°"; + title_[i]->SetText(updateTime.c_str()); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_FOUR); + title_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + } else if (i == LABEL_CURRENT_TEMP) { + oss << cur_.temp << "°"; std::string weatherTemp = oss.str(); - title[i]->SetText(weatherTemp.c_str()); - title[i]->SetPosition(posX[i], posY[i], WEATHER_TEMP_WIDTH, WEATHER_TEMP_HEIGHT); - title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_FOUR); + title_[i]->SetText(weatherTemp.c_str()); + title_[i]->SetPosition(posX[i], posY[i], WEATHER_TEMP_WIDTH, WEATHER_TEMP_HEIGHT); + title_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_FOUR); } - title[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - group->Add(title[i]); + title_[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group_->Add(title_[i]); } } -std::string WeatherMainPage::FormatTime(bool falg, const std::string &inputStr) +std::string WeatherMainPage::FormatTime(const std::string &inputStr) { - if (!flag) { + if (!flag_) { return "--"; } tm inputTm = {}; @@ -304,11 +418,11 @@ std::string WeatherMainPage::FormatTime(bool falg, const std::string &inputStr) time_t now = time(nullptr); tm *nowTm = localtime(&now); if (inputTm.tm_year == nowTm->tm_year && inputTm.tm_mon == nowTm->tm_mon && inputTm.tm_mday == nowTm->tm_mday) { - char buffer[6]; + char buffer[BUFFER_SIZE]; strftime(buffer, sizeof(buffer), "%H:%M", &inputTm); return std::string(buffer); } else { - char buffer[6]; + char buffer[BUFFER_SIZE]; strftime(buffer, sizeof(buffer), "%m/%d", &inputTm); return std::string(buffer); } @@ -319,13 +433,15 @@ bool WeatherMainPage::OnDrag(UIView &view, const DragEvent &event) UNUSED(view); if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().ChangeSliceToApplist(); } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { - NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_SECOND_PAGE, nullptr, - TransitionType::TRANSITION_INVALID, true); + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_HOURS_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_SUNRISE_PAGE, + TransitionType::TRANSITION_INVALID, false); } - return false; + return true; } bool WeatherMainPage::OnClick(UIView &view, const ClickEvent &event) @@ -333,4 +449,19 @@ bool WeatherMainPage::OnClick(UIView &view, const ClickEvent &event) UNUSED(event); return true; } + +uint8_t WeatherMainPage::GetConnectStatus() +{ + uint8_t conn_status = 0; +#ifdef _WIN32 + conn_status = 1; +#else + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_PHONE) { + conn_status = is_spp_connected(0) == true ? 1 : 0; + } else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + conn_status = msg_center_get_ble_conn_state(); + } +#endif + return conn_status; +} } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherModel.cpp index 6b77b9572..5735fa7fe 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherModel.cpp @@ -1,18 +1,24 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: WeatherModel * Create: 2025-03-23 */ -#include "weather/WeatherModel.h" -#include "weather/WeatherPresenter.h" -#include "wearable_log.h" #include "ui_resource_weather.h" +#include "wearable_log.h" #ifdef BUILD_IN_LINUX #include "localtime.h" #endif +#include "weather/WeatherPresenter.h" +#include "weather/WeatherModel.h" namespace OHOS { +static constexpr uint16_t IMAGEANIMATOERVIEW_SIZE = 28; +static const char *WEATHER_FILE = WEATHER_PATH "weather.json"; +const int g_imageInfo[IMAGEANIMATOERVIEW_SIZE] = { + IMAGE_WEATHER_MOON1, IMAGE_WEATHER_MOON2, IMAGE_WEATHER_MOON3, IMAGE_WEATHER_MOON4, + IMAGE_WEATHER_MOON5, IMAGE_WEATHER_MOON6, IMAGE_WEATHER_MOON7, IMAGE_WEATHER_MOON8, +}; WeatherModel::WeatherModel() {} @@ -26,45 +32,93 @@ WeatherModel &WeatherModel::GetInstance() uint8_t WeatherModel::GetWeatherListNum() { - return usedLen; + return usedLen_; } WeatherItem *WeatherModel::GetWeatherlistItems() { - if (weather[0].label_1 == nullptr) { - ImageInfo *imgSrc = - ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER47, WEATHER_IMAGE); - weather[SET_ZERO] = {"今天", imgSrc, "16°/26°", true}; - weather[SET_ONE] = {"明天", imgSrc, "18°/28°", false}; - weather[SET_TWO] = {"后天", imgSrc, "17°/27°", false}; - weather[SET_THREE] = {"周四", imgSrc, "15°/24°", false}; - weather[SET_FOUR] = {"周五", imgSrc, "14°/22°", false}; - weather[SET_FIVE] = {"周六", imgSrc, "16°/25°", false}; - weather[SET_SIX] = {"周日", imgSrc, "19°/29°", false}; - usedLen = SET_SEVEN; - } - return weather; + if (weather_[0].weatherWeek == nullptr) { + weather_[INDEX_0] = {"今天", smallWeatherImage[0], "16°/26°", true}; + weather_[INDEX_1] = {"明天", smallWeatherImage[0], "18°/28°", false}; + weather_[INDEX_2] = {"周三", smallWeatherImage[0], "17°/27°", false}; + weather_[INDEX_3] = {"周四", smallWeatherImage[0], "15°/24°", false}; + weather_[INDEX_4] = {"周五", smallWeatherImage[0], "14°/22°", false}; + weather_[INDEX_5] = {"周六", smallWeatherImage[0], "16°/25°", false}; + weather_[INDEX_6] = {"周日", smallWeatherImage[0], "19°/29°", false}; + usedLen_ = ONE_WEEK_DYAS; + } + return weather_; } CurWeather WeatherModel::GetCurWeather() { - if (curWeather.min_degree == nullptr) { - curWeather.min_degree = "10"; - curWeather.max_degree = "25"; - curWeather.address = "北京市"; - curWeather.weather_code = "02"; - curWeather.degree = "18"; - curWeather.updateTime = "2023-11-15 14:30:00 20"; - curWeather.humidity = "90"; - curWeather.sunSet = "17:30"; - curWeather.sunRise = "06:45"; - } - return curWeather; + if (curWeather_.min_temp == nullptr) { // 如果更新天气失败则输出打桩数据 + curWeather_.min_temp = "10"; + curWeather_.max_temp = "25"; + curWeather_.address = "北京市"; + curWeather_.weather_code = "02"; + curWeather_.temp = "18"; + curWeather_.updateTime = "2023-11-15 14:30:00 20"; + curWeather_.humidity = "90"; + curWeather_.sunSet = "17:30"; + curWeather_.sunRise = "06:45"; + } + return curWeather_; +} + +SunStruct *WeatherModel::GetSunData() +{ + if (sunData_[0].sunRise == nullptr) { // 如果更新天气失败则输出打桩数据 + sunData_[INDEX_0] = {"05:20", "17:43", "今天"}; + sunData_[INDEX_1] = {"06:30", "17:47", "明天"}; + sunData_[INDEX_2] = {"05:20", "17:21", "周三"}; + sunData_[INDEX_3] = {"05:02", "17:24", "周四"}; + sunData_[INDEX_4] = {"06:25", "17:44", "周五"}; + sunData_[INDEX_5] = {"05:21", "17:33", "周六"}; + sunData_[INDEX_6] = {"06:20", "17:12", "周日"}; + } + return sunData_; +} + +MonthStruct *WeatherModel::GetMonthData() +{ + // 无月出数据 打桩数据输出 + monthData_[INDEX_0] = {"月出 18:42", "月落 06:43", "今天"}; + monthData_[INDEX_1] = {"月出 18:32", "月落 05:47", "明天"}; + monthData_[INDEX_2] = {"月出 19:42", "月落 05:21", "周三"}; + monthData_[INDEX_3] = {"月出 18:42", "月落 06:24", "周四"}; + monthData_[INDEX_4] = {"月出 18:45", "月落 05:44", "周五"}; + monthData_[INDEX_5] = {"月出 18:22", "月落 05:33", "周六"}; + monthData_[INDEX_6] = {"月出 18:52", "月落 05:12", "周日"}; + if (!currentWeek_[0].empty()) { + for (int i = 0; i < ONE_WEEK_DYAS; i++) { + monthData_[i].weekTime = currentWeek_[i].c_str(); + } + } + return monthData_; +} + +LunarPhaseStruct *WeatherModel::GetLunarPhaseData() +{ + // 无月出数据 打桩数据输出 + parseData_[INDEX_0] = {"残月", g_imageInfo[INDEX_0], "月亮照亮66%", "月龄23天", "今天"}; + parseData_[INDEX_1] = {"亏凸月", g_imageInfo[INDEX_1], "月亮照亮23%", "月龄21天", "明天"}; + parseData_[INDEX_2] = {"盈凸月", g_imageInfo[INDEX_2], "月亮照亮51%", "月龄23天", "周三"}; + parseData_[INDEX_3] = {"娥眉月", g_imageInfo[INDEX_3], "月亮照亮11%", "月龄13天", "周四"}; + parseData_[INDEX_4] = {"下弦月", g_imageInfo[INDEX_4], "月亮照亮51%", "月龄25天", "周五"}; + parseData_[INDEX_5] = {"上弦月", g_imageInfo[INDEX_5], "月亮照亮80%", "月龄15天", "周六"}; + parseData_[INDEX_6] = {"新月", g_imageInfo[INDEX_6], "月亮照亮23%", "月龄18天", "周日"}; + if (!currentWeek_[0].empty()) { + for (int i = 0; i < ONE_WEEK_DYAS; i++) { + parseData_[i].weekTime = currentWeek_[i].c_str(); + } + } + return parseData_; } std::vector WeatherModel::GetHourWeather() { - if (houWeather.size() < WEATHER_COUNT) { + if (houWeather_.size() < ALL_HOURS_WEATHER_COUNT) { // 无天气文件或手机下发数据异常不够24个 输出打桩数据 HourWeather weatherData[] = { {"00:00", "18", "04"}, {"01:00", "17", "06"}, {"02:00", "17", "06"}, {"03:00", "16", "06"}, {"04:00", "16", "07"}, {"05:00", "15", "07"}, {"06:00", "16", "08"}, {"07:00", "17", "08"}, @@ -73,17 +127,17 @@ std::vector WeatherModel::GetHourWeather() {"16:00", "24", "06"}, {"17:00", "23", "06"}, {"18:00", "22", "06"}, {"19:00", "21", "07"}, {"20:00", "20", "07"}, {"21:00", "19", "10"}, {"22:00", "18", "10"}, {"23:00", "18", "10"}}; for (const auto &item : weatherData) { - houWeather.push_back(item); + houWeather_.push_back(item); } } - return houWeather; + return houWeather_; } bool WeatherModel::InitWeatherItem() { - std::ifstream file("/user/app/user/ace/data/com.vendor.Weather/weather.json"); + std::ifstream file(WEATHER_FILE); if (!file.is_open()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no file"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "open fail"); return false; } std::stringstream buffer; @@ -101,222 +155,237 @@ bool WeatherModel::InitWeatherItem() return false; } // 访问JSON数据 - bool updateMsg = InitVecObserve(root); - if (updateMsg) { - InitVecForecast(root); - InitVecRise(root); - InitVecWeek(root); - InitVecAddress(root); - InitFirstPageData(); - InitSecondPageData(); - InitThirdPageData(); - } else { - cJSON_Delete(root); + bool result = false; + result = InitVecObserve(root); + if (!result) { + return false; + } + result = InitVecForecast(root); + if (!result) { + return false; + } + result = InitVecWeek(root); + if (!result) { + return false; + } + result = InitVecAddress(root); + if (!result) { return false; } + InitStringData(); + result = InitVecRise(root); + if (!result) { + return false; + } + // 暂无月出、月相文件数据,后续增加相关字段后,需要自行加解析 cJSON_Delete(root); + + InitMainPageData(); + InitHoursPageData(); + InitDaysPageData(); return true; } -void WeatherModel::InitFirstPageData() +void WeatherModel::InitMainPageData() { - curWeather = {0}; + curWeather_ = {0}; static std::string sunset; static std::string sunrise; - if (map_observe.find("min_degree") != map_observe.end()) { - curWeather.min_degree = map_observe["min_degree"].c_str(); + if (map_observe_.find("min_temp") != map_observe_.end()) { + curWeather_.min_temp = map_observe_["min_temp"].c_str(); } - if (map_observe.find("max_degree") != map_observe.end()) { - curWeather.max_degree = map_observe["max_degree"].c_str(); + if (map_observe_.find("max_temp") != map_observe_.end()) { + curWeather_.max_temp = map_observe_["max_temp"].c_str(); } - if (map_observe.find("degree") != map_observe.end()) { - curWeather.degree = map_observe["degree"].c_str(); + if (map_observe_.find("temp") != map_observe_.end()) { + curWeather_.temp = map_observe_["temp"].c_str(); } - if (map_observe.find("weather_code") != map_observe.end()) { - curWeather.weather_code = map_observe["weather_code"].c_str(); + if (map_observe_.find("weather_code") != map_observe_.end()) { + curWeather_.weather_code = map_observe_["weather_code"].c_str(); } - if (map_observe.find("update_time") != map_observe.end()) { - curWeather.updateTime = map_observe["update_time"].c_str(); + if (map_observe_.find("update_time") != map_observe_.end()) { + curWeather_.updateTime = map_observe_["update_time"].c_str(); } - if (map_observe.find("humidity") != map_observe.end()) { - curWeather.humidity = map_observe["humidity"].c_str(); + if (map_observe_.find("humidity") != map_observe_.end()) { + curWeather_.humidity = map_observe_["humidity"].c_str(); } - if (map_address.find("city") != map_address.end()) { - curWeather.address = map_address["city"].c_str(); + if (map_address_.find("city") != map_address_.end()) { + curWeather_.address = map_address_["city"].c_str(); } - if (map_address.find("address") != map_address.end()) { - curWeather.address = map_address["address"].c_str(); + if (map_address_.find("address") != map_address_.end()) { + curWeather_.address = map_address_["address"].c_str(); } } -void WeatherModel::InitSecondPageData() +void WeatherModel::InitHoursPageData() { - houWeather.clear(); - static std::string dayTime[WEATHER_COUNT]; - static std::string dayTemp[WEATHER_COUNT]; - static std::string dayWeather[WEATHER_COUNT]; + houWeather_.clear(); + static std::string dayTime[ALL_HOURS_WEATHER_COUNT]; + static std::string dayTemp[ALL_HOURS_WEATHER_COUNT]; + static std::string dayWeather[ALL_HOURS_WEATHER_COUNT]; - for (const auto &item : vec_forecast_1h) { + for (const auto &item : vec_forecast_1h_) { const std::string name = std::get<0>(item); const std::string category = std::get<1>(item); - const int id = std::get(item); + const int id = std::get(item); HourWeather sample = {nullptr}; if (name == "update_time") { dayTime[id] = category; - } else if (name == "degree") { + } else if (name == "temp") { dayTemp[id] = category; } else if (name == "weather_code") { dayWeather[id] = category; } } - for (int i = 0; i < WEATHER_COUNT; i++) { + for (int i = 0; i < ALL_HOURS_WEATHER_COUNT; i++) { HourWeather sample = {nullptr}; sample.hour = dayTime[i].c_str(); - sample.degree = dayTemp[i].c_str(); + sample.temp = dayTemp[i].c_str(); sample.weather = dayWeather[i].c_str(); - houWeather.push_back(sample); + houWeather_.push_back(sample); + } +} + +void WeatherModel::InitDaysPageData() +{ + for (int i = 0; i < ONE_WEEK_DYAS; i++) { + strTmp_[i] = maxTemp_[i] + "° / " + minTemp_[i] + "°"; + } + for (int i = 0; i < ONE_WEEK_DYAS; i++) { + int weatherIndex = weatherValue_[i]; + weather_[i] = {currentWeek_[i].c_str(), smallWeatherImage[weatherIndex], strTmp_[i].c_str(), true}; } + usedLen_ = ONE_WEEK_DYAS; } -void WeatherModel::InitThirdPageData() +void WeatherModel::InitStringData() { - static std::string strTmp[SET_EIGHT]; - static std::string minTemp[SET_EIGHT]; - static std::string maxTemp[SET_EIGHT]; - static std::string currentWeek[SET_EIGHT]; - static int weatherValue[SET_EIGHT]; - for (const auto &item : vec_forecast_24h) { + for (const auto &item : vec_forecast_24h_) { const std::string name = std::get<0>(item); - const std::string category = std::get<1>(item); - const int id = std::get(item); + const std::string value = std::get<1>(item); + const int id = std::get(item); if (name == "current_week") { - if (id == SET_ZERO) { - currentWeek[id] = "今天"; - } else if (id == SET_ONE) { - currentWeek[id] = "明天"; - } else if (id == SET_TWO) { - currentWeek[id] = "后天"; + if (id == INDEX_0) { + currentWeek_[id] = "今天"; + } else if (id == INDEX_1) { + currentWeek_[id] = "明天"; } else { - currentWeek[id] = category; + currentWeek_[id] = value; } - } else if (name == "min_degree") { - minTemp[id] = category; - } else if (name == "max_degree") { - maxTemp[id] = category; + } else if (name == "min_temp") { + minTemp_[id] = value; + } else if (name == "max_temp") { + maxTemp_[id] = value; } else if (name == "day_weather_code") { - weatherValue[id] = std::atoi(category.c_str()); + weatherValue_[id] = std::atoi(value.c_str()); } } - for (int i = 0; i < SET_SEVEN; i++) { - strTmp[i] = maxTemp[i] + "°/" + minTemp[i] + "°"; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::InitWeatherItem:%s", strTmp[i].c_str()); - } - // 只显示七天的天气 - for (int i = 0; i < SET_SEVEN; i++) { - int weatherIndex = weatherValue[i]; - ImageInfo *imgSrc = - ImageCacheManager::GetInstance().LoadOneInMultiRes(smallWeatherImage[weatherIndex], WEATHER_IMAGE); - weather[i] = {currentWeek[i].c_str(), imgSrc, strTmp[i].c_str(), true}; - } - usedLen = SET_SEVEN; } bool WeatherModel::InitVecForecast(cJSON *root) { - vec_forecast_1h.clear(); - // 获取 forecast_1h 对象 + vec_forecast_1h_.clear(); cJSON *forecast_1h = cJSON_GetObjectItemCaseSensitive(root, "forecast_1h"); if (!cJSON_IsObject(forecast_1h)) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_1h:"); cJSON_Delete(root); return false; } - for (int i = 0; i < WEATHER_COUNT; i++) { + for (int i = 0; i < ALL_HOURS_WEATHER_COUNT; i++) { cJSON *forecast_1h_num = cJSON_GetObjectItemCaseSensitive(forecast_1h, std::to_string(i).c_str()); if (!cJSON_IsObject(forecast_1h_num)) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_1h_num:%d", i); - continue; // 跳过当前循环,继续处理下一个 + continue; } std::string str = cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "update_time")->valuestring; - std::string hour = str.substr(SET_TWELVE, SET_TWO); - // 确保字符串长度至少为12 + std::string hour = str.substr(INDEX_12, INDEX_2); if (str.length() >= WEATHER_HOUR) { - // 提取小时部分 - hour = str.substr(SET_EIGHT, SET_TWO) + ":00"; + hour = str.substr(INDEX_8, INDEX_2) + ":00"; } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_1h:"); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_1h hour size error"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_1h hour size error"); hour = "00:00"; } - vec_forecast_1h.push_back(std::make_tuple("update_time", hour, i)); - vec_forecast_1h.push_back( - std::make_tuple("degree", cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "degree")->valuestring, i)); - vec_forecast_1h.push_back(std::make_tuple( + vec_forecast_1h_.push_back(std::make_tuple("update_time", hour, i)); + vec_forecast_1h_.push_back( + std::make_tuple("temp", cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "degree")->valuestring, i)); + vec_forecast_1h_.push_back(std::make_tuple( "weather_code", cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "weather_code")->valuestring, i)); } + // 由外层函数释放cjson嵌套结构体内存 return true; } bool WeatherModel::InitVecObserve(cJSON *root) { - map_observe.clear(); + map_observe_.clear(); // 获取 observe 对象 cJSON *observe = cJSON_GetObjectItemCaseSensitive(root, "observe"); if (!cJSON_IsObject(observe)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error observe:"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error observe:"); cJSON_Delete(root); return false; } - map_observe.insert(std::make_pair("weather", cJSON_GetObjectItemCaseSensitive(observe, "weather")->valuestring)); - map_observe.insert(std::make_pair("degree", cJSON_GetObjectItemCaseSensitive(observe, "degree")->valuestring)); - map_observe.insert(std::make_pair("humidity", cJSON_GetObjectItemCaseSensitive(observe, "humidity")->valuestring)); - map_observe.insert( - std::make_pair("min_degree", cJSON_GetObjectItemCaseSensitive(observe, "min_degree")->valuestring)); - map_observe.insert( - std::make_pair("max_degree", cJSON_GetObjectItemCaseSensitive(observe, "max_degree")->valuestring)); - map_observe.insert( + map_observe_.insert(std::make_pair("weather", cJSON_GetObjectItemCaseSensitive(observe, "weather")->valuestring)); + map_observe_.insert(std::make_pair("temp", cJSON_GetObjectItemCaseSensitive(observe, "degree")->valuestring)); + map_observe_.insert(std::make_pair("humidity", cJSON_GetObjectItemCaseSensitive(observe, "humidity")->valuestring)); + map_observe_.insert( + std::make_pair("min_temp", cJSON_GetObjectItemCaseSensitive(observe, "min_degree")->valuestring)); + map_observe_.insert( + std::make_pair("max_temp", cJSON_GetObjectItemCaseSensitive(observe, "max_degree")->valuestring)); + map_observe_.insert( std::make_pair("update_time", cJSON_GetObjectItemCaseSensitive(observe, "update_time")->valuestring)); - map_observe.insert( + map_observe_.insert( std::make_pair("weather_code", cJSON_GetObjectItemCaseSensitive(observe, "weather_code")->valuestring)); + // 由外层函数释放cjson嵌套结构体内存 return true; } bool WeatherModel::InitVecRise(cJSON *root) { // 获取 rise 对象 - vec_rise.clear(); cJSON *rise = cJSON_GetObjectItemCaseSensitive(root, "rise"); if (!cJSON_IsObject(rise)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error rise:"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error rise:"); cJSON_Delete(root); return false; } - for (int i = 0; i < SET_FOURTEEN; i++) { + for (int i = 0; i < ONE_WEEK_DYAS; i++) { cJSON *rise_num = cJSON_GetObjectItemCaseSensitive(rise, std::to_string(i).c_str()); if (!cJSON_IsObject(rise_num)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error rise:%d", i); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error rise:%d", i); continue; // 跳过当前循环,继续处理下一个 } - std::string sunSet = cJSON_GetObjectItemCaseSensitive(rise_num, "sunset")->valuestring; - std::string sunRise = cJSON_GetObjectItemCaseSensitive(rise_num, "sunrise")->valuestring; - SetDayStatus(sunRise, sunSet); + strRise_[i] = cJSON_GetObjectItemCaseSensitive(rise_num, "sunrise")->valuestring; + strSet_[i] = cJSON_GetObjectItemCaseSensitive(rise_num, "sunset")->valuestring; + sunData_[i].sunRise = strRise_[i].c_str(); + sunData_[i].sunSet = strSet_[i].c_str(); + sunData_[i].weekTime = currentWeek_[i].c_str(); } + if (sunData_[0].sunRise != nullptr) { + SetDayStatus(sunData_[0].sunRise, sunData_[0].sunSet); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sunData_ is empty"); + cJSON_Delete(root); + return false; + } + // 由外层函数释放cjson嵌套结构体内存 return true; } bool WeatherModel::InitVecWeek(cJSON *root) { - vec_forecast_24h.clear(); + vec_forecast_24h_.clear(); cJSON *forecast_24h = cJSON_GetObjectItemCaseSensitive(root, "forecast_24h"); if (!cJSON_IsObject(forecast_24h)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_24h:"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_24h:"); cJSON_Delete(root); return false; } - for (int i = 0; i < SET_TEN; i++) { + // app写的数据包含了昨天,跳过第一个数据 + for (int i = 1; i <= ONE_WEEK_DYAS; i++) { cJSON *forecast_24h_num = cJSON_GetObjectItemCaseSensitive(forecast_24h, std::to_string(i).c_str()); if (!cJSON_IsObject(forecast_24h_num)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_24h_num:%d", i); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_24h_num:%d", i); continue; } std::istringstream iss(cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "time")->valuestring); @@ -337,75 +406,83 @@ bool WeatherModel::InitVecWeek(cJSON *root) timeinfo.tm_isdst = -1; std::time_t timestamp = mktime(&timeinfo); if (timestamp == -1) { + cJSON_Delete(root); return false; } std::tm localTimeInfo; -#ifdef _WIN32 - if (localtime_s(&localTimeInfo, ×tamp) != 0) { -#else if (localtime_r(×tamp, &localTimeInfo) == nullptr) { -#endif + cJSON_Delete(root); return false; } const char *current_weeks[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; - vec_forecast_24h.push_back(std::make_tuple("current_week", current_weeks[localTimeInfo.tm_wday], i)); - vec_forecast_24h.push_back(std::make_tuple( - "min_degree", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "min_degree")->valuestring, i)); - vec_forecast_24h.push_back(std::make_tuple( - "max_degree", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "max_degree")->valuestring, i)); - vec_forecast_24h.push_back(std::make_tuple( + vec_forecast_24h_.push_back(std::make_tuple("current_week", current_weeks[localTimeInfo.tm_wday], i - 1)); + vec_forecast_24h_.push_back(std::make_tuple( + "min_temp", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "min_degree")->valuestring, i - 1)); + vec_forecast_24h_.push_back(std::make_tuple( + "max_temp", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "max_degree")->valuestring, i - 1)); + vec_forecast_24h_.push_back(std::make_tuple( "day_weather_code", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "day_weather_code")->valuestring, - i)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "day_weather_code:%s ", - cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "day_weather_code")->valuestring); + i - 1)); } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error Date"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error Date"); } } + // 由外层函数释放cjson嵌套结构体内存 return true; } bool WeatherModel::InitVecAddress(cJSON *root) { - map_address.clear(); + map_address_.clear(); cJSON *address = cJSON_GetObjectItemCaseSensitive(root, "address"); if (!cJSON_IsObject(address)) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error address:"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error address:"); cJSON_Delete(root); return false; } - map_address.insert(std::make_pair("province", cJSON_GetObjectItemCaseSensitive(address, "province")->valuestring)); - map_address.insert(std::make_pair("city", cJSON_GetObjectItemCaseSensitive(address, "city")->valuestring)); - map_address.insert(std::make_pair("county", cJSON_GetObjectItemCaseSensitive(address, "county")->valuestring)); + map_address_.insert(std::make_pair("province", cJSON_GetObjectItemCaseSensitive(address, "province")->valuestring)); + map_address_.insert(std::make_pair("city", cJSON_GetObjectItemCaseSensitive(address, "city")->valuestring)); + map_address_.insert(std::make_pair("county", cJSON_GetObjectItemCaseSensitive(address, "county")->valuestring)); + // 由外层函数释放cjson嵌套结构体内存 return true; } void WeatherModel::SetDayStatus(const std::string &timeRise, const std::string &timeSet) { -#ifdef _WIN32 - struct timeval tv; - gettimeofday(&tv, NULL); -#else - struct timeval64 tv; - gettimeofday64(&tv, NULL); -#endif - uint64_t second = tv.tv_sec; - uint64_t minute = second / MIN_TO_HOUR; - uint64_t hour = minute / MIN_TO_HOUR; - uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + std::time_t now = std::time(nullptr); + std::tm *local = std::localtime(&now); + uint8_t realHour = static_cast(local->tm_hour); + uint8_t realMinute = static_cast(local->tm_min); int currentTime = realHour * MIN_TO_HOUR + realMinute; - int hours = (timeRise[SET_ZERO] - '0') * SET_TEN + (timeRise[SET_ONE] - '0'); - int minutes = (timeRise[SET_THREE] - '0') * SET_TEN + (timeRise[SET_FOUR] - '0'); + int hours = (timeRise[INDEX_0] - '0') * NUMBER_10 + (timeRise[INDEX_1] - '0'); + int minutes = (timeRise[INDEX_3] - '0') * NUMBER_10 + (timeRise[INDEX_4] - '0'); int rise = hours * MIN_TO_HOUR + minutes; - hours = (timeSet[SET_ZERO] - '0') * SET_TEN + (timeSet[SET_ONE] - '0'); - minutes = (timeSet[SET_THREE] - '0') * SET_TEN + (timeSet[SET_FOUR] - '0'); + hours = (timeSet[INDEX_0] - '0') * NUMBER_10 + (timeSet[INDEX_1] - '0'); + minutes = (timeSet[INDEX_3] - '0') * NUMBER_10 + (timeSet[INDEX_4] - '0'); int set = hours * MIN_TO_HOUR + minutes; - isDay = (currentTime >= rise && currentTime < set) ? true : false; + isDay_ = (currentTime >= rise && currentTime < set) ? true : false; +} + +void WeatherModel::LoadImageOfDayNight(UIImageView *view, uint32_t resDayId, uint32_t resNightId) +{ + if (isDay_) { + LOADIMG::LoadImageViewImg(view, WEATHER_IMAGE, resDayId); + } else { + LOADIMG::LoadImageViewImg(view, WEATHER_IMAGE, resNightId); + } +} + +void WeatherModel::LoadTextColorOfDayNight(UILabel *view, uint32_t colorDay, uint32_t colorNight) +{ + if (isDay_) { + view->SetStyle(STYLE_TEXT_COLOR, colorDay); + } else { + view->SetStyle(STYLE_TEXT_COLOR, colorNight); + } } -bool WeatherModel::GetDayStatus() +void WeatherModel::ClearData() { - return isDay; + std::remove(WEATHER_FILE); } } diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageDays.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageDays.cpp new file mode 100644 index 000000000..5df217ddc --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageDays.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageDays + * Create: 2025-03-23 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageDays.h" + +namespace OHOS { +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE = 25; +static constexpr int16_t WEATHER_RESIZE_SIZE_WIDTH = 200; +static constexpr int16_t WEATHER_RESIZE_SIZE_HEIGHT = 50; +static constexpr int16_t WEATHER_TITLE_POSITION_X = 130; +static constexpr int16_t WEATHER_LIST_POSITION_X = 32; +static constexpr int16_t WEATHER_LIST_POSITION_Y = 70; +static constexpr int16_t WEATHER_LIST_WIDTH = 390; +static constexpr int16_t WEATHER_LIST_HEIGHT = 318; +static constexpr int16_t WEATHER_LIST_SELECT_POSITION = 80; +static constexpr int16_t LIST_POS = 20; +static constexpr int16_t WEATHER_LABEL_FRONT_ONE = 20; +static constexpr int16_t WEATHER_LABEL_FRONT = 40; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_X = 199; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_Y = 429; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_WIDTH = 56; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_HEIGHT = 10; +static constexpr int16_t WEATHER_ITEM_BUTTON_WIDTH = 390; +static constexpr int16_t WEATHER_ITEM_BUTTON_HEIGHT = 83; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_DAYS_PAGE, WeatherPageDays, false); + +WeatherPageDays::WeatherPageDays() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::WeatherPageDays"); +} + +WeatherPageDays::~WeatherPageDays() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (contentList_ != nullptr) { + contentList_->ClearAll(); + delete contentList_; + contentList_ = nullptr; + } + + if (title_ != nullptr) { + delete title_; + title_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (pageIdxImg_ != nullptr) { + delete pageIdxImg_; + pageIdxImg_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::~WeatherPageDays"); +} + +void WeatherPageDays::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::group_ is nullptr"); + return; + } + group_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + group_->SetOnDragListener(this); + + title_ = new UILabel(); + if (title_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::title_ is nullptr"); + return; + } + title_->SetPosition(WEATHER_TITLE_POSITION_X, WEATHER_LABEL_FRONT_ONE); + title_->SetText("7日天气预报"); + title_->Resize(WEATHER_RESIZE_SIZE_WIDTH, WEATHER_RESIZE_SIZE_HEIGHT); + title_->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + title_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + title_->SetWidth(title_->GetTextWidth()); + int pageWidth = 454; + int half = 2; + title_->SetX((pageWidth - title_->GetTextWidth()) / half); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnStart bgImg_ new fail"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + InitScrollView(); + InitScrollData(); + AddViewToPageContainer(group_); +} + +void WeatherPageDays::InitScrollView() +{ + contentList_ = new UISimpleList(); + if (contentList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::contentList_ is nullptr"); + return; + } + + contentList_->SetPosition(WEATHER_LIST_POSITION_X, WEATHER_LIST_POSITION_Y); + contentList_->Resize(WEATHER_LIST_WIDTH, WEATHER_LIST_HEIGHT); + contentList_->SetSelectPosition(WEATHER_LIST_SELECT_POSITION); + contentList_->SetDraggable(true); + contentList_->SetThrowDrag(true); + contentList_->EnableAutoAlign(true); + contentList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + contentList_->SetElastic(true); + pageIdxImg_ = new UIImageView(); + if (pageIdxImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::pageIdxImg_ new image fail"); + return; + } + pageIdxImg_->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y, WEATHER_IMAGEPAGEKEY_WIDTH, + WEATHER_IMAGEPAGEKEY_HEIGHT); + pageIdxImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(pageIdxImg_, WEATHER_IMAGE, IMAGE_WEATHER_PAGE3); + group_->Add(bgImg_); + group_->Add(title_); + group_->Add(contentList_); + group_->Add(pageIdxImg_); +} + +bool WeatherPageDays::InitScrollData() +{ + WeatherItem *itemInfo = WeatherModel::GetInstance().GetWeatherlistItems(); + RefreshWeathersList(itemInfo, WeatherModel::GetInstance().GetWeatherListNum()); + return true; +} + +static UIView* CreateViewCb(uint8_t type) +{ + WeatherItemView* item = new WeatherItemView(); + if (item == nullptr) { + return nullptr; + } + + item->SetPosition(0, 0, WEATHER_ITEM_BUTTON_WIDTH, WEATHER_ITEM_BUTTON_HEIGHT); + item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + item->SetTouchable(true); + return item; +} + +static void UpdateViewCb(UIView* view, void* data, uint8_t type) +{ + WeatherItemView* item = dynamic_cast(view); + if (view == nullptr || data == nullptr || item == nullptr) { + return; + } + WeatherItem* content = static_cast(data); + item->SetItemInfo(*content); +} + + +void WeatherPageDays::RefreshWeathersList(WeatherItem *item, uint8_t count) +{ + if (item == nullptr) { + return; + } + if (contentList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherPageDays::contentList_ fail"); + return; + } + contentList_->ScrollTo(0); + for (uint8_t i = 0; i < count; ++i) { + Contents content; + content.createFunc = CreateViewCb; + content.updateFunc = UpdateViewCb; + content.data = reinterpret_cast(&item[i]); + contentList_->AddContent(content); + } + contentList_->RefreshList(); +} + +bool WeatherPageDays::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_HOURS_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void WeatherPageDays::OnSwipe(UISwipeView &view) +{ + UNUSED(view); + return; +} + +bool WeatherPageDays::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHours.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHours.cpp new file mode 100644 index 000000000..09a635cab --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHours.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageHours + * Create: 2025-03-15 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageHours.h" + +namespace OHOS { +static constexpr uint16_t ANIMATOR_TIME = 50; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_HOURS_PAGE, WeatherPageHours, false); + +WeatherPageHours::WeatherPageHours() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageHours::WeatherPageHours"); +} + +WeatherPageHours::~WeatherPageHours() +{ + if (weatherSwipeGroup_ != nullptr) { + weatherSwipeGroup_->RemoveAll(); + delete weatherSwipeGroup_; + weatherSwipeGroup_ = nullptr; + } + + for (int i = 0; i < GROUP_24H_COUNT; ++i) { + if (hoursGroup_[i] != nullptr) { + hoursGroup_[i]->RemoveAll(); + delete hoursGroup_[i]; + hoursGroup_[i] = nullptr; + } + } + WeatherModel::GetInstance().index_ = 0; + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageHours::~WeatherPageHours"); +} + +void WeatherPageHours::OnStart(void *data) +{ + weatherSwipeGroup_ = new UISwipeView(UISwipeView::VERTICAL); + if (weatherSwipeGroup_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherSwipeGroup_ new fail"); + return; + } + weatherSwipeGroup_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + weatherSwipeGroup_->SetViewId("weatherSwipeGroup_"); + weatherSwipeGroup_->SetOnDragListener(this); + weatherSwipeGroup_->SetOnSwipeListener(this); + weatherSwipeGroup_->SetDraggable(true); + weatherSwipeGroup_->SetTouchable(true); + weatherSwipeGroup_->SetAnimatorTime(ANIMATOR_TIME); + + for (int i = 0; i < GROUP_24H_COUNT; i++) { + hoursGroup_[i] = new WeatherPageHoursGroup(); + if (hoursGroup_[i] == nullptr) { + return; + } + WeatherModel::GetInstance().index_++; + weatherSwipeGroup_->Add(hoursGroup_[i]); + } + + AddViewToPageContainer(weatherSwipeGroup_); +} + +bool WeatherPageHours::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_DAYS_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +void WeatherPageHours::OnSwipe(UISwipeView &view) +{ + UNUSED(view); + return; +} + +bool WeatherPageHours::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHoursGroup.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHoursGroup.cpp new file mode 100644 index 000000000..5c4ce93fe --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageHoursGroup.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageHoursGroup + * Create: 2025-03-15 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageHoursGroup.h" + +namespace OHOS { +static constexpr uint16_t WEATHER_TITLE_WIDTH = 51; +static constexpr uint16_t WEATHER_TITLE_HEIGHT = 26; +static constexpr uint16_t WEATHER_TOPLABEL_X = 156; +static constexpr uint16_t WEATHER_TOPLABEL_Y = 22; +static constexpr uint16_t WEATHER_TOPLABEL_WIDTH = 150; +static constexpr uint16_t WEATHER_TOPLABEL_HEIGHT = 60; +static constexpr uint16_t WEATHER_TOPLABEL_FRONT = 26; +static constexpr uint16_t WEATHER_LABELTIME_FRONT = 20; +static constexpr uint16_t WEATHER_LABELTIME_FRONT_TWO = 24; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_X = 199; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_Y = 429; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_WIDTH = 56; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_HEIGHT = 10; + +WeatherPageHoursGroup::WeatherPageHoursGroup() +{ + WeatherInit(WeatherModel::GetInstance().index_); +} + +WeatherPageHoursGroup::~WeatherPageHoursGroup() +{ + for (int i = 0; i < WEATHER_24H_PER_8H; ++i) { + if (imgBack_[i] != nullptr) { + delete imgBack_[i]; + imgBack_[i] = nullptr; + } + } + + for (int i = 0; i < WEATHER_24H_PER_8H; ++i) { + if (labelTime_[i] != nullptr) { + delete labelTime_[i]; + labelTime_[i] = nullptr; + } + } + + for (int i = 0; i < WEATHER_24H_PER_8H; ++i) { + if (labelTemp_[i] != nullptr) { + delete labelTemp_[i]; + labelTemp_[i] = nullptr; + } + } + + for (int i = 0; i < WEATHER_24H_PER_8H; ++i) { + if (imgWeather_[i] != nullptr) { + delete imgWeather_[i]; + imgWeather_[i] = nullptr; + } + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (pageIdxImg_ != nullptr) { + delete pageIdxImg_; + pageIdxImg_ = nullptr; + } + + if (topLabel_ != nullptr) { + delete topLabel_; + topLabel_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~WeatherPageHoursGroup"); +} + +void WeatherPageHoursGroup::WeatherInit(int index) +{ + SetPosition(0, 0); + Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewId("weather"); + SetDraggable(true); + SetTouchable(true); + houWeather_ = WeatherModel::GetInstance().GetHourWeather(); + + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherInit bgImg_ new fail"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + Add(bgImg_); + + pageIdxImg_ = new UIImageView(); + if (pageIdxImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "pageIdxImg_ new fail"); + return; + } + pageIdxImg_->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y, WEATHER_IMAGEPAGEKEY_WIDTH, + WEATHER_IMAGEPAGEKEY_HEIGHT); + pageIdxImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(pageIdxImg_, WEATHER_IMAGE, IMAGE_WEATHER_PAGE2); + Add(pageIdxImg_); + + topLabel_ = new UILabel(); + if (topLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherInit new topLabel_ fail"); + return; + } + topLabel_->SetText("24小时预报"); + topLabel_->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_TOPLABEL_FRONT); + topLabel_->SetPosition(WEATHER_TOPLABEL_X, WEATHER_TOPLABEL_Y, WEATHER_TOPLABEL_WIDTH, WEATHER_TOPLABEL_HEIGHT); + Add(topLabel_); + + InitImage(index * WEATHER_24H_PER_8H); + InitLabel(index * WEATHER_24H_PER_8H); + return; +} + +void WeatherPageHoursGroup::InitImage(int index) +{ + int weatherPosX[WEATHER_24H_PER_8H] = {67, 161, 257, 351, 67, 161, 257, 351}; + int weatherPosY[WEATHER_24H_PER_8H] = {125, 125, 125, 125, 289, 289, 289, 289}; + int backPosX[WEATHER_24H_PER_8H] = {47, 141, 235, 329, 47, 141, 235, 329}; + int backPosY[WEATHER_24H_PER_8H] = {71, 71, 71, 71, 235, 235, 235, 235}; + for (int i = 0; i < WEATHER_24H_PER_8H; i++) { + imgBack_[i] = new UIImageView(); + if (imgBack_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImage new imgBack_ fail"); + return; + } + imgBack_[i]->SetPosition(backPosX[i], backPosY[i]); + WeatherModel::GetInstance().LoadImageOfDayNight(imgBack_[i], IMAGE_WEATHER_ITEM3, IMAGE_WEATHER_ITEM4); + + imgWeather_[i] = new UIImageView(); + if (imgWeather_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImage new labelTime_ fail"); + return; + } + imgWeather_[i]->SetPosition(weatherPosX[i], weatherPosY[i]); + int curWeatherCode_ = std::atoi(houWeather_[index + i].weather); + LOADIMG::LoadImageViewImg(imgWeather_[i], WEATHER_IMAGE, smallWeatherImage[curWeatherCode_]); + Add(imgBack_[i]); + Add(imgWeather_[i]); + } +} + +void WeatherPageHoursGroup::InitLabel(int index) +{ + int timePosX[WEATHER_24H_PER_8H] = {67, 161, 255, 349, 67, 161, 255, 349}; + int timePosY[WEATHER_24H_PER_8H] = {91, 91, 91, 91, 255, 255, 255, 255}; + int tempPosX[WEATHER_24H_PER_8H] = {75, 169, 263, 356, 75, 169, 263, 356}; + int tempPosY[WEATHER_24H_PER_8H] = {175, 175, 175, 175, 339, 339, 339, 339}; + + for (int i = 0; i < WEATHER_24H_PER_8H; i++) { + labelTime_[i] = new UILabel(); + if (labelTime_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel new labelTime_ fail"); + return; + } + std::string strHour = houWeather_[index + i].hour; + labelTime_[i]->SetText(strHour.c_str()); + labelTime_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABELTIME_FRONT); + labelTime_[i]->SetPosition(timePosX[i], timePosY[i], WEATHER_TITLE_WIDTH, WEATHER_TITLE_HEIGHT); + Add(labelTime_[i]); + + labelTemp_[i] = new UILabel(); + if (labelTemp_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel new labelTemp_ fail"); + return; + } + std::ostringstream oss; + oss << houWeather_[index + i].temp << "°"; + std::string temp = oss.str(); + labelTemp_[i]->SetText(temp.c_str()); + labelTemp_[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABELTIME_FRONT_TWO); + labelTemp_[i]->SetPosition(tempPosX[i], tempPosY[i], WEATHER_TITLE_WIDTH, WEATHER_TITLE_HEIGHT); + Add(labelTemp_[i]); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageLunarPhase.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageLunarPhase.cpp new file mode 100644 index 000000000..aef75f1a5 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageLunarPhase.cpp @@ -0,0 +1,328 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageLunarPhase + * Create: 2025-03-15 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageLunarPhase.h" + +namespace OHOS { +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE = 24; +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE_TWO = 30; +static constexpr int16_t WEATHER_TITLE_POSITION_X = 198; +static constexpr int16_t WEATHER_TITLE_POSITION_Y = 41; +static constexpr int16_t WEATHER_TITLE_SIZE_WIDTH = 454; +static constexpr int16_t WEATHER_TITLE_SIZE_HEIGHT = 49; +static constexpr int16_t WEATHER_LUNAR_POSITION_X = 169; +static constexpr int16_t WEATHER_LUNAR_POSITION_Y = 290; +static constexpr int16_t WEATHER_BUTTON_LEFT_POSITION_X = 76; +static constexpr int16_t WEATHER_BUTTON_RIGHT_POSITION_X = 306; +static constexpr int16_t WEATHER_BUTTON_POSITION_Y = 50; +static constexpr int16_t WEATHER_BUTTON_SIZE = 69; +static constexpr int16_t WEATHER_IMAGE_POSITION_X = 166; +static constexpr int16_t WEATHER_IMAGE_POSITION_Y = 160; +static constexpr int16_t WEATHER_LABEL_DAY_POSITION_X = 184; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_WIDTH = 89; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_HEIGHT = 30; +static constexpr int16_t WEATHER_PHASE_SIZE_WIDTH = 117; +static constexpr int16_t WEATHER_PHASE_SIZE_HEIGHT = 49; +static constexpr int16_t WEATHER_LIGHT_SIZE_WIDTH = 173; +static constexpr int16_t WEATHER_LIGHT_SIZE_HEIGHT = 39; +static constexpr int16_t WEATHER_LIGHT_POSITION_X = 141; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_LUNARPHASE_PAGE, WeatherPageLunarPhase, false); + +WeatherPageLunarPhase::WeatherPageLunarPhase() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageLunarPhase::WeatherPageLunarPhase"); +} + +WeatherPageLunarPhase::~WeatherPageLunarPhase() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (drawImg_ != nullptr) { + delete drawImg_; + drawImg_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelDay_ != nullptr) { + delete labelDay_; + labelDay_ = nullptr; + } + + if (labelLunarPhase_ != nullptr) { + delete labelLunarPhase_; + labelLunarPhase_ = nullptr; + } + + if (labelMonthLight_ != nullptr) { + delete labelMonthLight_; + labelMonthLight_ = nullptr; + } + + if (labelMonthDay_ != nullptr) { + delete labelMonthDay_; + labelMonthDay_ = nullptr; + } + + if (buttonChangeLeft_ != nullptr) { + delete buttonChangeLeft_; + buttonChangeLeft_ = nullptr; + } + + if (buttonChangeRight_ != nullptr) { + delete buttonChangeRight_; + buttonChangeRight_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageLunarPhase::~WeatherPageLunarPhase"); +} + +void WeatherPageLunarPhase::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetViewId("phaseGroup"); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + phase_ = WeatherModel::GetInstance().GetLunarPhaseData(); + InitImage(); + InitLabel(); + InitButton(); + InitMonthLabel(); + AddViewToPageContainer(group_); +} + +void WeatherPageLunarPhase::InitImage() +{ + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ new image fail"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + drawImg_ = new UIImageView(); + if (drawImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "drawImg_ new image fail"); + return; + } + drawImg_->SetPosition(WEATHER_IMAGE_POSITION_X, WEATHER_IMAGE_POSITION_Y); + drawImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(drawImg_, WEATHER_IMAGE, IMAGE_WEATHER_MOON1); + group_->Add(bgImg_); + group_->Add(drawImg_); +} + +void WeatherPageLunarPhase::InitLabel() +{ + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ is nullptr"); + return; + } + labelTitle_->SetPosition(WEATHER_TITLE_POSITION_X, WEATHER_TITLE_POSITION_Y); + labelTitle_->SetText("月相"); + labelTitle_->Resize(WEATHER_TITLE_SIZE_WIDTH, WEATHER_TITLE_SIZE_HEIGHT); + labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE_TWO); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelDay_ = new UILabel(); + if (labelDay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelDay_ is nullptr"); + return; + } + labelDay_->SetPosition(WEATHER_LABEL_DAY_POSITION_X, WEATHER_TITLE_POSITION_Y + labelTitle_->GetTextHeight()); + labelDay_->SetText("今天"); + labelDay_->Resize(WEATHER_LABEL_DAY_SIZE_WIDTH, WEATHER_LABEL_DAY_SIZE_HEIGHT); + labelDay_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelDay_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelDay_, Color::White().full, Color::Gray().full); + labelDay_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelDay_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + group_->Add(labelTitle_); + group_->Add(labelDay_); +} + +void WeatherPageLunarPhase::InitMonthLabel() +{ + labelLunarPhase_ = new UILabel(); + if (labelLunarPhase_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelLunarPhase_ is nullptr"); + return; + } + labelLunarPhase_->SetPosition(WEATHER_LUNAR_POSITION_X, WEATHER_LUNAR_POSITION_Y); + labelLunarPhase_->Resize(WEATHER_PHASE_SIZE_WIDTH, WEATHER_PHASE_SIZE_HEIGHT); + labelLunarPhase_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE_TWO); + labelLunarPhase_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelLunarPhase_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelLunarPhase_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelLunarPhase_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelLunarPhase_->SetText(phase_[0].phase); + + labelMonthLight_ = new UILabel(); + if (labelMonthLight_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelMonthLight_ is nullptr"); + return; + } + labelMonthLight_->SetPosition(WEATHER_LIGHT_POSITION_X, labelLunarPhase_->GetY() + + labelLunarPhase_->GetTextHeight()); + labelMonthLight_->Resize(WEATHER_LIGHT_SIZE_WIDTH, WEATHER_LIGHT_SIZE_HEIGHT); + labelMonthLight_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelMonthLight_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelMonthLight_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelMonthLight_, Color::White().full, Color::Gray().full); + labelMonthLight_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelMonthLight_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelMonthLight_->SetText(phase_[0].lightTime); + + labelMonthDay_ = new UILabel(); + if (labelMonthDay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelMonthDay_ is nullptr"); + return; + } + labelMonthDay_->SetPosition(WEATHER_LIGHT_POSITION_X, labelMonthLight_->GetY() + labelMonthLight_->GetTextHeight()); + labelMonthDay_->Resize(WEATHER_LIGHT_SIZE_WIDTH, WEATHER_LIGHT_SIZE_HEIGHT); + labelMonthDay_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelMonthDay_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelMonthDay_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelMonthDay_, Color::White().full, Color::Gray().full); + labelMonthDay_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelMonthDay_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelMonthDay_->SetText(phase_[0].monthDay); + group_->Add(labelLunarPhase_); + group_->Add(labelMonthLight_); + group_->Add(labelMonthDay_); +} + +void WeatherPageLunarPhase::InitButton() +{ + buttonChangeLeft_ = new UIButton(); + if (buttonChangeLeft_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeLeft_ is nullptr"); + return; + } + buttonChangeLeft_->SetPosition(WEATHER_BUTTON_LEFT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeLeft_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeLeft_->SetViewId("buttonLeft"); + buttonChangeLeft_->SetOnClickListener(this); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeLeft_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, IMAGE_WEATHER_PREV_GRAY); + buttonChangeRight_ = new UIButton(); + + if (buttonChangeRight_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeRight_ new fail"); + return; + } + buttonChangeRight_->SetPosition(WEATHER_BUTTON_RIGHT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeRight_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeRight_->SetViewId("buttonRight"); + buttonChangeRight_->SetOnClickListener(this); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeRight_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Disable(); + group_->Add(buttonChangeLeft_); + group_->Add(buttonChangeRight_); +} + +bool WeatherPageLunarPhase::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MONTHRISE_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool WeatherPageLunarPhase::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + + if (strcmp(view.GetViewId(), "buttonLeft") == 0) { + if (index_ > 0) { + labelDay_->SetText(phase_[--index_].weekTime); + labelLunarPhase_->SetText(phase_[index_].phase); + labelMonthLight_->SetText(phase_[index_].lightTime); + labelMonthDay_->SetText(phase_[index_].monthDay); + LOADIMG::LoadImageViewImg(drawImg_, WEATHER_IMAGE, phase_[index_].image); + if (index_ == 0) { + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, + IMAGE_WEATHER_PREV_GRAY); + buttonChangeLeft_->Disable(); + } else { + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } else if (strcmp(view.GetViewId(), "buttonRight") == 0) { + if (index_ < BUTTON_CHANGE_END) { + labelDay_->SetText(phase_[++index_].weekTime); + labelLunarPhase_->SetText(phase_[index_].phase); + labelMonthLight_->SetText(phase_[index_].lightTime); + labelMonthDay_->SetText(phase_[index_].monthDay); + LOADIMG::LoadImageViewImg(drawImg_, WEATHER_IMAGE, phase_[index_].image); + if (index_ == BUTTON_CHANGE_END) { + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT_GRAY, + IMAGE_WEATHER_NEXT_GRAY); + buttonChangeRight_->Disable(); + } else { + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageMonthRise.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageMonthRise.cpp new file mode 100644 index 000000000..672703526 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageMonthRise.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageMonthRise + * Create: 2025-03-15 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageMonthRise.h" + +namespace OHOS { +static constexpr uint8_t WEATHER_TITLE_FONT_SIZE = 30; +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE = 24; +static constexpr int16_t WEATHER_RESIZE_SIZE_WIDTH = 117; +static constexpr int16_t WEATHER_RESIZE_SIZE_HEIGHT = 38; +static constexpr int16_t WEATHER_TITLE_POSITION_X = 167; +static constexpr int16_t WEATHER_TITLE_POSITION_Y = 41; +static constexpr int16_t WEATHER_TITLE_DAY_POSITION_X = 49; +static constexpr int16_t WEATHER_TITLE_DAY_POSITION_Y = 318; +static constexpr int16_t WEATHER_BUTTON_LEFT_POSITION_X = 76; +static constexpr int16_t WEATHER_BUTTON_RIGHT_POSITION_X = 306; +static constexpr int16_t WEATHER_BUTTON_POSITION_Y = 50; +static constexpr int16_t WEATHER_BUTTON_SIZE = 69; +static constexpr int16_t WEATHER_IMAGE_POSITION_X = 0; +static constexpr int16_t WEATHER_IMAGE_POSITION_Y = 214; +static constexpr int16_t WEATHER_IMAGE_MONTH_POSITION_X = 280; +static constexpr int16_t WEATHER_IMAGE_MONTH_POSITION_Y = 264; +static constexpr int16_t WEATHER_LABEL_DAY_POSITION_X = 184; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_WIDTH = 89; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_HEIGHT = 30; +static constexpr int16_t WEATHER_LABEL_MOHTH_SIZE_WIDTH = 113; +static constexpr int16_t WEATHER_LABEL_MONTH_SIZE_HEIGHT = 30; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_MONTHRISE_PAGE, WeatherPageMonthRise, false); + +WeatherPageMonthRise::WeatherPageMonthRise() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageMonthRise::WeatherPageMonthRise"); +} + +WeatherPageMonthRise::~WeatherPageMonthRise() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (drawImg_ != nullptr) { + delete drawImg_; + drawImg_ = nullptr; + } + + if (monthImg_ != nullptr) { + delete monthImg_; + monthImg_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelDay_ != nullptr) { + delete labelDay_; + labelDay_ = nullptr; + } + + for (int i = 0; i < MONTHRISE_TIME_LABEL_COUNT; i++) { + if (labelMonth_[i] != nullptr) { + delete labelMonth_[i]; + labelMonth_[i] = nullptr; + } + } + + if (buttonChangeLeft_ != nullptr) { + delete buttonChangeLeft_; + buttonChangeLeft_ = nullptr; + } + + if (buttonChangeRight_ != nullptr) { + delete buttonChangeRight_; + buttonChangeRight_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageMonthRise::~WeatherPageMonthRise"); +} + +void WeatherPageMonthRise::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group_ new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetViewId("monthGroup"); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + month_ = WeatherModel::GetInstance().GetMonthData(); + InitImage(); + InitLabel(); + InitLabelMonth(); + InitButton(); + index_ = 0; + AddViewToPageContainer(group_); +} + +void WeatherPageMonthRise::InitImage() +{ + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ new image fail"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + + drawImg_ = new UIImageView(); + if (drawImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "drawImg_ new image fail"); + return; + } + drawImg_->SetPosition(WEATHER_IMAGE_POSITION_X, WEATHER_IMAGE_POSITION_Y); + drawImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(drawImg_, WEATHER_IMAGE, IMAGE_WEATHER_SUNSET); + + monthImg_ = new UIImageView(); + if (monthImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "monthImg_ new image fail"); + return; + } + monthImg_->SetPosition(WEATHER_IMAGE_MONTH_POSITION_X, WEATHER_IMAGE_MONTH_POSITION_Y); + monthImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(monthImg_, WEATHER_IMAGE, IMAGE_WEATHER_MOON); + group_->Add(bgImg_); + group_->Add(drawImg_); + group_->Add(monthImg_); +} + +void WeatherPageMonthRise::InitLabel() +{ + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ is nullptr"); + return; + } + labelTitle_->SetPosition(WEATHER_TITLE_POSITION_X, WEATHER_TITLE_POSITION_Y); + labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTitle_->SetText("月出月落"); + labelTitle_->Resize(WEATHER_RESIZE_SIZE_WIDTH, WEATHER_RESIZE_SIZE_HEIGHT); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_TITLE_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelDay_ = new UILabel(); + if (labelDay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelDay_ is nullptr"); + return; + } + labelDay_->SetPosition(WEATHER_LABEL_DAY_POSITION_X, WEATHER_TITLE_POSITION_Y + labelTitle_->GetTextHeight()); + labelDay_->SetText("今天"); + labelDay_->Resize(WEATHER_LABEL_DAY_SIZE_WIDTH, WEATHER_LABEL_DAY_SIZE_HEIGHT); + labelDay_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelDay_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelDay_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelDay_, Color::White().full, Color::Gray().full); + labelDay_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + std::string monthRise = std::string(); + std::string monthSet = std::string(); + labelDay_->SetText(month_[0].weekTime); + group_->Add(labelTitle_); + group_->Add(labelDay_); +} + +void WeatherPageMonthRise::InitLabelMonth() +{ + for (int i = 0; i < MONTHRISE_TIME_LABEL_COUNT; i++) { + labelMonth_[i] = new UILabel(); + if (labelMonth_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelMonth_:[%d] is nullptr", i); + return; + } + int offsetX = 250; + labelMonth_[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelMonth_[i]->SetPosition(WEATHER_TITLE_DAY_POSITION_X + i * offsetX, WEATHER_TITLE_DAY_POSITION_Y); + labelMonth_[i]->Resize(WEATHER_LABEL_MOHTH_SIZE_WIDTH, WEATHER_LABEL_MONTH_SIZE_HEIGHT); + labelMonth_[i]->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelMonth_[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelMonth_[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelMonth_[i], Color::White().full, Color::Gray().full); + labelMonth_[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(labelMonth_[i]); + } + labelMonth_[0]->SetText(month_[0].monthRise); + labelMonth_[1]->SetText(month_[0].monthSet); +} + +void WeatherPageMonthRise::InitButton() +{ + buttonChangeLeft_ = new UIButton(); + if (buttonChangeLeft_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeLeft_ new button fail"); + return; + } + buttonChangeLeft_->SetPosition(WEATHER_BUTTON_LEFT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeLeft_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeLeft_->SetViewId("buttonLeft"); + buttonChangeLeft_->SetOnClickListener(this); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeLeft_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, IMAGE_WEATHER_PREV_GRAY); + buttonChangeRight_ = new UIButton(); + if (buttonChangeRight_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeRight_ new button fail"); + return; + } + buttonChangeRight_->SetPosition(WEATHER_BUTTON_RIGHT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeRight_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeRight_->SetViewId("buttonRight"); + buttonChangeRight_->SetOnClickListener(this); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeRight_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Disable(); + group_->Add(buttonChangeLeft_); + group_->Add(buttonChangeRight_); +} + +bool WeatherPageMonthRise::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_SUNRISE_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_LUNARPHASE_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool WeatherPageMonthRise::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + + if (strcmp(view.GetViewId(), "buttonLeft") == 0) { + if (index_ > 0) { + labelDay_->SetText(month_[--index_].weekTime); + labelMonth_[0]->SetText(month_[index_].monthRise); + labelMonth_[1]->SetText(month_[index_].monthSet); + if (index_ == 0) { + monthImg_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, + IMAGE_WEATHER_PREV_GRAY); + buttonChangeLeft_->Disable(); + } else { + monthImg_->SetVisible(false); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } else if (strcmp(view.GetViewId(), "buttonRight") == 0) { + if (index_ < BUTTON_CHANGE_END) { + monthImg_->SetVisible(false); + labelDay_->SetText(month_[++index_].weekTime); + labelMonth_[0]->SetText(month_[index_].monthRise); + labelMonth_[1]->SetText(month_[index_].monthSet); + if (index_ == BUTTON_CHANGE_END) { + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT_GRAY, + IMAGE_WEATHER_NEXT_GRAY); + buttonChangeRight_->Disable(); + } else { + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageSunRise.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageSunRise.cpp new file mode 100644 index 000000000..790e2b246 --- /dev/null +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPageSunRise.cpp @@ -0,0 +1,315 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageSunRise + * Create: 2025-03-15 + */ + +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_weather.h" +#include "wearable_log.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherPageSunRise.h" + +namespace OHOS { +static constexpr uint8_t WEATHER_TITLE_FONT_SIZE = 30; +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE = 24; +static constexpr int16_t WEATHER_RESIZE_SIZE_WIDTH = 117; +static constexpr int16_t WEATHER_RESIZE_SIZE_HEIGHT = 38; +static constexpr int16_t WEATHER_TITLE_POSITION_X = 167; +static constexpr int16_t WEATHER_TITLE_POSITION_Y = 41; +static constexpr int16_t WEATHER_TITLE_DAY_POSITION_X = 49; +static constexpr int16_t WEATHER_TITLE_DAY_POSITION_Y = 318; +static constexpr int16_t WEATHER_TITLE_OFFSET = 250; +static constexpr int16_t WEATHER_BUTTON_LEFT_POSITION_X = 76; +static constexpr int16_t WEATHER_BUTTON_RIGHT_POSITION_X = 306; +static constexpr int16_t WEATHER_BUTTON_POSITION_Y = 50; +static constexpr int16_t WEATHER_BUTTON_SIZE = 69; +static constexpr int16_t WEATHER_IMAGE_POSITION_X = 0; +static constexpr int16_t WEATHER_IMAGE_POSITION_Y = 168; +static constexpr int16_t WEATHER_IMAGE_SUN_POSITION_X = 135; +static constexpr int16_t WEATHER_LABEL_DAY_POSITION_X = 184; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_WIDTH = 89; +static constexpr int16_t WEATHER_LABEL_DAY_SIZE_HEIGHT = 30; +static constexpr int16_t WEATHER_LABEL_SUN_SIZE_WIDTH = 113; +static constexpr int16_t WEATHER_LABEL_SUN_SIZE_HEIGHT = 30; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_SUNRISE_PAGE, WeatherPageSunRise, false); + +WeatherPageSunRise::WeatherPageSunRise() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSunRise::WeatherPageSunRise"); +} + +WeatherPageSunRise::~WeatherPageSunRise() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + + if (drawImg_ != nullptr) { + delete drawImg_; + drawImg_ = nullptr; + } + + if (sunImg_ != nullptr) { + delete sunImg_; + sunImg_ = nullptr; + } + + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + + if (labelDay_ != nullptr) { + delete labelDay_; + labelDay_ = nullptr; + } + + for (int i = 0; i < SUNRISE_TIME_LABEL_COUNT; i++) { + if (labelSun_[i] != nullptr) { + delete labelSun_[i]; + labelSun_[i] = nullptr; + } + } + + if (buttonChangeLeft_ != nullptr) { + delete buttonChangeLeft_; + buttonChangeLeft_ = nullptr; + } + + if (buttonChangeRight_ != nullptr) { + delete buttonChangeRight_; + buttonChangeRight_ = nullptr; + } + + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSunRise::~WeatherPageSunRise"); +} + +void WeatherPageSunRise::OnStart(void *data) +{ + group_ = new UIViewGroup(); + if (group_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Group new fail"); + return; + } + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetViewId("weatherSwipeGroup_"); + group_->SetOnDragListener(this); + group_->SetDraggable(true); + group_->SetTouchable(true); + sun_ = WeatherModel::GetInstance().GetSunData(); + InitImage(); + InitLabel(); + InitLabelSun(); + InitButton(); + index_ = 0; + AddViewToPageContainer(group_); +} + +void WeatherPageSunRise::InitImage() +{ + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bgImg_ new image fail"); + return; + } + bgImg_->SetPosition(0, 0); + bgImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadImageOfDayNight(bgImg_, IMAGE_WEATHER_BG1, IMAGE_WEATHER_BG2); + + drawImg_ = new UIImageView(); + if (drawImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "drawImg_ new image fail"); + return; + } + drawImg_->SetPosition(WEATHER_IMAGE_POSITION_X, WEATHER_IMAGE_POSITION_Y); + drawImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(drawImg_, WEATHER_IMAGE, IMAGE_WEATHER_SUNRISE); + + sunImg_ = new UIImageView(); + if (sunImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sunImg_ new image fail"); + return; + } + sunImg_->SetPosition(WEATHER_IMAGE_SUN_POSITION_X, WEATHER_IMAGE_POSITION_Y); + sunImg_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(sunImg_, WEATHER_IMAGE, IMAGE_WEATHER_SUN); + + group_->Add(bgImg_); + group_->Add(drawImg_); + group_->Add(sunImg_); +} + +void WeatherPageSunRise::InitLabel() +{ + labelTitle_ = new UILabel(); + if (labelTitle_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ is nullptr"); + return; + } + labelTitle_->SetPosition(WEATHER_TITLE_POSITION_X, WEATHER_TITLE_POSITION_Y); + labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelTitle_->SetText("日出日落"); + labelTitle_->Resize(WEATHER_RESIZE_SIZE_WIDTH, WEATHER_RESIZE_SIZE_HEIGHT); + labelTitle_->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_TITLE_FONT_SIZE); + labelTitle_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + labelDay_ = new UILabel(); + if (labelDay_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelDay_ is nullptr"); + return; + } + labelDay_->SetPosition(WEATHER_LABEL_DAY_POSITION_X, WEATHER_TITLE_POSITION_Y + labelTitle_->GetTextHeight()); + labelDay_->SetText("今天"); + labelDay_->Resize(WEATHER_LABEL_DAY_SIZE_WIDTH, WEATHER_LABEL_DAY_SIZE_HEIGHT); + labelDay_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelDay_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelDay_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelDay_, Color::White().full, Color::Gray().full); + labelDay_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelDay_->SetText(sun_[0].weekTime); + group_->Add(labelTitle_); + group_->Add(labelDay_); +} + +void WeatherPageSunRise::InitLabelSun() +{ + for (int i = 0; i < SUNRISE_TIME_LABEL_COUNT; i++) { + labelSun_[i] = new UILabel(); + if (labelSun_[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelSun_[%d] is nullptr", i); + return; + } + labelSun_[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + labelSun_[i]->SetPosition(WEATHER_TITLE_DAY_POSITION_X + i * WEATHER_TITLE_OFFSET, + WEATHER_TITLE_DAY_POSITION_Y); + labelSun_[i]->Resize(WEATHER_LABEL_SUN_SIZE_WIDTH, WEATHER_LABEL_SUN_SIZE_HEIGHT); + labelSun_[i]->SetFont(BOLD_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + labelSun_[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelSun_[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + WeatherModel::GetInstance().LoadTextColorOfDayNight(labelSun_[i], Color::White().full, Color::Gray().full); + labelSun_[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group_->Add(labelSun_[i]); + } + std::string sunRise = "日出 " + std::string(sun_[0].sunRise); + std::string sunSet = "日落 " + std::string(sun_[0].sunSet); + labelSun_[0]->SetText(sunRise.c_str()); + labelSun_[1]->SetText(sunSet.c_str()); +} + +void WeatherPageSunRise::InitButton() +{ + buttonChangeLeft_ = new UIButton(); + if (buttonChangeLeft_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeLeft_ is nullptr"); + return; + } + buttonChangeLeft_->SetPosition(WEATHER_BUTTON_LEFT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeLeft_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeLeft_->SetViewId("buttonLeft"); + buttonChangeLeft_->SetOnClickListener(this); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeLeft_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeLeft_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, IMAGE_WEATHER_PREV_GRAY); + + buttonChangeRight_ = new UIButton(); + if (buttonChangeRight_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonChangeRight_ is nullptr"); + return; + } + buttonChangeRight_->SetPosition(WEATHER_BUTTON_RIGHT_POSITION_X, WEATHER_BUTTON_POSITION_Y); + buttonChangeRight_->Resize(WEATHER_BUTTON_SIZE, WEATHER_BUTTON_SIZE); + buttonChangeRight_->SetViewId("buttonRight"); + buttonChangeRight_->SetOnClickListener(this); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonChangeRight_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + buttonChangeRight_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Disable(); + group_->Add(buttonChangeLeft_); + group_->Add(buttonChangeRight_); +} + +bool WeatherPageSunRise::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSliceToApplist(); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MONTHRISE_PAGE, + TransitionType::TRANSITION_INVALID, false); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MAIN_PAGE, + TransitionType::TRANSITION_INVALID, false); + } + return true; +} + +bool WeatherPageSunRise::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), "buttonLeft") == 0) { + if (index_ > 0) { + labelDay_->SetText(sun_[--index_].weekTime); + std::string sunRise = "日出 " + std::string(sun_[index_].sunRise); + std::string sunSet = "日落 " + std::string(sun_[index_].sunSet); + labelSun_[0]->SetText(sunRise.c_str()); + labelSun_[1]->SetText(sunSet.c_str()); + if (index_ == 0) { + sunImg_->SetVisible(true); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV_GRAY, + IMAGE_WEATHER_PREV_GRAY); + buttonChangeLeft_->Disable(); + } else { + sunImg_->SetVisible(false); + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } else if (strcmp(view.GetViewId(), "buttonRight") == 0) { + if (index_ < BUTTON_CHANGE_END) { + labelDay_->SetText(sun_[++index_].weekTime); + std::string sunRise = "日出 " + std::string(sun_[index_].sunRise); + std::string sunSet = "日落 " + std::string(sun_[index_].sunSet); + labelSun_[0]->SetText(sunRise.c_str()); + labelSun_[1]->SetText(sunSet.c_str()); + sunImg_->SetVisible(false); + if (index_ == BUTTON_CHANGE_END) { + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT_GRAY, + IMAGE_WEATHER_NEXT_GRAY); + buttonChangeRight_->Disable(); + } else { + LOADIMG::LoadBtnImage(buttonChangeLeft_, WEATHER_IMAGE, IMAGE_WEATHER_PREV, IMAGE_WEATHER_PREV); + LOADIMG::LoadBtnImage(buttonChangeRight_, WEATHER_IMAGE, IMAGE_WEATHER_NEXT, IMAGE_WEATHER_NEXT); + buttonChangeLeft_->Enable(); + buttonChangeRight_->Enable(); + } + } + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPresenter.cpp b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPresenter.cpp index c9438428f..2adafcdca 100644 --- a/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPresenter.cpp +++ b/code/sdk/application/wearable/evb/nativeapp/nativeui/weather/src/WeatherPresenter.cpp @@ -1,16 +1,13 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: WeatherPresenter * Create: 2025-03-23 */ +#include "NativeRegisterManager.h" #include "weather/WeatherView.h" -#include "weather/WeatherModel.h" #include "weather/WeatherPresenter.h" -#include "uiservice/ui_service.h" -#include "NativeRegisterManager.h" -#include "wearable_log.h" namespace OHOS { - REGIST_MENU(VIEW_WEATHER, WeatherView, WeatherPresenter, WEATHER_MAIN_ICON, WEATHER_MAIN_ICON, "天气"); +REGIST_MENU(VIEW_WEATHER, WeatherView, WeatherPresenter, WEATHER_ICON, WEATHER_ICON, "天气"); } diff --git a/code/sdk/application/wearable/evb/ohos_deps/wearable_log.h b/code/sdk/application/wearable/evb/ohos_deps/wearable_log.h new file mode 100644 index 000000000..c2945d201 --- /dev/null +++ b/code/sdk/application/wearable/evb/ohos_deps/wearable_log.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: Wearable log header file. + * Author: + * Create: + */ + +#ifndef WEARABLE_LOG_H +#define WEARABLE_LOG_H + +#if !defined(SW_UART_DEBUG) && !defined(SW_RTT_DEBUG) +#include "soc_diag_util.h" +#include "log_oam_logger.h" +#include "log_def.h" +#else +#include "debug_print.h" +#endif +#include "wearable_onlinelog.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +/** + * @brief Enumerates logging module types. + * + * The module type must be globally unique. A maximum of 64 module types can be defined. + * + * @since 1.0 + * @version 1.0 + */ +typedef enum { + /** applications */ + WEARABLE_LOG_MODULE_APP = 0, + /** Launcher Framework */ + WEARABLE_LOG_MODULE_LAUNCHER_FWK, + /** Main Service */ + WEARABLE_LOG_MODULE_MAIN_SERVICE, + /** Broadcast Service */ + WEARABLE_LOG_MODULE_BROADCASE_SERVICE, + /** Atomic Ability Framework */ + WEARABLE_LOG_MODULE_AAFWK, + /** smart voice */ + WEARABLE_LOG_MODULE_SMART_VOICE, + /* UI SERVICE */ + WEARABLE_LOG_MODULE_UI_SERVICE, + /* msg_center */ + WEARABLE_LOG_MODULE_MSG_CENTER, + + WEARABLE_LOG_MODULE_MAX +} WearableLogModuleType; + +#if !defined(SW_UART_DEBUG) && !defined(SW_RTT_DEBUG) && !defined(CONFIG_ONLINE_LOG) +#define WEARABLE_LOGE(mod, fmt, arg...) uapi_diag_error_log(0, fmt, ##arg) +#define WEARABLE_LOGW(mod, fmt, arg...) uapi_diag_warning_log(0, fmt, ##arg) +#define WEARABLE_LOGI(mod, fmt, arg...) uapi_diag_info_log(0, fmt, ##arg) +#ifdef WEARABLE_LOG_DEBUG +#define WEARABLE_LOGD(mod, fmt, arg...) uapi_diag_debug_log(0, fmt, ##arg) +#else +#define WEARABLE_LOGD(mod, fmt, arg...) +#endif +#elif (CONFIG_ONLINE_LOG == 1) && !defined(_WIN32) +#define WEARABLE_LOGE(mod, fmt, arg...) ONLINE_PRINT(ONLINE_ERROR, fmt "\n", ##arg) +#define WEARABLE_LOGW(mod, fmt, arg...) ONLINE_PRINT(ONLINE_WARN, fmt "\n", ##arg) +#define WEARABLE_LOGI(mod, fmt, arg...) ONLINE_PRINT(ONLINE_INFO, fmt "\n", ##arg) +#ifdef WEARABLE_LOG_DEBUG +#define WEARABLE_LOGD(mod, fmt, arg...) ONLINE_PRINT(ONLINE_DEBUG, fmt "\n", ##arg) +#else +#define WEARABLE_LOGD(mod, fmt, arg...) +#endif +#else +#define WEARABLE_LOGE(mod, fmt, arg...) PRINT("[WEARABLE E/] " fmt "\n", ##arg) +#define WEARABLE_LOGW(mod, fmt, arg...) PRINT("[WEARABLE W/] " fmt "\n", ##arg) +#define WEARABLE_LOGI(mod, fmt, arg...) PRINT("[WEARABLE I/] " fmt "\n", ##arg) +#ifdef WEARABLE_LOG_DEBUG +#define WEARABLE_LOGD(mod, fmt, arg...) PRINT("[WEARABLE D/] " fmt "\n", ##arg) +#else +#define WEARABLE_LOGD(mod, fmt, arg...) +#endif +#endif + +#define CHECK_NULL_AND_RETURN(pointer, mod, fmt) \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ + return; \ + } \ + } while (0) + +#define CHECK_NULL_AND_RETURN_NULL(pointer, mod, fmt) \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ + return nullptr; \ + } \ + } while (0) + +#define CHECK_NULL_AND_RETURN_CODE(pointer, mod, fmt, code) \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ + return (code); \ + } \ + } while (0) + +#define DELETE_IF_NOT_NULL(pointer) \ + do { \ + if ((pointer) != nullptr) { \ + delete (pointer); \ + (pointer) = nullptr; \ + } \ + } while (0) + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/code/sdk/application/wearable/evb/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/evb/service/broadcast/include/broadcast_feature.h index 8359e67ba..42e8d7308 100644 --- a/code/sdk/application/wearable/evb/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/evb/service/broadcast/include/broadcast_feature.h @@ -45,7 +45,7 @@ typedef enum { TOPIC_EVENT_HFP_WATCH_TO_PHONE, TOPIC_EVENT_BLOODOXYGEN_UPDATA, TOPIC_EVENT_SPORT_DISTANCE, - TOPIC_EVENT_LOCATION, + TOPIC_EVENT_CALENDAR_NOTIFY, TOPIC_END_NUM = 20000, } TopicNum; diff --git a/code/sdk/application/wearable/evb/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/evb/service/broadcast/src/broadcast_implement.c index 5fe38efd7..9f4bb8ba6 100644 --- a/code/sdk/application/wearable/evb/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/evb/service/broadcast/src/broadcast_implement.c @@ -34,7 +34,6 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_HFP_WATCH_TO_PHONE, A_CORE_MASK, 1}, {TOPIC_EVENT_BLOODOXYGEN_UPDATA, A_CORE_MASK, 1}, {TOPIC_EVENT_SPORT_DISTANCE, A_CORE_MASK, 1}, - {TOPIC_EVENT_LOCATION, A_CORE_MASK, 1}, }; /* 所有的topic,其对应的位图 */ diff --git a/code/sdk/application/wearable/evb/service/device_msg/CMakeLists.txt b/code/sdk/application/wearable/evb/service/device_msg/CMakeLists.txt index 972f58f50..0889ae212 100644 --- a/code/sdk/application/wearable/evb/service/device_msg/CMakeLists.txt +++ b/code/sdk/application/wearable/evb/service/device_msg/CMakeLists.txt @@ -1,7 +1,6 @@ set(COMPONENT_NAME "device_msg") set(PUBLIC_HEADER -${CMAKE_CURRENT_SOURCE_DIR} ) set(PRIVATE_HEADER @@ -9,22 +8,26 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits ${ROOT_DIR}/middleware/services/media/foundation/audiomanager/interfaces/kits/audiomanager ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${ROOT_DIR}/middleware/chips/brandy/nv/include ${ROOT_DIR}/middleware/chips/brandy/nv/nv_config + ${ROOT_DIR}/application/wearable/nativeapp/nativeui/include ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/open_source/openharmony/base/sensors/location/interfaces/kits/include ${ROOT_DIR}/middleware/utils/dfx/diag/ + ${ROOT_DIR}/open_source/openharmony/third_party/cJSON + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/utils/innerkits + ${ROOT_DIR}/application/wearable/nativeapp/nativeui/ ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/device_msg.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_proxy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/msg_center_device.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/device_location.cpp ) set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/application/wearable/evb/service/device_msg/device_msg.cpp b/code/sdk/application/wearable/evb/service/device_msg/device_msg.cpp index 3f54b45ab..79f0fc25a 100644 --- a/code/sdk/application/wearable/evb/service/device_msg/device_msg.cpp +++ b/code/sdk/application/wearable/evb/service/device_msg/device_msg.cpp @@ -1,9 +1,9 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. - * Description: Breath Ease - * Author: wangle - * Create: 2025-4-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Device Msg + * Create: 2025-06-06 */ + #include "msg_center_protocol.h" #include "msg_center_cmd.h" #include "ohos_init.h" @@ -14,8 +14,6 @@ #include "graphic_timer.h" #include "broadcast_feature.h" #include "ohos_timer.h" -#include "heartrate/HeartModel.h" -#include "device_location.h" #endif namespace OHOS { @@ -31,14 +29,7 @@ extern "C" { #define HEARTRATE_RANGE 60 static uint8_t g_rotation_publish = 0; static GraphicTimer *g_publishTestDataHandle = nullptr; -enum publishDataType { - PUBLISH_SETP = 0, - PUBLISH_DISTANCE, - PUBLISH_HEARTRATE, - PUBLISH_BLOODOXYGEN, - PUBLISH_TYPE_MAX -}; - +enum publishDataType { PUBLISH_SETP = 0, PUBLISH_DISTANCE, PUBLISH_HEARTRATE, PUBLISH_BLOODOXYGEN, PUBLISH_TYPE_MAX }; static void PublishTopicTestDataEvent(uint16_t topic, const void *data, size_t len) { int32_t ret; @@ -115,7 +106,7 @@ static void PublishTestDataCallback(void *) } } -void PublishTestData() +static void PublishTestData() { uint32 tick = GetOSTick(5000); // 5秒发布一次测试数据 if (g_publishTestDataHandle == nullptr) { @@ -141,28 +132,24 @@ static const msg_center_cmd_map_t g_msg_center_device_tbl[] = { {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_STORAGE_INFO, msg_center_get_storage_info}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_PRODUCT_INFO, msg_center_get_product_info}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_LANGUAGE_ID, msg_center_get_language_id}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_VOLUME_INFO, msg_center_get_volume_info}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_LANGUAGE_ID, msg_center_set_language_id}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_VOLUME_INFO, msg_center_set_volume_info}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_HEARTRATE, msg_center_device_heartrate}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_STEPDATA, msg_center_device_stepdata}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN, msg_center_device_bloodoxygen}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OFFLINE_LOG_SWITCH, msg_center_offline_log_switch}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_GET_INFO, msg_center_location_get_info}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_START, msg_center_location_start}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_STOP, msg_center_location_stop}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_ACTION, msg_center_sport_action}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_GET_DATA, msg_center_sport_get_data}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_DATA, msg_center_sport_report_data}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_GET_RECORD, msg_center_sport_get_record}, #if (CONFIG_ONLINE_LOG == 1) {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_ONLINELOG_CHANNEL, msg_center_set_online_log_channel}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_ONLINELOG_LEVEL, msg_center_set_online_log_level}, #endif {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OTA_INIT, msg_center_ota_init}, {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OTA_UPDATE, msg_center_ota_update}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OFF_FIND_PHONE, msg_center_device_findphone}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_CAMERA_WATCH_EXIT, msg_center_camera_exit}, - {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE_SUCCESS, msg_center_camera_online}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_STOP_FIND_PHONE, msg_center_device_findphone}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_WATCH_EXIT_CAMERA, msg_center_camera_exit}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_CAMERA_CONNECTED_PHONE, msg_center_camera_online}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SYNC_WEATHER_REC, msg_center_device_sync_weather_rec}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SYNC_DATE_REC, msg_center_device_sync_date_rec}, }; errcode_t msg_center_device_type_dispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) @@ -182,6 +169,9 @@ errcode_t msg_center_device_type_dispatch(uint8_t cmd_id, uint8_t type, void *us void device_init(void) { msg_center_register_cmd(MSGCENTER_CMD_DEVICE, msg_center_device_type_dispatch); +#ifdef PUBLISH_TEST_DATA + PublishTestData(); +#endif } APP_FEATURE_INIT_PRI(device_init, LAYER_INIT_LEVEL_4); diff --git a/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.cpp b/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.cpp index 56f89c1a8..80255a34d 100644 --- a/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.cpp +++ b/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.cpp @@ -1,19 +1,21 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. - * Description: Breath Ease - * Author: wangle - * Create: 2025-4-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MsgCenter Device + * Create: 2025-06-06 */ -#include "msg_center_protocol.h" + #include "msg_center_device.h" +#include "msg_center_protocol.h" #include "device_proxy.h" #include "wearable_log.h" -#include "device_location.h" #include "AppViewIDs.h" #include "NativeAbility.h" -#include "sports/SportsModel.h" +#include "sport/SportView.h" +#include "sport/SportModel.h" #include "findphone/FindPhoneMainPage.h" #include "camera/CameraMainPage.h" +#include "weather/WeatherMainPage.h" +#include "date/DateMainPage.h" #ifdef __cplusplus extern "C" { @@ -22,10 +24,9 @@ extern "C" { #include "diag_ind_src.h" uint8_t g_bloodoxygen = 0; -uint16_t g_heartrate = 0; +uint8_t g_heartrate = 0; uint32_t g_stepdata = 0; uint32_t g_distance = 0; -extern LocationInfo_t g_locationInfo; // 获取电量 errcode_t msg_center_get_battery_level(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { @@ -100,29 +101,6 @@ errcode_t msg_center_get_language_id(uint8_t cmd_id, uint8_t type, void *usr_dat } return ERRCODE_SUCC; } -// 获取音量 -errcode_t msg_center_get_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_volume_info"); - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - void *v_data = msg_center_get_tlv_payload(usr_data); - uint8_t v_len = usr_len - tl_len; - - uint8_t vol_type = 0; - if (v_len == sizeof(uint8_t)) { - vol_type = *(uint8_t *)v_data; - } - - std::vector vol_info; - OHOS::device_proxy::get_volume_info(vol_type, vol_info); - - errcode_t ret = msg_center_send_data(cmd_id, type, &vol_info[0], vol_info.size() * sizeof(OHOS::volume_info)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_volume_info_ack fail, ret = %d", ret); - return ERRCODE_FAIL; - } - return ERRCODE_SUCC; -} // 设置语言 errcode_t msg_center_set_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { @@ -147,30 +125,6 @@ errcode_t msg_center_set_language_id(uint8_t cmd_id, uint8_t type, void *usr_dat } return ERRCODE_SUCC; } -// 设置音量 -errcode_t msg_center_set_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "set_volume_info"); - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - void *v_data = msg_center_get_tlv_payload(usr_data); - uint8_t v_len = usr_len - tl_len; - - OHOS::volume_info info; - if (v_len != sizeof(OHOS::volume_info)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "v_len check error, v_len=%u, need=%u", v_len, sizeof(uint8_t)); - return ERRCODE_FAIL; - } - - memcpy_s(&info, sizeof(OHOS::volume_info), v_data, v_len); - OHOS::device_proxy::set_volume_info(info); - - errcode_t ret = msg_center_send_data(cmd_id, type, &info, sizeof(OHOS::volume_info)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send set_volume_info_ack fail, ret = %d", ret); - return ERRCODE_FAIL; - } - return ERRCODE_SUCC; -} // ota初始化 errcode_t msg_center_ota_init(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { @@ -218,7 +172,7 @@ errcode_t msg_center_ota_update(uint8_t cmd_id, uint8_t type, void *usr_data, ui return ERRCODE_FAIL; } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send ret = %d", ret); - OHOS::device_proxy::call_ui_ota_update(); + OHOS::device_proxy::call_ui_ota_update(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send ui over"); return ERRCODE_SUCC; @@ -274,89 +228,6 @@ errcode_t msg_center_device_bloodoxygen(uint8_t cmd_id, uint8_t type, void *usr_ return ERRCODE_SUCC; } - -/* LOCATION */ -errcode_t msg_center_location_get_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - uint16_t payload_len = usr_len - tl_len; - uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); - errcode_t ret = ERRCODE_SUCC; - - ret = msg_center_send_data(cmd_id, type, &g_locationInfo, sizeof(g_locationInfo)); - if (ret != ERRCODE_SUCC) { - return ERRCODE_FAIL; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_get_info latitude_:%d,longitude_:%d\n", - g_locationInfo.latitude_, g_locationInfo.longitude_); - /* notify UI or call UI load */ - - return ERRCODE_SUCC; -} - -errcode_t msg_center_location_start(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - uint16_t payload_len = usr_len - tl_len; - uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); - errcode_t ret = ERRCODE_SUCC; - uint8_t ack = 1; - - WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start finish\r\n"); - ret = deviceLocationStartLocating(); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start fail\r\n"); - ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start send msg fail\r\n"); - return ERRCODE_FAIL; - } - } else { - ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start send msg fail\r\n"); - return ERRCODE_FAIL; - } - } - - WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start finish\r\n"); - /* notify UI or call UI load */ - - return ERRCODE_SUCC; -} - -errcode_t msg_center_location_stop(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - uint16_t payload_len = usr_len - tl_len; - uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); - errcode_t ret = ERRCODE_SUCC; - uint8_t ack = 1; - - WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop\r\n"); - ret = deviceLocationStopLocating(); - ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop fail\r\n"); - ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop send msg fail\r\n"); - return ERRCODE_FAIL; - } - } else { - ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop send msg fail\r\n"); - return ERRCODE_FAIL; - } - } - - WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop\r\n"); - /* notify UI or call UI load */ - - return ERRCODE_SUCC; -} - /* SPORT */ errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { @@ -365,31 +236,27 @@ errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); errcode_t ret = ERRCODE_SUCC; uint8_t ack = 1; - sport_action_t action = (sport_action_t)*tlv_payload; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_action : %d\r\n", action); - - switch (action) { - case SPORT_ACTION_START: - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_SPORTS); - OHOS::SportsModel::GetInstance()->ResetSportsData(); - if (!OHOS::SportsModel::GetInstance()->StartSportsTimer()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_start StartSportsTimer failed\r\n"); - ret = ERRCODE_FAIL; - } + OHOS::sport_control_t *sport = (OHOS::sport_control_t *)tlv_payload; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_action=%d, type=%d", sport->action, sport->type); + + switch (sport->action) { + case OHOS::SPORT_ACTION_START: + OHOS::SportModel::GetInstance().SetSportType(static_cast(sport->type)); + OHOS::SportModel::GetInstance().StartSport(false); + OHOS::NativeAbility::GetInstance().SwitchSlice(VIEW_SPORT, OHOS::SportPages::SPORT_PAGE_DATA); break; - case SPORT_ACTION_PAUSE: - OHOS::SportsModel::GetInstance()->StopSportsTimer(false); + case OHOS::SPORT_ACTION_PAUSE: + OHOS::SportModel::GetInstance().PauseAndReport(false); + OHOS::NativeAbility::GetInstance().SwitchSlice(VIEW_SPORT, OHOS::SportPages::SPORT_PAGE_PAUSE); break; - case SPORT_ACTION_RESUME: - if (!OHOS::SportsModel::GetInstance()->StartSportsTimer()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_resume StartSportsTimer failed\r\n"); - ret = ERRCODE_FAIL; - } + case OHOS::SPORT_ACTION_RESUME: + OHOS::SportModel::GetInstance().ResumeAndReport(false); + OHOS::NativeAbility::GetInstance().SwitchSlice(VIEW_SPORT, OHOS::SportPages::SPORT_PAGE_DATA); break; - case SPORT_ACTION_STOP: - OHOS::SportsModel::GetInstance()->StopSportsTimer(false); - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + case OHOS::SPORT_ACTION_STOP: + OHOS::SportModel::GetInstance().StopAndReport(false); + OHOS::NativeAbility::GetInstance().SwitchSlice(VIEW_SPORT, OHOS::SportPages::SPORT_PAGE_MENU); break; default: ret = ERRCODE_FAIL; @@ -398,38 +265,65 @@ errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_resume send data failed\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_action send data failed\r\n"); return ERRCODE_FAIL; } return ERRCODE_SUCC; } -errcode_t msg_center_sport_get_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +errcode_t msg_center_sport_get_record(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); uint16_t payload_len = usr_len - tl_len; uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); errcode_t ret = ERRCODE_SUCC; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_data\r\n"); - OHOS::sport_data_t *sportData = OHOS::SportsModel::GetInstance()->GetSportsData(); - ret = msg_center_send_data(cmd_id, type, sportData, sizeof(OHOS::sport_data_t)); - if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_data end data failed\r\n"); + auto record = OHOS::SportModel::GetInstance().GetRecord(); + uint16_t num = record.size(); + uint16_t size = sizeof(uint16_t) + num * sizeof(OHOS::sport_data_t); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_record record num=%d, malloc szie=%d\r\n", num, + size); + uint8_t *data = (uint8_t *)malloc(size); + if (data == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_record malloc data failed\r\n"); return ERRCODE_FAIL; } - return ERRCODE_SUCC; -} + uint8_t *data_addr = data; + + memcpy_s(data, sizeof(uint16_t), &num, sizeof(uint16_t)); + data += sizeof(uint16_t); + + for (int i = 0; i < num; i++) { + memcpy_s(data, sizeof(OHOS::sport_data_t), &record[i], sizeof(OHOS::sport_data_t)); + data += sizeof(OHOS::sport_data_t); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "========record[%d]=============", i); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "type:%d", record[i].type); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "heartRate:%d", record[i].heartRate); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "calorie:%d", record[i].calorie); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "altitude:%d", record[i].altitude); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "ascent:%d", record[i].ascent); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "descent:%d", record[i].descent); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "distance:%d", record[i].distance); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "lap:%d", record[i].lap); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "startTime:%d", record[i].startTime); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "endTime:%d", record[i].endTime); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "elapsedTime:%d", record[i].elapsedTime); + } -errcode_t msg_center_sport_report_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) -{ + ret = msg_center_send_data(cmd_id, type, data_addr, size); + free(data_addr); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_record send data failed\r\n"); + return ERRCODE_FAIL; + } + OHOS::SportModel::GetInstance().ClearRecord(); return ERRCODE_SUCC; } errcode_t msg_center_camera_exit(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "recv exit camera from phone"); - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + OHOS::NativeAbility::GetInstance().ChangeSliceToApplist(); return ERRCODE_SUCC; } @@ -501,20 +395,38 @@ errcode_t msg_center_set_online_log_level(uint8_t cmd_id, uint8_t type, void *us errcode_t msg_center_device_findphone(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { - uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); - uint16_t payload_len = usr_len - tl_len; - uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); bool ret = true; - if ( OHOS::FindPhoneMainPage::GetInstance() != nullptr) { + if (OHOS::FindPhoneMainPage::GetInstance() != nullptr) { ret = OHOS::FindPhoneMainPage::GetInstance()->StopFindPhone(); } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "FindphonePage not exist\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "FindphonePage not exist\r\n"); } if (!ret) { return ERRCODE_FAIL; } return ERRCODE_SUCC; } + +errcode_t msg_center_device_sync_weather_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + if (OHOS::WeatherMainPage::GetInstance() != nullptr) { + OHOS::WeatherMainPage::GetInstance()->ReloadPage(); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "WeatherMainPage not exist\r\n"); + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_device_sync_date_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + if (OHOS::DateMainPage::GetInstance() != nullptr) { + OHOS::DateMainPage::GetInstance()->ReloadPage(); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "DateMainPage not exist\r\n"); + } + return ERRCODE_SUCC; +} + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.h b/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.h index 02f3c2583..57a66e464 100644 --- a/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.h +++ b/code/sdk/application/wearable/evb/service/device_msg/msg_center_device.h @@ -1,9 +1,9 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. - * Description: Breath Ease - * Author: wangle - * Create: 2025-4-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: MsgCenter Device + * Create: 2025-06-06 */ + #ifndef MSG_CENTER_DEVICE_H #define MSG_CENTER_DEVICE_H @@ -14,45 +14,37 @@ extern "C" { #endif -typedef enum sport_action { - SPORT_ACTION_START = 1, - SPORT_ACTION_PAUSE = 2, - SPORT_ACTION_RESUME = 3, - SPORT_ACTION_STOP = 4, -} sport_action_t; - typedef enum msg_center_device_type_id { - MSGCENTER_TYPE_ID_GET_BATTERY_LEVEL = 0x1, - MSGCENTER_TYPE_ID_GET_STORAGE_INFO = 0x2, - MSGCENTER_TYPE_ID_GET_PRODUCT_INFO = 0x3, - MSGCENTER_TYPE_ID_GET_LANGUAGE_ID = 0x4, - MSGCENTER_TYPE_ID_GET_VOLUME_INFO = 0x5, - MSGCENTER_TYPE_ID_SET_LANGUAGE_ID = 0x6, - MSGCENTER_TYPE_ID_SET_VOLUME_INFO = 0x7, - MSGCENTER_TYPE_ID_DEVICE_HEARTRATE = 0x8, - MSGCENTER_TYPE_ID_DEVICE_STEPDATA = 0x9, - MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN = 0xa, - MSGCENTER_TYPE_ID_OFFLINE_LOG_SWITCH = 0xb, - MSGCENTER_TYPE_ID_LOCATION_GET_INFO = 0x20, - MSGCENTER_TYPE_ID_LOCATION_START = 0x21, - MSGCENTER_TYPE_ID_LOCATION_STOP = 0x22, - MSGCENTER_TYPE_ID_LOCATION_REPORT = 0x23, - MSGCENTER_TYPE_ID_SPORT_ACTION = 0x27, - MSGCENTER_TYPE_ID_SPORT_GET_DATA = 0x28, - MSGCENTER_TYPE_ID_SPORT_REPORT_DATA = 0x29, - MSGCENTER_TYPE_ID_SET_ONLINELOG_CHANNEL = 0x30, - MSGCENTER_TYPE_ID_SET_ONLINELOG_LEVEL = 0x31, - MSGCENTER_TYPE_ID_ONLINELOG_REPORT = 0x33, - MSGCENTER_TYPE_ID_OTA_INIT = 0x34, - MSGCENTER_TYPE_ID_OTA_UPDATE = 0x35, - MSGCENTER_TYPE_ID_ON_FIND_PHONE = 0x36, - MSGCENTER_TYPE_ID_OFF_FIND_PHONE = 0x37, - MSGCENTER_TYPE_ID_SLEEP_DATA = 0x38, - MSGCENTER_TYPE_ID_ON_CAMERA = 0x39, - MSGCENTER_TYPE_ID_CAMERA_WATCH_EXIT = 0x40, - MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT = 0x41, - MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE = 0x42, - MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE_SUCCESS = 0x43, + MSGCENTER_TYPE_ID_GET_BATTERY_LEVEL = 0x01, + MSGCENTER_TYPE_ID_GET_STORAGE_INFO = 0x02, + MSGCENTER_TYPE_ID_GET_PRODUCT_INFO = 0x03, + MSGCENTER_TYPE_ID_GET_LANGUAGE_ID = 0x04, + MSGCENTER_TYPE_ID_SET_LANGUAGE_ID = 0x05, + MSGCENTER_TYPE_ID_DEVICE_HEARTRATE = 0x06, + MSGCENTER_TYPE_ID_DEVICE_STEPDATA = 0x07, + MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN = 0x08, + MSGCENTER_TYPE_ID_SPORT_ACTION = 0x09, + MSGCENTER_TYPE_ID_SPORT_REPORT_ACTION = 0x0a, + MSGCENTER_TYPE_ID_SPORT_REPORT_DATA = 0x0b, + MSGCENTER_TYPE_ID_SPORT_GET_RECORD = 0x0c, + MSGCENTER_TYPE_ID_SET_ONLINELOG_CHANNEL = 0x0d, + MSGCENTER_TYPE_ID_SET_ONLINELOG_LEVEL = 0x0e, + MSGCENTER_TYPE_ID_OFFLINE_LOG_SWITCH = 0x0f, + MSGCENTER_TYPE_ID_ONLINELOG_REPORT = 0x10, + MSGCENTER_TYPE_ID_START_FIND_PHONE = 0x11, + MSGCENTER_TYPE_ID_STOP_FIND_PHONE = 0x12, + MSGCENTER_TYPE_ID_SLEEP_DATA = 0x13, + MSGCENTER_TYPE_ID_ON_CAMERA = 0x14, + MSGCENTER_TYPE_ID_WATCH_EXIT_CAMERA = 0x15, + MSGCENTER_TYPE_ID_PHONE_EXIT_CAMERA = 0x16, + MSGCENTER_TYPE_ID_CAMERA_CONNECTING_PHONE = 0x17, + MSGCENTER_TYPE_ID_CAMERA_CONNECTED_PHONE = 0x18, + MSGCENTER_TYPE_ID_OTA_INIT = 0x19, + MSGCENTER_TYPE_ID_OTA_UPDATE = 0x1a, + MSGCENTER_TYPE_ID_SYNC_WEATHER_REQ = 0x1b, + MSGCENTER_TYPE_ID_SYNC_WEATHER_REC = 0x1c, + MSGCENTER_TYPE_ID_SYNC_DATE_REQ = 0x1d, + MSGCENTER_TYPE_ID_SYNC_DATE_REC = 0x1e, } msg_center_device_type_id_t; // 获取电量 @@ -63,12 +55,8 @@ errcode_t msg_center_get_storage_info(uint8_t cmd_id, uint8_t type, void *usr_da errcode_t msg_center_get_product_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); // 获取语言 errcode_t msg_center_get_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -// 获取音量 -errcode_t msg_center_get_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); // 设置语言 errcode_t msg_center_set_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -// 设置音量 -errcode_t msg_center_set_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); // ota初始化 errcode_t msg_center_ota_init(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); // ota检测和本地升级 @@ -78,15 +66,9 @@ errcode_t msg_center_device_heartrate(uint8_t cmd_id, uint8_t type, void *usr_da errcode_t msg_center_device_stepdata(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t msg_center_device_bloodoxygen(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -/* LOCATION */ -errcode_t msg_center_location_get_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -errcode_t msg_center_location_start(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -errcode_t msg_center_location_stop(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); - /* SPORT */ errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -errcode_t msg_center_sport_get_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); -errcode_t msg_center_sport_report_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_sport_get_record(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); /* 离线日志开关 */ errcode_t msg_center_offline_log_switch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); @@ -94,6 +76,12 @@ errcode_t msg_center_offline_log_switch(uint8_t cmd_id, uint8_t type, void *usr_ /* 查找手机 */ errcode_t msg_center_device_findphone(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +/* 天气 */ +errcode_t msg_center_device_sync_weather_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* 日历 */ +errcode_t msg_center_device_sync_date_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + /* CAMERA */ errcode_t msg_center_camera_exit(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t msg_center_camera_online(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); diff --git a/code/sdk/application/wearable/evb/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/evb/service/msg_center/CMakeLists.txt index 22745fe22..45c223cac 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/evb/service/msg_center/CMakeLists.txt @@ -3,7 +3,6 @@ set(COMPONENT_NAME "msg_center") set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/notify - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/include ) set(PRIVATE_HEADER @@ -17,6 +16,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/application/wearable/service/xiaodu_voice ${ROOT_DIR}/application/wearable/service/watch_setting_msg/include @@ -26,11 +26,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include ${ROOT_DIR}/application/wearable/nativeabilityfwk/include ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits - ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/include - ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include - ${ROOT_DIR}/zhihui/4g/cat1Service - ${ROOT_DIR}/zhihui/4g/cat1Service/include - ${ROOT_DIR}/zhihui/4g/cat1Service/Service ) set(SOURCES @@ -109,6 +104,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audio_player/interfaces/kits ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiomanager ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiocommon @@ -135,7 +131,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_customer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/alarm_notification.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/calendar_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_common.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_self_cmd.cpp @@ -147,7 +143,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_customer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/alarm_notification.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/src/NotifyOnKeyListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/phone_msg_notification.cpp ) diff --git a/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-cli/libmsg_center.a b/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-cli/libmsg_center.a index c6b588af4..f787fb876 100644 Binary files a/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-cli/libmsg_center.a and b/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-cli/libmsg_center.a differ diff --git a/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-ser/libmsg_center.a b/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-ser/libmsg_center.a index 19e2cb51d..59d450a64 100644 Binary files a/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-ser/libmsg_center.a and b/code/sdk/application/wearable/evb/service/msg_center/brandy-auto-ota-ser/libmsg_center.a differ diff --git a/code/sdk/application/wearable/evb/service/msg_center/brandy-native-js/libmsg_center.a b/code/sdk/application/wearable/evb/service/msg_center/brandy-native-js/libmsg_center.a index b1e105a9c..7e69f1c2a 100644 Binary files a/code/sdk/application/wearable/evb/service/msg_center/brandy-native-js/libmsg_center.a and b/code/sdk/application/wearable/evb/service/msg_center/brandy-native-js/libmsg_center.a differ diff --git a/code/sdk/application/wearable/evb/service/msg_center/brandy-xts/libmsg_center.a b/code/sdk/application/wearable/evb/service/msg_center/brandy-xts/libmsg_center.a index 7f842a9c9..26ab44fdc 100644 Binary files a/code/sdk/application/wearable/evb/service/msg_center/brandy-xts/libmsg_center.a and b/code/sdk/application/wearable/evb/service/msg_center/brandy-xts/libmsg_center.a differ diff --git a/code/sdk/application/wearable/evb/service/msg_center/include/msg_center_msg.h b/code/sdk/application/wearable/evb/service/msg_center/include/msg_center_msg.h index ae8cc4d84..3d25dfeb0 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/include/msg_center_msg.h +++ b/code/sdk/application/wearable/evb/service/msg_center/include/msg_center_msg.h @@ -19,6 +19,7 @@ typedef enum { BT_CONNECTED_TO_MSGCENTER, MSGCENTER_ADD_SLEEP_VETO, MSGCENTER_RM_SLEEP_VETO, + CALENDAR_TO_MSGCENTER, } MsgCenterServiceMsgId; #ifdef __cplusplus diff --git a/code/sdk/application/wearable/evb/service/msg_center/include/notify/calendar_notification.h b/code/sdk/application/wearable/evb/service/msg_center/include/notify/calendar_notification.h new file mode 100644 index 000000000..4f341bbc5 --- /dev/null +++ b/code/sdk/application/wearable/evb/service/msg_center/include/notify/calendar_notification.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: calendar notification api + * Author: CompanyName + * Create: 2025-10-23 + */ + +#ifndef CALENDAR_NOTIFICATION_H +#define CALENDAR_NOTIFICATION_H + +static constexpr const char* CALENDAR_IMAGE_DELETE = "calendar_delete"; +static constexpr const char* CALENDAR_IMAGE_CLOCK = "calendar_clock"; +static constexpr const char* CALENDAR_VIEW_CLOSE = "calendar_close"; +static constexpr const char* CALENDAR_VIEW_DELAY = "calendar_delay"; +static constexpr const char* CALENDAR_VIEW_POPUP = "calendar_popup"; + +enum class CalendarTimerType { + NOTIFY_CALENDAR_CLOSE = 0, + NOTIFY_CALENDAR_DELAY = 1, + NOTIFY_CALENDAR_RING = 2, + NOTIFY_CALENDAR_UNKNOWN = 10, +}; + +typedef struct { + int id; + int type; + int64_t startTime; + int64_t endTime; + bool isAllDay; + bool hasReminder; + bool isRepeat; + int64_t recurrenceFrequency; + char bundlename[64]; // 外部传入字符串,内部不负责释放 + char eventContent[256]; +} CalendarEvent; + + +namespace OHOS { +UIViewGroup* CreateCalendarView(CalendarEvent *event); +void FreeCalendarView(void); + +class CalendarViewEventListener : public OHOS::UIView::OnClickListener, + public OHOS::UIView::OnLongPressListener, + public OHOS::UIView::OnTouchListener, + public OHOS::UIView::OnDragListener { +public: + CalendarViewEventListener(); + virtual ~CalendarViewEventListener(); + static CalendarViewEventListener *GetInstance(void); + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event) override; + bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event) override; + bool OnPress(OHOS::UIView& view, const OHOS::PressEvent& event) override + { + return true; + } + bool OnLongPress(OHOS::UIView& view, const OHOS::LongPressEvent& event) override + { + return true; + } + bool OnRelease(OHOS::UIView& view, const OHOS::ReleaseEvent& event) override + { + return true; + } + + bool OnDragStart(OHOS::UIView& view, const OHOS::DragEvent& event) override + { + return true; + } +}; +}; // namespace OHOS + +#endif /* CALENDAR_NOTIFICATION_H */ \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/service/msg_center/include/notify/notification_manager.h b/code/sdk/application/wearable/evb/service/msg_center/include/notify/notification_manager.h index 345828de1..c378b5af6 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/include/notify/notification_manager.h +++ b/code/sdk/application/wearable/evb/service/msg_center/include/notify/notification_manager.h @@ -23,8 +23,8 @@ #include "components/root_view.h" #include "components/ui_view_group.h" #include "alarm_notification.h" -#include "makephone_notification.h" #include "phone_msg_notification.h" +#include "calendar_notification.h" constexpr uint16_t HALF_SCREEN = 2; constexpr int16_t NOTIFY_PRIORITY_DEFAULT = 4; diff --git a/code/sdk/application/wearable/evb/service/msg_center/include/notify/phone_msg_notification.h b/code/sdk/application/wearable/evb/service/msg_center/include/notify/phone_msg_notification.h index 735c01edf..8a4a34165 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/include/notify/phone_msg_notification.h +++ b/code/sdk/application/wearable/evb/service/msg_center/include/notify/phone_msg_notification.h @@ -1,19 +1,21 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. - * Description: phone message notification - * Author: + * Description: phone message notification + * Author: * Create: 2025-04-25 */ #ifndef PHONE_MSG_NOTIFICATION_H #define PHONE_MSG_NOTIFICATION_H +#include #include "components/ui_view_group.h" #include "components/ui_view_group.h" #include "components/ui_label.h" +#include "components/ui_image_view.h" #include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" #include "graphic_timer.h" -#include struct PhoneMsg { std::string appName; @@ -29,11 +31,14 @@ public: static void UpDatePhoneMsg(std::string appName, std::string titile, std::string content); static void StartPhoneMsgTimer(int32_t interval); static void DisablePhoneMsgTimer(); + static void ShowDateMsg(std::string appName, std::string title, std::string content); + static void SetControl(); static const uint32_t notifyTime = 5000; private: - static UIViewGroup *phoneMsgView_; + static UIScrollView *phoneMsgView_; static UILabel *appNameLabel_; + static UIImageView *appIcon_; static UILabel *titleLabel_; static UILabel *contentLabel_; static GraphicTimer *phoneMsgNotifyStop_; diff --git a/code/sdk/application/wearable/evb/service/msg_center/src/common/msg_center_utils.cpp b/code/sdk/application/wearable/evb/service/msg_center/src/common/msg_center_utils.cpp index 56f8f9e11..6647df929 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/src/common/msg_center_utils.cpp +++ b/code/sdk/application/wearable/evb/service/msg_center/src/common/msg_center_utils.cpp @@ -14,6 +14,7 @@ #include "element_name.h" #include "abilityms_slite_client.h" #include +#include "appexecfwk_errors.h" #ifdef __cplusplus extern "C" { @@ -64,12 +65,15 @@ errcode_t msg_center_install_js_app(char *bundleName) bool msg_center_is_js_app_install(char *bundleName) { - InstallState installState; - uint8_t installProcess; - OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName, &installState, &installProcess); - if (installState == BUNDLE_INSTALL_OK) { + if (bundleName == nullptr) { + return false; + } + BundleInfo bundleInfo; + uint8_t ret = OHOS::BundleMsClient::GetInstance().GetBundleInfo(bundleName, false, &bundleInfo); + if (ret == ERR_OK) { return true; } + return false; } diff --git a/code/sdk/application/wearable/evb/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/evb/service/msg_center/src/msg_center_customer.cpp index 6a39ae2a8..aeb792c6a 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/evb/service/msg_center/src/msg_center_customer.cpp @@ -16,7 +16,7 @@ #include "broadcast_service.h" #include "alarm/AlarmClockModel.h" #include "alarm/AlarmPopUpPresenter.h" -#include "callerlog/CallerLogModel.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" #include "notification_manager.h" #include "NativeAbility.h" #include "abilityms_slite_client.h" @@ -34,29 +34,23 @@ #include "main/VolumeSettingPresenter.h" #include "main/VolumeSettingView.h" #include "cJSON.h" -#include "heartrate/HeartModel.h" -#include "device_location.h" +#include "heartrate/HeartRateModel.h" +#include "phonemenu/PhoneMenuView.h" + namespace OHOS { #ifdef __cplusplus extern "C" { #endif -#ifdef SUPPORT_CYWEE_SERVICE -#include "cywee_data.h" -#include "cywee_hal.h" -#endif - extern uint8_t g_bloodoxygen; -extern uint16_t g_heartrate; +extern uint8_t g_heartrate; extern uint32_t g_stepdata; extern uint32_t g_distance; -extern LocationInfo_t g_locationInfo; /* 订阅事件设定优先级 */ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_ALARM_RING, PRIORITY_TWO}, - {TOPIC_EVENT_ON_TIME,PRIORITY_TWO}, {TOPIC_EVENT_NEXTDAY_UPDATE, PRIORITY_TWO}, {TOPIC_EVENT_HFP_INCOMMING, PRIORITY_ONE}, {TOPIC_EVENT_HFP_FINISHED, PRIORITY_ONE}, @@ -69,12 +63,12 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_HEARTRATE_UPDATA, PRIORITY_TWO}, {TOPIC_EVENT_BLOODOXYGEN_UPDATA, PRIORITY_TWO}, {TOPIC_EVENT_SPORT_DISTANCE, PRIORITY_TWO}, - {TOPIC_EVENT_LOCATION, PRIORITY_TWO}, + {TOPIC_EVENT_CALENDAR_NOTIFY, PRIORITY_TWO}, }; bool g_pressFlag = false; bool g_longPressFlag = false; - +CalendarEvent *g_tmpevent = nullptr; static bool CheckPriority(const Topic topic) { uint16_t mapperSize = sizeof(PRI_MAPPER) / sizeof(PRI_MAPPER[0]); @@ -95,7 +89,6 @@ static bool CheckPriority(const Topic topic) void MsgCenterSubscribe() { MsgCenterSubscribeTopic(TOPIC_EVENT_ALARM_RING); - MsgCenterSubscribeTopic(TOPIC_EVENT_ON_TIME); MsgCenterSubscribeTopic(TOPIC_EVENT_NEXTDAY_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_INCOMMING); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_PHONE_ACTIVE); @@ -107,7 +100,6 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA); MsgCenterSubscribeTopic(TOPIC_EVENT_BLOODOXYGEN_UPDATA); MsgCenterSubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE); - MsgCenterSubscribeTopic(TOPIC_EVENT_LOCATION); } static OHOS::UIViewGroup* ShowAlarmNotify(void) @@ -115,19 +107,21 @@ static OHOS::UIViewGroup* ShowAlarmNotify(void) return OHOS::CreateAlarmView(); } -static OHOS::UIViewGroup* ShowPhoneCallNotify(void) -{ - return OHOS::CreatePhoneCallView(); -} - -static OHOS::UIViewGroup* ShowCallingNotify(void) +static OHOS::UIViewGroup* ShowCalendarNotify(void) { - return OHOS::CreateCallingView(); -} - -static OHOS::UIViewGroup* ShowMultiPhoneCallNotify(void) -{ - return OHOS::CreateMultiplePhoneView(); + // only show one notify + if (!g_tmpevent) { + return nullptr; + } + OHOS::UIViewGroup* group = OHOS::CreateCalendarView(g_tmpevent); + if (g_tmpevent) { + free(g_tmpevent); + g_tmpevent = nullptr; + } + if (!group) { + return nullptr; + } + return group; } static OHOS::UIViewGroup* ShowMsgNotify(void) @@ -139,7 +133,6 @@ static OHOS::UIViewGroup* ShowMsgNotify(void) void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { unused(req); - // The alarm notification is not displayed if the incoming call notification is already being processed if (CheckPriority(topic)) { AlarmClockModel::GetInstance()->PopInterPlayMusic(); NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); @@ -152,6 +145,26 @@ void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) } } +void MsgCenterNotifyCalendarProc(const Topic topic, Request* req) +{ + if (g_tmpevent == nullptr) { + g_tmpevent = (CalendarEvent *)malloc(sizeof(CalendarEvent)); + if (g_tmpevent == nullptr) { + return; + } + } else { + return; + } + if (memcpy_s(g_tmpevent, sizeof(CalendarEvent), req->data, sizeof(CalendarEvent)) != EOK) { + return; + } + // The alarm notification is not displayed if the incoming call notification is already being processed + if (CheckPriority(topic)) { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(ShowCalendarNotify, static_cast(topic), true); + } +} + void MsgCenterNotifyNextDayProc(const Topic topic, Request* req) { unused(topic); @@ -168,14 +181,22 @@ void MsgCenterNotifyHfpIncomingProc(const Topic topic, Request* req) } else { // Prevent this from happening: // When the incoming call view is displayed, the calling number is not set in CallerLogModel. - CallerLogModel::GetInstance()->SetoperateNumber(callData.number, callData.number_len); + PhoneMenuCallerLogModel::GetInstance()->SetoperateNumber(callData.number, callData.number_len); } NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); - CallerLogModel::GetInstance()->SetNotifyFlag(true); + PhoneMenuCallerLogModel::GetInstance()->SetNotifyFlag(true); if (GetCurrCallNum() == 1) { - NotificationManager::GetInstance()->ShowNotify(ShowPhoneCallNotify, static_cast(topic), true); + PhoneMenuCallerLogModel::GetInstance()->SaveCurPage(); + } else { + PhoneMenuCallerLogModel::GetInstance()->SetCallStatus(false); + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(true); + } + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); } else { - EnableWaitingView(); + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); } NotificationManager::GetInstance()->SetWatchCallStatus(true); } @@ -184,10 +205,10 @@ void MsgCenterNotifyHfpPhoneProc(const Topic topic, Request* req) { unused(req); // finish a single-channel call, or switch to phone, stop the notify - if (CallerLogModel::GetInstance()->GetNotifyFlag()) { - DisableWatingView(); + if (PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); if ((topic == TOPIC_EVENT_HFP_FINISHED && GetCurrCallNum() == 0) || - topic == TOPIC_EVENT_HFP_PHONE_ACTIVE || topic == TOPIC_EVENT_HFP_WATCH_TO_PHONE) { + topic == TOPIC_EVENT_HFP_PHONE_ACTIVE || topic == TOPIC_EVENT_HFP_WATCH_TO_PHONE) { NotificationManager::GetInstance()->StopNotify(); NotificationManager::GetInstance()->SetWatchCallStatus(false); } @@ -197,15 +218,20 @@ void MsgCenterNotifyHfpPhoneProc(const Topic topic, Request* req) void MsgCenterNotifyHfpWatchProc(const Topic topic, Request* req) { unused(req); - if (CallerLogModel::GetInstance()->GetNotifyFlag()) { + if (PhoneMenuCallerLogModel::GetInstance()->GetNotifyFlag()) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); // default not mute SetMicMute(false); - if (CallerLogModel::GetInstance()->IsMulitplePhoneStatus()) { - NotificationManager::GetInstance()->ShowNotify(ShowMultiPhoneCallNotify, - static_cast(topic), true); + PhoneMenuCallerLogModel::GetInstance()->SetMicMute(false); + if (PhoneMenuCallerLogModel::GetInstance()->IsMulitplePhoneStatus()) { + PhoneMenuCallerLogModel::GetInstance()->SetWaitingStatus(false); + } + uint32_t targetId = NativeAbility::GetInstance().GetCurSliceId(); + if (targetId == VIEW_PHONE_MENU) { + NativeAbility::GetInstance().SwitchPageInSlice(PhoneMenuPages::PHONE_MENU_CALLING_PAGE, + TransitionType::TRANSITION_INVALID, false); } else { - NotificationManager::GetInstance()->ShowNotify(ShowCallingNotify, static_cast(topic), true); + NativeAbility::GetInstance().SwitchSlice(VIEW_PHONE_MENU, PhoneMenuPages::PHONE_MENU_CALLING_PAGE); } NotificationManager::GetInstance()->SetWatchCallStatus(true); } @@ -278,53 +304,9 @@ void MsgCenterNotifyDistanceProc(const Topic topic, Request* req) } } -void MsgCenterNotifyLocationProc(const Topic topic, Request* req) -{ - unused(topic); - if(req && req->data){ - LocationInfo_t* location = (LocationInfo_t*)req->data; - g_locationInfo.latitude_ = location->latitude_; - g_locationInfo.longitude_ = location->longitude_; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "latitude_:%d,longitude_:%d\n", g_locationInfo.latitude_, g_locationInfo.longitude_); - } -} - - -void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) -{ - unused(req); - AlarmClockEventData* time=(AlarmClockEventData*)req->data; - // The alarm notification is not displayed if the incoming call notification is already being processed -#ifdef SUPPORT_CYWEE_SERVICE - cywee_save_data(); - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数"); - - cywee_step_history_save(time->value); - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时站立数据"); - if(cywee_get_stand_flag()) - { - cywee_stand_history_save(time->value); - } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时卡路里数据"); - - cywee_calories_history_save(time->value); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时距离数据"); - - cywee_distances_history_save(time->value); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时燃脂数据"); - - cywee_fat_history_save(time->value); -#endif - // 保存完增加一次读取数据 - SendMsgToUIService(UI_UPDATE_GOAL, 0, nullptr, 0); -} - /* 订阅事件通知逻辑可定制 */ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc}, - {TOPIC_EVENT_ON_TIME, MsgCenterNotifyONtimeProc},//增加整点保存数据 {TOPIC_EVENT_NEXTDAY_UPDATE, MsgCenterNotifyNextDayProc}, {TOPIC_EVENT_HFP_INCOMMING, MsgCenterNotifyHfpIncomingProc}, {TOPIC_EVENT_HFP_PHONE_ACTIVE, MsgCenterNotifyHfpPhoneProc}, @@ -337,7 +319,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_STEPDATA_UPDATE, MsgCenterNotifyStepDataProc}, {TOPIC_EVENT_BLOODOXYGEN_UPDATA, MsgCenterNotifyBloodOxygenProc}, {TOPIC_EVENT_SPORT_DISTANCE, MsgCenterNotifyDistanceProc}, - {TOPIC_EVENT_LOCATION, MsgCenterNotifyLocationProc}, + {TOPIC_EVENT_CALENDAR_NOTIFY, MsgCenterNotifyCalendarProc}, }; static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx) diff --git a/code/sdk/application/wearable/evb/service/msg_center/src/notify/calendar_notification.cpp b/code/sdk/application/wearable/evb/service/msg_center/src/notify/calendar_notification.cpp new file mode 100644 index 000000000..32a93e002 --- /dev/null +++ b/code/sdk/application/wearable/evb/service/msg_center/src/notify/calendar_notification.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: calendar notification implement + * Author: CompanyName + * Create: 2025-10-23 + */ + +#include "notification_manager.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "ability_manager.h" + +namespace OHOS { +constexpr int32_t NOTIFY_THREE_SECONDS = 3000; +constexpr int32_t NOTIFY_ONE_SECOND = 1000; +constexpr int32_t NOTIFY_THIRTY_SECONDS = 30000; +constexpr int32_t NOTIFY_ONE_MINUTE = 60000; +constexpr int32_t NOTOFY_NO_OPERATE_TIME = 35000; + +UIViewGroup* g_calendarView = nullptr; +UIImageView* g_calendarExit = nullptr; +UIImageView* g_calendarConfirm = nullptr; +UILabel* g_tooltip = nullptr; +// calendar close view +constexpr int16_t MAX_SET_SRC_LEN = 90; +char g_bundlename[256] = {0}; +// calendar main view +constexpr int16_t CONTAINER_X = 0; +constexpr int16_t CONTAINER_Y = 0; +constexpr int16_t IMAGE_DELETE_X = 85; +constexpr int16_t IMAGE_DELETE_Y = 300; +constexpr int16_t IMAGE_CLOCK_X = 275; +constexpr int16_t IMAGE_CLOCK_Y = 300; +constexpr int16_t BASE_YEARS = 1900; + +// calendar delay view +constexpr int16_t DELAY_LABEL_X = 80; +constexpr int16_t DELAY_LABEL_Y = 100; +constexpr int16_t DELAY_LABEL_LENGTH = 350; +constexpr int16_t DELAY_LABEL_HEIGHT = 35; +constexpr int16_t DELAY_LABEL_FONT = 25; + +static bool CreateCalendarViewImage(void) +{ + g_calendarExit = new UIImageView(); + if (g_calendarExit == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showCalendarNotify g_calendarExit null!"); + return false; + } + g_calendarExit->SetPosition(IMAGE_DELETE_X, IMAGE_DELETE_Y); + g_calendarExit->SetWidth(MAX_SET_SRC_LEN); + g_calendarExit->SetHeight(MAX_SET_SRC_LEN); + g_calendarExit->SetViewId(CALENDAR_IMAGE_DELETE); + g_calendarExit->SetSrc(ALARM_DELETE_ADD_PATH); + g_calendarExit->SetTouchable(true); + UIView::OnClickListener *closeListener = static_cast\ + (CalendarViewEventListener::GetInstance()); + g_calendarExit->SetOnClickListener(closeListener); + g_calendarConfirm = new UIImageView(); + if (g_calendarConfirm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showCalendarNotify g_calendarConfirm null!"); + delete g_calendarExit; + return false; + } + g_calendarConfirm->SetPosition(IMAGE_CLOCK_X, IMAGE_CLOCK_Y); + g_calendarConfirm->SetWidth(MAX_SET_SRC_LEN); + g_calendarConfirm->SetHeight(MAX_SET_SRC_LEN); + g_calendarConfirm->SetViewId(CALENDAR_IMAGE_CLOCK); + g_calendarConfirm->SetSrc(ALARM_CLOCK_ADD_PATH); + g_calendarConfirm->SetTouchable(true); + UIView::OnClickListener *clockListener = static_cast\ + (OHOS::CalendarViewEventListener::GetInstance()); + g_calendarConfirm->SetOnClickListener(clockListener); + return true; +} + +static void FreeCalendarViewImage(void) +{ + delete g_calendarExit; + g_calendarExit = nullptr; + delete g_calendarConfirm; + g_calendarConfirm = nullptr; +} + +static const char* GetFormatTimestamp(long long timestamp) +{ + static char buffer[20]; + + time_t seconds = (time_t)(timestamp / NOTIFY_ONE_SECOND); + + struct tm *localTime = localtime(&seconds); + if (localTime == NULL) { + return NULL; + } + + int size = sprintf_s(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", + localTime->tm_year + BASE_YEARS, + localTime->tm_mon + 1, + localTime->tm_mday, + localTime->tm_hour, + localTime->tm_min, + localTime->tm_sec); + if (size < 0) { + return NULL; + } + return buffer; +} + +UIViewGroup* CreateCalendarView(CalendarEvent *event) +{ + g_calendarView = new UIViewGroup(); + if (g_calendarView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateCalendarView g_calendarView null!"); + return nullptr; + } + g_calendarView->SetPosition(CONTAINER_X, CONTAINER_Y, + Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + g_calendarView->SetViewId(CALENDAR_VIEW_POPUP); + + if (!CreateCalendarViewImage()) { + delete g_calendarView; + g_calendarView = nullptr; + return nullptr; + } + g_tooltip = new UILabel(); + if (g_tooltip == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmRingView::g_tooltip null!"); + delete g_calendarView; + g_calendarView = nullptr; + FreeCalendarViewImage(); + return nullptr; + } + g_tooltip->SetPosition(DELAY_LABEL_X, DELAY_LABEL_Y, DELAY_LABEL_LENGTH, DELAY_LABEL_HEIGHT); + g_tooltip->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + g_tooltip->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DELAY_LABEL_FONT); + char text[256] = {0}; + int size = sprintf_s(text, sizeof(text), "id = %d bundle = %s eventContent = %s starttime = %s", + event->id, event->bundlename, event->eventContent, GetFormatTimestamp(event->startTime)); + memset_s(g_bundlename, sizeof(g_bundlename), 0, sizeof(g_bundlename)); + int ret = memcpy_s(g_bundlename, sizeof(g_bundlename), event->bundlename, strlen(event->bundlename)); + if (size < 0 || ret != EOK) { + FreeCalendarView(); + return nullptr; + } + g_tooltip->SetText(text); + g_calendarView->Add(g_calendarExit); + g_calendarView->Add(g_calendarConfirm); + g_calendarView->Add(g_tooltip); + g_calendarView->SetDraggable(true); + g_calendarView->SetTouchable(true); + UIView::OnDragListener *listener = static_cast(CalendarViewEventListener::GetInstance()); + g_calendarView->SetOnDragListener(listener); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeCalendarView); + return g_calendarView; +} +void FreeCalendarView(void) +{ + if (g_calendarView != nullptr) { + g_calendarView->RemoveAll(); + FreeCalendarViewImage(); + delete g_tooltip; + g_tooltip = nullptr; + RootView::GetInstance()->Remove(g_calendarView); + delete g_calendarView; + g_calendarView = nullptr; + } +} + +CalendarViewEventListener::CalendarViewEventListener() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalendarViewEventListener :%p", this); +} + +CalendarViewEventListener::~CalendarViewEventListener() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~CalendarViewEventListener"); +} + +CalendarViewEventListener *CalendarViewEventListener::GetInstance(void) +{ + static CalendarViewEventListener calendarViewEventListener; + return &calendarViewEventListener; +} + +bool CalendarViewEventListener::OnDrag(UIView& view, const DragEvent& event) +{ + return true; +} + +bool CalendarViewEventListener::OnDragEnd(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if (strcmp(view.GetViewId(), CALENDAR_VIEW_POPUP) == 0) { + NotificationManager::GetInstance()->screenContainer_->SetVisible(false); + NotificationManager::GetInstance()->StopNotify(); + } else if (strcmp(view.GetViewId(), CALENDAR_VIEW_CLOSE) == 0 || + strcmp(view.GetViewId(), CALENDAR_VIEW_DELAY) == 0) { + NotificationManager::GetInstance()->screenContainer_->SetVisible(false); + NotificationManager::GetInstance()->StopNotify(); + } + } + return true; +} + +bool CalendarViewEventListener::OnClick(UIView& view, const ClickEvent& event) +{ + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlamNotify ClickListener %s", view.GetViewId()); + if (strcmp(view.GetViewId(), CALENDAR_IMAGE_DELETE) == 0) { + NotificationManager::GetInstance()->screenContainer_->SetVisible(false); + Want *want = new Want(); + memset_s(want, sizeof(Want), 0, sizeof(Want)); + ElementName startElement = {}; + startElement.abilityName = (char *)"default"; + startElement.bundleName = g_bundlename; + startElement.deviceId = nullptr; + SetWantElement(want, startElement); + StartAbility(want); + ClearWant(want); + delete want; + NotificationManager::GetInstance()->StopNotify(); + } else if (strcmp(view.GetViewId(), CALENDAR_IMAGE_CLOCK) == 0) { + NotificationManager::GetInstance()->screenContainer_->SetVisible(false); + NotificationManager::GetInstance()->StopNotify(); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp b/code/sdk/application/wearable/evb/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp index cfff9a774..d1958e345 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp +++ b/code/sdk/application/wearable/evb/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp @@ -18,9 +18,9 @@ #include "dock/input_device.h" #include "notification_manager.h" #include "alarm/AlarmPopUpPresenter.h" -#include "callerlog/CallerLogModel.h" -#include "makephone/MainCallingPresenter.h" +#include "phonemenu/PhoneMenuCallerLogModel.h" #include "applist/ApplistModel.h" + namespace OHOS { static bool IsNotifyCallStatus() { diff --git a/code/sdk/application/wearable/evb/service/msg_center/src/notify/phone_msg_notification.cpp b/code/sdk/application/wearable/evb/service/msg_center/src/notify/phone_msg_notification.cpp index eb6a40883..9000a1d69 100644 --- a/code/sdk/application/wearable/evb/service/msg_center/src/notify/phone_msg_notification.cpp +++ b/code/sdk/application/wearable/evb/service/msg_center/src/notify/phone_msg_notification.cpp @@ -9,41 +9,45 @@ #include "wearable_log.h" #include #include "main/MessageModel.h" +#include "ui_resource_message.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" namespace OHOS { // 三方应用名 -static const uint32_t APP_NAME_POS_X = 180; -static const uint32_t APP_NAME_POS_Y = 82; -static const uint32_t APP_NAME_WIDTH = 200; -static const uint32_t APP_NAME_HEIGHT = 60; +static const uint32_t APP_NAME_POS_X = 170; +static const uint32_t APP_NAME_POS_Y = 40; +static const uint32_t APP_NAME_WIDTH = 160; +static const uint32_t APP_NAME_HEIGHT = 53; // 三方消息主题 -static const uint32_t MSG_TITLE_POS_X = 81; -static const uint32_t MSG_TITLE_POS_Y = 122; -static const uint32_t MSG_TITLE_WIDTH = 409; -static const uint32_t MSG_TITLE_HEIGHT = 83; +static const uint32_t MSG_TITLE_POS_X = 15; +static const uint32_t MSG_TITLE_POS_Y = 138; +static const uint32_t MSG_TITLE_WIDTH = 370; +static const uint32_t MSG_TITLE_HEIGHT = 50; // 三方消息内容 -static const uint32_t MSG_CONTENT_POS_X = 78; -static const uint32_t MSG_CONTENT_POS_Y = 176; -static const uint32_t MSG_CONTENT_WIDTH = 457; -static const uint32_t MSG_CONTENT_HEIGHT = 269; -// 取消通知 -static const uint32_t CANCEL_BUTTON_POS_X = 150; -static const uint32_t CANCEL_BUTTON_POS_Y = 323; -static const uint32_t CANCEL_BUTTON_WIDTH = 165; -static const uint32_t CANCEL_BUTTON_HEIGHT = 44; +static const uint32_t MSG_CONTENT_POS_X = 15; +static const uint32_t MSG_CONTENT_POS_Y = 201; +static const uint32_t MSG_CONTENT_WIDTH = 370; +static const uint32_t MSG_CONTENT_HEIGHT = 200; +// 通知图标 +static const uint32_t MSG_ICON_POS_X = 130; +static const uint32_t MSG_ICON_POS_Y = 50; +static const uint32_t MSG_ICON_WIDTH = 40; +static const uint32_t MSG_ICON_HEIGHT = 40; +static const uint32_t MSG_PAGE_WIDTH = 454; // 设置字体大小 -static const uint32_t APP_NAME_FONT_SIZE = 20; -static const uint32_t MSG_TITLE_FONT_SIZE = 20; -static const uint32_t MSG_CONTENT_FONT_SIZE = 40; +static const uint32_t APP_NAME_FONT_SIZE = 38; +static const uint32_t MSG_TITLE_FONT_SIZE = 36; +static const uint32_t MSG_CONTENT_FONT_SIZE = 36; -UIViewGroup *PhoneMsgView::phoneMsgView_ = nullptr; +UIScrollView *PhoneMsgView::phoneMsgView_ = nullptr; UILabel *PhoneMsgView::appNameLabel_ = nullptr; +UIImageView *PhoneMsgView::appIcon_ = nullptr; UILabel *PhoneMsgView::titleLabel_ = nullptr; UILabel *PhoneMsgView::contentLabel_ = nullptr; GraphicTimer *PhoneMsgView::phoneMsgNotifyStop_ = nullptr; PhoneMsg PhoneMsgView::phoneMsg_; -UILabelButtonExt *PhoneMsgView::cancelButton_ = nullptr; void PhoneMsgStopNotifyCallback(void *data) { @@ -71,9 +75,11 @@ void PhoneMsgView::DisablePhoneMsgTimer() UIViewGroup *PhoneMsgView::CreatePhoneMsgView() { if (phoneMsgView_ == nullptr) { - phoneMsgView_ = new UIViewGroup(); - phoneMsgView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + phoneMsgView_ = new UIScrollView(); + phoneMsgView_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); phoneMsgView_->SetViewId("phoneMsgView"); + phoneMsgView_->SetThrowDrag(true); + phoneMsgView_->SetScrollBlankSize(40); } if (appNameLabel_ == nullptr) { @@ -83,20 +89,22 @@ UIViewGroup *PhoneMsgView::CreatePhoneMsgView() appNameLabel_->SetText(phoneMsg_.appName.c_str()); appNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, APP_NAME_FONT_SIZE); appNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - // Add to rootView phoneMsgView_->Add(appNameLabel_); - appNameLabel_->SetVisible(true); + + if (appIcon_ == nullptr) { + appIcon_ = new UIImageView(); + } + appIcon_->SetPosition(MSG_ICON_POS_X, MSG_ICON_POS_Y, MSG_ICON_WIDTH, MSG_ICON_HEIGHT); + phoneMsgView_->Add(appIcon_); + appIcon_->SetVisible(true); if (titleLabel_ == nullptr) { titleLabel_ = new UILabel(); } titleLabel_->SetPosition(MSG_TITLE_POS_X, MSG_TITLE_POS_Y, MSG_TITLE_WIDTH, MSG_TITLE_HEIGHT); - titleLabel_->SetText(phoneMsg_.msgTitle.c_str()); titleLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MSG_TITLE_FONT_SIZE); titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - // Add to rootView phoneMsgView_->Add(titleLabel_); - titleLabel_->SetVisible(true); if (contentLabel_ == nullptr) { contentLabel_ = new UILabel(); @@ -105,21 +113,11 @@ UIViewGroup *PhoneMsgView::CreatePhoneMsgView() contentLabel_->SetText(phoneMsg_.msgContent.c_str()); contentLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MSG_CONTENT_FONT_SIZE); contentLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - // Add to rootView + contentLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); phoneMsgView_->Add(contentLabel_); - contentLabel_->SetVisible(true); - - if (cancelButton_ == nullptr) { - cancelButton_ = new UILabelButtonExt(); - } - cancelButton_->SetPosition(CANCEL_BUTTON_POS_X, CANCEL_BUTTON_POS_Y, CANCEL_BUTTON_WIDTH, CANCEL_BUTTON_HEIGHT); - cancelButton_->SetViewId("cancelButton"); - cancelButton_->SetText("取消通知"); - cancelButton_->SetTouchable(true); - cancelButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, APP_NAME_FONT_SIZE); - // Add to rootView - phoneMsgView_->Add(cancelButton_); + SetControl(); + phoneMsgView_->Invalidate(); phoneMsgView_->SetDraggable(true); phoneMsgView_->SetTouchable(true); UIView::OnDragListener *dragListener = @@ -128,29 +126,78 @@ UIViewGroup *PhoneMsgView::CreatePhoneMsgView() static_cast(PhoneMsgViewEventListener::GetInstance()); phoneMsgView_->SetOnDragListener(dragListener); phoneMsgView_->SetOnClickListener(clickListener); - cancelButton_->SetOnClickListener(clickListener); StartPhoneMsgTimer(PhoneMsgView::notifyTime); NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreePhoneMsgView); return phoneMsgView_; } +void PhoneMsgView::SetControl() +{ + if (strcmp(phoneMsg_.appName.c_str(), "微信") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WX); + } else if (strcmp(phoneMsg_.appName.c_str(), "QQ") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_QQ); + } else if (strcmp(phoneMsg_.appName.c_str(), "抖音") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DY); + } else if (strcmp(phoneMsg_.appName.c_str(), "日历") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_CALENDAR); + } else if (strcmp(phoneMsg_.appName.c_str(), "信息") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(phoneMsg_.appName.c_str(), "短信") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_DUANXIN); + } else if (strcmp(phoneMsg_.appName.c_str(), "今日头条") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_TOUTIAO); + } else if (strcmp(phoneMsg_.appName.c_str(), "微博") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_WB); + } else if (strcmp(phoneMsg_.appName.c_str(), "小红书") == 0) { + LOADIMG::LoadImageViewImg(appIcon_, MESSAGE_IMAGE, IMAGE_MESSAGE_XHS); + } + int controlOffset = 10; + int cut = 2; + int posX = (MSG_PAGE_WIDTH - appNameLabel_->GetTextWidth() - appIcon_->GetWidth() - controlOffset) / cut; + appIcon_->SetX(posX); + appNameLabel_->SetWidth(appNameLabel_->GetTextWidth()); + appNameLabel_->SetX(posX + appIcon_->GetWidth() + controlOffset); + + titleLabel_->SetText(phoneMsg_.msgTitle.c_str()); + if (titleLabel_->GetTextWidth() > MSG_TITLE_WIDTH) { + titleLabel_->SetWidth(MSG_TITLE_WIDTH); + } else { + titleLabel_->SetWidth(titleLabel_->GetTextWidth()); + } + titleLabel_->SetX((MSG_PAGE_WIDTH - titleLabel_->GetWidth()) / cut); + + int height = contentLabel_->GetTextHeight(); + contentLabel_->SetHeight(height); + posX = (MSG_PAGE_WIDTH - contentLabel_->GetWidth()) / cut; + contentLabel_->SetX(posX); +} + void PhoneMsgView::FreePhoneMsgView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreePhoneMsgView"); if (phoneMsgView_ != nullptr) { DisablePhoneMsgTimer(); phoneMsgView_->RemoveAll(); + RootView::GetInstance()->Remove(phoneMsgView_); + delete phoneMsgView_; + phoneMsgView_ = nullptr; + } + if (appNameLabel_ != nullptr) { delete appNameLabel_; appNameLabel_ = nullptr; + } + if (appIcon_ != nullptr) { + delete appIcon_; + appIcon_ = nullptr; + } + if (titleLabel_ != nullptr) { delete titleLabel_; titleLabel_ = nullptr; + } + if (contentLabel_ != nullptr) { delete contentLabel_; contentLabel_ = nullptr; - delete cancelButton_; - cancelButton_ = nullptr; - RootView::GetInstance()->Remove(phoneMsgView_); - delete phoneMsgView_; - phoneMsgView_ = nullptr; } } @@ -159,7 +206,23 @@ void PhoneMsgView::UpDatePhoneMsg(std::string appName, std::string titile, std:: phoneMsg_.appName = appName; phoneMsg_.msgTitle = titile; phoneMsg_.msgContent = content; - MessageModel::GetInstance().GetMessageInfo(appName, titile, content); + MessageModel::GetInstance().SaveMsgToModel(appName, titile, content); + MessageModel::GetInstance().SetMsgListItems(); +} + +static OHOS::UIViewGroup* ShowMsgNotify(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ShowMsgNotify"); + return OHOS::PhoneMsgView::CreatePhoneMsgView(); +} + +void PhoneMsgView::ShowDateMsg(std::string appName, std::string title, std::string content) +{ + const uint16_t TOPIC_DEMO_ALL_MSG = 10001; + UpDatePhoneMsg(appName, title, content); + int prio = 2; + NotificationManager::GetInstance()->SetNotifyPriority(prio); + NotificationManager::GetInstance()->ShowNotify(ShowMsgNotify, static_cast(TOPIC_DEMO_ALL_MSG), true); } PhoneMsgViewEventListener::PhoneMsgViewEventListener() @@ -188,7 +251,7 @@ bool PhoneMsgViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) std::string viewId = view.GetViewId(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMsgViewEventListener OnDragEnd %s", viewId.c_str()); if (viewId == "phoneMsgView") { - NotificationManager::GetInstance()->StopNotify(); + // NotificationManager::GetInstance()->StopNotify(); } return true; } diff --git a/code/sdk/application/wearable/evb/service/remote_msg/CMakeLists.txt b/code/sdk/application/wearable/evb/service/remote_msg/CMakeLists.txt index f8e5abb7a..4ae08b733 100644 --- a/code/sdk/application/wearable/evb/service/remote_msg/CMakeLists.txt +++ b/code/sdk/application/wearable/evb/service/remote_msg/CMakeLists.txt @@ -6,10 +6,12 @@ set(PUBLIC_HEADER set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${ROOT_DIR}/application/wearable/nativeapp/nativeui/include/phonemenu ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/remote_msg.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/phone_contacts.cpp ) set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.cpp b/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.cpp new file mode 100644 index 000000000..b55356a22 --- /dev/null +++ b/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneContacts + * Create: 2025-07-12 + */ + +#include "wearable_log.h" +#include "message.h" +#include "PhoneMenuSync.h" +#include "phone_contacts.h" + +#ifdef __cplusplus +extern "C" { +#endif +uint8_t updata_contacts(Request *request) +{ + std::string content((char *)request->data, request->len); + uint8_t ret = OHOS::PhoneMenuSync::ParseContactsMsg(content); + if (ret != OHOS::OK) { + return ret; + } + OHOS::PhoneMenuSync::WriteFileContact(OHOS::CONTACTS_FILE_PATH, content); + return 0; +} + +uint8_t lookup_contacts(std::string &lookupContacts) +{ + return OHOS::PhoneMenuSync::LookContacts(lookupContacts); +} +#ifdef __cplusplus +} +#endif diff --git a/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.h b/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.h new file mode 100644 index 000000000..8e517a3f8 --- /dev/null +++ b/code/sdk/application/wearable/evb/service/remote_msg/phone_contacts.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PhoneContacts + * Create: 2025-07-12 + */ + +#ifndef PHONE_CONTACTS_H +#define PHONE_CONTACTS_H +#include +#include "message.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif +uint8_t updata_contacts(Request *request); // 同步手机侧联系人到表侧 +uint8_t lookup_contacts(std::string &lookupContacts); // 查询表侧联系人到手机 +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif /* PHONE_CONTACTS_H */ \ No newline at end of file diff --git a/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.cpp b/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.cpp index a33965430..5f8a4509f 100644 --- a/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.cpp +++ b/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.cpp @@ -1,8 +1,9 @@ /* - * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. * Description: ota upgrade handle. * This file should be changed only infrequently and with great care. */ + #include #include "securec.h" #include "msg_center.h" @@ -13,7 +14,9 @@ #include "msg_center.h" #include "msg_center_common.h" #include "ohos_init.h" +#include "phone_contacts.h" #include "remote_msg.h" + #ifdef __cplusplus extern "C" { #endif @@ -22,6 +25,8 @@ static const msg_center_cmd_map_t g_msg_center_phone_msg_tbl[] = { {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_THIRD_APP, msg_center_phone_msg_rec}, {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_SMS, msg_center_phone_msg_rec}, {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_PHONE, msg_center_phone_msg_rec}, + {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_UPDATE_CONTACTS, msg_center_update_contacts}, + {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_LOOKUP_CONTACTS, msg_center_lookup_contacts}, }; errcode_t msg_center_phone_msg_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) @@ -45,6 +50,50 @@ errcode_t msg_center_phone_msg_rec(uint8_t cmd_id, uint8_t type, void *usr_data, return ERRCODE_SUCC; } +errcode_t msg_center_update_contacts(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t msg_result = 0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "update_contacts, cmd_id = %d, type = %d\r\n", cmd_id, type); + Request request; + request.msgId = type; + request.len = payload_len; + request.data = tlv_payload; + updata_contacts(&request); + ret = msg_center_send_data(cmd_id, type, &msg_result, sizeof(msg_result)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_update_contacts fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_lookup_contacts(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t msg_result = 0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "lookup_contacts, cmd_id = %d, type = %d\r\n", cmd_id, type); + std::string lookupContacts; + uint8_t result = lookup_contacts(lookupContacts); + if (!result) { + ret = msg_center_send_data(cmd_id, type, (void *)lookupContacts.c_str(), lookupContacts.size()); + } else { + ret = msg_center_send_data(cmd_id, type, (void *)&result, 1); + } + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_lookup_contacts fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + + errcode_t msg_center_phone_msg_type_dispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_phone_msg_type_dispatch, cmd_id = %d, type = %d\r\n", diff --git a/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.h b/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.h index 2787377ff..e974e4c31 100644 --- a/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.h +++ b/code/sdk/application/wearable/evb/service/remote_msg/remote_msg.h @@ -20,10 +20,14 @@ typedef enum msg_center_phone_msg_type_id { MSGCENTER_TYPE_ID_MSG_THIRD_APP = 0x1, // 三方应用消息 MSGCENTER_TYPE_ID_MSG_SMS, // 短信 MSGCENTER_TYPE_ID_MSG_PHONE, // 电话 + MSGCENTER_TYPE_ID_UPDATE_CONTACTS, + MSGCENTER_TYPE_ID_LOOKUP_CONTACTS, MSGCENTER_TYPE_ID_MSG_MAX, } msg_center_msg_notify_type_id_t; errcode_t msg_center_phone_msg_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_update_contacts(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_lookup_contacts(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); #ifdef __cplusplus #if __cplusplus