From: CCC <2393524978@qq.com> Date: Mon, 25 Sep 2023 12:22:31 +0000 (+0800) Subject: gengxin X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=94c638abe3ccce8a1a4f96a77e04d62e353d6f27;p=mirrors%2FASR3603_Z5.git gengxin --- diff --git a/2.sdk/project/Z5_D12/gui/lv_watch/mmi_default_CUSTOM.h b/2.sdk/project/Z5_D12/gui/lv_watch/mmi_default_CUSTOM.h index d31da711..9cb2c8f8 100644 --- a/2.sdk/project/Z5_D12/gui/lv_watch/mmi_default_CUSTOM.h +++ b/2.sdk/project/Z5_D12/gui/lv_watch/mmi_default_CUSTOM.h @@ -79,6 +79,8 @@ // dial pad #define MMI_CUSTOMER_DIAL_PAD_SWITCH (1) +// white list +#define MMI_CUSTOMER_WHITE_LIST_SWITCH (0) // 1-open //main menu style #define MMI_CUSTOMER_MAIN_MENU_STYLE (MMI_MAIN_MENU_STYLE_LIST) diff --git a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png deleted file mode 100644 index ad8b6fd3..00000000 Binary files a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png and /dev/null differ diff --git a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON.png b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON.png index 03de46b3..cb71ad34 100644 Binary files a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON.png and b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON.png differ diff --git a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON_PRESSED.png b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON_PRESSED.png index 61a42868..a8eb140c 100644 Binary files a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON_PRESSED.png and b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/ICON_WECHAT_RECORD_BUTTON_PRESSED.png differ diff --git a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png b/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png deleted file mode 100644 index bbe0e1fa..00000000 Binary files a/2.sdk/project/Z5_D12/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png and /dev/null differ diff --git a/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png b/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png deleted file mode 100644 index ad8b6fd3..00000000 Binary files a/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png and /dev/null differ diff --git a/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png b/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png deleted file mode 100644 index bbe0e1fa..00000000 Binary files a/2.sdk/project/Z5_K6/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png and /dev/null differ diff --git a/2.sdk/project/Z5_K7/gui/lv_watch/mmi_default_CUSTOM.h b/2.sdk/project/Z5_K7/gui/lv_watch/mmi_default_CUSTOM.h index d37538dd..6a5b80fc 100644 --- a/2.sdk/project/Z5_K7/gui/lv_watch/mmi_default_CUSTOM.h +++ b/2.sdk/project/Z5_K7/gui/lv_watch/mmi_default_CUSTOM.h @@ -79,6 +79,8 @@ // dial pad #define MMI_CUSTOMER_DIAL_PAD_SWITCH (1) +// white list +#define MMI_CUSTOMER_WHITE_LIST_SWITCH (0) // 1-open //main menu style #define MMI_CUSTOMER_MAIN_MENU_STYLE (MMI_MAIN_MENU_STYLE_FOUR_GRID) diff --git a/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png b/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png deleted file mode 100644 index ad8b6fd3..00000000 Binary files a/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/ICON_WECHAT_NO_NETWORK.png and /dev/null differ diff --git a/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png b/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png deleted file mode 100644 index bbe0e1fa..00000000 Binary files a/2.sdk/project/Z5_K7/gui/lv_watch/resource/png/wechat/icon_nonet_debt2.png and /dev/null differ diff --git a/2.sdk/sdk/gui/lv_watch/CMakeLists.txt b/2.sdk/sdk/gui/lv_watch/CMakeLists.txt index b28c99b4..36833c39 100644 --- a/2.sdk/sdk/gui/lv_watch/CMakeLists.txt +++ b/2.sdk/sdk/gui/lv_watch/CMakeLists.txt @@ -212,8 +212,6 @@ set(lv_watch_sources lv_apps/mmi_video_call/mmi_jrtc_client_tongxin.c #wechat lv_apps/mmi_wechat/wechat_ui.c -#primary menu data - lv_apps/primary_menu/primary_menu_data.c #health_measure lv_apps/health_measure/health_measure.c lv_apps/health_measure/health_heart_rate.c diff --git a/2.sdk/sdk/gui/lv_watch/framework/language/lang_ch.c b/2.sdk/sdk/gui/lv_watch/framework/language/lang_ch.c index de0b18ae..aeb0e45c 100644 --- a/2.sdk/sdk/gui/lv_watch/framework/language/lang_ch.c +++ b/2.sdk/sdk/gui/lv_watch/framework/language/lang_ch.c @@ -277,7 +277,7 @@ const void * lang_text_ch[] = { "松开发送", "选择联系人", "条新消息", - "上滑取消录音", + "上滑取消", /*restart_and_reset.c*/ "重新启动", diff --git a/2.sdk/sdk/gui/lv_watch/framework/language/lang_en.c b/2.sdk/sdk/gui/lv_watch/framework/language/lang_en.c index 0ee7c36f..88458779 100644 --- a/2.sdk/sdk/gui/lv_watch/framework/language/lang_en.c +++ b/2.sdk/sdk/gui/lv_watch/framework/language/lang_en.c @@ -278,7 +278,7 @@ const void * lang_text_en[] = { "Release to send", "Choose contact", " new messages", - "Slide up to cancel recording", + "Slide up to cancel", /*restart_and_reset.c*/ "Restart", diff --git a/2.sdk/sdk/gui/lv_watch/framework/message/watch_msg_handle.h b/2.sdk/sdk/gui/lv_watch/framework/message/watch_msg_handle.h index 8eb2406e..8ceb78a3 100644 --- a/2.sdk/sdk/gui/lv_watch/framework/message/watch_msg_handle.h +++ b/2.sdk/sdk/gui/lv_watch/framework/message/watch_msg_handle.h @@ -24,7 +24,7 @@ enum MMI_MODEM_CALL_RESPONSE_DISCONNECT, MMI_MODEM_CALL_RESPONSE_NO_CARRIER, MMI_MODEM_CALL_RESPONSE_DIAL, - MMI_MODEM_CALL_RESPONSE_CLIP, + MMI_MODEM_CALL_RESPONSE_CLIP, // 10 MMI_MODEM_CALL_RESPONSE_CCWA, MMI_MODEM_CALL_RESPONSE_STATE_CHANGE, MMI_MODEM_CALL_RESPONSE_REMOTE_HOLD, @@ -34,7 +34,7 @@ enum MMI_MODEM_PLMN_SEARCH_CNF, MMI_MODEM_CALL_FORWARD_SET_CNF, MMI_MODEM_CALL_FORWARD_QUERY_CNF, - MMI_MODEM_CALL_WAIT_SET_CNF, + MMI_MODEM_CALL_WAIT_SET_CNF, // 20 MMI_MODEM_CALL_WAIT_QUERY_CNF, MMI_MODEM_SIGNAL_BAR_IND, MMI_MODEM_OPERATOR_IND, @@ -44,7 +44,7 @@ enum MMI_MODEM_WRITE_PHONEBOOK_CNF, MMI_MODEM_READ_PHONEBOOK_CNF, MMI_MODEM_PHONEBOOK_INIT_IND, - MMI_MODEM_SEND_SMS_CNF, + MMI_MODEM_SEND_SMS_CNF, // 30 MMI_MODEM_DELETE_SMS_CNF, MMI_MODEM_READ_SMS_INFO_CNF, MMI_MODEM_READ_SMS_DETAIL_ON_SIM_CNF, @@ -54,7 +54,7 @@ enum MMI_MODEM_REP_NEW_SMS_IND, MMI_MODEM_SMS_STATUS_REP_IND, MMI_MODEM_SIM_SMS_STORAGE_STATUS_IND, - MMI_MODEM_SEND_USSD_CNF, + MMI_MODEM_SEND_USSD_CNF, // 40 MMI_MODEM_LTE_CELLS_INFO, MMI_MODEM_GSM_CELLS_INFO, MMI_HAL_LOW_POWER_IND, @@ -63,7 +63,7 @@ enum MMI_FOTA_CHECK_VERSION_IND, MMI_FOTA_DOWNLOAD_PERCENT_IND, MMI_FOTA_RESTART_IND, - MMI_FOTA_RESULT_IND, + MMI_FOTA_RESULT_IND, // 49 #if USE_LV_WATCH_UPGRADE_RS != 0 MMI_APP_ADAPTOR_FOTA_NOTIFY_VERSION_CMD, MMI_APP_ADAPTOR_FOTA_NOTIFY_CURR_DOWNLOAD_PERCENT_CMD, diff --git a/2.sdk/sdk/gui/lv_watch/include/ui_textid.h b/2.sdk/sdk/gui/lv_watch/include/ui_textid.h index 53376f78..8a0bc790 100644 --- a/2.sdk/sdk/gui/lv_watch/include/ui_textid.h +++ b/2.sdk/sdk/gui/lv_watch/include/ui_textid.h @@ -276,7 +276,7 @@ enum WATCH_TEXT_ID_RELEASE_SENDING, /* "松开发送" "Release to send" */ WATCH_TEXT_ID_CHOOSE_CONTACT, /* "选择联系人" "Choose Contact"*/ WATCH_TEXT_ID_MULTI_NEW_MSG, /* "条新消息" " new messages"*/ - WATCH_TEXT_ID_SLIDE_UP_WARNING, /* "上滑取消录音" "Slide up to cancel recording"*/ + WATCH_TEXT_ID_SLIDE_UP_WARNING, /* "上滑取消" "Slide up to cancel"*/ /*restart_and_reset.c*/ WATCH_TEXT_ID_RESTART, /* "重新启动" "Restart" */ diff --git a/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat.c b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat.c new file mode 100644 index 00000000..db3562ae --- /dev/null +++ b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat.c @@ -0,0 +1,2034 @@ + + + +#ifdef __MMI_WECHAT_SUPPORT__ + + +static lv_signal_cb_t ancient_scrl_signal; + +static uint8_t s_wechat_msg_init_flag = 0; +static nv_watch_wechat_msg_info_t * s_wechat_msg_info = NULL; +static nv_watch_wechat_msg_item_info_t s_wechat_msg_item_info = {0}; +static uint8_t s_wechat_play_anim_count = 0; +static char s_wechat_selected_item_index = -1; +static bool s_item_receive_playing = false; + + +void wechat_msg_info_nv_write(void) +{ + uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, NV_SECTION_UI_WEHAT_MSG); + + if(nv_data_length != UI_NV_Write_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG write fail\n", __FUNCTION__, __LINE__); + } +} + +void mmi_wechat_msg_info_init(void) +{ + if(0 == s_wechat_msg_init_flag) + { + uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); + + s_wechat_msg_info = (nv_watch_wechat_msg_info_t *)lv_mem_alloc(nv_data_length); + if(NULL == s_wechat_msg_info) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: memory alloc fail\n", __FUNCTION__, __LINE__); + return; + } + _lv_memset_00(s_wechat_msg_info, nv_data_length); + + if(nv_data_length != UI_NV_Read_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG read fail\n", __FUNCTION__, __LINE__); + //lv_mem_free(s_wechat_msg_info); + //s_wechat_msg_info = NULL; + } + + s_wechat_msg_init_flag = 1; + } +} + +uint8_t wechat_msg_info_count_get(void) +{ + uint8_t msg_count = s_wechat_msg_info->msg_count; + + return msg_count; +} + +uint8_t wechat_msg_info_index_item_msg_from_get(uint8_t msg_index) +{ + // 0-slef; 1-other + uint8_t msg_from = s_wechat_msg_info->msg_item[msg_index].msg_from; + + return msg_from; +} + +void wechat_msg_info_index_item_get(uint8_t msg_index, nv_watch_wechat_msg_item_info_t ** msg_item) +{ + *msg_item = &(s_wechat_msg_info->msg_item[msg_index]); +} + +void wechat_msg_info_index_item_delete(uint8_t msg_index) +{ + if(msg_index >= s_wechat_msg_info->msg_count) + return; + + uint8_t i = 0; + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + lv_fs_remove(s_wechat_msg_info->msg_item[msg_index].msg_data_full_file_name); + _lv_memset_00(&(s_wechat_msg_info->msg_item[msg_index]), msg_item_info_size); + + if(msg_index < s_wechat_msg_info->msg_count - 1) + { + for(i = msg_index; i < s_wechat_msg_info->msg_count; i++) + { + _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); + } + } + s_wechat_msg_info->msg_count--; +} + +void wechat_msg_info_all_item_delete(void) +{ + uint8_t i = 0; + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + for(i = 0; i < s_wechat_msg_info->msg_count; i++) + { + lv_fs_remove(s_wechat_msg_info->msg_item[i].msg_data_full_file_name); + _lv_memset_00(&(s_wechat_msg_info->msg_item[i]), msg_item_info_size); + } + s_wechat_msg_info->msg_count = 0; +} + +void wechat_msg_info_new_item_add(nv_watch_wechat_msg_item_info_t * msg_item) +{ + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NV_WATCH_WECHAT_NUM_MAX <= s_wechat_msg_info->msg_count) + { + lv_fs_remove(s_wechat_msg_info->msg_item[0].msg_data_full_file_name); + //_lv_memset_00(&(s_wechat_msg_info->msg_item[0]), msg_item_info_size); + + uint8_t i = 0; + for(i = 0; i < NV_WATCH_WECHAT_NUM_MAX - 1; i++) + { + _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); + } + s_wechat_msg_info->msg_count--; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + s_wechat_msg_info->msg_count++; + _lv_memcpy(&(s_wechat_msg_info->msg_item[s_wechat_msg_info->msg_count - 1]), msg_item, msg_item_info_size); +} + +void * wechat_actId_ext_get(lv_watch_Activity_Id_t actId) +{ + lv_obj_t * activity_obj = lv_watch_get_activity_obj(actId); + if(NULL == activity_obj) + return NULL; + + lv_obj_t * watch_obj = NULL; + lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); + if(NULL != watch_obj) + { + void * ext = lv_obj_get_ext_attr(watch_obj); + return ext; + } + + return NULL; +} + +static lv_obj_t * wechat_main_get_obj(void) +{ + lv_obj_t * watch_obj = NULL; + + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN); + if(NULL != activity_obj) + { + lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); + } + + return watch_obj; +} + +void wechat_common_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); +} + +void wechat_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(WECHAT_CREATED_FROM_ALBUM == ext->from) + { + album_photo_share_flag_reset(); + } + else if(WECHAT_CREATED_FROM_IMGVIEWER == ext->from) + { + imgviewer_photo_share_flag_reset(); + } + + if(NULL != ext->delete_timer_id) + { + Hal_Timer_Stop(ext->delete_timer_id); + ext->delete_timer_id = NULL; + } + + wechat_msg_voice_item_playing_stop(ext); + wechat_chat_list_msg_item_style_reset(ext); + + // + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); +} + +static void wechat_chat_list_set_slide_enable(lv_watch_obj_ext_t * ext, bool enable) +{ + if(enable) + { + ext->slide_enable = 1; /*enable to slide to the right*/ + } + else + { + ext->slide_enable = 0; /*disable to slide to the right*/ + } +} + +bool wechat_msg_voice_is_playing(void) +{ + bool result = false; + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->list) + { + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); + if(NULL != list_page_ext->voice_playing_anim.var) + { + result = true; + } + } + + return result; +} + +bool wechat_msg_voice_is_recording(void) +{ + bool result = false; + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING)) + { + result = true; + } + + return result; +} + +bool wechat_msg_item_is_sending(void) +{ + bool result = false; + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING)) + { + result = true; + } + + return result; +} + +void wechat_receive_audio_play_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; + } +} + +void wechat_receive_audio_play_over_cb(void *para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; +} + +static bool wechat_msg_item_info_write_to_file(char * file_path, char * file_buf, uint32_t file_size) +{ + lv_fs_file_t file_p; + lv_fs_res_t res; + uint32_t bytes_write = 0; + + res = lv_fs_open(&file_p, file_path, LV_FS_MODE_WR); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + return false; + } + res = lv_fs_write(&file_p, file_buf, file_size, &bytes_write); + lv_fs_close(&file_p); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + return false; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, file_size, bytes_write); + + return true; +} + +void wechat_msg_receive_update_ui(void) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_receive_audio_play_audio_ctrl_callback)) + { + if(false == s_item_receive_playing) + { + s_item_receive_playing = true; + + Hal_NFFS_File_Play_Onetime(AUDIO_WECHAT_RECEIVE, (HAL_SPEAKER_GAIN)query_current_volume(), wechat_receive_audio_play_over_cb, NULL); + Hal_Vibrator_Play_Onetime(NULL, 1000); + } + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN)) + { + wechat_main_screen_refresh(); + } + else + { + wechat_create_event_cb(NULL, LV_EVENT_CLICKED); + } + } +} + +bool wechat_msg_receive_from_server(char * data_buff, int data_buff_len, nv_wechat_msg_type_e type) +{ + if(NULL == data_buff || 0 == data_buff_len) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + if(WECHAT_MSG_TYPE_MAX <= type) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + + nv_watch_wechat_msg_item_info_t wechat_msg_item_info = {0}; + hal_rtc_t cur_time = {0}; + char * t_file_ext[WECHAT_MSG_TYPE_MAX] = {"amr", "txt", "png", "png"}; // match nv_wechat_msg_type_e + + Hal_Rtc_Gettime(&cur_time); + _lv_memcpy(&(wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); + + wechat_msg_item_info.msg_from = 1; + wechat_msg_item_info.unread_flag = 1; + wechat_msg_item_info.msg_type = type; // WECHAT_MSG_TYPE_VOICE; + wechat_msg_item_info.msg_data_size = data_buff_len; + sprintf(wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_r%04d%02d%02d_%02d%02d%02d.%s", /*WECHAT_MSG_DATA_FILE_PATH, */ + wechat_msg_item_info.msg_time.tm_year, + wechat_msg_item_info.msg_time.tm_mon, + wechat_msg_item_info.msg_time.tm_mday, + wechat_msg_item_info.msg_time.tm_hour, + wechat_msg_item_info.msg_time.tm_min, + wechat_msg_item_info.msg_time.tm_sec, + t_file_ext[type]); + + if(false == wechat_msg_item_info_write_to_file(wechat_msg_item_info.msg_data_full_file_name, data_buff, data_buff_len)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + wechat_msg_voice_item_playing_stop(ext); + } + + wechat_msg_info_new_item_add(&wechat_msg_item_info); + + // ui + if(false == mmi_active_screen_is_prohibit_interrupted() + && false == mmi_health_measure_state_is_ui_measure() +// && false == wechat_msg_voice_is_playing() + && false == wechat_msg_voice_is_recording() + && false == wechat_msg_item_is_sending() + #ifdef __MMI_ZHSX_SUPPORT_DO_NOT_DISTURB__ + && false == mmi_watch_is_in_do_not_disturb_time() + #endif + ) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + mmi_watch_wake_up(); + mmi_ui_msg_action_wechat_incoming(); + } + + return true; +} + +bool wechat_msg_send_to_server(void) +{ + bool result = false; // true-success; false-fail + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return false; + + uint32_t file_size = ext->record_size; + char * file_buf = lv_mem_alloc(file_size + 1); + if(NULL == file_buf || WECHAT_MSG_DATA_AMR_HEAD_SIZE >= file_size) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + _lv_memset_00(file_buf, file_size + 1); + _lv_memcpy(file_buf, ext->record_buffer, file_size); + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + + if(true == wechat_msg_item_info_write_to_file(s_wechat_msg_item_info.msg_data_full_file_name, file_buf, file_size)) + { + if(true == mmi_protocol_action_send_talk(file_buf, file_size)) + { + s_wechat_msg_item_info.msg_data_size = file_size; + wechat_msg_info_new_item_add(&s_wechat_msg_item_info); + result = true; + } + else + { + lv_fs_remove(s_wechat_msg_item_info.msg_data_full_file_name); + } + } + + lv_mem_free(file_buf); + _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); + + return result; +} + +void wechat_msg_item_delete_success_timer_cb(void *para) +{ + //lv_wechat_ext_t * ext = (lv_wechat_ext_t *)para; + + wechat_main_screen_refresh(); +} + +void wechat_msg_item_delete_ok_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->delete_bg) + { + uint32_t value = lv_watch_get_free_num(obj); + if(0 == value) + wechat_msg_info_index_item_delete(s_wechat_selected_item_index); + else if(1 == value) + wechat_msg_info_all_item_delete(); + + lv_obj_clean(ext->delete_bg); + + lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); + lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_SUCCESS); + lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -10); + + //ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, ext, false); + ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, NULL, false); + } + } +} + +void wechat_msg_item_delete_cancel_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->delete_bg) + { + lv_obj_del(ext->delete_bg); + ext->delete_bg = NULL; + } + } +} + +void wechat_msg_item_delete_select_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED != e) + { + return; + } + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + uint32_t value = lv_watch_get_free_num(obj); + + lv_obj_set_hidden(ext->delete_current, true); + lv_obj_set_hidden(ext->delete_all, true); + lv_obj_set_hidden(ext->delete_back, true); + + lv_obj_set_hidden(ext->delete_label_prompt, false); + lv_obj_set_hidden(ext->delete_btn_cancel, false); + lv_obj_set_hidden(ext->delete_btn_ok, false); + lv_watch_set_free_num(ext->delete_btn_ok, value); + } +} + +void wechat_chat_list_msg_item_delete_create(void) +{ + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->cont) + { + ext->delete_bg = lv_cont_create(ext->cont, NULL); + lv_obj_set_size(ext->delete_bg, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style_local_bg_color(ext->delete_bg, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xB6, 0xF7, 0xFF)); + + // current + lv_obj_t * btn_delete_current = lv_cont_create(ext->delete_bg, NULL); + lv_obj_set_size(btn_delete_current, LV_HOR_RES - 40, 56); + lv_obj_set_style_local_bg_color(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xB9, 0x86, 0xFF)); + lv_obj_set_style_local_radius(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_click(btn_delete_current, true); + lv_obj_set_event_cb(btn_delete_current, wechat_msg_item_delete_select_btn_event_cb); + lv_obj_align(btn_delete_current, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); + lv_watch_set_free_num(btn_delete_current, 0); + ext->delete_current = btn_delete_current; + + lv_obj_t * label_delete_current = lv_label_create(btn_delete_current, NULL); + lv_obj_add_style(label_delete_current, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_current, WATCH_TEXT_ID_DELETE_CURRENT_ITEM); + lv_label_set_align(label_delete_current, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_current, btn_delete_current, LV_ALIGN_CENTER, 0, 0); + + // all + lv_obj_t * btn_delete_all = lv_cont_create(ext->delete_bg, btn_delete_current); + lv_obj_set_style_local_bg_color(btn_delete_all, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xFF, 0x6F, 0x91)); + lv_obj_align(btn_delete_all, btn_delete_current, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); + lv_watch_set_free_num(btn_delete_all, 1); + ext->delete_all = btn_delete_all; + + lv_obj_t * label_delete_all = lv_label_create(btn_delete_all, NULL); + lv_obj_add_style(label_delete_all, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_all, WATCH_TEXT_ID_DELETE_ALL_ITEM); + lv_label_set_align(label_delete_all, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_all, btn_delete_all, LV_ALIGN_CENTER, 0, 0); + + // back + lv_obj_t * btn_delete_back = lv_cont_create(ext->delete_bg, btn_delete_current); + lv_obj_set_style_local_bg_color(btn_delete_back, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_event_cb(btn_delete_back, wechat_msg_item_delete_cancel_btn_event_cb); + lv_obj_align(btn_delete_back, btn_delete_all, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); + ext->delete_back = btn_delete_back; + + lv_obj_t * label_delete_back = lv_label_create(btn_delete_back, NULL); + lv_obj_add_style(label_delete_back, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_back, WATCH_TEXT_ID_CANCEL); + lv_label_set_align(label_delete_back, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_back, btn_delete_back, LV_ALIGN_CENTER, 0, 0); + + + lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); + lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_Q); + lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -30); + ext->delete_label_prompt = label_prompt; + + lv_obj_t * btn_cancel = lv_btn_create(ext->delete_bg, NULL); + lv_obj_set_size(btn_cancel, 100, 56); + lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); + lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); + lv_obj_align(btn_cancel, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 10, -20); + lv_obj_set_event_cb(btn_cancel, wechat_msg_item_delete_cancel_btn_event_cb); + ext->delete_btn_cancel = btn_cancel; + + lv_obj_t * label_cancel = lv_label_create(btn_cancel, NULL); + lv_obj_add_style(label_cancel, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_cancel, WATCH_TEXT_ID_CANCEL); + + lv_obj_t * btn_ok = lv_btn_create(ext->delete_bg, btn_cancel); + lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xFF, 0x6F, 0x91)); + lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0xFF, 0x6F, 0x91)); + lv_obj_align(btn_ok, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -20); + lv_obj_set_event_cb(btn_ok, wechat_msg_item_delete_ok_btn_event_cb); + ext->delete_btn_ok = btn_ok; + + lv_obj_t * label_ok = lv_label_create(btn_ok, label_cancel); + lv_label_set_text_id(label_ok, WATCH_TEXT_ID_OK); + + // display + lv_obj_set_hidden(label_prompt, true); + lv_obj_set_hidden(btn_cancel, true); + lv_obj_set_hidden(btn_ok, true); + } +} + +void wechat_msg_sending_anim_cb(lv_anim_t * a) +{ + lv_obj_t * img = a->var; + + switch(s_wechat_play_anim_count % 3) + { + case 0: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT1); + break; + + case 1: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT2); + break; + + case 2: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT3); + break; + + default: + break; + } + s_wechat_play_anim_count++; +} + +void wechat_msg_sending_result_screen_timeout(void *para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_sending_screen_prepare_destory(NULL); + + //delete sending screen + //lv_watch_del_interface(ACT_ID_WECHAT_SENDING); + lv_obj_t * obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING); + if(NULL != obj) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + lv_obj_del(obj); + } + + //return main list screen + wechat_main_screen_refresh(); +} + +void wechat_msg_sending_screen_timeout(void *para) +{ + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)para; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL != sending_ext->sending_timer_id) + { + Hal_Timer_Stop(sending_ext->sending_timer_id); + sending_ext->sending_timer_id = NULL; + } + + if(NULL != sending_ext->sending_anim.var) + { + lv_obj_t * img_bkg = lv_obj_get_parent(sending_ext->sending_anim.var); + lv_img_set_src(img_bkg, ((true == sending_ext->send_result) ? ICON_WECHAT_SENDING_SUCC : ICON_WECHAT_SENDING_FAILED)); + + lv_anim_del(sending_ext->sending_anim.var, NULL); + lv_obj_del(sending_ext->sending_anim.var); + sending_ext->sending_anim.var = NULL; + } + + sending_ext->result_timer_id = Hal_Timer_Start(1500, wechat_msg_sending_result_screen_timeout, sending_ext, FALSE); +} + +void wechat_msg_sending_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_SENDING); + if(NULL != sending_ext) + { + if(NULL != sending_ext->sending_timer_id) + { + Hal_Timer_Stop(sending_ext->sending_timer_id); + sending_ext->sending_timer_id = NULL; + } + if(NULL != sending_ext->result_timer_id) + { + Hal_Timer_Stop(sending_ext->result_timer_id); + sending_ext->result_timer_id = NULL; + } + } +} + +lv_obj_t * wechat_msg_sending_screen_create(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == activity_obj) + { + lv_watch_activity_ext_t activity_ext = {0}; + + activity_ext.actId = ACT_ID_WECHAT_SENDING; + activity_ext.create = (lv_watch_activity_create_f_t)wechat_msg_sending_screen_create; + activity_ext.prepare_destory = wechat_msg_sending_screen_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + if(NULL == activity_obj) + return NULL; + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + if(NULL == obj) + return NULL; + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_sending_ext_t)); + if(NULL == sending_ext) + return NULL; + + wechat_chat_list_set_slide_enable(&sending_ext->old_ext, false); /*prevent to slide out while recording*/ + _lv_memset_00(&(sending_ext->sending_anim), sizeof(lv_anim_t)); + sending_ext->send_result = wechat_msg_send_to_server(); + sending_ext->sending_timer_id = Hal_Timer_Start(1000 * 3, wechat_msg_sending_screen_timeout, sending_ext, FALSE); + sending_ext->result_timer_id = NULL; + + lv_obj_t * img_bkg = lv_img_create(obj, NULL); + lv_img_set_src(img_bkg, ICON_WECHAT_SENDING_BG); + lv_obj_align(img_bkg, obj, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * img_sending = lv_img_create(img_bkg, NULL); + lv_img_set_src(img_sending, ICON_WECHAT_SENDING_PROMPT3); +#if USE_LV_WATCH_UI_240_320 + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); +#elif USE_LV_WATCH_UI_240_280 + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -40); +#else + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); +#endif + + lv_anim_t * a = &(sending_ext->sending_anim); + lv_anim_init(a); + lv_anim_set_var(a, img_sending); + //lv_anim_set_exec_cb(a, (lv_anim_exec_xcb_t)wechat_msg_sending_anim_exec_cb); + lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_msg_sending_anim_cb); + lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_repeat_delay(a, 500); + lv_anim_start(a); + s_wechat_play_anim_count = 0; + + return obj; +} + +void wechat_msg_recording_release_event_cb(lv_obj_t * obj, lv_event_t e) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); + +#if 0 + if(LV_EVENT_RELEASED == e) //(LV_EVENT_CLICKED == e) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); + wechat_msg_sending_screen_create(NULL); + } +#endif +} + +void wechat_msg_recording_anim(lv_anim_t * a) +{ + lv_obj_t * img = a->var; + + switch(s_wechat_play_anim_count % 5) + { + case 0: + lv_img_set_src(img, ICON_WECHAT_RECORDING1); + break; + case 1: + lv_img_set_src(img, ICON_WECHAT_RECORDING2); + break; + case 2: + lv_img_set_src(img, ICON_WECHAT_RECORDING3); + break; + case 3: + lv_img_set_src(img, ICON_WECHAT_RECORDING4); + break; + case 4: + lv_img_set_src(img, ICON_WECHAT_RECORDING5); + break; + default: + break; + } + s_wechat_play_anim_count++; + + if(0 == (s_wechat_play_anim_count % 4)) + { + lv_wechat_msg_recording_ext_t * recording_ext = (lv_wechat_msg_recording_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_RECORDING); + if(NULL == recording_ext) + return; + + int8_t count_down = WECHAT_MSG_DATA_RECORD_DURATION_MAX - s_wechat_play_anim_count / 4; + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: count down=%d\n", __FUNCTION__, __LINE__, count_down); + + if(0 < count_down) + { + const char * content = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); + uint8_t len = strlen(content) + 8; + char * text = (char *)lv_mem_alloc(len); + snprintf(text, len, "%s %d", content, count_down); + lv_label_set_text(recording_ext->label, text); + lv_mem_free(text); + //lv_obj_align(recording_ext->label, img, LV_ALIGN_OUT_BOTTOM_MID, 0, 6); + } + } +} + +bool wechat_msg_recording_stop(bool is_cancel) +{ + uint32_t duration_ms = 0; + uint32_t size = 0; + + Hal_Record_Buffer_Stop_Req(&size, &duration_ms); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return false; + + if(true == is_cancel) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + + if(WECHAT_MSG_DATA_AMR_HEAD_SIZE >= size) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + ext->record_size = size; + + return true; +} + +void wechat_msg_recording_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + if(false == watch_is_ready()) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + wechat_msg_recording_stop(true); + + //lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + } +} + +void wechat_msg_recording_task_cb(lv_task_t * task) +{ + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + if(0 == ext->old_ext.element_click_en) + { + /*sliding to the right, not click button*/ + return; + } + + lv_obj_t * activity_obj; + MCI_EVNET_T event = (MCI_EVNET_T) (task->user_data); + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, event); + + switch(event) + { + case MCI_EVENT_EOS: + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_recording_stop(false); + activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + wechat_msg_sending_screen_create(NULL); + break; + + case MCI_EVENT_ERROR: + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_recording_stop(true); + activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + break; + + //case MCI_EVENT_INFO: + // break; + + default: + break; + } +} + +void wechat_msg_recording_cb(MCI_EVNET_T event, MCI_INFO_T info_type, int32_t value) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d,type=%d,value=%d\n", __FUNCTION__, __LINE__, event, info_type, value); + + if(MCI_EVENT_INFO != event) + { + //recording_ext->event = event; + lv_task_t * record_task = lv_task_create(wechat_msg_recording_task_cb, 10, LV_TASK_PRIO_HIGH, event); + lv_task_once(record_task); + } +} + + +void wechat_msg_recording_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + wechat_msg_recording_stop(true); +} + +lv_obj_t * wechat_msg_recording_screen_create(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == activity_obj) + { + lv_watch_activity_ext_t activity_ext = {0}; + + activity_ext.actId = ACT_ID_WECHAT_RECORDING; + activity_ext.create = wechat_msg_recording_screen_create; + activity_ext.prepare_destory = wechat_msg_recording_screen_prepare_destory; // wechat_common_screen_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + if(NULL == activity_obj) + return NULL; + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + LV_ASSERT_MEM(obj); + + lv_wechat_msg_recording_ext_t * recording_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_recording_ext_t)); + LV_ASSERT_MEM(recording_ext); + + lv_obj_t * cont = lv_cont_create(obj, NULL); + lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); + lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); + //lv_obj_set_click(cont, true); + //lv_obj_set_event_cb(cont, wechat_msg_recording_release_event_cb); + //lv_obj_add_protect(cont, LV_PROTECT_PRESS_LOST); + + lv_obj_t * label_warning = lv_label_create(cont, NULL); + //lv_obj_set_style_local_text_font(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_THEME_WATCH_NIGHT_FONT_SMALL); + //lv_obj_set_style_local_text_color(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_add_style(label_warning, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + //lv_label_set_long_mode(label_warning, LV_LABEL_LONG_BREAK); + //lv_obj_set_width(label_warning, lv_obj_get_width(obj) * 2 / 3); + lv_label_set_text_id(label_warning, WATCH_TEXT_ID_SLIDE_UP_WARNING); + lv_label_set_align(label_warning, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_warning, cont, LV_ALIGN_IN_TOP_MID, 0, 8); + + lv_obj_t * img = lv_img_create(cont, NULL); + lv_img_set_src(img, ICON_WECHAT_RECORDING1); + lv_obj_align(img, cont, LV_ALIGN_IN_TOP_MID, 0, 36); + + recording_ext->label = lv_label_create(cont, NULL); + lv_obj_add_style(recording_ext->label, LV_LABEL_PART_MAIN, &lv_watch_font20_black); + const char * rel_snd = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); + uint8_t len = strlen(rel_snd) + 4; + char * text = (char *)lv_mem_alloc(len); + snprintf(text, len, "%s %d", rel_snd, WECHAT_MSG_DATA_RECORD_DURATION_MAX); + lv_label_set_text(recording_ext->label, text); + lv_mem_free(text); + lv_obj_align(recording_ext->label, img, LV_ALIGN_OUT_BOTTOM_MID, 0, 6); + + lv_obj_t * img_release_snd = lv_img_create(cont, NULL); + lv_img_set_src(img_release_snd, ICON_WECHAT_RECORD_BUTTON_PRESSED); + lv_obj_align(img_release_snd, cont, LV_ALIGN_IN_BOTTOM_MID, 0, -8); + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, img); + lv_anim_set_start_cb(&a, (lv_anim_ready_cb_t)wechat_msg_recording_anim); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(&a, 249); + lv_anim_start(&a); + s_wechat_play_anim_count = 0; + + //fill info + _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); +#if 0 + //system crashed. unknown reason //20230327 + Hal_Rtc_Gettime(&(s_wechat_msg_item_info.msg_time)); +#else + hal_rtc_t cur_time; + Hal_Rtc_Gettime(&cur_time); + _lv_memcpy(&(s_wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); +#endif + s_wechat_msg_item_info.msg_type = WECHAT_MSG_TYPE_VOICE; + sprintf(s_wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_s%04d%02d%02d_%02d%02d%02d.amr", /*WECHAT_MSG_DATA_FILE_PATH, */ + s_wechat_msg_item_info.msg_time.tm_year, + s_wechat_msg_item_info.msg_time.tm_mon, + s_wechat_msg_item_info.msg_time.tm_mday, + s_wechat_msg_item_info.msg_time.tm_hour, + s_wechat_msg_item_info.msg_time.tm_min, + s_wechat_msg_item_info.msg_time.tm_sec + ); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d, file_name=%s\n", __FUNCTION__, __LINE__, + s_wechat_msg_item_info.msg_from, s_wechat_msg_item_info.msg_data_full_file_name); + + //recording +#if 0 + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) + { + Hal_File_Record_Start_Req(s_wechat_msg_item_info.msg_data_full_file_name, wechat_msg_recording_cb); + } + +#else + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return NULL; + + if(NULL != ext->record_buffer) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + } + ext->record_buffer = (uint8_t *)lv_mem_alloc(WECHAT_MSG_DATA_RECORD_SIZE_MAX); + if(NULL != ext->record_buffer) + { + _lv_memset_00(ext->record_buffer, WECHAT_MSG_DATA_RECORD_SIZE_MAX); + + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) + { + Hal_Record_Buffer_Start_Req(ext->record_buffer, + WECHAT_MSG_DATA_RECORD_SIZE_MAX, + WECHAT_MSG_DATA_RECORD_DURATION_MAX * 1000, + wechat_msg_recording_cb); + } + } +#endif + + return obj; +} + +static void wechat_out_of_memory_btn_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_obj_del(lv_obj_get_parent(btn)); + + //return main list screen + wechat_main_screen_refresh(); + } +} + +void wechat_list_out_of_memory_create(lv_obj_t * obj) +{ + lv_obj_t * cont_bg = lv_cont_create(obj, NULL); + lv_obj_set_size(cont_bg, LV_HOR_RES, LV_VER_RES); + lv_obj_add_style(cont_bg, LV_CONT_PART_MAIN, &lv_watch_black_tight); + + lv_obj_t * img_mem = lv_img_create(cont_bg, NULL); + lv_img_set_src(img_mem, ICON_CAMERA_MEMORY); + lv_obj_align(img_mem, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); + + lv_obj_t * label = lv_label_create(cont_bg, NULL); + lv_label_set_text_id(label, WATCH_TEXT_ID_OUT_OF_MEM); + lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label, LV_HOR_RES - 40); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, img_mem, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + + lv_obj_t * btn = lv_btn_create(cont_bg, NULL); + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); + lv_obj_set_size(btn, 200, 56); + lv_obj_set_event_cb(btn, wechat_out_of_memory_btn_event_cb); + lv_obj_align(btn, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -20); + + lv_obj_t * btn_label = lv_label_create(btn, NULL); + lv_label_set_text_id(btn_label, WATCH_TEXT_ID_GOT_IT); + lv_obj_add_style(btn_label,LV_LABEL_PART_MAIN, &lv_watch_font26); +} + +void wechat_msg_record_button_event_cb(lv_obj_t * obj, lv_event_t e) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); + + if(LV_EVENT_LONG_PRESSED == e) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ + + if(0 == ext->old_ext.element_click_en) + { + /*sliding to the right, not click button*/ + return; + } + + uint32_t fs_total = 0, fs_free = 0; + lv_fs_free_space('C', &fs_total, &fs_free); + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total=%dB,free=%dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); + if(28 * 1024 > fs_free) // 30 * 1024 + { + lv_obj_t * obj = wechat_main_get_obj(); + wechat_list_out_of_memory_create(obj); + } + #if 0 + else if(NV_WATCH_WECHAT_NUM_MAX <= wechat_msg_info_count_get()) + //else if(2 <= wechat_msg_info_count_get()) + { + lv_obj_t * obj = wechat_main_get_obj(); + wechat_list_out_of_memory_create(obj); + } + #endif + else + { + wechat_chat_list_set_slide_enable(&ext->old_ext, false); /*prevent to slide out while recording*/ + + wechat_msg_recording_screen_create(NULL); + } + } + else if(LV_EVENT_CLICKED == e || LV_EVENT_PRESS_LOST == e) + { + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + lv_wechat_msg_recording_ext_t * recording_ext = (lv_wechat_msg_recording_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_RECORDING); + if(NULL == recording_ext) + return NULL; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ + + lv_indev_t * indev = lv_indev_get_act(); + if(indev) + { + lv_coord_t point_y = indev->proc.types.pointer.last_point.y; + lv_coord_t img_record_top = obj->coords.y1; + if(30 < img_record_top - point_y) // (point_y < (img_record_top - 20)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: indev_y=%d, img_y=%d\n", __FUNCTION__, __LINE__, point_y, img_record_top); + wechat_msg_recording_stop(true); + lv_obj_del(activity_obj); + //return main list screen + wechat_main_screen_refresh(); + + return; + } + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + wechat_msg_recording_stop(false); + lv_obj_del(activity_obj); + wechat_msg_sending_screen_create(NULL); + } + } + else if(LV_EVENT_PRESSED == e) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + // + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + + wechat_msg_voice_item_playing_stop(ext); + } +} + +void wechat_msg_voice_item_reset_play_state(lv_wechat_msg_list_ext_t * list_page_ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + uint8_t msg_from = list_page_ext->voice_playing_msg_from; + + lv_anim_del(list_page_ext->voice_playing_anim.var, NULL); + lv_img_set_src(list_page_ext->voice_playing_anim.var, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); + list_page_ext->voice_playing_anim.var = NULL; +} + +void wechat_msg_voice_item_playing_stop(lv_wechat_ext_t * ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == ext || NULL == ext->list) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(ext->list); + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + wechat_msg_voice_item_reset_play_state(list_page_ext); +} + +void wechat_chat_list_msg_item_style_reset(lv_wechat_ext_t * ext) +{ + if(NULL == ext || NULL == ext->list) + return; + + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); + if(NULL == list_page_ext) + return; + + lv_style_reset(&(list_page_ext->style_cont_self)); + lv_style_reset(&(list_page_ext->style_cont_other)); + lv_style_reset(&(list_page_ext->style_label_time)); + //lv_style_reset(&(list_page_ext->style_text)); + lv_style_reset(&(list_page_ext->style_label_len_self)); + lv_style_reset(&(list_page_ext->style_label_len_other)); +} + +void wechat_chat_list_msg_item_time(char * time_str, hal_rtc_t * cur_time, hal_rtc_t * msg_time, hal_rtc_t * last_msg_time) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(0 == last_msg_time->tm_year) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, msg_time->tm_mday, + msg_time->tm_hour, msg_time->tm_min); + + return; + } + + uint32_t msg_sec = time_to_seconds(msg_time); + uint32_t last_msg_sec = time_to_seconds(last_msg_time); + if(msg_sec < last_msg_sec) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, + msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + else if(msg_sec > (last_msg_sec + WECHAT_MSG_CHAT_TIME_INTERVAL)) + { + uint32_t cur_sec = time_to_seconds(cur_time); + if((msg_sec > cur_sec) || (msg_time->tm_year < cur_time->tm_year)) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, + msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + else + { + uint32_t today_sec = cur_sec - cur_time->tm_hour * 3600 - cur_time->tm_min * 60 - cur_time->tm_sec; + + if(msg_sec >= today_sec) + { + /*today*/ + sprintf(time_str, "%02d:%02d", msg_time->tm_hour, msg_time->tm_min); + } + else if(msg_sec >= (today_sec - 24 * 3600)) + { + /*yesterday*/ + const char * yesterday = lv_lang_get_text(WATCH_TEXT_ID_YESTERDAY); + + sprintf(time_str, "%s %02d:%02d", yesterday, msg_time->tm_hour, msg_time->tm_min); + } + else + { + uint8_t wday; + if(0 == cur_time->tm_wday) + { + /*today is Sunday*/ + wday = 6; + } + else + { + wday = cur_time->tm_wday - 1; + } + /*the start of a week is monday, the end is sunday*/ + if(msg_sec >= (today_sec - wday * 24 * 3600)) { + /*current week before yesterday*/ + const char * wday_str; + switch(rtc_calc_weekday(msg_time)) + { + case 1: + /*Monday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_MONDAY); + break; + case 2: + /*Tuesday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_TUESDAY); + break; + case 3: + /*Wednesday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_WEDNESDAY); + break; + case 4: + /*Thursday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_THURSDAY); + break; + case 5: + /*Friday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_FRIDAY); + break; + default: + printf("%s: week error\n", __FUNCTION__); + break; + } + + sprintf(time_str, "%s %02d:%02d", wday_str, msg_time->tm_hour, msg_time->tm_min); + } + else + { + sprintf(time_str, "%d/%d %02d:%02d", msg_time->tm_mon, msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + } + } + } +} + +void wechat_chat_list_voice_item_playing_anim_cb(lv_anim_t * a) +{ + lv_obj_t * play_img = (lv_obj_t *)a->var; + uint8_t msg_from = wechat_msg_info_index_item_msg_from_get(s_wechat_selected_item_index); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d\n", __FUNCTION__, __LINE__, msg_from); + + switch(s_wechat_play_anim_count % 3) + { + case 0: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING1 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING1)); + break; + + case 1: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING2 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING2)); + break; + + case 2: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); + break; + + default: + break; + } + s_wechat_play_anim_count++; +} + +void wechat_chat_list_voice_item_playing_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + if(false == watch_is_ready()) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + wechat_msg_voice_item_playing_stop(ext); + } + } +} + +void wechat_chat_list_voice_item_play_over_cb(void * para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)para; + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + wechat_msg_voice_item_reset_play_state(list_page_ext); +} + +void wechat_chat_list_voice_item_play_action(lv_wechat_msg_list_ext_t * list_page_ext, lv_obj_t * play_img, lv_obj_t * unread_img) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + //display ui + lv_anim_t * a = &(list_page_ext->voice_playing_anim); + + lv_anim_init(a); + lv_anim_set_var(a, play_img); + lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_chat_list_voice_item_playing_anim_cb); + lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(a, 400); + lv_anim_start(a); + s_wechat_play_anim_count = 1; + + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); + msg_item->unread_flag = 0; + if(NULL != unread_img) + { + lv_obj_del(unread_img); + unread_img = NULL; + } + list_page_ext->voice_playing_msg_from = msg_item->msg_from; + + //play voice + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_chat_list_voice_item_playing_audio_ctrl_callback)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + Hal_File_Play_Onetime(msg_item->msg_data_full_file_name, query_current_volume(), wechat_chat_list_voice_item_play_over_cb, list_page_ext, 0); + } +} + +void wechat_chat_list_voice_item_event_cb(lv_obj_t * cont, lv_event_t e) +{ + lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); + if(NULL == list_item_ext) + return; + + s_wechat_selected_item_index = list_item_ext->item_index; + + lv_obj_t * scrl = lv_obj_get_parent(cont); + lv_obj_t * list_page = lv_obj_get_parent(scrl); + //lv_obj_t * scrl = lv_page_get_scrl(list_page); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(LV_EVENT_PRESSED == e) + { + list_page_ext->pressing = true; + } + else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item + { + list_page_ext->pressing = false; + + wechat_chat_list_msg_item_delete_create(); + } + else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // playing voice msg + { + list_page_ext->pressing = false; + + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); + + if(0 != msg_item->msg_data_size) + { + if(NULL != list_page_ext->voice_playing_anim.var) // exist voice playing + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); + + //stop item voice + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + wechat_msg_voice_item_reset_play_state(list_page_ext); + } + else if(NULL != msg_item->msg_data_full_file_name) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); + + lv_obj_t * play_img = lv_obj_get_child_back(cont, NULL); + wechat_chat_list_voice_item_play_action(list_page_ext, play_img, ((1 == msg_item->unread_flag) ? list_item_ext->unread_img : NULL)); + } + } + } +} + +void wechat_chat_list_text_item_event_cb(lv_obj_t * cont, lv_event_t e) +{ + lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); + if(NULL == list_item_ext) + return; + + s_wechat_selected_item_index = list_item_ext->item_index; + + lv_obj_t * scrl = lv_obj_get_parent(cont); + lv_obj_t * list_page = lv_obj_get_parent(scrl); + //lv_obj_t * scrl = lv_page_get_scrl(list_page); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(LV_EVENT_PRESSED == e) + { + list_page_ext->pressing = true; + } + else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item + { + list_page_ext->pressing = false; + + wechat_chat_list_msg_item_delete_create(); + } + else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // display text msg + { + list_page_ext->pressing = false; + } +} + +//display time & content +lv_obj_t * wechat_chat_list_msg_item_add(lv_obj_t * list_page, nv_watch_wechat_msg_item_info_t * msg_item, char * time_str, uint8_t i) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_t * obj = NULL; + lv_wechat_msg_list_item_ext_t * list_item_ext = NULL; + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(list_page); + lv_obj_t * scrl = lv_page_get_scrl(list_page); + lv_obj_t * last_obj = lv_obj_get_child(scrl, NULL); + lv_coord_t obj_y = 0; + + if(NULL != last_obj) + { + obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); + } + else + { + obj_y = lv_obj_get_style_pad_top(scrl, LV_STATE_DEFAULT); + } + + if(0 != strlen(time_str)) + { + obj = lv_label_create(list_page, NULL); + + //lv_obj_set_base_dir(obj, LV_BIDI_DIR_LTR); + lv_label_set_text(obj, time_str); + lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &list_page_ext->style_label_time); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_MID, 0, obj_y); + + last_obj = obj; + obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_type=%d,file=%s,size=%d,obj_y=%d\n", __FUNCTION__, __LINE__, + msg_item->msg_type, msg_item->msg_data_full_file_name, msg_item->msg_data_size, obj_y); + + switch(msg_item->msg_type) + { + case WECHAT_MSG_TYPE_VOICE: + lv_obj_t * unread_img = lv_img_create(list_page, NULL); + //obj = lv_img_create(list_page, NULL); + obj = lv_cont_create(list_page, NULL); + list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); + list_item_ext->item_index = i; + list_item_ext->unread_img = NULL; + lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); + lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); + + lv_obj_t * play_img = lv_img_create(obj, NULL); + lv_obj_t * len_label = lv_label_create(obj, NULL); + uint32_t duration = 0; + + if(LV_FS_RES_OK != Hal_File_Get_AudioDurationTime((const char *)msg_item->msg_data_full_file_name, &duration)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: read file error. %s\n", __FUNCTION__, __LINE__, msg_item->msg_data_full_file_name); + } + else + { + duration = (duration + 999) / 1000; + } + + if(0 == duration) + { + /*invalid voice*/ + lv_img_set_src(play_img, ICON_WECHAT_VOICE_ITEM_DAMAGE); + lv_label_set_text(len_label, ""); + } + else + { + char len_str[8] = {0}; + + if(WECHAT_MSG_DATA_RECORD_DURATION_MAX < duration) + duration = WECHAT_MSG_DATA_RECORD_DURATION_MAX; + + sprintf(len_str, "%d\"", duration); + lv_label_set_text(len_label, len_str); + } + + if(0 == msg_item->msg_from) // msg from slef + { + lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_self); + //lv_img_set_src(obj, ICON_WECHAT_MY_VOICE_ITEM_BG); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_self)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_RIGHT, -10, obj_y); + if(0 < duration) + { + lv_img_set_src(play_img, ICON_WECHAT_MY_VOICE_ITEM_PLAYING3); + } + lv_obj_align(play_img, obj, LV_ALIGN_IN_LEFT_MID, 15, 0); + lv_obj_align(len_label, play_img, LV_ALIGN_OUT_RIGHT_MID, 10, 0); + lv_obj_del(unread_img); + } + else // msg from other + { + lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_other); + //lv_img_set_src(obj, ICON_WECHAT_OTHER_VOICE_ITEM_BG); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); + if(0 < duration) + { + lv_img_set_src(play_img, ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3); + } + lv_obj_align(play_img, obj, LV_ALIGN_IN_RIGHT_MID, -15, 0); + lv_obj_align(len_label, play_img, LV_ALIGN_OUT_LEFT_MID, -10, 0); + if(1 == msg_item->unread_flag) + { + lv_img_set_src(unread_img, ICON_WECHAT_UNREAD_FLAG); + lv_obj_align(unread_img, obj, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + list_item_ext->unread_img = unread_img; + } + else + { + lv_obj_del(unread_img); + } + } + + lv_obj_set_click(obj, true); + lv_obj_set_event_cb(obj, wechat_chat_list_voice_item_event_cb); + lv_obj_set_adv_hittest(obj, false); + lv_page_focus(list_page, obj, 0); + lv_page_glue_obj(obj, true); + lv_watch_obj_add_element(obj); + break; + + case WECHAT_MSG_TYPE_TEXT: + obj = lv_cont_create(list_page, NULL); + list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); + list_item_ext->item_index = i; + list_item_ext->unread_img = NULL; + lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); //lv_obj_set_size(obj, 153, 53); // same with voice item + lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); + //lv_cont_set_layout(obj, LV_LAYOUT_COLUMN_LEFT); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); + + lv_fs_file_t file_p; + lv_fs_res_t res; + uint32_t file_size = 0, bytes_read = 0; + char * file_buf = NULL; + + res = lv_fs_open(&file_p, msg_item->msg_data_full_file_name, LV_FS_MODE_RD); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + break; + } + + lv_fs_size(&file_p, &file_size); + file_buf = (char *)lv_mem_alloc(file_size + 1); + _lv_memset_00(file_buf, file_size + 1); + res = lv_fs_read(&file_p, file_buf, file_size, &bytes_read); + lv_fs_close(&file_p); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_mem_free(file_buf); + break; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d,%d,%s\n", __FUNCTION__, __LINE__, file_size, bytes_read, file_buf); + + lv_obj_t * label_text = lv_label_create(obj, NULL); + lv_obj_add_style(label_text, LV_LABEL_PART_MAIN, &(list_page_ext->style_label_len_other)); + lv_label_set_align(label_text, LV_LABEL_ALIGN_CENTER); + lv_label_set_long_mode(label_text, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label_text, lv_obj_get_width(obj) - 20); + lv_label_set_text(label_text, file_buf); + lv_obj_align(label_text, obj, LV_ALIGN_IN_LEFT_MID, 10, 0); + + lv_obj_set_click(obj, true); + lv_obj_set_event_cb(obj, wechat_chat_list_text_item_event_cb); + lv_obj_set_adv_hittest(obj, false); + lv_page_focus(list_page, obj, 0); + lv_page_glue_obj(obj, true); + lv_watch_obj_add_element(obj); + + lv_mem_free(file_buf); + break; + + case WECHAT_MSG_TYPE_EXPRESSION: + case WECHAT_MSG_TYPE_IMAGE: + #if 0 + obj = lv_img_create(list, NULL); + + lv_watch_obj_add_element(obj); + #endif + break; + + default: + break; + } + + return obj; +} + +lv_res_t wechat_chat_list_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancient_scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) + return res; + + if(LV_SIGNAL_COORD_CHG == sign) + { + lv_obj_t * list_page = lv_obj_get_parent(scrl); + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(true == list_page_ext->pressing) + { + list_page_ext->pressing = false; + } + } + + return LV_RES_OK; +} + +void wechat_chat_list_create(lv_obj_t * obj, lv_wechat_ext_t * ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_t * list_page = lv_page_create(obj, NULL); + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_allocate_ext_attr(list_page, sizeof(lv_wechat_msg_list_ext_t)); + if(NULL == ext) + return; + + lv_obj_set_size(list_page, lv_obj_get_width(obj), lv_obj_get_height(obj) - 5 - lv_obj_get_height(ext->img_record) - 8); + lv_page_set_scrollbar_mode(list_page, LV_SCROLLBAR_MODE_OFF); + lv_obj_set_style_local_bg_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_border_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_outline_width(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_pad_bottom(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 4); + //lv_obj_set_style_local_pad_top(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 2); + //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 8); + //lv_obj_set_style_local_bg_color(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, lv_color_make(16, 112, 194)); + //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, LV_DPI / 20); + //lv_obj_set_style_local_pad_left(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_pad_right(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_radius(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + + lv_page_set_scrl_layout(list_page, LV_LAYOUT_OFF); + lv_page_set_scrollable_fit2(list_page, LV_FIT_NONE, LV_FIT_TIGHT); + + lv_obj_t * scrl = lv_page_get_scrollable(list_page); + ancient_scrl_signal = lv_obj_get_signal_cb(scrl); + lv_obj_set_signal_cb(scrl, wechat_chat_list_scrl_signal); + + lv_watch_obj_add_element(list_page); + lv_watch_obj_add_element(scrl); + + lv_style_init(&(list_page_ext->style_label_time)); + lv_style_copy(&(list_page_ext->style_label_time), &lv_watch_font20); + lv_style_set_text_color(&(list_page_ext->style_label_time), LV_STATE_DEFAULT, lv_color_make(20, 187, 242)); + + //lv_style_init(&(list_page_ext->style_text)); + //lv_style_copy(&(list_page_ext->style_text), &lv_style_pretty); + //lv_style_set_bg_color(&(list_page_ext->style_text), LV_STATE_DEFAULT, lv_color_make(0xFF, 0xE1, 0xE1)); + //lv_style_set_border_width(&(list_page_ext->style_text), LV_STATE_DEFAULT, 0); + //lv_style_set_shadow_width(&(list_page_ext->style_text), LV_STATE_DEFAULT, 0); + + lv_style_init(&(list_page_ext->style_label_len_other)); + lv_style_copy(&(list_page_ext->style_label_len_other), &lv_watch_font26); + lv_style_set_text_color(&(list_page_ext->style_label_len_other), LV_STATE_DEFAULT, lv_color_make(202, 134, 255)); + + lv_style_init(&(list_page_ext->style_label_len_self)); + lv_style_copy(&(list_page_ext->style_label_len_self), &lv_watch_font26); + lv_style_set_text_color(&(list_page_ext->style_label_len_self), LV_STATE_DEFAULT, lv_color_make(108, 189, 5)); + + lv_style_init(&(list_page_ext->style_cont_self)); + lv_style_set_bg_color(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, LV_COLOR_MAKE(175, 242, 89)); + lv_style_set_radius(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 15); // 30 + lv_style_set_pad_top(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 + lv_style_set_pad_bottom(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 + lv_style_set_pad_left(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 + lv_style_set_pad_right(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 + + lv_style_init(&(list_page_ext->style_cont_other)); + lv_style_set_bg_color(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, LV_COLOR_MAKE(0xE2, 0xBD, 0xFF)); + lv_style_set_radius(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 15); + lv_style_set_pad_top(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); + lv_style_set_pad_bottom(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); + lv_style_set_pad_left(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); + lv_style_set_pad_right(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); + + _lv_memset_00(&(list_page_ext->voice_playing_anim), sizeof(lv_anim_t)); + list_page_ext->voice_playing_msg_from = 0; + list_page_ext->pressing = false; + ext->list = list_page; + + uint8_t i = 0; + uint8_t msg_count = wechat_msg_info_count_get(); + hal_rtc_t cur_time = {0}, last_msg_item_time = {0}, msg_time = {0}; + + Hal_Rtc_Gettime(&cur_time); + for(i = 0; i < msg_count; i++) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: i=%d, msg_count=%d\n", __FUNCTION__, __LINE__, i, msg_count); + + char time_str[32] = {0}; + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + + wechat_msg_info_index_item_get(i, &msg_item); + _lv_memcpy(&msg_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); + wechat_chat_list_msg_item_time(time_str, &cur_time, &msg_time, &last_msg_item_time); + _lv_memcpy(&last_msg_item_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); + + wechat_chat_list_msg_item_add(list_page, msg_item, time_str, i); + } + + if((lv_obj_get_height(list_page) - lv_obj_get_style_pad_top(list_page, LV_LIST_PART_BG) * 2) > lv_obj_get_height(scrl)) + { + lv_cont_set_layout(scrl, LV_LAYOUT_OFF); + } +} + +void wechat_main_screen_refresh(void) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_chat_list_set_slide_enable(&ext->old_ext, true); + + wechat_msg_voice_item_playing_stop(ext); + + wechat_chat_list_msg_item_style_reset(ext); + if(NULL != ext->list) + { + lv_obj_del(ext->list); + ext->list = NULL; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + if(NULL != ext->delete_timer_id) + { + Hal_Timer_Stop(ext->delete_timer_id); + ext->delete_timer_id = NULL; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + if(NULL != ext->delete_bg) + { + lv_obj_del(ext->delete_bg); + ext->delete_bg = NULL; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + uint8_t msg_count = wechat_msg_info_count_get(); + if(0 == msg_count) + { + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_set_hidden(ext->label_no_msg, false); + } + else + { + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_set_hidden(ext->label_no_msg, true); + + wechat_chat_list_create(ext->cont, ext); + } +} + +lv_obj_t * wechat_create(lv_obj_t * activity_obj, lv_wechat_created_from_e from) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(activity_obj == NULL) + { + lv_watch_activity_ext_t activity_ext; + + _lv_memset_00(&activity_ext, sizeof(lv_watch_activity_ext_t)); + activity_ext.actId = ACT_ID_WECHAT_MAIN; + activity_ext.create = (lv_watch_activity_create_f_t)wechat_create; //NULL; + activity_ext.prepare_destory = wechat_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + LV_ASSERT_MEM(activity_obj); + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + if(NULL == obj) + return NULL; + /*Allocate the tab type specific extended data*/ + lv_wechat_ext_t * ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_ext_t)); + if(NULL == ext) + return NULL; + + ext->cont = NULL; + ext->list = NULL; + ext->from = from; + ext->delete_timer_id = NULL; + ext->delete_bg = NULL; + ext->record_buffer = NULL; + ext->record_size = 0; + + lv_obj_t * cont = lv_cont_create(obj, NULL); + lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); + lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); + lv_watch_obj_add_element(cont); + ext->cont = cont; + + if(false == watch_modem_sim_present_check_req() + //|| (MMI_MODEM_SIGNAL_BAR_0 == watch_modem_get_signal_bar_req()) + ) + { + // no network + lv_obj_t * label = lv_label_create(cont, NULL); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NO_NETWORK); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); + + return obj; + } + else if(true != mmi_watch_tcp_connect_state_get() + || true != mmi_protocol_watch_bind_state_get() + ) + { + // not bind + lv_obj_t * label = lv_label_create(cont, NULL); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NOT_BIND); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); + + return obj; + } + + //create no msg label + ext->label_no_msg = lv_label_create(cont, NULL); + lv_obj_add_style(ext->label_no_msg, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(ext->label_no_msg, WATCH_TEXT_ID_NO_VOICE_MSG); + //lv_label_set_align(ext->label_no_msg, LV_LABEL_ALIGN_CENTER); + lv_obj_align(ext->label_no_msg, cont, LV_ALIGN_CENTER, 0, -10); + + ext->img_record = lv_img_create(cont, NULL); + lv_img_set_src(ext->img_record, ICON_WECHAT_RECORD_BUTTON); + lv_obj_set_click(ext->img_record, true); + lv_obj_set_event_cb(ext->img_record, wechat_msg_record_button_event_cb); + lv_obj_set_adv_hittest(ext->img_record, false); + lv_obj_add_protect(ext->img_record, LV_PROTECT_PRESS_LOST); + lv_watch_obj_add_element(ext->img_record); + lv_obj_align(ext->img_record, cont, LV_ALIGN_IN_BOTTOM_MID, 0, -8); + + uint8_t msg_count = wechat_msg_info_count_get(); + if(0 == msg_count) + { + lv_obj_set_hidden(ext->label_no_msg, false); + } + else + { + lv_obj_set_hidden(ext->label_no_msg, true); + + wechat_chat_list_create(cont, ext); + } + + //uint32_t fs_total = 0; + //uint32_t fs_free = 0; + //lv_fs_free_space('C', &fs_total, &fs_free); + //WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total = %dB, free = %dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); + + return obj; +} + +void wechat_create_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_watch_png_cache_all_free(); + lv_obj_t * obj = wechat_create(NULL, WECHAT_CREATED_FROM_APP); + LV_ASSERT_MEM(obj); + } +} + +#endif diff --git a/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_circle.c b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_circle.c new file mode 100644 index 00000000..714bf1b1 --- /dev/null +++ b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_circle.c @@ -0,0 +1,1996 @@ + + + +#ifdef __MMI_WECHAT_SUPPORT__ + + +static lv_signal_cb_t ancient_scrl_signal; + +static uint8_t s_wechat_msg_init_flag = 0; +static nv_watch_wechat_msg_info_t * s_wechat_msg_info = NULL; +static nv_watch_wechat_msg_item_info_t s_wechat_msg_item_info = {0}; +static uint8_t s_wechat_play_anim_count = 0; +static char s_wechat_selected_item_index = -1; +static bool s_item_receive_playing = false; + + +void wechat_msg_info_nv_write(void) +{ + uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, NV_SECTION_UI_WEHAT_MSG); + + if(nv_data_length != UI_NV_Write_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG write fail\n", __FUNCTION__, __LINE__); + } +} + +void mmi_wechat_msg_info_init(void) +{ + if(0 == s_wechat_msg_init_flag) + { + uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); + + s_wechat_msg_info = (nv_watch_wechat_msg_info_t *)lv_mem_alloc(nv_data_length); + if(NULL == s_wechat_msg_info) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: memory alloc fail\n", __FUNCTION__, __LINE__); + return; + } + _lv_memset_00(s_wechat_msg_info, nv_data_length); + + if(nv_data_length != UI_NV_Read_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG read fail\n", __FUNCTION__, __LINE__); + //lv_mem_free(s_wechat_msg_info); + //s_wechat_msg_info = NULL; + } + + s_wechat_msg_init_flag = 1; + } +} + +uint8_t wechat_msg_info_count_get(void) +{ + uint8_t msg_count = s_wechat_msg_info->msg_count; + + return msg_count; +} + +uint8_t wechat_msg_info_index_item_msg_from_get(uint8_t msg_index) +{ + // 0-slef; 1-other + uint8_t msg_from = s_wechat_msg_info->msg_item[msg_index].msg_from; + + return msg_from; +} + +void wechat_msg_info_index_item_get(uint8_t msg_index, nv_watch_wechat_msg_item_info_t ** msg_item) +{ + *msg_item = &(s_wechat_msg_info->msg_item[msg_index]); +} + +void wechat_msg_info_index_item_delete(uint8_t msg_index) +{ + if(msg_index >= s_wechat_msg_info->msg_count) + return; + + uint8_t i = 0; + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + lv_fs_remove(s_wechat_msg_info->msg_item[msg_index].msg_data_full_file_name); + _lv_memset_00(&(s_wechat_msg_info->msg_item[msg_index]), msg_item_info_size); + + if(msg_index < s_wechat_msg_info->msg_count - 1) + { + for(i = msg_index; i < s_wechat_msg_info->msg_count; i++) + { + _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); + } + } + s_wechat_msg_info->msg_count--; +} + +void wechat_msg_info_all_item_delete(void) +{ + uint8_t i = 0; + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + for(i = 0; i < s_wechat_msg_info->msg_count; i++) + { + lv_fs_remove(s_wechat_msg_info->msg_item[i].msg_data_full_file_name); + _lv_memset_00(&(s_wechat_msg_info->msg_item[i]), msg_item_info_size); + } + s_wechat_msg_info->msg_count = 0; +} + +void wechat_msg_info_new_item_add(nv_watch_wechat_msg_item_info_t * msg_item) +{ + uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NV_WATCH_WECHAT_NUM_MAX <= s_wechat_msg_info->msg_count) + { + lv_fs_remove(s_wechat_msg_info->msg_item[0].msg_data_full_file_name); + //_lv_memset_00(&(s_wechat_msg_info->msg_item[0]), msg_item_info_size); + + uint8_t i = 0; + for(i = 0; i < NV_WATCH_WECHAT_NUM_MAX - 1; i++) + { + _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); + } + s_wechat_msg_info->msg_count--; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + s_wechat_msg_info->msg_count++; + _lv_memcpy(&(s_wechat_msg_info->msg_item[s_wechat_msg_info->msg_count - 1]), msg_item, msg_item_info_size); +} + +void * wechat_actId_ext_get(lv_watch_Activity_Id_t actId) +{ + lv_obj_t * activity_obj = lv_watch_get_activity_obj(actId); + if(NULL == activity_obj) + return NULL; + + lv_obj_t * watch_obj = NULL; + lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); + if(NULL != watch_obj) + { + void * ext = lv_obj_get_ext_attr(watch_obj); + return ext; + } + + return NULL; +} + +static lv_obj_t * wechat_main_get_obj(void) +{ + lv_obj_t * watch_obj = NULL; + + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN); + if(NULL != activity_obj) + { + lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); + } + + return watch_obj; +} + +void wechat_common_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); +} + +void wechat_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(WECHAT_CREATED_FROM_ALBUM == ext->from) + { + album_photo_share_flag_reset(); + } + else if(WECHAT_CREATED_FROM_IMGVIEWER == ext->from) + { + imgviewer_photo_share_flag_reset(); + } + + if(NULL != ext->delete_timer_id) + { + Hal_Timer_Stop(ext->delete_timer_id); + ext->delete_timer_id = NULL; + } + + wechat_msg_voice_item_playing_stop(ext); + wechat_chat_list_msg_item_style_reset(ext); + + // + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); +} + +static void wechat_chat_list_set_slide_enable(lv_watch_obj_ext_t * ext, bool enable) +{ + if(enable) + { + ext->slide_enable = 1; /*enable to slide to the right*/ + } + else + { + ext->slide_enable = 0; /*disable to slide to the right*/ + } +} + +bool wechat_msg_voice_is_playing(void) +{ + bool result = false; + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->list) + { + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); + if(NULL != list_page_ext->voice_playing_anim.var) + { + result = true; + } + } + + return result; +} + +bool wechat_msg_voice_is_recording(void) +{ + bool result = false; + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING)) + { + result = true; + } + + return result; +} + +bool wechat_msg_item_is_sending(void) +{ + bool result = false; + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING)) + { + result = true; + } + + return result; +} + +void wechat_receive_audio_play_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; + } +} + +void wechat_receive_audio_play_over_cb(void *para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + s_item_receive_playing = false; +} + +static bool wechat_msg_item_info_write_to_file(char * file_path, char * file_buf, uint32_t file_size) +{ + lv_fs_file_t file_p; + lv_fs_res_t res; + uint32_t bytes_write = 0; + + res = lv_fs_open(&file_p, file_path, LV_FS_MODE_WR); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + return false; + } + res = lv_fs_write(&file_p, file_buf, file_size, &bytes_write); + lv_fs_close(&file_p); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + return false; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, file_size, bytes_write); + + return true; +} + +void wechat_msg_receive_update_ui(void) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_receive_audio_play_audio_ctrl_callback)) + { + if(false == s_item_receive_playing) + { + s_item_receive_playing = true; + + Hal_NFFS_File_Play_Onetime(AUDIO_WECHAT_RECEIVE, (HAL_SPEAKER_GAIN)query_current_volume(), wechat_receive_audio_play_over_cb, NULL); + Hal_Vibrator_Play_Onetime(NULL, 1000); + } + + if(lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN)) + { + wechat_main_screen_refresh(); + } + else + { + wechat_create_event_cb(NULL, LV_EVENT_CLICKED); + } + } +} + +bool wechat_msg_receive_from_server(char * data_buff, int data_buff_len, nv_wechat_msg_type_e type) +{ + if(NULL == data_buff || 0 == data_buff_len) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + if(WECHAT_MSG_TYPE_MAX <= type) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + + nv_watch_wechat_msg_item_info_t wechat_msg_item_info = {0}; + hal_rtc_t cur_time = {0}; + char * t_file_ext[WECHAT_MSG_TYPE_MAX] = {"amr", "txt", "png", "png"}; // match nv_wechat_msg_type_e + + Hal_Rtc_Gettime(&cur_time); + _lv_memcpy(&(wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); + + wechat_msg_item_info.msg_from = 1; + wechat_msg_item_info.unread_flag = 1; + wechat_msg_item_info.msg_type = type; // WECHAT_MSG_TYPE_VOICE; + wechat_msg_item_info.msg_data_size = data_buff_len; + sprintf(wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_r%04d%02d%02d_%02d%02d%02d.%s", /*WECHAT_MSG_DATA_FILE_PATH, */ + wechat_msg_item_info.msg_time.tm_year, + wechat_msg_item_info.msg_time.tm_mon, + wechat_msg_item_info.msg_time.tm_mday, + wechat_msg_item_info.msg_time.tm_hour, + wechat_msg_item_info.msg_time.tm_min, + wechat_msg_item_info.msg_time.tm_sec, + t_file_ext[type]); + + if(false == wechat_msg_item_info_write_to_file(wechat_msg_item_info.msg_data_full_file_name, data_buff, data_buff_len)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return false; + } + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + wechat_msg_voice_item_playing_stop(ext); + } + + wechat_msg_info_new_item_add(&wechat_msg_item_info); + + // ui + if(false == mmi_active_screen_is_prohibit_interrupted() + && false == mmi_health_measure_state_is_ui_measure() +// && false == wechat_msg_voice_is_playing() + && false == wechat_msg_voice_is_recording() + && false == wechat_msg_item_is_sending() + #ifdef __MMI_ZHSX_SUPPORT_DO_NOT_DISTURB__ + && false == mmi_watch_is_in_do_not_disturb_time() + #endif + ) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + mmi_watch_wake_up(); + mmi_ui_msg_action_wechat_incoming(); + } + + return true; +} + +bool wechat_msg_send_to_server(void) +{ + bool result = false; // true-success; false-fail + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return false; + + uint32_t file_size = ext->record_size; + char * file_buf = lv_mem_alloc(file_size + 1); + if(NULL == file_buf || WECHAT_MSG_DATA_AMR_HEAD_SIZE >= file_size) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + _lv_memset_00(file_buf, file_size + 1); + _lv_memcpy(file_buf, ext->record_buffer, file_size); + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + + if(true == wechat_msg_item_info_write_to_file(s_wechat_msg_item_info.msg_data_full_file_name, file_buf, file_size)) + { + if(true == mmi_protocol_action_send_talk(file_buf, file_size)) + { + s_wechat_msg_item_info.msg_data_size = file_size; + wechat_msg_info_new_item_add(&s_wechat_msg_item_info); + result = true; + } + else + { + lv_fs_remove(s_wechat_msg_item_info.msg_data_full_file_name); + } + } + + lv_mem_free(file_buf); + _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); + + return result; +} + +void wechat_msg_item_delete_success_timer_cb(void *para) +{ + //lv_wechat_ext_t * ext = (lv_wechat_ext_t *)para; + + wechat_main_screen_refresh(); +} + +void wechat_msg_item_delete_ok_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->delete_bg) + { + uint32_t value = lv_watch_get_free_num(obj); + if(0 == value) + wechat_msg_info_index_item_delete(s_wechat_selected_item_index); + else if(1 == value) + wechat_msg_info_all_item_delete(); + + lv_obj_clean(ext->delete_bg); + + lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); + lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_SUCCESS); + lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -10); + + //ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, ext, false); + ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, NULL, false); + } + } +} + +void wechat_msg_item_delete_cancel_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->delete_bg) + { + lv_obj_del(ext->delete_bg); + ext->delete_bg = NULL; + } + } +} + +void wechat_msg_item_delete_select_btn_event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(LV_EVENT_CLICKED != e) + { + return; + } + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + uint32_t value = lv_watch_get_free_num(obj); + + lv_obj_set_hidden(ext->delete_current, true); + lv_obj_set_hidden(ext->delete_all, true); + lv_obj_set_hidden(ext->delete_back, true); + + lv_obj_set_hidden(ext->delete_label_prompt, false); + lv_obj_set_hidden(ext->delete_btn_cancel, false); + lv_obj_set_hidden(ext->delete_btn_ok, false); + lv_watch_set_free_num(ext->delete_btn_ok, value); + } +} + +void wechat_chat_list_msg_item_delete_create(void) +{ + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext && NULL != ext->cont) + { + ext->delete_bg = lv_cont_create(ext->cont, NULL); + lv_obj_set_size(ext->delete_bg, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style_local_bg_color(ext->delete_bg, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xB6, 0xF7, 0xFF)); + + // current + lv_obj_t * btn_delete_current = lv_cont_create(ext->delete_bg, NULL); + lv_obj_set_size(btn_delete_current, LV_HOR_RES - 40, 56); + lv_obj_set_style_local_bg_color(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xB9, 0x86, 0xFF)); + lv_obj_set_style_local_radius(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_click(btn_delete_current, true); + lv_obj_set_event_cb(btn_delete_current, wechat_msg_item_delete_select_btn_event_cb); + lv_obj_align(btn_delete_current, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); + lv_watch_set_free_num(btn_delete_current, 0); + ext->delete_current = btn_delete_current; + + lv_obj_t * label_delete_current = lv_label_create(btn_delete_current, NULL); + lv_obj_add_style(label_delete_current, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_current, WATCH_TEXT_ID_DELETE_CURRENT_ITEM); + lv_label_set_align(label_delete_current, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_current, btn_delete_current, LV_ALIGN_CENTER, 0, 0); + + // all + lv_obj_t * btn_delete_all = lv_cont_create(ext->delete_bg, btn_delete_current); + lv_obj_set_style_local_bg_color(btn_delete_all, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xFF, 0x6F, 0x91)); + lv_obj_align(btn_delete_all, btn_delete_current, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); + lv_watch_set_free_num(btn_delete_all, 1); + ext->delete_all = btn_delete_all; + + lv_obj_t * label_delete_all = lv_label_create(btn_delete_all, NULL); + lv_obj_add_style(label_delete_all, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_all, WATCH_TEXT_ID_DELETE_ALL_ITEM); + lv_label_set_align(label_delete_all, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_all, btn_delete_all, LV_ALIGN_CENTER, 0, 0); + + // back + lv_obj_t * btn_delete_back = lv_cont_create(ext->delete_bg, btn_delete_current); + lv_obj_set_style_local_bg_color(btn_delete_back, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_event_cb(btn_delete_back, wechat_msg_item_delete_cancel_btn_event_cb); + lv_obj_align(btn_delete_back, btn_delete_all, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); + ext->delete_back = btn_delete_back; + + lv_obj_t * label_delete_back = lv_label_create(btn_delete_back, NULL); + lv_obj_add_style(label_delete_back, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_delete_back, WATCH_TEXT_ID_CANCEL); + lv_label_set_align(label_delete_back, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_delete_back, btn_delete_back, LV_ALIGN_CENTER, 0, 0); + + + lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); + lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_Q); + lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -30); + ext->delete_label_prompt = label_prompt; + + lv_obj_t * btn_cancel = lv_btn_create(ext->delete_bg, NULL); + lv_obj_set_size(btn_cancel, 100, 56); + lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); + lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); + lv_obj_align(btn_cancel, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 10, -20); + lv_obj_set_event_cb(btn_cancel, wechat_msg_item_delete_cancel_btn_event_cb); + ext->delete_btn_cancel = btn_cancel; + + lv_obj_t * label_cancel = lv_label_create(btn_cancel, NULL); + lv_obj_add_style(label_cancel, LV_LABEL_PART_MAIN, &lv_watch_font26); + lv_label_set_text_id(label_cancel, WATCH_TEXT_ID_CANCEL); + + lv_obj_t * btn_ok = lv_btn_create(ext->delete_bg, btn_cancel); + lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xFF, 0x6F, 0x91)); + lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0xFF, 0x6F, 0x91)); + lv_obj_align(btn_ok, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -20); + lv_obj_set_event_cb(btn_ok, wechat_msg_item_delete_ok_btn_event_cb); + ext->delete_btn_ok = btn_ok; + + lv_obj_t * label_ok = lv_label_create(btn_ok, label_cancel); + lv_label_set_text_id(label_ok, WATCH_TEXT_ID_OK); + + // display + lv_obj_set_hidden(label_prompt, true); + lv_obj_set_hidden(btn_cancel, true); + lv_obj_set_hidden(btn_ok, true); + } +} + +void wechat_msg_sending_anim_cb(lv_anim_t * a) +{ + lv_obj_t * img = a->var; + + switch(s_wechat_play_anim_count % 3) + { + case 0: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT1); + break; + + case 1: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT2); + break; + + case 2: + lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT3); + break; + + default: + break; + } + s_wechat_play_anim_count++; +} + +void wechat_msg_sending_result_screen_timeout(void *para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_sending_screen_prepare_destory(NULL); + + //delete sending screen + //lv_watch_del_interface(ACT_ID_WECHAT_SENDING); + lv_obj_t * obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING); + if(NULL != obj) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + lv_obj_del(obj); + } + + //return main list screen + wechat_main_screen_refresh(); +} + +void wechat_msg_sending_screen_timeout(void *para) +{ + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)para; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL != sending_ext->sending_timer_id) + { + Hal_Timer_Stop(sending_ext->sending_timer_id); + sending_ext->sending_timer_id = NULL; + } + + if(NULL != sending_ext->sending_anim.var) + { + lv_obj_t * img_bkg = lv_obj_get_parent(sending_ext->sending_anim.var); + lv_img_set_src(img_bkg, ((true == sending_ext->send_result) ? ICON_WECHAT_SENDING_SUCC : ICON_WECHAT_SENDING_FAILED)); + + lv_anim_del(sending_ext->sending_anim.var, NULL); + lv_obj_del(sending_ext->sending_anim.var); + sending_ext->sending_anim.var = NULL; + } + + sending_ext->result_timer_id = Hal_Timer_Start(1500, wechat_msg_sending_result_screen_timeout, sending_ext, FALSE); +} + +void wechat_msg_sending_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_SENDING); + if(NULL != sending_ext) + { + if(NULL != sending_ext->sending_timer_id) + { + Hal_Timer_Stop(sending_ext->sending_timer_id); + sending_ext->sending_timer_id = NULL; + } + if(NULL != sending_ext->result_timer_id) + { + Hal_Timer_Stop(sending_ext->result_timer_id); + sending_ext->result_timer_id = NULL; + } + } +} + +lv_obj_t * wechat_msg_sending_screen_create(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == activity_obj) + { + lv_watch_activity_ext_t activity_ext = {0}; + + activity_ext.actId = ACT_ID_WECHAT_SENDING; + activity_ext.create = (lv_watch_activity_create_f_t)wechat_msg_sending_screen_create; + activity_ext.prepare_destory = wechat_msg_sending_screen_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + if(NULL == activity_obj) + return NULL; + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + if(NULL == obj) + return NULL; + lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_sending_ext_t)); + if(NULL == sending_ext) + return NULL; + + wechat_chat_list_set_slide_enable(&sending_ext->old_ext, false); /*prevent to slide out while recording*/ + _lv_memset_00(&(sending_ext->sending_anim), sizeof(lv_anim_t)); + sending_ext->send_result = wechat_msg_send_to_server(); + sending_ext->sending_timer_id = Hal_Timer_Start(1000 * 3, wechat_msg_sending_screen_timeout, sending_ext, FALSE); + sending_ext->result_timer_id = NULL; + + lv_obj_t * img_bkg = lv_img_create(obj, NULL); + lv_img_set_src(img_bkg, ICON_WECHAT_SENDING_BG); + lv_obj_align(img_bkg, obj, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * img_sending = lv_img_create(img_bkg, NULL); + lv_img_set_src(img_sending, ICON_WECHAT_SENDING_PROMPT3); +#if USE_LV_WATCH_UI_240_320 + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); +#elif USE_LV_WATCH_UI_240_280 + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -40); +#else + lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); +#endif + + lv_anim_t * a = &(sending_ext->sending_anim); + lv_anim_init(a); + lv_anim_set_var(a, img_sending); + //lv_anim_set_exec_cb(a, (lv_anim_exec_xcb_t)wechat_msg_sending_anim_exec_cb); + lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_msg_sending_anim_cb); + lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_repeat_delay(a, 500); + lv_anim_start(a); + s_wechat_play_anim_count = 0; + + return obj; +} + +void wechat_msg_recording_release_event_cb(lv_obj_t * obj, lv_event_t e) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); + +#if 0 + if(LV_EVENT_RELEASED == e) //(LV_EVENT_CLICKED == e) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); + wechat_msg_sending_screen_create(NULL); + } +#endif +} + +void wechat_msg_recording_anim(lv_anim_t * a) +{ + s_wechat_play_anim_count++; + if(0 == (s_wechat_play_anim_count % 4)) + { + int8_t count_down = WECHAT_MSG_DATA_RECORD_DURATION_MAX - s_wechat_play_anim_count / 4; + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: count down=%d\n", __FUNCTION__, __LINE__, count_down); + + if(0 < count_down) + { + lv_obj_t * label_time = a->var; + const char * content = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); + uint8_t len = strlen(content) + 8; + char * text = (char *)lv_mem_alloc(len); + snprintf(text, len, "%s %d", content, count_down); + lv_label_set_text(label_time, text); + lv_mem_free(text); + } + } +} + +bool wechat_msg_recording_stop(bool is_cancel) +{ + uint32_t duration_ms = 0; + uint32_t size = 0; + + Hal_Record_Buffer_Stop_Req(&size, &duration_ms); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return false; + + if(true == is_cancel) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + + if(WECHAT_MSG_DATA_AMR_HEAD_SIZE >= size) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + ext->record_size = 0; + return false; + } + ext->record_size = size; + + return true; +} + +void wechat_msg_recording_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + if(false == watch_is_ready()) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + wechat_msg_recording_stop(true); + + //lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + } +} + +void wechat_msg_recording_task_cb(lv_task_t * task) +{ + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + if(0 == ext->old_ext.element_click_en) + { + /*sliding to the right, not click button*/ + return; + } + + lv_obj_t * activity_obj; + MCI_EVNET_T event = (MCI_EVNET_T) (task->user_data); + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, event); + + switch(event) + { + case MCI_EVENT_EOS: + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_recording_stop(false); + activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + wechat_msg_sending_screen_create(NULL); + break; + + case MCI_EVENT_ERROR: + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_msg_recording_stop(true); + activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_obj_del(activity_obj); + } + break; + + //case MCI_EVENT_INFO: + // break; + + default: + break; + } +} + +void wechat_msg_recording_cb(MCI_EVNET_T event, MCI_INFO_T info_type, int32_t value) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d,type=%d,value=%d\n", __FUNCTION__, __LINE__, event, info_type, value); + + if(MCI_EVENT_INFO != event) + { + //recording_ext->event = event; + lv_task_t * record_task = lv_task_create(wechat_msg_recording_task_cb, 10, LV_TASK_PRIO_HIGH, event); + lv_task_once(record_task); + } +} + + +void wechat_msg_recording_screen_prepare_destory(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_watch_png_cache_all_free(); + + wechat_msg_recording_stop(true); +} + +lv_obj_t * wechat_msg_recording_screen_create(lv_obj_t * activity_obj) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == activity_obj) + { + lv_watch_activity_ext_t activity_ext = {0}; + + activity_ext.actId = ACT_ID_WECHAT_RECORDING; + activity_ext.create = wechat_msg_recording_screen_create; + activity_ext.prepare_destory = wechat_msg_recording_screen_prepare_destory; // wechat_common_screen_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + if(NULL == activity_obj) + return NULL; + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + LV_ASSERT_MEM(obj); + + lv_wechat_msg_recording_ext_t * recording_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_recording_ext_t)); + LV_ASSERT_MEM(recording_ext); + + lv_obj_t * cont = lv_cont_create(obj, NULL); + lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); + lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); + + lv_obj_t * label_warning = lv_label_create(cont, NULL); + //lv_obj_set_style_local_text_font(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_THEME_WATCH_NIGHT_FONT_SMALL); + //lv_obj_set_style_local_text_color(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_add_style(label_warning, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + //lv_label_set_long_mode(label_warning, LV_LABEL_LONG_BREAK); + //lv_obj_set_width(label_warning, lv_obj_get_width(obj) * 2 / 3); + lv_label_set_text_id(label_warning, WATCH_TEXT_ID_SLIDE_UP_WARNING); + lv_label_set_align(label_warning, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_warning, cont, LV_ALIGN_IN_TOP_MID, 0, 30); + + lv_obj_t * label_time = lv_label_create(cont, NULL); + lv_obj_add_style(label_time, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + const char * rel_snd = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); + uint8_t len = strlen(rel_snd) + 4; + char * text = (char *)lv_mem_alloc(len); + snprintf(text, len, "%s %d", rel_snd, WECHAT_MSG_DATA_RECORD_DURATION_MAX); + lv_label_set_text(label_time, text); + lv_mem_free(text); + lv_obj_align(label_time, label_warning, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); + recording_ext->label = label_time; + + lv_obj_t * img_release_snd = lv_img_create(cont, NULL); + lv_img_set_src(img_release_snd, ICON_WECHAT_RECORD_BUTTON_PRESSED); + lv_obj_align(img_release_snd, cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, label_time); + lv_anim_set_start_cb(&a, (lv_anim_ready_cb_t)wechat_msg_recording_anim); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(&a, 249); + lv_anim_start(&a); + s_wechat_play_anim_count = 0; + + //fill info + _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); +#if 0 + //system crashed. unknown reason //20230327 + Hal_Rtc_Gettime(&(s_wechat_msg_item_info.msg_time)); +#else + hal_rtc_t cur_time; + Hal_Rtc_Gettime(&cur_time); + _lv_memcpy(&(s_wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); +#endif + s_wechat_msg_item_info.msg_type = WECHAT_MSG_TYPE_VOICE; + sprintf(s_wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_s%04d%02d%02d_%02d%02d%02d.amr", /*WECHAT_MSG_DATA_FILE_PATH, */ + s_wechat_msg_item_info.msg_time.tm_year, + s_wechat_msg_item_info.msg_time.tm_mon, + s_wechat_msg_item_info.msg_time.tm_mday, + s_wechat_msg_item_info.msg_time.tm_hour, + s_wechat_msg_item_info.msg_time.tm_min, + s_wechat_msg_item_info.msg_time.tm_sec + ); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d, file_name=%s\n", __FUNCTION__, __LINE__, + s_wechat_msg_item_info.msg_from, s_wechat_msg_item_info.msg_data_full_file_name); + + //recording +#if 0 + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) + { + Hal_File_Record_Start_Req(s_wechat_msg_item_info.msg_data_full_file_name, wechat_msg_recording_cb); + } + +#else + + lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return NULL; + + if(NULL != ext->record_buffer) + { + lv_mem_free(ext->record_buffer); + ext->record_buffer = NULL; + } + ext->record_buffer = (uint8_t *)lv_mem_alloc(WECHAT_MSG_DATA_RECORD_SIZE_MAX); + if(NULL != ext->record_buffer) + { + _lv_memset_00(ext->record_buffer, WECHAT_MSG_DATA_RECORD_SIZE_MAX); + + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) + { + Hal_Record_Buffer_Start_Req(ext->record_buffer, + WECHAT_MSG_DATA_RECORD_SIZE_MAX, + WECHAT_MSG_DATA_RECORD_DURATION_MAX * 1000, + wechat_msg_recording_cb); + } + } +#endif + + return obj; +} + +static void wechat_out_of_memory_btn_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_obj_del(lv_obj_get_parent(btn)); + + //return main list screen + wechat_main_screen_refresh(); + } +} + +void wechat_list_out_of_memory_create(lv_obj_t * obj) +{ + lv_obj_t * cont_bg = lv_cont_create(obj, NULL); + lv_obj_set_size(cont_bg, LV_HOR_RES, LV_VER_RES); + lv_obj_add_style(cont_bg, LV_CONT_PART_MAIN, &lv_watch_black_tight); + + lv_obj_t * img_mem = lv_img_create(cont_bg, NULL); + lv_img_set_src(img_mem, ICON_CAMERA_MEMORY); + lv_obj_align(img_mem, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); + + lv_obj_t * label = lv_label_create(cont_bg, NULL); + lv_label_set_text_id(label, WATCH_TEXT_ID_OUT_OF_MEM); + lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label, LV_HOR_RES - 40); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, img_mem, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + + lv_obj_t * btn = lv_btn_create(cont_bg, NULL); + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); + lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); + lv_obj_set_size(btn, 200, 56); + lv_obj_set_event_cb(btn, wechat_out_of_memory_btn_event_cb); + lv_obj_align(btn, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -20); + + lv_obj_t * btn_label = lv_label_create(btn, NULL); + lv_label_set_text_id(btn_label, WATCH_TEXT_ID_GOT_IT); + lv_obj_add_style(btn_label,LV_LABEL_PART_MAIN, &lv_watch_font26); +} + +void wechat_msg_record_button_event_cb(lv_obj_t * obj, lv_event_t e) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); + + if(LV_EVENT_LONG_PRESSED == e) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ + + if(0 == ext->old_ext.element_click_en) + { + /*sliding to the right, not click button*/ + return; + } + + uint32_t fs_total = 0, fs_free = 0; + lv_fs_free_space('C', &fs_total, &fs_free); + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total=%dB,free=%dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); + if(28 * 1024 > fs_free) // 30 * 1024 + { + lv_obj_t * obj = wechat_main_get_obj(); + wechat_list_out_of_memory_create(obj); + } + #if 0 + else if(NV_WATCH_WECHAT_NUM_MAX <= wechat_msg_info_count_get()) + //else if(2 <= wechat_msg_info_count_get()) + { + lv_obj_t * obj = wechat_main_get_obj(); + wechat_list_out_of_memory_create(obj); + } + #endif + else + { + wechat_chat_list_set_slide_enable(&ext->old_ext, false); /*prevent to slide out while recording*/ + + wechat_msg_recording_screen_create(NULL); + } + } + else if(LV_EVENT_CLICKED == e || LV_EVENT_PRESS_LOST == e) + { + lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); + if(NULL != activity_obj) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + lv_wechat_msg_recording_ext_t * recording_ext = (lv_wechat_msg_recording_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_RECORDING); + if(NULL == recording_ext) + return NULL; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ + + lv_indev_t * indev = lv_indev_get_act(); + if(indev) + { + lv_coord_t point_y = indev->proc.types.pointer.last_point.y; + lv_coord_t img_record_top = obj->coords.y1; + if(30 < img_record_top - point_y) // (point_y < (img_record_top - 20)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: indev_y=%d, img_y=%d\n", __FUNCTION__, __LINE__, point_y, img_record_top); + wechat_msg_recording_stop(true); + lv_obj_del(activity_obj); + //return main list screen + wechat_main_screen_refresh(); + + return; + } + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + wechat_msg_recording_stop(false); + lv_obj_del(activity_obj); + wechat_msg_sending_screen_create(NULL); + } + } + else if(LV_EVENT_PRESSED == e) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return ; + + // + Hal_NFFS_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + Hal_Vibrator_Play_End(); + + wechat_msg_voice_item_playing_stop(ext); + } +} + +void wechat_msg_voice_item_reset_play_state(lv_wechat_msg_list_ext_t * list_page_ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + uint8_t msg_from = list_page_ext->voice_playing_msg_from; + + lv_anim_del(list_page_ext->voice_playing_anim.var, NULL); + lv_img_set_src(list_page_ext->voice_playing_anim.var, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); + list_page_ext->voice_playing_anim.var = NULL; +} + +void wechat_msg_voice_item_playing_stop(lv_wechat_ext_t * ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(NULL == ext || NULL == ext->list) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(ext->list); + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + wechat_msg_voice_item_reset_play_state(list_page_ext); +} + +void wechat_chat_list_msg_item_style_reset(lv_wechat_ext_t * ext) +{ + if(NULL == ext || NULL == ext->list) + return; + + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); + if(NULL == list_page_ext) + return; + + lv_style_reset(&(list_page_ext->style_cont_self)); + lv_style_reset(&(list_page_ext->style_cont_other)); + lv_style_reset(&(list_page_ext->style_label_time)); + //lv_style_reset(&(list_page_ext->style_text)); + lv_style_reset(&(list_page_ext->style_label_len_self)); + lv_style_reset(&(list_page_ext->style_label_len_other)); +} + +void wechat_chat_list_msg_item_time(char * time_str, hal_rtc_t * cur_time, hal_rtc_t * msg_time, hal_rtc_t * last_msg_time) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(0 == last_msg_time->tm_year) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, msg_time->tm_mday, + msg_time->tm_hour, msg_time->tm_min); + + return; + } + + uint32_t msg_sec = time_to_seconds(msg_time); + uint32_t last_msg_sec = time_to_seconds(last_msg_time); + if(msg_sec < last_msg_sec) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, + msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + else if(msg_sec > (last_msg_sec + WECHAT_MSG_CHAT_TIME_INTERVAL)) + { + uint32_t cur_sec = time_to_seconds(cur_time); + if((msg_sec > cur_sec) || (msg_time->tm_year < cur_time->tm_year)) + { + sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, + msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + else + { + uint32_t today_sec = cur_sec - cur_time->tm_hour * 3600 - cur_time->tm_min * 60 - cur_time->tm_sec; + + if(msg_sec >= today_sec) + { + /*today*/ + sprintf(time_str, "%02d:%02d", msg_time->tm_hour, msg_time->tm_min); + } + else if(msg_sec >= (today_sec - 24 * 3600)) + { + /*yesterday*/ + const char * yesterday = lv_lang_get_text(WATCH_TEXT_ID_YESTERDAY); + + sprintf(time_str, "%s %02d:%02d", yesterday, msg_time->tm_hour, msg_time->tm_min); + } + else + { + uint8_t wday; + if(0 == cur_time->tm_wday) + { + /*today is Sunday*/ + wday = 6; + } + else + { + wday = cur_time->tm_wday - 1; + } + /*the start of a week is monday, the end is sunday*/ + if(msg_sec >= (today_sec - wday * 24 * 3600)) { + /*current week before yesterday*/ + const char * wday_str; + switch(rtc_calc_weekday(msg_time)) + { + case 1: + /*Monday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_MONDAY); + break; + case 2: + /*Tuesday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_TUESDAY); + break; + case 3: + /*Wednesday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_WEDNESDAY); + break; + case 4: + /*Thursday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_THURSDAY); + break; + case 5: + /*Friday*/ + wday_str = lv_lang_get_text(WATCH_TEXT_ID_FRIDAY); + break; + default: + printf("%s: week error\n", __FUNCTION__); + break; + } + + sprintf(time_str, "%s %02d:%02d", wday_str, msg_time->tm_hour, msg_time->tm_min); + } + else + { + sprintf(time_str, "%d/%d %02d:%02d", msg_time->tm_mon, msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); + } + } + } + } +} + +void wechat_chat_list_voice_item_playing_anim_cb(lv_anim_t * a) +{ + lv_obj_t * play_img = (lv_obj_t *)a->var; + uint8_t msg_from = wechat_msg_info_index_item_msg_from_get(s_wechat_selected_item_index); + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d\n", __FUNCTION__, __LINE__, msg_from); + + switch(s_wechat_play_anim_count % 3) + { + case 0: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING1 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING1)); + break; + + case 1: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING2 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING2)); + break; + + case 2: + lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); + break; + + default: + break; + } + s_wechat_play_anim_count++; +} + +void wechat_chat_list_voice_item_playing_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); + + if(AUDIO_CTRL_PRIORITY_5 == priority) + { + if(false == watch_is_ready()) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + } + else if(AUDIO_CTRL_PRIORITY_5 > priority) + { + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL != ext) + { + wechat_msg_voice_item_playing_stop(ext); + } + } +} + +void wechat_chat_list_voice_item_play_over_cb(void * para) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)para; + if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + return; + } + wechat_msg_voice_item_reset_play_state(list_page_ext); +} + +void wechat_chat_list_voice_item_play_action(lv_wechat_msg_list_ext_t * list_page_ext, lv_obj_t * play_img, lv_obj_t * unread_img) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + //display ui + lv_anim_t * a = &(list_page_ext->voice_playing_anim); + + lv_anim_init(a); + lv_anim_set_var(a, play_img); + lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_chat_list_voice_item_playing_anim_cb); + lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(a, 400); + lv_anim_start(a); + s_wechat_play_anim_count = 1; + + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); + msg_item->unread_flag = 0; + if(NULL != unread_img) + { + lv_obj_del(unread_img); + unread_img = NULL; + } + list_page_ext->voice_playing_msg_from = msg_item->msg_from; + + //play voice + if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_chat_list_voice_item_playing_audio_ctrl_callback)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + Hal_File_Play_Onetime(msg_item->msg_data_full_file_name, query_current_volume(), wechat_chat_list_voice_item_play_over_cb, list_page_ext, 0); + } +} + +void wechat_chat_list_voice_item_event_cb(lv_obj_t * cont, lv_event_t e) +{ + lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); + if(NULL == list_item_ext) + return; + + s_wechat_selected_item_index = list_item_ext->item_index; + + lv_obj_t * scrl = lv_obj_get_parent(cont); + lv_obj_t * list_page = lv_obj_get_parent(scrl); + //lv_obj_t * scrl = lv_page_get_scrl(list_page); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(LV_EVENT_PRESSED == e) + { + list_page_ext->pressing = true; + } + else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item + { + list_page_ext->pressing = false; + + wechat_chat_list_msg_item_delete_create(); + } + else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // playing voice msg + { + list_page_ext->pressing = false; + + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); + + if(0 != msg_item->msg_data_size) + { + if(NULL != list_page_ext->voice_playing_anim.var) // exist voice playing + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); + + //stop item voice + Hal_File_Play_End(); + Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); + wechat_msg_voice_item_reset_play_state(list_page_ext); + } + else if(NULL != msg_item->msg_data_full_file_name) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); + + lv_obj_t * play_img = lv_obj_get_child_back(cont, NULL); + wechat_chat_list_voice_item_play_action(list_page_ext, play_img, ((1 == msg_item->unread_flag) ? list_item_ext->unread_img : NULL)); + } + } + } +} + +void wechat_chat_list_text_item_event_cb(lv_obj_t * cont, lv_event_t e) +{ + lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); + if(NULL == list_item_ext) + return; + + s_wechat_selected_item_index = list_item_ext->item_index; + + lv_obj_t * scrl = lv_obj_get_parent(cont); + lv_obj_t * list_page = lv_obj_get_parent(scrl); + //lv_obj_t * scrl = lv_page_get_scrl(list_page); + + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(LV_EVENT_PRESSED == e) + { + list_page_ext->pressing = true; + } + else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item + { + list_page_ext->pressing = false; + + wechat_chat_list_msg_item_delete_create(); + } + else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // display text msg + { + list_page_ext->pressing = false; + } +} + +//display time & content +lv_obj_t * wechat_chat_list_msg_item_add(lv_obj_t * list_page, nv_watch_wechat_msg_item_info_t * msg_item, char * time_str, uint8_t i) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_t * obj = NULL; + lv_wechat_msg_list_item_ext_t * list_item_ext = NULL; + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(list_page); + lv_obj_t * scrl = lv_page_get_scrl(list_page); + lv_obj_t * last_obj = lv_obj_get_child(scrl, NULL); + lv_coord_t obj_y = 0; + + if(NULL != last_obj) + { + obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); + } + else + { + obj_y = lv_obj_get_style_pad_top(scrl, LV_STATE_DEFAULT); + } + + if(0 != strlen(time_str)) + { + obj = lv_label_create(list_page, NULL); + + //lv_obj_set_base_dir(obj, LV_BIDI_DIR_LTR); + lv_label_set_text(obj, time_str); + lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &list_page_ext->style_label_time); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_MID, 0, obj_y); + + last_obj = obj; + obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_type=%d,file=%s,size=%d,obj_y=%d\n", __FUNCTION__, __LINE__, + msg_item->msg_type, msg_item->msg_data_full_file_name, msg_item->msg_data_size, obj_y); + + switch(msg_item->msg_type) + { + case WECHAT_MSG_TYPE_VOICE: + lv_obj_t * unread_img = lv_img_create(list_page, NULL); + //obj = lv_img_create(list_page, NULL); + obj = lv_cont_create(list_page, NULL); + list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); + list_item_ext->item_index = i; + list_item_ext->unread_img = NULL; + lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); + lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); + + lv_obj_t * play_img = lv_img_create(obj, NULL); + lv_obj_t * len_label = lv_label_create(obj, NULL); + uint32_t duration = 0; + + if(LV_FS_RES_OK != Hal_File_Get_AudioDurationTime((const char *)msg_item->msg_data_full_file_name, &duration)) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: read file error. %s\n", __FUNCTION__, __LINE__, msg_item->msg_data_full_file_name); + } + else + { + duration = (duration + 999) / 1000; + } + + if(0 == duration) + { + /*invalid voice*/ + lv_img_set_src(play_img, ICON_WECHAT_VOICE_ITEM_DAMAGE); + lv_label_set_text(len_label, ""); + } + else + { + char len_str[8] = {0}; + + if(WECHAT_MSG_DATA_RECORD_DURATION_MAX < duration) + duration = WECHAT_MSG_DATA_RECORD_DURATION_MAX; + + sprintf(len_str, "%d\"", duration); + lv_label_set_text(len_label, len_str); + } + + if(0 == msg_item->msg_from) // msg from slef + { + lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_self); + //lv_img_set_src(obj, ICON_WECHAT_MY_VOICE_ITEM_BG); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_self)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_RIGHT, -10, obj_y); + if(0 < duration) + { + lv_img_set_src(play_img, ICON_WECHAT_MY_VOICE_ITEM_PLAYING3); + } + lv_obj_align(play_img, obj, LV_ALIGN_IN_LEFT_MID, 15, 0); + lv_obj_align(len_label, play_img, LV_ALIGN_OUT_RIGHT_MID, 10, 0); + lv_obj_del(unread_img); + } + else // msg from other + { + lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_other); + //lv_img_set_src(obj, ICON_WECHAT_OTHER_VOICE_ITEM_BG); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); + if(0 < duration) + { + lv_img_set_src(play_img, ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3); + } + lv_obj_align(play_img, obj, LV_ALIGN_IN_RIGHT_MID, -15, 0); + lv_obj_align(len_label, play_img, LV_ALIGN_OUT_LEFT_MID, -10, 0); + if(1 == msg_item->unread_flag) + { + lv_img_set_src(unread_img, ICON_WECHAT_UNREAD_FLAG); + lv_obj_align(unread_img, obj, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + list_item_ext->unread_img = unread_img; + } + else + { + lv_obj_del(unread_img); + } + } + + lv_obj_set_click(obj, true); + lv_obj_set_event_cb(obj, wechat_chat_list_voice_item_event_cb); + lv_obj_set_adv_hittest(obj, false); + lv_page_focus(list_page, obj, 0); + lv_page_glue_obj(obj, true); + lv_watch_obj_add_element(obj); + break; + + case WECHAT_MSG_TYPE_TEXT: + obj = lv_cont_create(list_page, NULL); + list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); + list_item_ext->item_index = i; + list_item_ext->unread_img = NULL; + lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); //lv_obj_set_size(obj, 153, 53); // same with voice item + lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); + //lv_cont_set_layout(obj, LV_LAYOUT_COLUMN_LEFT); + lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); + lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); + + lv_fs_file_t file_p; + lv_fs_res_t res; + uint32_t file_size = 0, bytes_read = 0; + char * file_buf = NULL; + + res = lv_fs_open(&file_p, msg_item->msg_data_full_file_name, LV_FS_MODE_RD); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + break; + } + + lv_fs_size(&file_p, &file_size); + file_buf = (char *)lv_mem_alloc(file_size + 1); + _lv_memset_00(file_buf, file_size + 1); + res = lv_fs_read(&file_p, file_buf, file_size, &bytes_read); + lv_fs_close(&file_p); + if(LV_FS_RES_OK != res) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_mem_free(file_buf); + break; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d,%d,%s\n", __FUNCTION__, __LINE__, file_size, bytes_read, file_buf); + + lv_obj_t * label_text = lv_label_create(obj, NULL); + lv_obj_add_style(label_text, LV_LABEL_PART_MAIN, &(list_page_ext->style_label_len_other)); + lv_label_set_align(label_text, LV_LABEL_ALIGN_CENTER); + lv_label_set_long_mode(label_text, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label_text, lv_obj_get_width(obj) - 20); + lv_label_set_text(label_text, file_buf); + lv_obj_align(label_text, obj, LV_ALIGN_IN_LEFT_MID, 10, 0); + + lv_obj_set_click(obj, true); + lv_obj_set_event_cb(obj, wechat_chat_list_text_item_event_cb); + lv_obj_set_adv_hittest(obj, false); + lv_page_focus(list_page, obj, 0); + lv_page_glue_obj(obj, true); + lv_watch_obj_add_element(obj); + + lv_mem_free(file_buf); + break; + + case WECHAT_MSG_TYPE_EXPRESSION: + case WECHAT_MSG_TYPE_IMAGE: + #if 0 + obj = lv_img_create(list, NULL); + + lv_watch_obj_add_element(obj); + #endif + break; + + default: + break; + } + + return obj; +} + +lv_res_t wechat_chat_list_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancient_scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) + return res; + + if(LV_SIGNAL_COORD_CHG == sign) + { + lv_obj_t * list_page = lv_obj_get_parent(scrl); + lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); + if(NULL == list_page_ext) + return; + + if(true == list_page_ext->pressing) + { + list_page_ext->pressing = false; + } + } + + return LV_RES_OK; +} + +void wechat_chat_list_create(lv_obj_t * obj, lv_wechat_ext_t * ext) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_t * list_page = lv_page_create(obj, NULL); + lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_allocate_ext_attr(list_page, sizeof(lv_wechat_msg_list_ext_t)); + if(NULL == ext) + return; + + lv_obj_set_size(list_page, lv_obj_get_width(obj) - 20, lv_obj_get_height(obj) - 20 - 5 - lv_obj_get_height(ext->img_record)); + lv_obj_align(list_page, obj, LV_ALIGN_IN_TOP_MID, 0, 20); + lv_page_set_scrollbar_mode(list_page, LV_SCROLLBAR_MODE_OFF); + lv_obj_set_style_local_bg_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_border_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_outline_width(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_pad_bottom(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 4); + //lv_obj_set_style_local_pad_top(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 2); + //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 8); + //lv_obj_set_style_local_bg_color(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, lv_color_make(16, 112, 194)); + //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, LV_DPI / 20); + //lv_obj_set_style_local_pad_left(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_pad_right(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + //lv_obj_set_style_local_radius(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); + + lv_page_set_scrl_layout(list_page, LV_LAYOUT_OFF); + lv_page_set_scrollable_fit2(list_page, LV_FIT_NONE, LV_FIT_TIGHT); + + lv_obj_t * scrl = lv_page_get_scrollable(list_page); + ancient_scrl_signal = lv_obj_get_signal_cb(scrl); + lv_obj_set_signal_cb(scrl, wechat_chat_list_scrl_signal); + + lv_watch_obj_add_element(list_page); + lv_watch_obj_add_element(scrl); + + lv_style_init(&(list_page_ext->style_label_time)); + lv_style_copy(&(list_page_ext->style_label_time), &lv_watch_font20); + lv_style_set_text_color(&(list_page_ext->style_label_time), LV_STATE_DEFAULT, lv_color_make(20, 187, 242)); + + lv_style_init(&(list_page_ext->style_label_len_other)); + lv_style_copy(&(list_page_ext->style_label_len_other), &lv_watch_font26); + lv_style_set_text_color(&(list_page_ext->style_label_len_other), LV_STATE_DEFAULT, lv_color_make(202, 134, 255)); + + lv_style_init(&(list_page_ext->style_label_len_self)); + lv_style_copy(&(list_page_ext->style_label_len_self), &lv_watch_font26); + lv_style_set_text_color(&(list_page_ext->style_label_len_self), LV_STATE_DEFAULT, lv_color_make(108, 189, 5)); + + lv_style_init(&(list_page_ext->style_cont_self)); + lv_style_set_bg_color(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, LV_COLOR_MAKE(175, 242, 89)); + lv_style_set_radius(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 15); // 30 + lv_style_set_pad_top(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 + lv_style_set_pad_bottom(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 + lv_style_set_pad_left(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 + lv_style_set_pad_right(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 + + lv_style_init(&(list_page_ext->style_cont_other)); + lv_style_set_bg_color(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, LV_COLOR_MAKE(0xE2, 0xBD, 0xFF)); + lv_style_set_radius(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 15); + lv_style_set_pad_top(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); + lv_style_set_pad_bottom(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); + lv_style_set_pad_left(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); + lv_style_set_pad_right(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); + + _lv_memset_00(&(list_page_ext->voice_playing_anim), sizeof(lv_anim_t)); + list_page_ext->voice_playing_msg_from = 0; + list_page_ext->pressing = false; + ext->list = list_page; + + uint8_t i = 0; + uint8_t msg_count = wechat_msg_info_count_get(); + hal_rtc_t cur_time = {0}, last_msg_item_time = {0}, msg_time = {0}; + + Hal_Rtc_Gettime(&cur_time); + for(i = 0; i < msg_count; i++) + { + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: i=%d, msg_count=%d\n", __FUNCTION__, __LINE__, i, msg_count); + + char time_str[32] = {0}; + nv_watch_wechat_msg_item_info_t * msg_item = NULL; + + wechat_msg_info_index_item_get(i, &msg_item); + _lv_memcpy(&msg_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); + wechat_chat_list_msg_item_time(time_str, &cur_time, &msg_time, &last_msg_item_time); + _lv_memcpy(&last_msg_item_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); + + wechat_chat_list_msg_item_add(list_page, msg_item, time_str, i); + } + + if((lv_obj_get_height(list_page) - lv_obj_get_style_pad_top(list_page, LV_LIST_PART_BG) * 2) > lv_obj_get_height(scrl)) + { + lv_cont_set_layout(scrl, LV_LAYOUT_OFF); + } +} + +void wechat_main_screen_refresh(void) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); + if(NULL == ext) + return; + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + wechat_chat_list_set_slide_enable(&ext->old_ext, true); + + wechat_msg_voice_item_playing_stop(ext); + + wechat_chat_list_msg_item_style_reset(ext); + if(NULL != ext->list) + { + lv_obj_del(ext->list); + ext->list = NULL; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + if(NULL != ext->delete_timer_id) + { + Hal_Timer_Stop(ext->delete_timer_id); + ext->delete_timer_id = NULL; + } + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + if(NULL != ext->delete_bg) + { + lv_obj_del(ext->delete_bg); + ext->delete_bg = NULL; + } + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + uint8_t msg_count = wechat_msg_info_count_get(); + if(0 == msg_count) + { + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_set_hidden(ext->label_no_msg, false); + } + else + { + + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + lv_obj_set_hidden(ext->label_no_msg, true); + + wechat_chat_list_create(ext->cont, ext); + } +} + +lv_obj_t * wechat_create(lv_obj_t * activity_obj, lv_wechat_created_from_e from) +{ + WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); + + if(activity_obj == NULL) + { + lv_watch_activity_ext_t activity_ext; + + _lv_memset_00(&activity_ext, sizeof(lv_watch_activity_ext_t)); + activity_ext.actId = ACT_ID_WECHAT_MAIN; + activity_ext.create = (lv_watch_activity_create_f_t)wechat_create; //NULL; + activity_ext.prepare_destory = wechat_prepare_destory; + activity_obj = lv_watch_creat_activity_obj(&activity_ext); + LV_ASSERT_MEM(activity_obj); + } + + lv_obj_t * obj = lv_watch_obj_create(activity_obj); + if(NULL == obj) + return NULL; + /*Allocate the tab type specific extended data*/ + lv_wechat_ext_t * ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_ext_t)); + if(NULL == ext) + return NULL; + + ext->cont = NULL; + ext->list = NULL; + ext->from = from; + ext->delete_timer_id = NULL; + ext->delete_bg = NULL; + ext->record_buffer = NULL; + ext->record_size = 0; + + lv_obj_t * cont = lv_cont_create(obj, NULL); + lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); + lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); + lv_watch_obj_add_element(cont); + ext->cont = cont; + + if(false == watch_modem_sim_present_check_req() + //|| (MMI_MODEM_SIGNAL_BAR_0 == watch_modem_get_signal_bar_req()) + ) + { + // no network + lv_obj_t * label = lv_label_create(cont, NULL); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NO_NETWORK); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); + + return obj; + } + else if(true != mmi_watch_tcp_connect_state_get() + || true != mmi_protocol_watch_bind_state_get() + ) + { + // not bind + lv_obj_t * label = lv_label_create(cont, NULL); + lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NOT_BIND); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); + + return obj; + } + + //create no msg label + ext->label_no_msg = lv_label_create(cont, NULL); + lv_obj_add_style(ext->label_no_msg, LV_LABEL_PART_MAIN, &lv_watch_font26_black); + lv_label_set_text_id(ext->label_no_msg, WATCH_TEXT_ID_NO_VOICE_MSG); + //lv_label_set_align(ext->label_no_msg, LV_LABEL_ALIGN_CENTER); + lv_obj_align(ext->label_no_msg, cont, LV_ALIGN_CENTER, 0, -10); + + ext->img_record = lv_img_create(cont, NULL); + lv_img_set_src(ext->img_record, ICON_WECHAT_RECORD_BUTTON); + lv_obj_set_click(ext->img_record, true); + lv_obj_set_event_cb(ext->img_record, wechat_msg_record_button_event_cb); + lv_obj_set_adv_hittest(ext->img_record, false); + lv_obj_add_protect(ext->img_record, LV_PROTECT_PRESS_LOST); + lv_watch_obj_add_element(ext->img_record); + lv_obj_align(ext->img_record, cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + uint8_t msg_count = wechat_msg_info_count_get(); + if(0 == msg_count) + { + lv_obj_set_hidden(ext->label_no_msg, false); + } + else + { + lv_obj_set_hidden(ext->label_no_msg, true); + + wechat_chat_list_create(cont, ext); + } + + //uint32_t fs_total = 0; + //uint32_t fs_free = 0; + //lv_fs_free_space('C', &fs_total, &fs_free); + //WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total = %dB, free = %dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); + + return obj; +} + +void wechat_create_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(LV_EVENT_CLICKED == e) + { + lv_watch_png_cache_all_free(); + lv_obj_t * obj = wechat_create(NULL, WECHAT_CREATED_FROM_APP); + LV_ASSERT_MEM(obj); + } +} + +#endif diff --git a/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_ui.c b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_ui.c index 2cd1b30d..1a0b44d4 100644 --- a/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_ui.c +++ b/2.sdk/sdk/gui/lv_watch/lv_apps/mmi_wechat/wechat_ui.c @@ -6,2031 +6,13 @@ #ifdef __MMI_WECHAT_SUPPORT__ -static lv_signal_cb_t ancient_scrl_signal; +#ifdef USE_LV_WATCH_UI_240_240_CIRCLE +#include "wechat_circle.c" -static uint8_t s_wechat_msg_init_flag = 0; -static nv_watch_wechat_msg_info_t * s_wechat_msg_info = NULL; -static nv_watch_wechat_msg_item_info_t s_wechat_msg_item_info = {0}; -static uint8_t s_wechat_play_anim_count = 0; -static char s_wechat_selected_item_index = -1; -static bool s_item_receive_playing = false; - - -void wechat_msg_info_nv_write(void) -{ - uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, NV_SECTION_UI_WEHAT_MSG); - - if(nv_data_length != UI_NV_Write_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG write fail\n", __FUNCTION__, __LINE__); - } -} - -void mmi_wechat_msg_info_init(void) -{ - if(0 == s_wechat_msg_init_flag) - { - uint32_t nv_data_length = sizeof(nv_watch_wechat_msg_info_t); - - s_wechat_msg_info = (nv_watch_wechat_msg_info_t *)lv_mem_alloc(nv_data_length); - if(NULL == s_wechat_msg_info) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: memory alloc fail\n", __FUNCTION__, __LINE__); - return; - } - _lv_memset_00(s_wechat_msg_info, nv_data_length); - - if(nv_data_length != UI_NV_Read_Req(NV_SECTION_UI_WEHAT_MSG, 0, nv_data_length, (uint8_t *)s_wechat_msg_info)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: NV_SECTION_UI_WEHAT_MSG read fail\n", __FUNCTION__, __LINE__); - //lv_mem_free(s_wechat_msg_info); - //s_wechat_msg_info = NULL; - } - - s_wechat_msg_init_flag = 1; - } -} - -uint8_t wechat_msg_info_count_get(void) -{ - uint8_t msg_count = s_wechat_msg_info->msg_count; - - return msg_count; -} - -uint8_t wechat_msg_info_index_item_msg_from_get(uint8_t msg_index) -{ - // 0-slef; 1-other - uint8_t msg_from = s_wechat_msg_info->msg_item[msg_index].msg_from; - - return msg_from; -} - -void wechat_msg_info_index_item_get(uint8_t msg_index, nv_watch_wechat_msg_item_info_t ** msg_item) -{ - *msg_item = &(s_wechat_msg_info->msg_item[msg_index]); -} - -void wechat_msg_info_index_item_delete(uint8_t msg_index) -{ - if(msg_index >= s_wechat_msg_info->msg_count) - return; - - uint8_t i = 0; - uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); - - lv_fs_remove(s_wechat_msg_info->msg_item[msg_index].msg_data_full_file_name); - _lv_memset_00(&(s_wechat_msg_info->msg_item[msg_index]), msg_item_info_size); - - if(msg_index < s_wechat_msg_info->msg_count - 1) - { - for(i = msg_index; i < s_wechat_msg_info->msg_count; i++) - { - _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); - } - } - s_wechat_msg_info->msg_count--; -} - -void wechat_msg_info_all_item_delete(void) -{ - uint8_t i = 0; - uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); - - for(i = 0; i < s_wechat_msg_info->msg_count; i++) - { - lv_fs_remove(s_wechat_msg_info->msg_item[i].msg_data_full_file_name); - _lv_memset_00(&(s_wechat_msg_info->msg_item[i]), msg_item_info_size); - } - s_wechat_msg_info->msg_count = 0; -} - -void wechat_msg_info_new_item_add(nv_watch_wechat_msg_item_info_t * msg_item) -{ - uint32_t msg_item_info_size = sizeof(nv_watch_wechat_msg_item_info_t); - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NV_WATCH_WECHAT_NUM_MAX <= s_wechat_msg_info->msg_count) - { - lv_fs_remove(s_wechat_msg_info->msg_item[0].msg_data_full_file_name); - //_lv_memset_00(&(s_wechat_msg_info->msg_item[0]), msg_item_info_size); - - uint8_t i = 0; - for(i = 0; i < NV_WATCH_WECHAT_NUM_MAX - 1; i++) - { - _lv_memcpy(&(s_wechat_msg_info->msg_item[i]), &(s_wechat_msg_info->msg_item[i + 1]), msg_item_info_size); - } - s_wechat_msg_info->msg_count--; - } - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - s_wechat_msg_info->msg_count++; - _lv_memcpy(&(s_wechat_msg_info->msg_item[s_wechat_msg_info->msg_count - 1]), msg_item, msg_item_info_size); -} - -void * wechat_actId_ext_get(lv_watch_Activity_Id_t actId) -{ - lv_obj_t * activity_obj = lv_watch_get_activity_obj(actId); - if(NULL == activity_obj) - return NULL; - - lv_obj_t * watch_obj = NULL; - lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); - if(NULL != watch_obj) - { - void * ext = lv_obj_get_ext_attr(watch_obj); - return ext; - } - - return NULL; -} - -static lv_obj_t * wechat_main_get_obj(void) -{ - lv_obj_t * watch_obj = NULL; - - lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN); - if(NULL != activity_obj) - { - lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj); - } - - return watch_obj; -} - -void wechat_common_screen_prepare_destory(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_watch_png_cache_all_free(); -} - -void wechat_prepare_destory(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_watch_png_cache_all_free(); - - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return ; - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(WECHAT_CREATED_FROM_ALBUM == ext->from) - { - album_photo_share_flag_reset(); - } - else if(WECHAT_CREATED_FROM_IMGVIEWER == ext->from) - { - imgviewer_photo_share_flag_reset(); - } - - if(NULL != ext->delete_timer_id) - { - Hal_Timer_Stop(ext->delete_timer_id); - ext->delete_timer_id = NULL; - } - - wechat_msg_voice_item_playing_stop(ext); - wechat_chat_list_msg_item_style_reset(ext); - - // - Hal_NFFS_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - Hal_Vibrator_Play_End(); - s_item_receive_playing = false; - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); -} - -static void wechat_chat_list_set_slide_enable(lv_watch_obj_ext_t * ext, bool enable) -{ - if(enable) - { - ext->slide_enable = 1; /*enable to slide to the right*/ - } - else - { - ext->slide_enable = 0; /*disable to slide to the right*/ - } -} - -bool wechat_msg_voice_is_playing(void) -{ - bool result = false; - - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext && NULL != ext->list) - { - lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); - if(NULL != list_page_ext->voice_playing_anim.var) - { - result = true; - } - } - - return result; -} - -bool wechat_msg_voice_is_recording(void) -{ - bool result = false; - - if(lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING)) - { - result = true; - } - - return result; -} - -bool wechat_msg_item_is_sending(void) -{ - bool result = false; - - if(lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING)) - { - result = true; - } - - return result; -} - -void wechat_receive_audio_play_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); - - if(AUDIO_CTRL_PRIORITY_5 == priority) - { - - } - else if(AUDIO_CTRL_PRIORITY_5 > priority) - { - Hal_NFFS_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - Hal_Vibrator_Play_End(); - s_item_receive_playing = false; - } -} - -void wechat_receive_audio_play_over_cb(void *para) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - Hal_NFFS_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - Hal_Vibrator_Play_End(); - s_item_receive_playing = false; -} - -static bool wechat_msg_item_info_write_to_file(char * file_path, char * file_buf, uint32_t file_size) -{ - lv_fs_file_t file_p; - lv_fs_res_t res; - uint32_t bytes_write = 0; - - res = lv_fs_open(&file_p, file_path, LV_FS_MODE_WR); - if(LV_FS_RES_OK != res) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); - lv_fs_close(&file_p); - return false; - } - res = lv_fs_write(&file_p, file_buf, file_size, &bytes_write); - lv_fs_close(&file_p); - if(LV_FS_RES_OK != res) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); - return false; - } - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, file_size, bytes_write); - - return true; -} - -void wechat_msg_receive_update_ui(void) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_receive_audio_play_audio_ctrl_callback)) - { - if(false == s_item_receive_playing) - { - s_item_receive_playing = true; - - Hal_NFFS_File_Play_Onetime(AUDIO_WECHAT_RECEIVE, (HAL_SPEAKER_GAIN)query_current_volume(), wechat_receive_audio_play_over_cb, NULL); - Hal_Vibrator_Play_Onetime(NULL, 1000); - } - - if(lv_watch_get_activity_obj(ACT_ID_WECHAT_MAIN)) - { - wechat_main_screen_refresh(); - } - else - { - wechat_create_event_cb(NULL, LV_EVENT_CLICKED); - } - } -} - -bool wechat_msg_receive_from_server(char * data_buff, int data_buff_len, nv_wechat_msg_type_e type) -{ - if(NULL == data_buff || 0 == data_buff_len) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return false; - } - if(WECHAT_MSG_TYPE_MAX <= type) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return false; - } - - nv_watch_wechat_msg_item_info_t wechat_msg_item_info = {0}; - hal_rtc_t cur_time = {0}; - char * t_file_ext[WECHAT_MSG_TYPE_MAX] = {"amr", "txt", "png", "png"}; // match nv_wechat_msg_type_e - - Hal_Rtc_Gettime(&cur_time); - _lv_memcpy(&(wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); - - wechat_msg_item_info.msg_from = 1; - wechat_msg_item_info.unread_flag = 1; - wechat_msg_item_info.msg_type = type; // WECHAT_MSG_TYPE_VOICE; - wechat_msg_item_info.msg_data_size = data_buff_len; - sprintf(wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_r%04d%02d%02d_%02d%02d%02d.%s", /*WECHAT_MSG_DATA_FILE_PATH, */ - wechat_msg_item_info.msg_time.tm_year, - wechat_msg_item_info.msg_time.tm_mon, - wechat_msg_item_info.msg_time.tm_mday, - wechat_msg_item_info.msg_time.tm_hour, - wechat_msg_item_info.msg_time.tm_min, - wechat_msg_item_info.msg_time.tm_sec, - t_file_ext[type]); - - if(false == wechat_msg_item_info_write_to_file(wechat_msg_item_info.msg_data_full_file_name, data_buff, data_buff_len)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return false; - } - - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext) - { - wechat_msg_voice_item_playing_stop(ext); - } - - wechat_msg_info_new_item_add(&wechat_msg_item_info); - - // ui - if(false == mmi_active_screen_is_prohibit_interrupted() - && false == mmi_health_measure_state_is_ui_measure() -// && false == wechat_msg_voice_is_playing() - && false == wechat_msg_voice_is_recording() - && false == wechat_msg_item_is_sending() - #ifdef __MMI_ZHSX_SUPPORT_DO_NOT_DISTURB__ - && false == mmi_watch_is_in_do_not_disturb_time() - #endif - ) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - mmi_watch_wake_up(); - mmi_ui_msg_action_wechat_incoming(); - } - - return true; -} - -bool wechat_msg_send_to_server(void) -{ - bool result = false; // true-success; false-fail - - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return false; - - uint32_t file_size = ext->record_size; - char * file_buf = lv_mem_alloc(file_size + 1); - if(NULL == file_buf || WECHAT_MSG_DATA_AMR_HEAD_SIZE >= file_size) - { - lv_mem_free(ext->record_buffer); - ext->record_buffer = NULL; - ext->record_size = 0; - return false; - } - _lv_memset_00(file_buf, file_size + 1); - _lv_memcpy(file_buf, ext->record_buffer, file_size); - lv_mem_free(ext->record_buffer); - ext->record_buffer = NULL; - - if(true == wechat_msg_item_info_write_to_file(s_wechat_msg_item_info.msg_data_full_file_name, file_buf, file_size)) - { - if(true == mmi_protocol_action_send_talk(file_buf, file_size)) - { - s_wechat_msg_item_info.msg_data_size = file_size; - wechat_msg_info_new_item_add(&s_wechat_msg_item_info); - result = true; - } - else - { - lv_fs_remove(s_wechat_msg_item_info.msg_data_full_file_name); - } - } - - lv_mem_free(file_buf); - _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); - - return result; -} - -void wechat_msg_item_delete_success_timer_cb(void *para) -{ - //lv_wechat_ext_t * ext = (lv_wechat_ext_t *)para; - - wechat_main_screen_refresh(); -} - -void wechat_msg_item_delete_ok_btn_event_cb(lv_obj_t * obj, lv_event_t e) -{ - if(LV_EVENT_CLICKED == e) - { - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext && NULL != ext->delete_bg) - { - uint32_t value = lv_watch_get_free_num(obj); - if(0 == value) - wechat_msg_info_index_item_delete(s_wechat_selected_item_index); - else if(1 == value) - wechat_msg_info_all_item_delete(); - - lv_obj_clean(ext->delete_bg); - - lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); - lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_SUCCESS); - lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -10); - - //ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, ext, false); - ext->delete_timer_id = Hal_Timer_Start(1500, wechat_msg_item_delete_success_timer_cb, NULL, false); - } - } -} - -void wechat_msg_item_delete_cancel_btn_event_cb(lv_obj_t * obj, lv_event_t e) -{ - if(LV_EVENT_CLICKED == e) - { - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext && NULL != ext->delete_bg) - { - lv_obj_del(ext->delete_bg); - ext->delete_bg = NULL; - } - } -} - -void wechat_msg_item_delete_select_btn_event_cb(lv_obj_t * obj, lv_event_t e) -{ - if(LV_EVENT_CLICKED != e) - { - return; - } - - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext) - { - uint32_t value = lv_watch_get_free_num(obj); - - lv_obj_set_hidden(ext->delete_current, true); - lv_obj_set_hidden(ext->delete_all, true); - lv_obj_set_hidden(ext->delete_back, true); - - lv_obj_set_hidden(ext->delete_label_prompt, false); - lv_obj_set_hidden(ext->delete_btn_cancel, false); - lv_obj_set_hidden(ext->delete_btn_ok, false); - lv_watch_set_free_num(ext->delete_btn_ok, value); - } -} - -void wechat_chat_list_msg_item_delete_create(void) -{ - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext && NULL != ext->cont) - { - ext->delete_bg = lv_cont_create(ext->cont, NULL); - lv_obj_set_size(ext->delete_bg, LV_HOR_RES, LV_VER_RES); - lv_obj_set_style_local_bg_color(ext->delete_bg, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xB6, 0xF7, 0xFF)); - - // current - lv_obj_t * btn_delete_current = lv_cont_create(ext->delete_bg, NULL); - lv_obj_set_size(btn_delete_current, LV_HOR_RES - 40, 56); - lv_obj_set_style_local_bg_color(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xB9, 0x86, 0xFF)); - lv_obj_set_style_local_radius(btn_delete_current, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_click(btn_delete_current, true); - lv_obj_set_event_cb(btn_delete_current, wechat_msg_item_delete_select_btn_event_cb); - lv_obj_align(btn_delete_current, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); - lv_watch_set_free_num(btn_delete_current, 0); - ext->delete_current = btn_delete_current; - - lv_obj_t * label_delete_current = lv_label_create(btn_delete_current, NULL); - lv_obj_add_style(label_delete_current, LV_LABEL_PART_MAIN, &lv_watch_font26); - lv_label_set_text_id(label_delete_current, WATCH_TEXT_ID_DELETE_CURRENT_ITEM); - lv_label_set_align(label_delete_current, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_delete_current, btn_delete_current, LV_ALIGN_CENTER, 0, 0); - - // all - lv_obj_t * btn_delete_all = lv_cont_create(ext->delete_bg, btn_delete_current); - lv_obj_set_style_local_bg_color(btn_delete_all, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xFF, 0x6F, 0x91)); - lv_obj_align(btn_delete_all, btn_delete_current, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); - lv_watch_set_free_num(btn_delete_all, 1); - ext->delete_all = btn_delete_all; - - lv_obj_t * label_delete_all = lv_label_create(btn_delete_all, NULL); - lv_obj_add_style(label_delete_all, LV_LABEL_PART_MAIN, &lv_watch_font26); - lv_label_set_text_id(label_delete_all, WATCH_TEXT_ID_DELETE_ALL_ITEM); - lv_label_set_align(label_delete_all, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_delete_all, btn_delete_all, LV_ALIGN_CENTER, 0, 0); - - // back - lv_obj_t * btn_delete_back = lv_cont_create(ext->delete_bg, btn_delete_current); - lv_obj_set_style_local_bg_color(btn_delete_back, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); - lv_obj_set_event_cb(btn_delete_back, wechat_msg_item_delete_cancel_btn_event_cb); - lv_obj_align(btn_delete_back, btn_delete_all, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); - ext->delete_back = btn_delete_back; - - lv_obj_t * label_delete_back = lv_label_create(btn_delete_back, NULL); - lv_obj_add_style(label_delete_back, LV_LABEL_PART_MAIN, &lv_watch_font26); - lv_label_set_text_id(label_delete_back, WATCH_TEXT_ID_CANCEL); - lv_label_set_align(label_delete_back, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_delete_back, btn_delete_back, LV_ALIGN_CENTER, 0, 0); - - - lv_obj_t * label_prompt = lv_label_create(ext->delete_bg, NULL); - lv_obj_add_style(label_prompt, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - lv_label_set_text_id(label_prompt, WATCH_TEXT_ID_DEL_Q); - lv_obj_align(label_prompt, ext->delete_bg, LV_ALIGN_CENTER, 0, -30); - ext->delete_label_prompt = label_prompt; - - lv_obj_t * btn_cancel = lv_btn_create(ext->delete_bg, NULL); - lv_obj_set_size(btn_cancel, 100, 56); - lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0x47, 0xA6, 0xFF)); - lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); - lv_obj_set_style_local_bg_color(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0x47, 0xA6, 0xFF)); - lv_obj_set_style_local_radius(btn_cancel, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); - lv_obj_align(btn_cancel, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 10, -20); - lv_obj_set_event_cb(btn_cancel, wechat_msg_item_delete_cancel_btn_event_cb); - ext->delete_btn_cancel = btn_cancel; - - lv_obj_t * label_cancel = lv_label_create(btn_cancel, NULL); - lv_obj_add_style(label_cancel, LV_LABEL_PART_MAIN, &lv_watch_font26); - lv_label_set_text_id(label_cancel, WATCH_TEXT_ID_CANCEL); - - lv_obj_t * btn_ok = lv_btn_create(ext->delete_bg, btn_cancel); - lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0xFF, 0x6F, 0x91)); - lv_obj_set_style_local_bg_color(btn_ok, LV_BTN_PART_MAIN, LV_STATE_PRESSED, lv_color_make(0xFF, 0x6F, 0x91)); - lv_obj_align(btn_ok, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -20); - lv_obj_set_event_cb(btn_ok, wechat_msg_item_delete_ok_btn_event_cb); - ext->delete_btn_ok = btn_ok; - - lv_obj_t * label_ok = lv_label_create(btn_ok, label_cancel); - lv_label_set_text_id(label_ok, WATCH_TEXT_ID_OK); - - // display - lv_obj_set_hidden(label_prompt, true); - lv_obj_set_hidden(btn_cancel, true); - lv_obj_set_hidden(btn_ok, true); - } -} - -void wechat_msg_sending_anim_cb(lv_anim_t * a) -{ - lv_obj_t * img = a->var; - - switch(s_wechat_play_anim_count % 3) - { - case 0: - lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT1); - break; - - case 1: - lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT2); - break; - - case 2: - lv_img_set_src(img, ICON_WECHAT_SENDING_PROMPT3); - break; - - default: - break; - } - s_wechat_play_anim_count++; -} - -void wechat_msg_sending_result_screen_timeout(void *para) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - wechat_msg_sending_screen_prepare_destory(NULL); - - //delete sending screen - //lv_watch_del_interface(ACT_ID_WECHAT_SENDING); - lv_obj_t * obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_SENDING); - if(NULL != obj) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - lv_obj_del(obj); - } - - //return main list screen - wechat_main_screen_refresh(); -} - -void wechat_msg_sending_screen_timeout(void *para) -{ - lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)para; - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NULL != sending_ext->sending_timer_id) - { - Hal_Timer_Stop(sending_ext->sending_timer_id); - sending_ext->sending_timer_id = NULL; - } - - if(NULL != sending_ext->sending_anim.var) - { - lv_obj_t * img_bkg = lv_obj_get_parent(sending_ext->sending_anim.var); - lv_img_set_src(img_bkg, ((true == sending_ext->send_result) ? ICON_WECHAT_SENDING_SUCC : ICON_WECHAT_SENDING_FAILED)); - - lv_anim_del(sending_ext->sending_anim.var, NULL); - lv_obj_del(sending_ext->sending_anim.var); - sending_ext->sending_anim.var = NULL; - } - - sending_ext->result_timer_id = Hal_Timer_Start(1500, wechat_msg_sending_result_screen_timeout, sending_ext, FALSE); -} - -void wechat_msg_sending_screen_prepare_destory(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_watch_png_cache_all_free(); - - lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_SENDING); - if(NULL != sending_ext) - { - if(NULL != sending_ext->sending_timer_id) - { - Hal_Timer_Stop(sending_ext->sending_timer_id); - sending_ext->sending_timer_id = NULL; - } - if(NULL != sending_ext->result_timer_id) - { - Hal_Timer_Stop(sending_ext->result_timer_id); - sending_ext->result_timer_id = NULL; - } - } -} - -lv_obj_t * wechat_msg_sending_screen_create(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NULL == activity_obj) - { - lv_watch_activity_ext_t activity_ext = {0}; - - activity_ext.actId = ACT_ID_WECHAT_SENDING; - activity_ext.create = (lv_watch_activity_create_f_t)wechat_msg_sending_screen_create; - activity_ext.prepare_destory = wechat_msg_sending_screen_prepare_destory; - activity_obj = lv_watch_creat_activity_obj(&activity_ext); - if(NULL == activity_obj) - return NULL; - } - - lv_obj_t * obj = lv_watch_obj_create(activity_obj); - if(NULL == obj) - return NULL; - lv_wechat_msg_sending_ext_t * sending_ext = (lv_wechat_msg_sending_ext_t *)lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_sending_ext_t)); - if(NULL == sending_ext) - return NULL; - - wechat_chat_list_set_slide_enable(&sending_ext->old_ext, false); /*prevent to slide out while recording*/ - _lv_memset_00(&(sending_ext->sending_anim), sizeof(lv_anim_t)); - sending_ext->send_result = wechat_msg_send_to_server(); - sending_ext->sending_timer_id = Hal_Timer_Start(1000 * 3, wechat_msg_sending_screen_timeout, sending_ext, FALSE); - sending_ext->result_timer_id = NULL; - - lv_obj_t * img_bkg = lv_img_create(obj, NULL); - lv_img_set_src(img_bkg, ICON_WECHAT_SENDING_BG); - lv_obj_align(img_bkg, obj, LV_ALIGN_CENTER, 0, 0); - - lv_obj_t * img_sending = lv_img_create(img_bkg, NULL); - lv_img_set_src(img_sending, ICON_WECHAT_SENDING_PROMPT3); -#if USE_LV_WATCH_UI_240_320 - lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); -#elif USE_LV_WATCH_UI_240_280 - lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -40); #else - lv_obj_align(img_sending, img_bkg, LV_ALIGN_IN_BOTTOM_MID, 0, -20); -#endif - - lv_anim_t * a = &(sending_ext->sending_anim); - lv_anim_init(a); - lv_anim_set_var(a, img_sending); - //lv_anim_set_exec_cb(a, (lv_anim_exec_xcb_t)wechat_msg_sending_anim_exec_cb); - lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_msg_sending_anim_cb); - lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_repeat_delay(a, 500); - lv_anim_start(a); - s_wechat_play_anim_count = 0; - return obj; -} - -void wechat_msg_recording_release_event_cb(lv_obj_t * obj, lv_event_t e) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); - -#if 0 - if(LV_EVENT_RELEASED == e) //(LV_EVENT_CLICKED == e) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); - wechat_msg_sending_screen_create(NULL); - } +#include "wechat.c" #endif -} - -void wechat_msg_recording_anim(lv_anim_t * a) -{ - lv_obj_t * img = a->var; - - switch(s_wechat_play_anim_count % 5) - { - case 0: - lv_img_set_src(img, ICON_WECHAT_RECORDING1); - break; - case 1: - lv_img_set_src(img, ICON_WECHAT_RECORDING2); - break; - case 2: - lv_img_set_src(img, ICON_WECHAT_RECORDING3); - break; - case 3: - lv_img_set_src(img, ICON_WECHAT_RECORDING4); - break; - case 4: - lv_img_set_src(img, ICON_WECHAT_RECORDING5); - break; - default: - break; - } - s_wechat_play_anim_count++; - - if(0 == (s_wechat_play_anim_count % 4)) - { - lv_wechat_msg_recording_ext_t * recording_ext = (lv_wechat_msg_recording_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_RECORDING); - if(NULL == recording_ext) - return; - - int8_t count_down = WECHAT_MSG_DATA_RECORD_DURATION_MAX - s_wechat_play_anim_count / 4; - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: count down=%d\n", __FUNCTION__, __LINE__, count_down); - - if(0 < count_down) - { - const char * content = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); - uint8_t len = strlen(content) + 8; - char * text = (char *)lv_mem_alloc(len); - snprintf(text, len, "%s %d", content, count_down); - lv_label_set_text(recording_ext->label, text); - lv_mem_free(text); - lv_obj_align(recording_ext->label, img, LV_ALIGN_OUT_BOTTOM_MID, 0, 6); - } - } -} - -bool wechat_msg_recording_stop(bool is_cancel) -{ - uint32_t duration_ms = 0; - uint32_t size = 0; - - Hal_Record_Buffer_Stop_Req(&size, &duration_ms); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return false; - - if(true == is_cancel) - { - lv_mem_free(ext->record_buffer); - ext->record_buffer = NULL; - ext->record_size = 0; - return false; - } - - if(WECHAT_MSG_DATA_AMR_HEAD_SIZE >= size) - { - lv_mem_free(ext->record_buffer); - ext->record_buffer = NULL; - ext->record_size = 0; - return false; - } - ext->record_size = size; - - return true; -} - -void wechat_msg_recording_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); - - if(AUDIO_CTRL_PRIORITY_5 == priority) - { - if(false == watch_is_ready()) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - } - else if(AUDIO_CTRL_PRIORITY_5 > priority) - { - wechat_msg_recording_stop(true); - - //lv_watch_del_interface(ACT_ID_WECHAT_RECORDING); - lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); - if(NULL != activity_obj) - { - lv_obj_del(activity_obj); - } - } -} - -void wechat_msg_recording_task_cb(lv_task_t * task) -{ - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return ; - - if(0 == ext->old_ext.element_click_en) - { - /*sliding to the right, not click button*/ - return; - } - - lv_obj_t * activity_obj; - MCI_EVNET_T event = (MCI_EVNET_T) (task->user_data); - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, event); - - switch(event) - { - case MCI_EVENT_EOS: - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - wechat_msg_recording_stop(false); - activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); - if(NULL != activity_obj) - { - lv_obj_del(activity_obj); - } - wechat_msg_sending_screen_create(NULL); - break; - - case MCI_EVENT_ERROR: - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - wechat_msg_recording_stop(true); - activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); - if(NULL != activity_obj) - { - lv_obj_del(activity_obj); - } - break; - - //case MCI_EVENT_INFO: - // break; - - default: - break; - } -} - -void wechat_msg_recording_cb(MCI_EVNET_T event, MCI_INFO_T info_type, int32_t value) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d,type=%d,value=%d\n", __FUNCTION__, __LINE__, event, info_type, value); - - if(MCI_EVENT_INFO != event) - { - //recording_ext->event = event; - lv_task_t * record_task = lv_task_create(wechat_msg_recording_task_cb, 10, LV_TASK_PRIO_HIGH, event); - lv_task_once(record_task); - } -} - - -void wechat_msg_recording_screen_prepare_destory(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_watch_png_cache_all_free(); - - wechat_msg_recording_stop(true); -} -lv_obj_t * wechat_msg_recording_screen_create(lv_obj_t * activity_obj) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NULL == activity_obj) - { - lv_watch_activity_ext_t activity_ext = {0}; - - activity_ext.actId = ACT_ID_WECHAT_RECORDING; - activity_ext.create = wechat_msg_recording_screen_create; - activity_ext.prepare_destory = wechat_msg_recording_screen_prepare_destory; // wechat_common_screen_prepare_destory; - activity_obj = lv_watch_creat_activity_obj(&activity_ext); - if(NULL == activity_obj) - return NULL; - } - - lv_obj_t * obj = lv_watch_obj_create(activity_obj); - LV_ASSERT_MEM(obj); - - lv_wechat_msg_recording_ext_t * recording_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_recording_ext_t)); - LV_ASSERT_MEM(recording_ext); - - lv_obj_t * cont = lv_cont_create(obj, NULL); - lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); - lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); - //lv_obj_set_click(cont, true); - //lv_obj_set_event_cb(cont, wechat_msg_recording_release_event_cb); - //lv_obj_add_protect(cont, LV_PROTECT_PRESS_LOST); - - lv_obj_t * img = lv_img_create(cont, NULL); - lv_img_set_src(img, ICON_WECHAT_RECORDING1); - lv_obj_align(img, cont, LV_ALIGN_IN_TOP_MID, 0, 36); - - recording_ext->label = lv_label_create(cont, NULL); - lv_obj_add_style(recording_ext->label, LV_LABEL_PART_MAIN, &lv_watch_font20_black); - const char * rel_snd = lv_lang_get_text(WATCH_TEXT_ID_RELEASE_SENDING); - uint8_t len = strlen(rel_snd) + 4; - char * text = (char *)lv_mem_alloc(len); - snprintf(text, len, "%s %d", rel_snd, WECHAT_MSG_DATA_RECORD_DURATION_MAX); - lv_label_set_text(recording_ext->label, text); - lv_mem_free(text); - lv_obj_align(recording_ext->label, img, LV_ALIGN_OUT_BOTTOM_MID, 0, 6); - - lv_obj_t * img_release_snd = lv_img_create(cont, NULL); - lv_img_set_src(img_release_snd, ICON_WECHAT_RECORD_BUTTON_PRESSED); - lv_obj_align(img_release_snd, cont, LV_ALIGN_IN_BOTTOM_MID, 0, -8); - - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, img); - lv_anim_set_start_cb(&a, (lv_anim_ready_cb_t)wechat_msg_recording_anim); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_time(&a, 249); - lv_anim_start(&a); - s_wechat_play_anim_count = 0; - - lv_obj_t * label_warning = lv_label_create(cont, NULL); - //lv_obj_set_style_local_text_font(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_THEME_WATCH_NIGHT_FONT_SMALL); - //lv_obj_set_style_local_text_color(label_warning, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_obj_add_style(label_warning, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - //lv_label_set_long_mode(label_warning, LV_LABEL_LONG_BREAK); - //lv_obj_set_width(label_warning, lv_obj_get_width(obj) * 2 / 3); - lv_label_set_text_id(label_warning, WATCH_TEXT_ID_SLIDE_UP_WARNING); - lv_label_set_align(label_warning, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_warning, cont, LV_ALIGN_IN_TOP_MID, 0, 8); - - //fill info - _lv_memset_00(&s_wechat_msg_item_info, sizeof(nv_watch_wechat_msg_item_info_t)); -#if 0 - //system crashed. unknown reason //20230327 - Hal_Rtc_Gettime(&(s_wechat_msg_item_info.msg_time)); -#else - hal_rtc_t cur_time; - Hal_Rtc_Gettime(&cur_time); - _lv_memcpy(&(s_wechat_msg_item_info.msg_time), &cur_time, sizeof(hal_rtc_t)); -#endif - s_wechat_msg_item_info.msg_type = WECHAT_MSG_TYPE_VOICE; - sprintf(s_wechat_msg_item_info.msg_data_full_file_name, "C:/wechat_s%04d%02d%02d_%02d%02d%02d.amr", /*WECHAT_MSG_DATA_FILE_PATH, */ - s_wechat_msg_item_info.msg_time.tm_year, - s_wechat_msg_item_info.msg_time.tm_mon, - s_wechat_msg_item_info.msg_time.tm_mday, - s_wechat_msg_item_info.msg_time.tm_hour, - s_wechat_msg_item_info.msg_time.tm_min, - s_wechat_msg_item_info.msg_time.tm_sec - ); - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d, file_name=%s\n", __FUNCTION__, __LINE__, - s_wechat_msg_item_info.msg_from, s_wechat_msg_item_info.msg_data_full_file_name); - - //recording -#if 0 - if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) - { - Hal_File_Record_Start_Req(s_wechat_msg_item_info.msg_data_full_file_name, wechat_msg_recording_cb); - } - -#else - - lv_wechat_ext_t * ext = (lv_wechat_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return NULL; - - if(NULL != ext->record_buffer) - { - lv_mem_free(ext->record_buffer); - ext->record_buffer = NULL; - } - ext->record_buffer = (uint8_t *)lv_mem_alloc(WECHAT_MSG_DATA_RECORD_SIZE_MAX); - if(NULL != ext->record_buffer) - { - _lv_memset_00(ext->record_buffer, WECHAT_MSG_DATA_RECORD_SIZE_MAX); - - if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_msg_recording_audio_ctrl_callback)) - { - Hal_Record_Buffer_Start_Req(ext->record_buffer, - WECHAT_MSG_DATA_RECORD_SIZE_MAX, - WECHAT_MSG_DATA_RECORD_DURATION_MAX * 1000, - wechat_msg_recording_cb); - } - } #endif - - return obj; -} - -static void wechat_out_of_memory_btn_event_cb(lv_obj_t * btn, lv_event_t e) -{ - if(LV_EVENT_CLICKED == e) - { - lv_obj_del(lv_obj_get_parent(btn)); - - //return main list screen - wechat_main_screen_refresh(); - } -} - -void wechat_list_out_of_memory_create(lv_obj_t * obj) -{ - lv_obj_t * cont_bg = lv_cont_create(obj, NULL); - lv_obj_set_size(cont_bg, LV_HOR_RES, LV_VER_RES); - lv_obj_add_style(cont_bg, LV_CONT_PART_MAIN, &lv_watch_black_tight); - - lv_obj_t * img_mem = lv_img_create(cont_bg, NULL); - lv_img_set_src(img_mem, ICON_CAMERA_MEMORY); - lv_obj_align(img_mem, NULL, LV_ALIGN_IN_TOP_MID, 0, 40); - - lv_obj_t * label = lv_label_create(cont_bg, NULL); - lv_label_set_text_id(label, WATCH_TEXT_ID_OUT_OF_MEM); - lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); - lv_obj_set_width(label, LV_HOR_RES - 40); - lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20); - lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label, img_mem, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); - - lv_obj_t * btn = lv_btn_create(cont_bg, NULL); - lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); - lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); - lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, LV_COLOR_MAKE(0x47, 0xA6, 0xFF)); - lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_PRESSED, 30); - lv_obj_set_size(btn, 200, 56); - lv_obj_set_event_cb(btn, wechat_out_of_memory_btn_event_cb); - lv_obj_align(btn, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -20); - - lv_obj_t * btn_label = lv_label_create(btn, NULL); - lv_label_set_text_id(btn_label, WATCH_TEXT_ID_GOT_IT); - lv_obj_add_style(btn_label,LV_LABEL_PART_MAIN, &lv_watch_font26); -} - -void wechat_msg_record_button_event_cb(lv_obj_t * obj, lv_event_t e) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: event=%d\n", __FUNCTION__, __LINE__, e); - - if(LV_EVENT_LONG_PRESSED == e) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return ; - - wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ - - if(0 == ext->old_ext.element_click_en) - { - /*sliding to the right, not click button*/ - return; - } - - uint32_t fs_total = 0, fs_free = 0; - lv_fs_free_space('C', &fs_total, &fs_free); - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total=%dB,free=%dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); - if(28 * 1024 > fs_free) // 30 * 1024 - { - lv_obj_t * obj = wechat_main_get_obj(); - wechat_list_out_of_memory_create(obj); - } - #if 0 - else if(NV_WATCH_WECHAT_NUM_MAX <= wechat_msg_info_count_get()) - //else if(2 <= wechat_msg_info_count_get()) - { - lv_obj_t * obj = wechat_main_get_obj(); - wechat_list_out_of_memory_create(obj); - } - #endif - else - { - wechat_chat_list_set_slide_enable(&ext->old_ext, false); /*prevent to slide out while recording*/ - - wechat_msg_recording_screen_create(NULL); - } - } - else if(LV_EVENT_CLICKED == e || LV_EVENT_PRESS_LOST == e) - { - lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_WECHAT_RECORDING); - if(NULL != activity_obj) - { - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return ; - - lv_wechat_msg_recording_ext_t * recording_ext = (lv_wechat_msg_recording_ext_t *)wechat_actId_ext_get(ACT_ID_WECHAT_RECORDING); - if(NULL == recording_ext) - return NULL; - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - wechat_chat_list_set_slide_enable(&ext->old_ext, true); /*reset slide_enable at the end of recording*/ - - lv_indev_t * indev = lv_indev_get_act(); - if(indev) - { - lv_coord_t point_y = indev->proc.types.pointer.last_point.y; - lv_coord_t img_record_top = obj->coords.y1; - if(30 < img_record_top - point_y) // (point_y < (img_record_top - 20)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: indev_y=%d, img_y=%d\n", __FUNCTION__, __LINE__, point_y, img_record_top); - wechat_msg_recording_stop(true); - lv_obj_del(activity_obj); - //return main list screen - wechat_main_screen_refresh(); - - return; - } - } - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - wechat_msg_recording_stop(false); - lv_obj_del(activity_obj); - wechat_msg_sending_screen_create(NULL); - } - } - else if(LV_EVENT_PRESSED == e) - { - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return ; - - // - Hal_NFFS_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - Hal_Vibrator_Play_End(); - - wechat_msg_voice_item_playing_stop(ext); - } -} - -void wechat_msg_voice_item_reset_play_state(lv_wechat_msg_list_ext_t * list_page_ext) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - - uint8_t msg_from = list_page_ext->voice_playing_msg_from; - - lv_anim_del(list_page_ext->voice_playing_anim.var, NULL); - lv_img_set_src(list_page_ext->voice_playing_anim.var, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); - list_page_ext->voice_playing_anim.var = NULL; -} - -void wechat_msg_voice_item_playing_stop(lv_wechat_ext_t * ext) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(NULL == ext || NULL == ext->list) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - - lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(ext->list); - if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - - Hal_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - wechat_msg_voice_item_reset_play_state(list_page_ext); -} - -void wechat_chat_list_msg_item_style_reset(lv_wechat_ext_t * ext) -{ - if(NULL == ext || NULL == ext->list) - return; - - lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(ext->list); - if(NULL == list_page_ext) - return; - - lv_style_reset(&(list_page_ext->style_cont_self)); - lv_style_reset(&(list_page_ext->style_cont_other)); - lv_style_reset(&(list_page_ext->style_label_time)); - //lv_style_reset(&(list_page_ext->style_text)); - lv_style_reset(&(list_page_ext->style_label_len_self)); - lv_style_reset(&(list_page_ext->style_label_len_other)); -} - -void wechat_chat_list_msg_item_time(char * time_str, hal_rtc_t * cur_time, hal_rtc_t * msg_time, hal_rtc_t * last_msg_time) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(0 == last_msg_time->tm_year) - { - sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, msg_time->tm_mday, - msg_time->tm_hour, msg_time->tm_min); - - return; - } - - uint32_t msg_sec = time_to_seconds(msg_time); - uint32_t last_msg_sec = time_to_seconds(last_msg_time); - if(msg_sec < last_msg_sec) - { - sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, - msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); - } - else if(msg_sec > (last_msg_sec + WECHAT_MSG_CHAT_TIME_INTERVAL)) - { - uint32_t cur_sec = time_to_seconds(cur_time); - if((msg_sec > cur_sec) || (msg_time->tm_year < cur_time->tm_year)) - { - sprintf(time_str, "%d/%d/%d %02d:%02d", msg_time->tm_year, msg_time->tm_mon, - msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); - } - else - { - uint32_t today_sec = cur_sec - cur_time->tm_hour * 3600 - cur_time->tm_min * 60 - cur_time->tm_sec; - - if(msg_sec >= today_sec) - { - /*today*/ - sprintf(time_str, "%02d:%02d", msg_time->tm_hour, msg_time->tm_min); - } - else if(msg_sec >= (today_sec - 24 * 3600)) - { - /*yesterday*/ - const char * yesterday = lv_lang_get_text(WATCH_TEXT_ID_YESTERDAY); - - sprintf(time_str, "%s %02d:%02d", yesterday, msg_time->tm_hour, msg_time->tm_min); - } - else - { - uint8_t wday; - if(0 == cur_time->tm_wday) - { - /*today is Sunday*/ - wday = 6; - } - else - { - wday = cur_time->tm_wday - 1; - } - /*the start of a week is monday, the end is sunday*/ - if(msg_sec >= (today_sec - wday * 24 * 3600)) { - /*current week before yesterday*/ - const char * wday_str; - switch(rtc_calc_weekday(msg_time)) - { - case 1: - /*Monday*/ - wday_str = lv_lang_get_text(WATCH_TEXT_ID_MONDAY); - break; - case 2: - /*Tuesday*/ - wday_str = lv_lang_get_text(WATCH_TEXT_ID_TUESDAY); - break; - case 3: - /*Wednesday*/ - wday_str = lv_lang_get_text(WATCH_TEXT_ID_WEDNESDAY); - break; - case 4: - /*Thursday*/ - wday_str = lv_lang_get_text(WATCH_TEXT_ID_THURSDAY); - break; - case 5: - /*Friday*/ - wday_str = lv_lang_get_text(WATCH_TEXT_ID_FRIDAY); - break; - default: - printf("%s: week error\n", __FUNCTION__); - break; - } - - sprintf(time_str, "%s %02d:%02d", wday_str, msg_time->tm_hour, msg_time->tm_min); - } - else - { - sprintf(time_str, "%d/%d %02d:%02d", msg_time->tm_mon, msg_time->tm_mday, msg_time->tm_hour, msg_time->tm_min); - } - } - } - } -} - -void wechat_chat_list_voice_item_playing_anim_cb(lv_anim_t * a) -{ - lv_obj_t * play_img = (lv_obj_t *)a->var; - uint8_t msg_from = wechat_msg_info_index_item_msg_from_get(s_wechat_selected_item_index); - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_from=%d\n", __FUNCTION__, __LINE__, msg_from); - - switch(s_wechat_play_anim_count % 3) - { - case 0: - lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING1 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING1)); - break; - - case 1: - lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING2 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING2)); - break; - - case 2: - lv_img_set_src(play_img, ((0 == msg_from) ? ICON_WECHAT_MY_VOICE_ITEM_PLAYING3 : ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3)); - break; - - default: - break; - } - s_wechat_play_anim_count++; -} - -void wechat_chat_list_voice_item_playing_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: priority=%d\n", __FUNCTION__, __LINE__, priority); - - if(AUDIO_CTRL_PRIORITY_5 == priority) - { - if(false == watch_is_ready()) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - } - else if(AUDIO_CTRL_PRIORITY_5 > priority) - { - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL != ext) - { - wechat_msg_voice_item_playing_stop(ext); - } - } -} - -void wechat_chat_list_voice_item_play_over_cb(void * para) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - Hal_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - - lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)para; - if(NULL == list_page_ext || NULL == list_page_ext->voice_playing_anim.var) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - return; - } - wechat_msg_voice_item_reset_play_state(list_page_ext); -} - -void wechat_chat_list_voice_item_play_action(lv_wechat_msg_list_ext_t * list_page_ext, lv_obj_t * play_img, lv_obj_t * unread_img) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - //display ui - lv_anim_t * a = &(list_page_ext->voice_playing_anim); - - lv_anim_init(a); - lv_anim_set_var(a, play_img); - lv_anim_set_start_cb(a, (lv_anim_ready_cb_t)wechat_chat_list_voice_item_playing_anim_cb); - lv_anim_set_repeat_count(a, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_time(a, 400); - lv_anim_start(a); - s_wechat_play_anim_count = 1; - - nv_watch_wechat_msg_item_info_t * msg_item = NULL; - wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); - msg_item->unread_flag = 0; - if(NULL != unread_img) - { - lv_obj_del(unread_img); - unread_img = NULL; - } - list_page_ext->voice_playing_msg_from = msg_item->msg_from; - - //play voice - if(AUDIO_CTRL_PRIORITY_5 == Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY_5, wechat_chat_list_voice_item_playing_audio_ctrl_callback)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - Hal_File_Play_Onetime(msg_item->msg_data_full_file_name, query_current_volume(), wechat_chat_list_voice_item_play_over_cb, list_page_ext, 0); - } -} - -void wechat_chat_list_voice_item_event_cb(lv_obj_t * cont, lv_event_t e) -{ - lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); - if(NULL == list_item_ext) - return; - - s_wechat_selected_item_index = list_item_ext->item_index; - - lv_obj_t * scrl = lv_obj_get_parent(cont); - lv_obj_t * list_page = lv_obj_get_parent(scrl); - //lv_obj_t * scrl = lv_page_get_scrl(list_page); - - lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); - if(NULL == list_page_ext) - return; - - if(LV_EVENT_PRESSED == e) - { - list_page_ext->pressing = true; - } - else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item - { - list_page_ext->pressing = false; - wechat_chat_list_msg_item_delete_create(); - } - else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // playing voice msg - { - list_page_ext->pressing = false; - - nv_watch_wechat_msg_item_info_t * msg_item = NULL; - wechat_msg_info_index_item_get(s_wechat_selected_item_index, &msg_item); - - if(0 != msg_item->msg_data_size) - { - if(NULL != list_page_ext->voice_playing_anim.var) // exist voice playing - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); - - //stop item voice - Hal_File_Play_End(); - Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY_5); - wechat_msg_voice_item_reset_play_state(list_page_ext); - } - else if(NULL != msg_item->msg_data_full_file_name) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: index=%d\n", __FUNCTION__, __LINE__, list_item_ext->item_index); - - lv_obj_t * play_img = lv_obj_get_child_back(cont, NULL); - wechat_chat_list_voice_item_play_action(list_page_ext, play_img, ((1 == msg_item->unread_flag) ? list_item_ext->unread_img : NULL)); - } - } - } -} - -void wechat_chat_list_text_item_event_cb(lv_obj_t * cont, lv_event_t e) -{ - lv_wechat_msg_list_item_ext_t * list_item_ext = (lv_wechat_msg_list_item_ext_t *)lv_obj_get_ext_attr(cont); - if(NULL == list_item_ext) - return; - - s_wechat_selected_item_index = list_item_ext->item_index; - - lv_obj_t * scrl = lv_obj_get_parent(cont); - lv_obj_t * list_page = lv_obj_get_parent(scrl); - //lv_obj_t * scrl = lv_page_get_scrl(list_page); - - lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); - if(NULL == list_page_ext) - return; - - if(LV_EVENT_PRESSED == e) - { - list_page_ext->pressing = true; - } - else if((LV_EVENT_LONG_PRESSED == e) && (true == list_page_ext->pressing)) // delete msg item - { - list_page_ext->pressing = false; - - wechat_chat_list_msg_item_delete_create(); - } - else if((LV_EVENT_CLICKED == e) && (true == list_page_ext->pressing)) // display text msg - { - list_page_ext->pressing = false; - } -} - -//display time & content -lv_obj_t * wechat_chat_list_msg_item_add(lv_obj_t * list_page, nv_watch_wechat_msg_item_info_t * msg_item, char * time_str, uint8_t i) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_obj_t * obj = NULL; - lv_wechat_msg_list_item_ext_t * list_item_ext = NULL; - lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_get_ext_attr(list_page); - lv_obj_t * scrl = lv_page_get_scrl(list_page); - lv_obj_t * last_obj = lv_obj_get_child(scrl, NULL); - lv_coord_t obj_y = 0; - - if(NULL != last_obj) - { - obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); - } - else - { - obj_y = lv_obj_get_style_pad_top(scrl, LV_STATE_DEFAULT); - } - - if(0 != strlen(time_str)) - { - obj = lv_label_create(list_page, NULL); - - //lv_obj_set_base_dir(obj, LV_BIDI_DIR_LTR); - lv_label_set_text(obj, time_str); - lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &list_page_ext->style_label_time); - lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_MID, 0, obj_y); - - last_obj = obj; - obj_y = lv_obj_get_y(last_obj) + lv_obj_get_height(last_obj) + lv_obj_get_style_pad_inner(scrl, LV_STATE_DEFAULT); - } - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: msg_type=%d,file=%s,size=%d,obj_y=%d\n", __FUNCTION__, __LINE__, - msg_item->msg_type, msg_item->msg_data_full_file_name, msg_item->msg_data_size, obj_y); - - switch(msg_item->msg_type) - { - case WECHAT_MSG_TYPE_VOICE: - lv_obj_t * unread_img = lv_img_create(list_page, NULL); - //obj = lv_img_create(list_page, NULL); - obj = lv_cont_create(list_page, NULL); - list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); - list_item_ext->item_index = i; - list_item_ext->unread_img = NULL; - lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); - lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); - - lv_obj_t * play_img = lv_img_create(obj, NULL); - lv_obj_t * len_label = lv_label_create(obj, NULL); - uint32_t duration = 0; - - if(LV_FS_RES_OK != Hal_File_Get_AudioDurationTime((const char *)msg_item->msg_data_full_file_name, &duration)) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: read file error. %s\n", __FUNCTION__, __LINE__, msg_item->msg_data_full_file_name); - } - else - { - duration = (duration + 999) / 1000; - } - - if(0 == duration) - { - /*invalid voice*/ - lv_img_set_src(play_img, ICON_WECHAT_VOICE_ITEM_DAMAGE); - lv_label_set_text(len_label, ""); - } - else - { - char len_str[8] = {0}; - - if(WECHAT_MSG_DATA_RECORD_DURATION_MAX < duration) - duration = WECHAT_MSG_DATA_RECORD_DURATION_MAX; - - sprintf(len_str, "%d\"", duration); - lv_label_set_text(len_label, len_str); - } - - if(0 == msg_item->msg_from) // msg from slef - { - lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_self); - //lv_img_set_src(obj, ICON_WECHAT_MY_VOICE_ITEM_BG); - lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_self)); - lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_RIGHT, -10, obj_y); - if(0 < duration) - { - lv_img_set_src(play_img, ICON_WECHAT_MY_VOICE_ITEM_PLAYING3); - } - lv_obj_align(play_img, obj, LV_ALIGN_IN_LEFT_MID, 15, 0); - lv_obj_align(len_label, play_img, LV_ALIGN_OUT_RIGHT_MID, 10, 0); - lv_obj_del(unread_img); - } - else // msg from other - { - lv_obj_add_style(len_label, LV_LABEL_PART_MAIN, &list_page_ext->style_label_len_other); - //lv_img_set_src(obj, ICON_WECHAT_OTHER_VOICE_ITEM_BG); - lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); - lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); - if(0 < duration) - { - lv_img_set_src(play_img, ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3); - } - lv_obj_align(play_img, obj, LV_ALIGN_IN_RIGHT_MID, -15, 0); - lv_obj_align(len_label, play_img, LV_ALIGN_OUT_LEFT_MID, -10, 0); - if(1 == msg_item->unread_flag) - { - lv_img_set_src(unread_img, ICON_WECHAT_UNREAD_FLAG); - lv_obj_align(unread_img, obj, LV_ALIGN_OUT_RIGHT_MID, 5, 0); - list_item_ext->unread_img = unread_img; - } - else - { - lv_obj_del(unread_img); - } - } - - lv_obj_set_click(obj, true); - lv_obj_set_event_cb(obj, wechat_chat_list_voice_item_event_cb); - lv_obj_set_adv_hittest(obj, false); - lv_page_focus(list_page, obj, 0); - lv_page_glue_obj(obj, true); - lv_watch_obj_add_element(obj); - break; - - case WECHAT_MSG_TYPE_TEXT: - obj = lv_cont_create(list_page, NULL); - list_item_ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_msg_list_item_ext_t)); - list_item_ext->item_index = i; - list_item_ext->unread_img = NULL; - lv_obj_set_size(obj, LV_HOR_RES * 2 / 3, 50); //lv_obj_set_size(obj, 153, 53); // same with voice item - lv_cont_set_fit4(obj, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_NONE, LV_FIT_TIGHT); - //lv_cont_set_layout(obj, LV_LAYOUT_COLUMN_LEFT); - lv_obj_add_style(obj, LV_CONT_PART_MAIN, &(list_page_ext->style_cont_other)); - lv_obj_align(obj, scrl, LV_ALIGN_IN_TOP_LEFT, 10, obj_y); - - lv_fs_file_t file_p; - lv_fs_res_t res; - uint32_t file_size = 0, bytes_read = 0; - char * file_buf = NULL; - - res = lv_fs_open(&file_p, msg_item->msg_data_full_file_name, LV_FS_MODE_RD); - if(LV_FS_RES_OK != res) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); - lv_fs_close(&file_p); - break; - } - - lv_fs_size(&file_p, &file_size); - file_buf = (char *)lv_mem_alloc(file_size + 1); - _lv_memset_00(file_buf, file_size + 1); - res = lv_fs_read(&file_p, file_buf, file_size, &bytes_read); - lv_fs_close(&file_p); - if(LV_FS_RES_OK != res) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); - lv_mem_free(file_buf); - break; - } - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d,%d,%s\n", __FUNCTION__, __LINE__, file_size, bytes_read, file_buf); - - lv_obj_t * label_text = lv_label_create(obj, NULL); - lv_obj_add_style(label_text, LV_LABEL_PART_MAIN, &(list_page_ext->style_label_len_other)); - lv_label_set_align(label_text, LV_LABEL_ALIGN_CENTER); - lv_label_set_long_mode(label_text, LV_LABEL_LONG_BREAK); - lv_obj_set_width(label_text, lv_obj_get_width(obj) - 20); - lv_label_set_text(label_text, file_buf); - lv_obj_align(label_text, obj, LV_ALIGN_IN_LEFT_MID, 10, 0); - - lv_obj_set_click(obj, true); - lv_obj_set_event_cb(obj, wechat_chat_list_text_item_event_cb); - lv_obj_set_adv_hittest(obj, false); - lv_page_focus(list_page, obj, 0); - lv_page_glue_obj(obj, true); - lv_watch_obj_add_element(obj); - - lv_mem_free(file_buf); - break; - - case WECHAT_MSG_TYPE_EXPRESSION: - case WECHAT_MSG_TYPE_IMAGE: - #if 0 - obj = lv_img_create(list, NULL); - - lv_watch_obj_add_element(obj); - #endif - break; - - default: - break; - } - - return obj; -} - -lv_res_t wechat_chat_list_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) -{ - lv_res_t res; - - /* Include the ancient signal function */ - res = ancient_scrl_signal(scrl, sign, param); - if(res != LV_RES_OK) - return res; - - if(LV_SIGNAL_COORD_CHG == sign) - { - lv_obj_t * list_page = lv_obj_get_parent(scrl); - lv_wechat_msg_list_ext_t * list_page_ext = (lv_wechat_msg_list_ext_t *)lv_obj_get_ext_attr(list_page); - if(NULL == list_page_ext) - return; - - if(true == list_page_ext->pressing) - { - list_page_ext->pressing = false; - } - } - - return LV_RES_OK; -} - -void wechat_chat_list_create(lv_obj_t * obj, lv_wechat_ext_t * ext) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_obj_t * list_page = lv_page_create(obj, NULL); - lv_wechat_msg_list_ext_t * list_page_ext = lv_obj_allocate_ext_attr(list_page, sizeof(lv_wechat_msg_list_ext_t)); - if(NULL == ext) - return; - - lv_obj_set_size(list_page, lv_obj_get_width(obj), lv_obj_get_height(obj) - 5 - lv_obj_get_height(ext->img_record) - 8); - lv_page_set_scrollbar_mode(list_page, LV_SCROLLBAR_MODE_OFF); - lv_obj_set_style_local_bg_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); - lv_obj_set_style_local_border_opa(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, LV_OPA_0); - lv_obj_set_style_local_outline_width(list_page, LV_PAGE_PART_BG, LV_STATE_DEFAULT, 0); - //lv_obj_set_style_local_pad_bottom(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 4); - //lv_obj_set_style_local_pad_top(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 2); - //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLABLE, LV_STATE_DEFAULT, 8); - //lv_obj_set_style_local_bg_color(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, lv_color_make(16, 112, 194)); - //lv_obj_set_style_local_pad_inner(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, LV_DPI / 20); - //lv_obj_set_style_local_pad_left(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); - //lv_obj_set_style_local_pad_right(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); - //lv_obj_set_style_local_radius(list_page, LV_PAGE_PART_SCROLLBAR, LV_STATE_DEFAULT, 0); - - lv_page_set_scrl_layout(list_page, LV_LAYOUT_OFF); - lv_page_set_scrollable_fit2(list_page, LV_FIT_NONE, LV_FIT_TIGHT); - - lv_obj_t * scrl = lv_page_get_scrollable(list_page); - ancient_scrl_signal = lv_obj_get_signal_cb(scrl); - lv_obj_set_signal_cb(scrl, wechat_chat_list_scrl_signal); - - lv_watch_obj_add_element(list_page); - lv_watch_obj_add_element(scrl); - - lv_style_init(&(list_page_ext->style_label_time)); - lv_style_copy(&(list_page_ext->style_label_time), &lv_watch_font20); - lv_style_set_text_color(&(list_page_ext->style_label_time), LV_STATE_DEFAULT, lv_color_make(20, 187, 242)); - - //lv_style_init(&(list_page_ext->style_text)); - //lv_style_copy(&(list_page_ext->style_text), &lv_style_pretty); - //lv_style_set_bg_color(&(list_page_ext->style_text), LV_STATE_DEFAULT, lv_color_make(0xFF, 0xE1, 0xE1)); - //lv_style_set_border_width(&(list_page_ext->style_text), LV_STATE_DEFAULT, 0); - //lv_style_set_shadow_width(&(list_page_ext->style_text), LV_STATE_DEFAULT, 0); - - lv_style_init(&(list_page_ext->style_label_len_other)); - lv_style_copy(&(list_page_ext->style_label_len_other), &lv_watch_font26); - lv_style_set_text_color(&(list_page_ext->style_label_len_other), LV_STATE_DEFAULT, lv_color_make(202, 134, 255)); - - lv_style_init(&(list_page_ext->style_label_len_self)); - lv_style_copy(&(list_page_ext->style_label_len_self), &lv_watch_font26); - lv_style_set_text_color(&(list_page_ext->style_label_len_self), LV_STATE_DEFAULT, lv_color_make(108, 189, 5)); - - lv_style_init(&(list_page_ext->style_cont_self)); - lv_style_set_bg_color(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, LV_COLOR_MAKE(175, 242, 89)); - lv_style_set_radius(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 15); // 30 - lv_style_set_pad_top(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 - lv_style_set_pad_bottom(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 10); // 8 - lv_style_set_pad_left(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 - lv_style_set_pad_right(&(list_page_ext->style_cont_self), LV_STATE_DEFAULT, 5); // 8 - - lv_style_init(&(list_page_ext->style_cont_other)); - lv_style_set_bg_color(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, LV_COLOR_MAKE(0xE2, 0xBD, 0xFF)); - lv_style_set_radius(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 15); - lv_style_set_pad_top(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); - lv_style_set_pad_bottom(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 10); - lv_style_set_pad_left(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); - lv_style_set_pad_right(&(list_page_ext->style_cont_other), LV_STATE_DEFAULT, 5); - - _lv_memset_00(&(list_page_ext->voice_playing_anim), sizeof(lv_anim_t)); - list_page_ext->voice_playing_msg_from = 0; - list_page_ext->pressing = false; - ext->list = list_page; - - uint8_t i = 0; - uint8_t msg_count = wechat_msg_info_count_get(); - hal_rtc_t cur_time = {0}, last_msg_item_time = {0}, msg_time = {0}; - - Hal_Rtc_Gettime(&cur_time); - for(i = 0; i < msg_count; i++) - { - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: i=%d, msg_count=%d\n", __FUNCTION__, __LINE__, i, msg_count); - - char time_str[32] = {0}; - nv_watch_wechat_msg_item_info_t * msg_item = NULL; - - wechat_msg_info_index_item_get(i, &msg_item); - _lv_memcpy(&msg_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); - wechat_chat_list_msg_item_time(time_str, &cur_time, &msg_time, &last_msg_item_time); - _lv_memcpy(&last_msg_item_time, &(msg_item->msg_time), sizeof(hal_rtc_t)); - - wechat_chat_list_msg_item_add(list_page, msg_item, time_str, i); - } - - if((lv_obj_get_height(list_page) - lv_obj_get_style_pad_top(list_page, LV_LIST_PART_BG) * 2) > lv_obj_get_height(scrl)) - { - lv_cont_set_layout(scrl, LV_LAYOUT_OFF); - } -} - -void wechat_main_screen_refresh(void) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_wechat_ext_t * ext = wechat_actId_ext_get(ACT_ID_WECHAT_MAIN); - if(NULL == ext) - return; - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - wechat_chat_list_set_slide_enable(&ext->old_ext, true); - - wechat_msg_voice_item_playing_stop(ext); - - wechat_chat_list_msg_item_style_reset(ext); - if(NULL != ext->list) - { - lv_obj_del(ext->list); - ext->list = NULL; - } - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - if(NULL != ext->delete_timer_id) - { - Hal_Timer_Stop(ext->delete_timer_id); - ext->delete_timer_id = NULL; - } - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - if(NULL != ext->delete_bg) - { - lv_obj_del(ext->delete_bg); - ext->delete_bg = NULL; - } - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - uint8_t msg_count = wechat_msg_info_count_get(); - if(0 == msg_count) - { - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_obj_set_hidden(ext->label_no_msg, false); - } - else - { - - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - lv_obj_set_hidden(ext->label_no_msg, true); - - wechat_chat_list_create(ext->cont, ext); - } -} - -lv_obj_t * wechat_create(lv_obj_t * activity_obj, lv_wechat_created_from_e from) -{ - WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__); - - if(activity_obj == NULL) - { - lv_watch_activity_ext_t activity_ext; - - _lv_memset_00(&activity_ext, sizeof(lv_watch_activity_ext_t)); - activity_ext.actId = ACT_ID_WECHAT_MAIN; - activity_ext.create = (lv_watch_activity_create_f_t)wechat_create; //NULL; - activity_ext.prepare_destory = wechat_prepare_destory; - activity_obj = lv_watch_creat_activity_obj(&activity_ext); - LV_ASSERT_MEM(activity_obj); - } - - lv_obj_t * obj = lv_watch_obj_create(activity_obj); - if(NULL == obj) - return NULL; - /*Allocate the tab type specific extended data*/ - lv_wechat_ext_t * ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_wechat_ext_t)); - if(NULL == ext) - return NULL; - - ext->cont = NULL; - ext->list = NULL; - ext->from = from; - ext->delete_timer_id = NULL; - ext->delete_bg = NULL; - ext->record_buffer = NULL; - ext->record_size = 0; - - lv_obj_t * cont = lv_cont_create(obj, NULL); - lv_obj_set_size(cont, lv_obj_get_width(obj), lv_obj_get_height(obj)); - lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_style_local_bg_color(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(194, 252, 252)); - lv_watch_obj_add_element(cont); - ext->cont = cont; - - if(false == watch_modem_sim_present_check_req() - //|| (MMI_MODEM_SIGNAL_BAR_0 == watch_modem_get_signal_bar_req()) - ) - { - // no network - lv_obj_t * label = lv_label_create(cont, NULL); - lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NO_NETWORK); - lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); - - return obj; - } - else if(true != mmi_watch_tcp_connect_state_get() - || true != mmi_protocol_watch_bind_state_get() - ) - { - // not bind - lv_obj_t * label = lv_label_create(cont, NULL); - lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - lv_label_set_text_id(label, WATCH_TEXT_ID_DEVICE_NOT_BIND); - lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label, cont, LV_ALIGN_CENTER, 0, -10); - - return obj; - } - - //create no msg label - ext->label_no_msg = lv_label_create(cont, NULL); - lv_obj_add_style(ext->label_no_msg, LV_LABEL_PART_MAIN, &lv_watch_font26_black); - lv_label_set_text_id(ext->label_no_msg, WATCH_TEXT_ID_NO_VOICE_MSG); - //lv_label_set_align(ext->label_no_msg, LV_LABEL_ALIGN_CENTER); - lv_obj_align(ext->label_no_msg, cont, LV_ALIGN_CENTER, 0, -10); - - ext->img_record = lv_img_create(cont, NULL); - lv_img_set_src(ext->img_record, ICON_WECHAT_RECORD_BUTTON); - lv_obj_set_click(ext->img_record, true); - lv_obj_set_event_cb(ext->img_record, wechat_msg_record_button_event_cb); - lv_obj_set_adv_hittest(ext->img_record, false); - lv_obj_add_protect(ext->img_record, LV_PROTECT_PRESS_LOST); - lv_watch_obj_add_element(ext->img_record); - lv_obj_align(ext->img_record, cont, LV_ALIGN_IN_BOTTOM_MID, 0, -8); - - uint8_t msg_count = wechat_msg_info_count_get(); - if(0 == msg_count) - { - lv_obj_set_hidden(ext->label_no_msg, false); - } - else - { - lv_obj_set_hidden(ext->label_no_msg, true); - - wechat_chat_list_create(cont, ext); - } - - //uint32_t fs_total = 0; - //uint32_t fs_free = 0; - //lv_fs_free_space('C', &fs_total, &fs_free); - //WECHAT_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: space total = %dB, free = %dB\n", __FUNCTION__, __LINE__, fs_total, fs_free); - - return obj; -} - -void wechat_create_event_cb(lv_obj_t * btn, lv_event_t e) -{ - if(LV_EVENT_CLICKED == e) - { - lv_watch_png_cache_all_free(); - lv_obj_t * obj = wechat_create(NULL, WECHAT_CREATED_FROM_APP); - LV_ASSERT_MEM(obj); - } -} - -#endif diff --git a/2.sdk/sdk/gui/lv_watch/lv_watch_res.h b/2.sdk/sdk/gui/lv_watch/lv_watch_res.h index 29ff9b9b..8e1c6857 100644 --- a/2.sdk/sdk/gui/lv_watch/lv_watch_res.h +++ b/2.sdk/sdk/gui/lv_watch/lv_watch_res.h @@ -751,7 +751,7 @@ LV_IMG_DECLARE(img_poweron_logo); // wechat #ifdef __MMI_WECHAT_SUPPORT__ -#define ICON_WECHAT_NO_NETWORK "R:/png/wechat/ICON_WECHAT_NO_NETWORK.png" +//#define ICON_WECHAT_NO_NETWORK "R:/png/wechat/ICON_WECHAT_NO_NETWORK.png" #define ICON_WECHAT_TEXT_ITEM_BG "R:/png/wechat/ICON_WECHAT_TEXT_ITEM_BG.png" #define ICON_WECHAT_RECORD_BUTTON "R:/png/wechat/ICON_WECHAT_RECORD_BUTTON.png" #define ICON_WECHAT_RECORD_BUTTON_PRESSED "R:/png/wechat/ICON_WECHAT_RECORD_BUTTON_PRESSED.png" @@ -764,11 +764,13 @@ LV_IMG_DECLARE(img_poweron_logo); #define ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING2 "R:/png/wechat/ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING2.png" #define ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3 "R:/png/wechat/ICON_WECHAT_OTHER_VOICE_ITEM_PLAYING3.png" #define ICON_WECHAT_VOICE_ITEM_DAMAGE "R:/png/wechat/ICON_WECHAT_VOICE_ITEM_DAMAGE.png" +#ifndef USE_LV_WATCH_UI_240_240_CIRCLE #define ICON_WECHAT_RECORDING1 "R:/png/wechat/ICON_WECHAT_RECORDING1.png" #define ICON_WECHAT_RECORDING2 "R:/png/wechat/ICON_WECHAT_RECORDING2.png" #define ICON_WECHAT_RECORDING3 "R:/png/wechat/ICON_WECHAT_RECORDING3.png" #define ICON_WECHAT_RECORDING4 "R:/png/wechat/ICON_WECHAT_RECORDING4.png" #define ICON_WECHAT_RECORDING5 "R:/png/wechat/ICON_WECHAT_RECORDING5.png" +#endif #define ICON_WECHAT_SENDING_BG "R:/png/wechat/ICON_WECHAT_SENDING_BG.png" #define ICON_WECHAT_SENDING_PROMPT1 "R:/png/wechat/ICON_WECHAT_SENDING_PROMPT1.png" #define ICON_WECHAT_SENDING_PROMPT2 "R:/png/wechat/ICON_WECHAT_SENDING_PROMPT2.png" diff --git a/2.sdk/sdk/gui/lv_watch/mmi_default.h b/2.sdk/sdk/gui/lv_watch/mmi_default.h index e9eeb7c8..7f06768a 100644 --- a/2.sdk/sdk/gui/lv_watch/mmi_default.h +++ b/2.sdk/sdk/gui/lv_watch/mmi_default.h @@ -198,7 +198,14 @@ extern "C" #ifdef MMI_CUSTOMER_DIAL_PAD_SWITCH #define MMI_DIAL_PAD_SWITCH_DEFAULT MMI_CUSTOMER_DIAL_PAD_SWITCH #else -#define MMI_DIAL_PAD_SWITCH_DEFAULT (1) // open +#define MMI_DIAL_PAD_SWITCH_DEFAULT (1) // 0-close; 1-open +#endif + +// white list +#ifdef MMI_CUSTOMER_WHITE_LIST_SWITCH +#define MMI_WHITE_LIST_SWITCH_DEFAULT MMI_CUSTOMER_WHITE_LIST_SWITCH +#else +#define MMI_WHITE_LIST_SWITCH_DEFAULT (0) // 0-close; 1-open #endif diff --git a/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.c b/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.c index 6c9d3008..6a812474 100644 --- a/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.c +++ b/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.c @@ -237,6 +237,56 @@ bool mmi_unicode_hex_str_to_utf8_str(unsigned char * src, uint32_t src_len, unsi } +bool mmi_debug_info_write_to_file(char * info_buf) +{ + lv_fs_file_t file_p; + lv_fs_res_t res; + uint32_t bytes_write = 0; + uint32_t info_size = strlen(info_buf); + + res = lv_fs_open(&file_p, MMI_DEBUG_LOG_FILE, LV_FS_MODE_WR | LV_FS_MODE_APPEND); + if(LV_FS_RES_OK != res) + { + printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + return false; + } + + hal_rtc_t cur_time = {0}; + char str_time[24] = {0}; + + Hal_Rtc_Gettime(&cur_time); + sprintf(str_time, "\n[%04d%02d%02d_%02d%02d%02d]", + cur_time.tm_year, + cur_time.tm_mon, + cur_time.tm_mday, + cur_time.tm_hour, + cur_time.tm_min, + cur_time.tm_sec); + + //lv_fs_seek + res = lv_fs_write(&file_p, str_time, strlen(str_time), &bytes_write); + if(LV_FS_RES_OK != res) + { + printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + lv_fs_close(&file_p); + return false; + } + + res = lv_fs_write(&file_p, info_buf, info_size, &bytes_write); + lv_fs_close(&file_p); + if(LV_FS_RES_OK != res) + { + printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res); + return false; + } + printf("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, info_size, bytes_write); + + return true; +} + + + #endif diff --git a/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.h b/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.h index 37aa71eb..a9f36706 100644 --- a/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.h +++ b/2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_common.h @@ -20,6 +20,7 @@ extern "C" #ifdef __MMI_ZHSX_SUPPORT__ +#define MMI_DEBUG_LOG_FILE "C:/debug_log.txt" #define MMI_ABS(x) (((x) < 0) ? (-(x)) : (x)) @@ -35,6 +36,8 @@ signed int mmi_hex_string_to_number(signed char* hex_str, unsigned char hex_str_ bool mmi_unicode_hex_str_to_utf8_str(unsigned char * src, uint32_t src_len, unsigned char * dest, uint32_t * dest_len); +bool mmi_debug_info_write_to_file(char * info_buf); + #endif #ifdef __cplusplus