Exemple #1
0
BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) {
    battery_state_service_subscribe(battery_handler);

    BatteryComponent *c = malloc(sizeof(BatteryComponent));
    c->icon_layer = NULL;
    c->icon_bitmap = NULL;
    c->text_layer = NULL;

    if (get_prefs()->battery_as_number) {

        FontChoice font = get_font(BATTERY_FONT);
        c->text_layer = add_text_layer(
                            parent,
                            GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom),
                            fonts_get_system_font(font.key),
                            element_fg(parent),
                            align_right ? GTextAlignmentRight : GTextAlignmentLeft
                        );

    } else {

        c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT));
        bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent));
        layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer));

    }

    // XXX
    s_component = c;
    battery_handler(battery_state_service_peek());

    return c;
}
Exemple #2
0
void handle_init(AppContextRef ctx)
{
    window_init(&window, "SDDT");
    window_stack_push(&window, true);
    window_set_background_color(&window, GColorBlack);

    GFont font_condensed = fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21);
    GFont font_bold = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);

    add_text_layer(&date_layer,         GRect(8, 8, 128, 52),   font_condensed, GTextAlignmentCenter);
    add_text_layer(&seconds_layer,      GRect(104, 80, 32, 22), font_condensed, GTextAlignmentRight);
    add_text_layer(&ampm_layer,         GRect(8, 80, 32, 22),   font_condensed, GTextAlignmentLeft);
    add_text_layer(&hour_minutes_layer, GRect(8, 96, 128, 50),  font_bold,      GTextAlignmentCenter);

    layer_init(&decoration_layer, window.layer.frame);
    decoration_layer.update_proc = &update_decoration;
    layer_add_child(&window.layer, &decoration_layer);

    // Update the time now.
    PblTm time;
    get_time(&time);
    update_time(&time);
}