关机充电界面百分比显示
一些关键代码片段
资源获取
PngHandler::PngHandler(const std::string& name) : error_code_(0), png_fp_(nullptr, fclose) {
std::string res_path = android::base::StringPrintf("/res/images/%s.png", name.c_str());
png_fp_.reset(fopen(res_path.c_str(), "rbe"));
if (!png_fp_) {
error_code_ = -1;
return;
}
结构定义
struct text_field {
std::string font_file;
int pos_x;
int pos_y;
int color_r;
int color_g;
int color_b;
int color_a;
GRFont* font;
};
资源加载判断
if (!anim->text_percent.font_file.empty() &&
(res = gr_init_font(anim->text_percent.font_file.c_str(),
&anim->text_percent.font)) < 0) {
资源初始化
static void gr_init_font(void) {
int res = gr_init_font("font", &gr_font);
//xcz
LOGE("xcz enter %s ---- %d\n", __func__, __LINE__);
if (res == 0) {
//xcz
LOGE("xcz enter %s ---- %d\n", __func__, __LINE__);
return;
}
LOGE("failed to read font: res=%d\n", res);
手工push资源
adb push font.png /res/images/
log:
[ 23.564744] xcz charger: ================================= gr_init
[ 23.564760] xcz graphics: xcz enter gr_init_font ---- 302
[ 23.564905] xcz resource: xcz enter res_create_alpha_surface ---- 361
[ 23.564921] xcz graphics: xcz enter gr_init_font ---- 316
[ 23.564934] xcz graphics: xcz enter gr_init_font ---- 339
[ 23.564947] xcz graphics: failed to read font: res=-1
[ 23.565084] xcz graphics: xcz enter gr_init_font ---- 370 == exit okay
[ 23.925104] xcz charger: ================================= gr_init
[ 23.925119] xcz graphics: xcz enter gr_init_font ---- 302
[ 23.926421] xcz resource: xcz enter res_create_alpha_surface ---- 361
[ 23.926436] xcz resource: xcz enter res_create_alpha_surface ---- 366
[ 23.926449] xcz resource: xcz enter res_create_alpha_surface ---- 374
[ 23.927838] xcz resource: xcz enter res_create_alpha_surface ---- 403
[ 23.927887] xcz graphics: xcz enter gr_init_font ---- 330 -- exit okay
[ 23.927901] xcz graphics: xcz enter gr_init_font ---- 339
[ 23.927914] xcz graphics: xcz enter gr_init_font ---- 343
[ 27.639309] xcz charger: ==== screen_width (1080) screen_height (1920) //没有走到
[ 27.639402] xcz charger: Could load time font (5)
[ 27.644847] xcz charger: Could load percent font (5)
换个资源名字
anim->text_percent.font_file = "percent_font";
adb push percent_font.png /res/images/
[ 27.545465] xcz charger: Could load time font (5)
[ 27.551146] xcz graphics: xcz enter gr_init_font ---- 302
[ 27.566021] xcz resource: xcz enter res_create_alpha_surface ---- 361
[ 27.566104] xcz resource: xcz enter res_create_alpha_surface ---- 366
[ 27.573268] xcz resource: xcz enter res_create_alpha_surface ---- 374
[ 27.588422] xcz resource: xcz enter res_create_alpha_surface ---- 403
[ 27.588641] xcz graphics: xcz enter gr_init_font ---- 330 -- exit okay
[ 27.594972] xcz charger: Could load percent font (0)
====》左上角有个小图标了
接下来其他细节修改:
1-修改位置
2-颜色