關機充電界面百分比顯示

關機充電界面百分比顯示

一些關鍵代碼片段
資源獲取

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章