コード例 #1
0
int ui_start_menu(const char** headers, char** items, int initial_selection) {
    int i;
    pthread_mutex_lock(&gUpdateMutex);
    if (text_rows > 0 && text_cols > 0) {
        for (i = 0; i < text_rows; ++i) {
            if (headers[i] == NULL) break;
#ifndef USE_CHINESE_FONT
            strncpy(menu[i], headers[i], text_cols-1);
            menu[i][text_cols-1] = '\0';
#else
            int j = 0, fwidth = 0, fwidth_sum = 0;
            for(j=0; headers[i][j] != '\0' && fwidth_sum < gr_fb_width(); j++) {
                fwidth = gr_measure(&headers[i][j]);
                fwidth_sum += fwidth;
                //if (j == sizeof(menu[i])) break;
            }
            strncpy(menu[i], headers[i], j);
            menu[i][j] = '\0';
            //LOGI("%d %s\n", j, menu[i]);
#endif
        }
        menu_top = i;
        for (; i < MENU_MAX_ROWS; ++i) {
            if (items[i-menu_top] == NULL) break;
            strcpy(menu[i], MENU_ITEM_HEADER);
            strncpy(menu[i] + MENU_ITEM_HEADER_LENGTH, items[i-menu_top], MENU_MAX_COLS - 1 - MENU_ITEM_HEADER_LENGTH);
            menu[i][MENU_MAX_COLS-1] = '\0';
        }

        if (gShowBackButton && !ui_root_menu) {
#ifdef USE_CHINESE_FONT
            strcpy(menu[i], " < 返回");
#else
            strcpy(menu[i], " < Go Back");
#endif
            ++i;
        }

        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = menu_show_start = initial_selection;
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    if (gShowBackButton && !ui_root_menu) {
        return menu_items - 1;
    }
    return menu_items;
}
コード例 #2
0
void healthd_board_mode_charger_draw_battery(
                struct android::BatteryProperties *batt_prop)
{
    char cap_str[STR_LEN];
    int x, y;
    int str_len_px;
    static int char_height = -1, char_width = -1;

    if (char_height == -1 && char_width == -1)
        gr_font_size(gr_sys_font(), &char_width, &char_height);
    snprintf(cap_str, (STR_LEN - 1), "%d%%", batt_prop->batteryLevel);
    str_len_px = gr_measure(gr_sys_font(), cap_str);
    x = (gr_fb_width() - str_len_px) / 2;
    y = (gr_fb_height() + char_height) / 2;
    gr_color(0, 0, 0, 255);
    gr_text(gr_sys_font(), x, y, cap_str, 0);
}
コード例 #3
0
void ui_print(const char *fmt, ...) {
    char buf[256];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, 256, fmt, ap);
    va_end(ap);

    if (ui_log_stdout)
        fputs(buf, stdout);

    // This can get called before ui_init(), so be careful.
    pthread_mutex_lock(&gUpdateMutex);
    if (text_rows > 0 && text_cols > 0) {
        char *ptr;
#ifdef USE_CHINESE_FONT
        int fwidth = 0, fwidth_sum = 0;
#endif
        for (ptr = buf; *ptr != '\0'; ++ptr) {
#ifdef USE_CHINESE_FONT
            fwidth = gr_measure(&*ptr);
            //LOGI("%d \n", fwidth);
            fwidth_sum += fwidth;

            if (*ptr == '\n' || fwidth_sum >= gr_fb_width()) {
                fwidth_sum = 0;
#else
            if (*ptr == '\n' || text_col >= text_cols) {
#endif
                text[text_row][text_col] = '\0';
                text_col = 0;
                text_row = (text_row + 1) % text_rows;
                if (text_row == text_top) text_top = (text_top + 1) % text_rows;
            }
            if (*ptr != '\n') text[text_row][text_col++] = *ptr;
        }
        text[text_row][text_col] = '\0';
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
}

void ui_printlogtail(int nb_lines) {
    char * log_data;
    char tmp[PATH_MAX];
    FILE * f;
    int line=0;
    //don't log output to recovery.log
    ui_log_stdout=0;
    sprintf(tmp, "tail -n %d /tmp/recovery.log > /tmp/tail.log", nb_lines);
    __system(tmp);
    f = fopen("/tmp/tail.log", "rb");
    if (f != NULL) {
        while (line < nb_lines) {
            log_data = fgets(tmp, PATH_MAX, f);
            if (log_data == NULL) break;
            ui_print("%s", tmp);
            line++;
        }
        fclose(f);
    }
    ui_print("Return to menu with any key.\n");
    ui_log_stdout=1;
}