X-AIOS-LT00-V1.0.4/sdk/X-AIOS-LT00/core/apps/launcher/home.c

268 lines
9.0 KiB
C
Raw Normal View History

2026-01-19 09:23:53 +00:00
/*
* Copyright (c) Quaming Intelligent Technology Co., Ltd.
* (C) Copyright All Rights Reserved.
*
*/
/**
* @file launcher.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lvgl/lvgl.h"
#include "xos_app_conf.h"
#if CONFIG_XOS_USE_APP_LAUNCHER != 0
#include <stdio.h>
#include "launcher.h"
#include "lang/xos_strid.h"
#include "xos_misc.h"
#include "home_setting.h"
#include "appmanager.h"
#include "appmanager.h"
#include "home.h"
#include "app_path_conf.h"
#include "qm_lv_obj.h"
#include "param.h"
#include "config/launcher_conf.h"
#include "app_name.h"
#include "view/home_statusbar.h"
/**********************
* GLOBAL DECLARATION
**********************/
// extern lv_theme_t * lv_ability_theme_init(void);
// extern void qm_homebody_key_event_cb(lv_event_t *e);
/*********************
* DEFINES
*********************/
//
#define WIDGET_DATE_TIME 1
#define WIDGET_PAGE_NUM 0
//
/**********************
* TYPEDEFS
**********************/
xos_app_entry_t* s_app_table = NULL;
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static home_data_info home_data = {0};
/**********************
* STATIC FUNCTIONS
**********************/
static bool _filter_app_entry(app_info *item) {
if (item == NULL) return false;
if (0 == strcmp(item->app_name, "launcher")
|| 0 == strcmp(item->app_name, "imageviewer")
|| 0 == strcmp(item->app_name, "videoplayer")) {
return false;
}
LV_LOG_USER("item->name=%s", item->app_name);
return launcher_get_srcmapping(item->app_name) != NULL;
}
static int launcher_getappregcounts(void) {
static int s_apps_count = 0;
if (s_apps_count == 0) {
app_info *item = NULL;
_LV_LL_READ_BACK(app_manager_get_reglist(), item) {
if (_filter_app_entry(item)) s_apps_count++;
}
}
LV_LOG_USER("get apps counts=%d", s_apps_count);
return s_apps_count;
}
static int launcher_getappmapentrys(void) {
static int s_apps_entrys = 0;
if (s_apps_entrys == 0) {
s_apps_entrys = launcher_get_srcmapping_max_item_num();
}
LV_LOG_USER("get apps entrys=%d", s_apps_entrys);
return s_apps_entrys;
}
static int launcher_getappcounts(void) {
#if (defined(CONFIG_PRODUCT_KIDCAMERA) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_STUDYPILOT) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_CAMERA) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_DEMO_LV) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_DEMO_LD))
return launcher_getappmapentrys();
#else
return launcher_getappregcounts();
#endif
}
static void launcher_load_app_table(void)
{
app_info *item = NULL;
app_src_mapping *src = NULL;
int app_count = launcher_getappcounts();
int index = 0;
s_app_table = (xos_app_entry_t*)malloc(app_count * sizeof(xos_app_entry_t));
#if (defined(CONFIG_PRODUCT_KIDCAMERA) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_STUDYPILOT) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_CAMERA) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_DEMO_LV) && defined(CONFIG_XOS_APP_GRID_STYLE)) || \
(defined(CONFIG_PRODUCT_DEMO_LD))
for(int i = 0; i < app_count; i++) {
src = launcher_get_srcmapping_by_id(i);
if (src) {
s_app_table[index].name = src->name;
s_app_table[index].image_src = src->image_src;
s_app_table[index].text_id = src->text_id;
index++;
}
}
#else
_LV_LL_READ(app_manager_get_reglist(), item) {
if (_filter_app_entry(item)) {
if (item->app_name) s_app_table[index].name = item->app_name;
src = launcher_get_srcmapping(item->app_name);
s_app_table[index].image_src = src->image_src;
s_app_table[index].text_id = src->text_id;
index++;
}
}
#endif
LV_ASSERT_MSG(app_count == index, "app count != s_app_table.count");
}
#if CONFIG_XOS_USE_APP_SCREEN_PROTECT
static void screen_protect_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_KEY) {
LV_LOG_USER("screen_protect_cb");
extern lcd_service_reset();
lcd_service_reset();
}
return;
}
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void xos_home_sleep(void) {
LV_LOG_USER("xos_home_sleep ENTRY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
const char *app_name = app_manager_get_startname();
// 当应用不是bat_charging、alarm_alerter、study_shutdn时才执行背景窗口隐藏操作
#if !defined(CONFIG_PRODUCT_DEMO_LD) && !defined(CONFIG_PRODUCT_DEMO_LH)
if(strcmp(app_name, APP_NAME_DEVICE_CHARGE) != 0 &&
strcmp(app_name, APP_NAME_ALARM_ALERTER) != 0 &&
strcmp(app_name, APP_NAME_DEVICE_SHUTDN) != 0) {
if (home_data.bg_wnd != NULL) lv_obj_add_flag(home_data.bg_wnd, LV_OBJ_FLAG_HIDDEN);
}
#endif
//for kidcamera: not remove cb here, because xos_home_sleep will be invoked in qm_homebody_key_event_cb
//if there are multiple cbs added(LV_EVENT_KEY + LV_EVENT_LONG_PRESSED), it will cause a crash in lv_send_event by removed here;
//modified: in the qm_homebody_key_event_cb: when the obj is hidden, not to handle the events;
#if !defined(CONFIG_PRODUCT_KIDCAMERA) && !defined(CONFIG_XOS_USE_CAMERA)
#if !defined(BUILD_SIMULATOR) || BUILD_SIMULATOR == 0
lv_obj_remove_event_cb(home_data.bg_wnd, qm_homebody_key_event_cb);
#endif //not BUILD_SIMULATOR
#endif //not CONFIG_PRODUCT_KIDCAMERA
//
// if (home_data.bg_wnd != NULL) {
// lv_obj_set_style_bg_image_src(home_data.bg_wnd, NULL, 0);
// }
}
void xos_home_wakeup(void) {
LV_LOG_USER("xos_home_wakeup ENTRY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
if (home_data.bg_wnd && lv_obj_is_valid(home_data.bg_wnd) &&
lv_obj_has_flag(home_data.bg_wnd, LV_OBJ_FLAG_HIDDEN))
lv_obj_clear_flag(home_data.bg_wnd, LV_OBJ_FLAG_HIDDEN);
lv_group_focus_obj(home_data.bg_wnd);
#if !defined(CONFIG_PRODUCT_KIDCAMERA) && !defined(CONFIG_XOS_USE_CAMERA)
#if !defined(BUILD_SIMULATOR) || BUILD_SIMULATOR == 0
lv_obj_add_event_cb(home_data.bg_wnd, qm_homebody_key_event_cb, LV_EVENT_KEY, NULL); //for kidcamera: not add event cb here, it will be added in the qm_create_home_body
lv_obj_add_event_cb(home_data.bg_wnd, qm_homebody_key_event_cb, LV_EVENT_LONG_PRESSED, NULL); //attention: see the note in xos_home_sleep for multiple add_event_cb and remove_event_cb
#endif //not BUILD_SIMULATOR
#endif //not CONFIG_PRODUCT_KIDCAMERA
lv_obj_add_state(home_data.img_info[home_data.cur_selected], LV_STATE_FOCUS_KEY);
//
// if (home_data.bg_wnd != NULL) {
// #ifdef k_path_bg
// lv_obj_set_style_bg_img_src(home_data.bg_wnd, k_path_bg, 0);
// #endif
// }
#ifdef CONFIG_XOS_USE_APP_STATUS_BAR
home_update_status_bar();
#endif
}
void launcher_body_init(lv_obj_t * active_layer)
{
// lv_ability_theme_init();
launcher_load_app_table();
home_data.img_info = (lv_obj_t**)calloc(launcher_getappcounts(), sizeof(lv_obj_t*));
//create page bg
lv_obj_t *bg_wnd = qm_lv_obj_create(active_layer);
lv_group_add_obj(lv_group_get_default(), bg_wnd);
lv_group_focus_obj(bg_wnd);
lv_obj_center(bg_wnd);
lv_obj_set_size(bg_wnd, LV_USE_HOR_SIZE, LV_USE_VER_SIZE);
lv_obj_clear_flag(bg_wnd, LV_OBJ_FLAG_SCROLLABLE);
//lv_obj_clear_flag(bg_wnd, LV_OBJ_FLAG_CLICKABLE);
#if !defined(CONFIG_PRODUCT_STUDYPILOT)
#if CONFIG_XOS_USE_APP_SCREEN_PROTECT
lv_obj_add_event_cb(bg_wnd, screen_protect_cb, LV_EVENT_KEY, NULL);
#endif
#endif
//create nine grid apps tile
int app_total_cnt = launcher_getappcounts();
extern lv_obj_t *qm_create_home_body(lv_obj_t *bg_wnd, home_data_info *img_info, int app_total_cnt);
lv_obj_t *body_view = qm_create_home_body(bg_wnd, &home_data, app_total_cnt);
home_data.body_view = body_view;
home_data.bg_wnd = bg_wnd;
#ifdef CONFIG_XOS_DARK_MODE
lv_obj_set_style_bg_color(bg_wnd, lv_color_black(), 0);
lv_obj_set_style_bg_color(body_view, lv_color_black(), 0);
#elif CONFIG_PRODUCT_MOMOTALK
lv_obj_set_style_bg_color(bg_wnd, lv_color_hex(0x808080), 0);
lv_obj_set_style_bg_color(body_view, lv_color_hex(0x808080), 0);
#else
lv_obj_set_style_bg_color(bg_wnd, lv_color_white(), 0);
lv_obj_set_style_bg_color(body_view, lv_color_white(), 0);
#endif
#ifndef CONFIG_XOS_USE_APP_SPHOTO
lv_obj_add_state(home_data.img_info[home_data.cur_selected], LV_STATE_FOCUS_KEY);
#endif
}
void xos_update_launcher_app_label(void) {
int app_count = launcher_getappcounts();
for (int i=0; i< app_count; i++) {
lv_label_set_text(s_app_table[i].label, GetTextRes(s_app_table[i].text_id));
LV_LOG_USER("%s %s\n", s_app_table[i].name, GetTextRes(s_app_table[i].text_id));
}
}
#endif/* CONFIG_XOS_USE_APP_LAUNCHER*/