关机充电界面百分比显示

关机充电界面百分比显示

一些关键代码片段
资源获取

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-颜色

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值