#include "include.h" #include "func.h" #include "ble_protocol_msg.h" #include "app_variable.h" #include "spirit_island_api.h" #define TRACE_EN 0 #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif #define SIDEBAR_PAGE_HEIGHT 1082 //长图总高度 #define QDEC_STEP_Y 86 //编码器步进距离 #define MESSAGE_BOX_HEIGHT 86 //中心点 static BleProtocol_Msg_t *g_message = NULL; static MsgStorageCnt = 0; static Refresh = 0; //卡片/按钮id enum{ COMPO_ID_CARDBOX_MESSAGE = 1, }; typedef struct f_sidebar_t_ { page_tp_move_t *ptm; u8 message_number; } f_sidebar_t; static const int message_title_str_table[STORE_MESSAGE_MAX] = { [STORE_MESSAGE_GENERAL] = STR_MESSAGE, [STORE_MESSAGE_QQ] = STR_MESSAGE_QQ, [STORE_MESSAGE_WECHAT] = STR_MESSAGE_WECHAT, [STORE_MESSAGE_FACEBOOK] = STR_MESSAGE_FACEBOOK, [STORE_MESSAGE_TWITTER] = STR_MESSAGE_TWITTER, [STORE_MESSAGE_WHATSAPP] = STR_MESSAGE_WHATSAPP, }; //创建右滑菜单 compo_form_t * func_message_form_create(void) { compo_cardbox_t *cardbox; compo_picturebox_t *pic; //新建窗体 compo_form_t *frm = compo_form_create(true); //创建遮罩层 compo_shape_t *masklayer = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE); compo_shape_set_color(masklayer, COLOR_BLACK); compo_shape_set_location(masklayer, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH, GUI_SCREEN_HEIGHT); compo_shape_set_alpha(masklayer, 229); compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME); compo_form_set_title(frm, i18n[message_title_str_table[SysVariable.Stroage_type]]); if (MsgStorageCnt == 0) { compo_textbox_t *text = (component_t *)compo_textbox_create(frm, 20); compo_textbox_set_location((compo_textbox_t *)text, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH - GUI_SCREEN_WIDTH/12, 30); compo_textbox_set(text, i18n[STR_NO_MESSAGE]); } for (u16 i = 0; i < MsgStorageCnt; i++) { g_message = &SysVariable.Message[SysVariable.Stroage_type].MsgContent[i]; cardbox = compo_cardbox_create(frm, 1, 1, 3, 126, 65); compo_cardbox_set_pos(cardbox, GUI_SCREEN_CENTER_X, 68 + MESSAGE_BOX_HEIGHT * i); compo_cardbox_rect_set_location(cardbox, 0, 0, 0, 126, 65, 20); compo_cardbox_rect_set_color(cardbox, 0, make_color(68, 68, 68)); compo_setid(cardbox, COMPO_ID_CARDBOX_MESSAGE + i); // compo_cardbox_icon_set(cardbox, 0, UI_BUF_ICON_CALENDAR_BIN); //图标 // compo_cardbox_icon_set_location(cardbox, 0, 126-241, 612-631, 72, 72); compo_cardbox_text_set_location(cardbox, 0, 12, -20, 124, 20); compo_cardbox_text_set_font(cardbox, 0, UI_BUF_0FONT_FONT_BIN); compo_cardbox_text_set(cardbox, 0, g_message->msg_time); // 心率值--------->>>todo // compo_cardbox_text_set_font(cardbox, 1, UI_BUF_0FONT_FONT_BIN); // compo_cardbox_text_set_location(cardbox, 1, -73, -15, 99, 20); // compo_cardbox_text_set(cardbox, 1, i18n[STR_CALENDAR]); //日历 compo_cardbox_text_set_font(cardbox, 2, UI_BUF_0FONT_FONT_BIN); compo_cardbox_text_set_location(cardbox, 2, 0, -5, 99, 40); compo_cardbox_text_set(cardbox, 2, g_message->pdata); // 日历 // pic = compo_picturebox_create(frm, tbl_message_list[get_message_icon(g_message->type)].res_addr); pic = compo_picturebox_create(frm, UI_BUF_MESSAGE_SHOW_TYPE_BIN); compo_picturebox_cut(pic, get_message_icon(g_message->type), 22); compo_picturebox_set_pos(pic, 22, 38 + MESSAGE_BOX_HEIGHT * i); pic = compo_picturebox_create(frm, UI_BUF_MESSAGE_RED_REMIND_BIN); compo_picturebox_set_pos(pic, 22+10, 38-10 + MESSAGE_BOX_HEIGHT * i); compo_picturebox_set_visible(pic, g_message->is_noread & SysVariable.red_dot_reminder); } if (MsgStorageCnt > 0) { cardbox = compo_cardbox_create(frm, 0, 1, 0, 32, 32); compo_cardbox_set_pos(cardbox, GUI_SCREEN_CENTER_X, 50 + MESSAGE_BOX_HEIGHT * (MsgStorageCnt)); compo_setid(cardbox, COMPO_ID_CARDBOX_MESSAGE + MsgStorageCnt); compo_cardbox_icon_set(cardbox, 0, UI_BUF_MESSAGE_DELETE_BIN); // 图标 compo_cardbox_icon_set_location(cardbox, 0, 0, 0, 32, 32); } widget_page_update(); return frm; } //刷新右滑组件Widget(时间、温度、图标等) void func_message_update(void) { f_sidebar_t *f_sidebar = (f_sidebar_t *)func_cb.f_cb; compo_cardbox_t *cardbox; if (Refresh) { printf("MsgStorageCnt = %d", MsgStorageCnt); Refresh = 0; compo_form_t *frm = func_cb.frm_main; compo_form_destroy(frm); func_cb.frm_main = func_message_form_create(); if (f_sidebar->ptm) { page_move_info_t info = { .title_used = 1, .page_size = 110, .page_count = MsgStorageCnt, .quick_jump_perc = 50, .up_over_perc = 5, .down_over_perc = 5, .down_spring_perc = MsgStorageCnt ? 0 : 0, }; compo_page_move_init(f_sidebar->ptm, func_cb.frm_main->page_body, &info); } } } //时钟表盘右滑菜单点击处理 static void func_message_click_handler(void) { compo_cardbox_t *cardbox; rect_t rect; u8 func_jump = FUNC_NULL; if (MsgStorageCnt == 0) return; point_t pt = ctp_get_sxy(); u16 id = 0; for (u8 i = COMPO_ID_CARDBOX_MESSAGE; i < COMPO_ID_CARDBOX_MESSAGE + MsgStorageCnt + 1; i++) { if (compo_cardbox_btn_is(compo_getobj_byid(i), pt)) { id = i; } } printf("click id:%d %d\n", id, COMPO_ID_CARDBOX_MESSAGE + MsgStorageCnt); if ((id >= COMPO_ID_CARDBOX_MESSAGE) && (id < COMPO_ID_CARDBOX_MESSAGE + MsgStorageCnt)) { g_message = &SysVariable.Message[SysVariable.Stroage_type].MsgContent[id - COMPO_ID_CARDBOX_MESSAGE]; SysVariable.Message[SysVariable.Stroage_type].MsgContent[id - COMPO_ID_CARDBOX_MESSAGE].is_noread = false; char *msg = g_message->pdata; char *title = NULL; printf("click id2:%d\n", id); Refresh = 1; int res = msgbox(msg, title, MSGBOX_MODE_BTN_DELETE, g_message->type); if (res == MSGBOX_RES_DELETE) { BleProtocol_Message_StroageClear_index(SysVariable.Stroage_type, id - COMPO_ID_CARDBOX_MESSAGE); MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; return; } } if (id == COMPO_ID_CARDBOX_MESSAGE + MsgStorageCnt) { BleProtocol_Message_Clear_msgtype(SysVariable.Stroage_type); MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; Refresh = 1; } } //时钟表盘右滑菜单主要事件流程处理 static void func_message_process(void) { f_sidebar_t *f_sidebar = (f_sidebar_t *)func_cb.f_cb; compo_page_move_process(f_sidebar->ptm); func_message_update(); func_process(); } //时钟表盘右滑菜单功能消息处理 static void func_message_message(size_msg_t msg) { f_sidebar_t *f_sidebar = (f_sidebar_t *)func_cb.f_cb; switch (msg) { case MSG_CTP_TOUCH: if(MsgStorageCnt != 0){ compo_page_move_touch_handler(f_sidebar->ptm); } break; case MSG_CTP_SHORT_UP: case MSG_CTP_SHORT_DOWN: // case MSG_CTP_SHORT_RIGHT: case MSG_CTP_LONG: break; case MSG_CTP_CLICK: func_message_click_handler(); break; case MSG_QDEC_FORWARD: compo_page_move_set(f_sidebar->ptm, -QDEC_STEP_Y); break; case MSG_QDEC_BACKWARD: compo_page_move_set(f_sidebar->ptm, QDEC_STEP_Y); break; // case KU_BACK: // func_switch_to(FUNC_CLOCK, FUNC_SWITCH_LR_ZOOM_LEFT | FUNC_SWITCH_AUTO); // break; default: func_message(msg); break; } } //时钟表盘右滑菜单进入处理 static void func_message_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_sidebar_t)); func_cb.frm_main = func_message_form_create(); f_sidebar_t *f_sidebar = (f_sidebar_t *)func_cb.f_cb; // f_sidebar->message_number = MsgStorageCnt; f_sidebar->ptm = (page_tp_move_t *)func_zalloc(sizeof(page_tp_move_t)); printf("func_message_enter MsgStorageCnt = %d",MsgStorageCnt); page_move_info_t info = { .title_used = 1, .page_size = 110, .page_count = MsgStorageCnt, .quick_jump_perc = 50, .up_over_perc = 5, .down_over_perc = 5, .down_spring_perc = MsgStorageCnt ? 0 : 0, }; compo_page_move_init(f_sidebar->ptm, func_cb.frm_main->page_body, &info); } //时钟表盘右滑菜单退出处理 static void func_message_exit(void) { f_sidebar_t *f_sidebar = (f_sidebar_t *)func_cb.f_cb; if (f_sidebar->ptm) { func_free(f_sidebar->ptm); } if(!BleProtocol_Message_Judge_Noread()) { #if defined(TJD_GUI_SPIRIT_ISLAND_SHOW) si_delet_task(message); #endif } } compo_form_t * func_message_gengeral_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_GENERAL; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } compo_form_t * func_message_qq_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_QQ; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } compo_form_t * func_message_wechat_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_WECHAT; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } compo_form_t * func_message_facebook_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_FACEBOOK; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } compo_form_t * func_message_twitter_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_TWITTER; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } compo_form_t * func_message_whatapp_form_create(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_WHATSAPP; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_form_create(); } //时钟表盘右滑菜单 void func_message_gengeral_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_GENERAL; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_MESSAGE) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); } //时钟表盘右滑菜单 void func_message_qq_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_QQ; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_SET_QQ) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); } //时钟表盘右滑菜单 void func_message_wechat_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_WECHAT; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_SET_WECHAT) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); } //时钟表盘右滑菜单 void func_message_facebook_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_FACEBOOK; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_SET_FACEBOOK) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); } //时钟表盘右滑菜单 void func_message_twitter_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_TWITTER; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_SET_TWITTER) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); } //时钟表盘右滑菜单 void func_message_whatapp_info(void) { printf("%s\n", __func__); SysVariable.Stroage_type = STORE_MESSAGE_WHATSAPP; MsgStorageCnt = SysVariable.Message[SysVariable.Stroage_type].MsgStorageCnt; func_message_enter(); while (func_cb.sta == FUNC_SET_WHATSAPP) { func_message_process(); func_message_message(msg_dequeue()); } func_message_exit(); }