#define VIDEO_PATH "A:/data/video"
#define CAMERA_PATH "A:/data/camera"
static void event_handler(lv_event_t* e);
static void clear_list(lv_obj_t *list);
/*static uint32_t get_list_size(lv_obj_t *list) {
uint32_t size = 0;
lv_obj_t *btn = lv_obj_get_child(list, NULL); // 获取列表的第一个子对象
while (btn != NULL) {
size++; // 增加列表大小
btn = lv_obj_get_child(list, btn); // 获取下一个子对象
}
return size;
}*/
int list_size=0;
static void refresh_list(lv_obj_t *list) {
uint32_t btn_count = list_size;
ALOGD("refresh_list:%d",btn_count);
for (uint32_t i = 0; i < btn_count; i++) {
lv_obj_t *btn = lv_obj_get_child(list, 0); // 获取列表的第一个子对象
const char *btn_text = lv_list_get_btn_text(ui_video_list, btn);
ALOGD("Clicked: %s", btn_text); //打印list对应点击的文本内容
ALOGD("11111111111");
lv_obj_del(btn); // 删除按钮
ALOGD("lv_obj_del");
}
}
static void clear_list1(lv_obj_t *list) {
lv_obj_t *btn;
// 获取列表中的第一个按钮
btn = lv_obj_get_child(list, 0);
// 逐个删除按钮
while (btn != NULL) {
const char *btn_text = lv_list_get_btn_text(ui_video_list, btn);
ALOGD("clear_list1: %s", btn_text); //打印list对应点击的文本内容
ALOGD("11111111111");
lv_obj_remove_event_cb(btn,event_handler);
lv_obj_del(btn); // 删除当前按钮
btn=NULL;
ALOGD("2222222222");
btn = lv_obj_get_child(list, 0); // 获取下一个按钮
}
}
void lv_fs_read_dir(lv_obj_t *list, const char *path)
{
ALOGD("111111111111111111111");
// 清空列表中的所有按钮
clear_list1(list);
//refresh_list(list);
ALOGD("2222222222222222222222");
list_size =0;
lv_fs_dir_t dir;
lv_fs_res_t res;
res = lv_fs_dir_open(&dir, path);
if (res != LV_FS_RES_OK) {
ALOGD("Open DIR error! Error code: %d\n", res);
return;
}
if((strcmp(path, VIDEO_PATH) != 0)&&(strcmp(path, CAMERA_PATH) != 0)){ //path不等于DIR_PATH
// 创建一个按钮并将文件名添加到列表中
lv_obj_t *list_btn = lv_list_add_btn(list, NULL, "..");
list_size++;
// 可以在这里设置按钮的事件回调函数
lv_obj_add_event_cb(list_btn, event_handler, LV_EVENT_ALL, NULL);
}
char fn[256]; // 缓冲区
while (1) {
res = lv_fs_dir_read(&dir, fn);
if (res != LV_FS_RES_OK) {
ALOGD("Read DIR error! Error code: %d\n", res);
break;
}
// 如果没有更多文件可以读取时 fn 就为空
if (strlen(fn) == 0) {
ALOGD("Fn is empty, if not more files to read.\n");
break;
}
ALOGD("%s\n", fn);
// 创建一个按钮并将文件名添加到列表中
lv_obj_t *list_btn = lv_list_add_btn(list, NULL, fn);
list_size++;
// 可以在这里设置按钮的事件回调函数
lv_obj_add_event_cb(list_btn, event_handler, LV_EVENT_ALL, NULL);
}
lv_fs_dir_close(&dir);
}
// 清空列表中的所有按钮
static void clear_list(lv_obj_t *list) {
// 获取列表中的所有按钮并删除
lv_obj_clean(list);
}
void remove_drive(char *path) {
// 检查路径是否以"A:/"开头
if (strncmp(path, "A:/", 2) == 0) {
// 移动剩余的路径部分到路径的开头
memmove(path, path + 2, strlen(path) - 1);
}
}
static void event_handler(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e); // 获取对象产生的事件码
lv_obj_t* obj = lv_event_get_target(e); // 获取产生事件的对象
char new_path[256];
char file_path[128];
if (code == LV_EVENT_CLICKED) { // LV_EVENT_CLICKED事件处理
const char *btn_text = lv_list_get_btn_text(ui_video_list, obj);
ALOGD("Clicked: %s", btn_text); //打印list对应点击的文本内容
if (strcmp(btn_text, "..") == 0) {
// 返回上一级目录
lv_obj_add_flag(ui_TipPanel, LV_OBJ_FLAG_HIDDEN); /// Flags
char *last_slash = strrchr(current_path, '/');
if (last_slash != NULL) {
*last_slash = '\0'; // 去掉最后一个子目录
}
lv_fs_read_dir(ui_video_list, current_path);
} else if (strstr(btn_text, "/") != NULL) { // 判断是否有“/”
snprintf(new_path, sizeof(new_path), "%s%s", current_path, btn_text);
ALOGD("new_path: %s", new_path); // 打印新的路径
if(del_flag ==1){
//弹窗
ALOGD("删除"); // 删除
remove_drive(new_path);
memset(del_file_path,0,sizeof(del_file_path));
strncpy(del_file_path,new_path,sizeof(del_file_path));
ALOGD("del_file_path: %s", del_file_path); // 打印新的路径
show_tip_dialog("ARE YOU SURE TO DELETE THE FILE?",1);
}else{
strcpy(current_path, new_path); // 更新当前路径
lv_fs_read_dir(ui_video_list, current_path);
}
} else {
snprintf(file_path, sizeof(file_path), "%s/%s", current_path, btn_text);
ALOGD("file_path: %s", file_path); // 打印文件路径
if(del_flag ==1){
//弹窗
ALOGD("删除"); // 删除
remove_drive(file_path);
memset(del_file_path,0,sizeof(del_file_path));
strncpy(del_file_path,file_path,sizeof(del_file_path));
show_tip_dialog("ARE YOU SURE TO DELETE THE FILE?",1);
}else{
}
}
}
}
void ui_event_home_camera_butt(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(&ui_video_main, LV_SCR_LOAD_ANIM_NONE, 0, 0, &ui_video_main_screen_init);
_ui_flag_modify(ui_video_img, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
_ui_flag_modify(ui_camera_img, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
strcpy(current_path,CAMERA_PATH);
lv_fs_read_dir(ui_video_list,CAMERA_PATH);
}
}
void ui_event_home_video_butt(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(&ui_video_main, LV_SCR_LOAD_ANIM_NONE, 0, 0, &ui_video_main_screen_init);
strcpy(current_path,VIDEO_PATH);
lv_fs_read_dir(ui_video_list,VIDEO_PATH);
}
}
用与读取本地文件目录,选中其中目录刷新列表,更新其子目录的一个文件系统
现在是一使用lv_obj_del或lv_obj_clean,概率会出现卡死在这个位置上。
有什么好的解决办法 或者排除问题的办法