void ui_set_condition(int condition, int error) { if (error == FETCH_ERROR) { if (connection_service_peek_pebble_app_connection()) { strncpy(ui.texts.condition, "\uf03e", sizeof(ui.texts.condition)); } else { strncpy(ui.texts.condition, "\uf27f", sizeof(ui.texts.condition)); } } else if (error == WEATHER_ERROR) { strncpy(ui.texts.condition, "\uf21b", sizeof(ui.texts.condition)); } else if (error == LOCATION_ERROR) { strncpy(ui.texts.condition, "\uf1aa", sizeof(ui.texts.condition)); } else if (error == AQI_ERROR) { strncpy(ui.texts.condition, "\uf368", sizeof(ui.texts.condition)); } else { weather_set_condition(condition, is_day, ui.texts.condition); } //For pretty screenshots //SCREENSHOT_0 strncpy(ui.texts.condition, "\uf00d", sizeof(ui.texts.condition)); //SCREENSHOT_1 strncpy(ui.texts.condition, "\uf02a", sizeof(ui.texts.condition)); //SCREENSHOT_2 strncpy(ui.texts.condition, "\uf008", sizeof(ui.texts.condition)); //SCREENSHOT_3 strncpy(ui.texts.condition, "\uf056", sizeof(ui.texts.condition)); ui_set_info(STATUS_ITEMS_WEATHER_CONDITION, ui.texts.condition); }
void load_batteries(Window *window, Layer *window_layer, GRect bounds) { s_watch_battery_layer = text_layer_create( GRect(25, 70, bounds.size.w, 50)); s_phone_battery_layer = text_layer_create( GRect(100, 70, bounds.size.w, 50)); text_layer_set_background_color(s_watch_battery_layer, GColorClear); text_layer_set_background_color(s_phone_battery_layer, GColorClear); text_layer_set_text_color(s_watch_battery_layer, GColorWhite); text_layer_set_text_color(s_phone_battery_layer, GColorWhite); text_layer_set_text(s_watch_battery_layer, " ?"); text_layer_set_text(s_phone_battery_layer, " ?"); text_layer_set_text_alignment(s_watch_battery_layer, GTextAlignmentLeft); text_layer_set_text_alignment(s_phone_battery_layer, GTextAlignmentLeft); text_layer_set_font(s_watch_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_font(s_phone_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); // Create the Bluetooth icon GBitmap s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BLUETOOTH_DISABLED); // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = bitmap_layer_create(GRect(95, 70, 30, 30)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer)); layer_add_child(window_layer, text_layer_get_layer(s_watch_battery_layer)); layer_add_child(window_layer, text_layer_get_layer(s_phone_battery_layer)); // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); }
static void main_window_load(Window *window) { GRect bounds = layer_get_bounds(window_get_root_layer(window)); //Create GBitmap, then set to created BitmapLayer //s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND); //s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); //bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); //layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); // Create canvas layer s_vert_layer = layer_create(bounds); s_vert2_layer = layer_create(bounds); s_canvas_layer = layer_create(bounds); s_canvas2_layer = layer_create(bounds); // Assign the custom drawing procedure layer_set_update_proc(s_vert_layer, vert_update_proc); layer_set_update_proc(s_vert2_layer, vert2_update_proc); layer_set_update_proc(s_canvas_layer, canvas_update_proc); layer_set_update_proc(s_canvas2_layer, canvas2_update_proc); // Add to Window layer_add_child(window_get_root_layer(window), s_vert_layer); layer_add_child(window_get_root_layer(window), s_vert2_layer); layer_add_child(window_get_root_layer(window), s_canvas_layer); layer_add_child(window_get_root_layer(window), s_canvas2_layer); // Create GFonts s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPEN_60)); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPEN_17)); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 30, 144, 60)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorLightGray); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); // Create date TextLayer s_date_layer = text_layer_create(GRect(0, 120, 144, 23)); text_layer_set_text_color(s_date_layer, GColorLightGray); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_text(s_date_layer, "Sept 23"); text_layer_set_font(s_date_layer, s_date_font); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Initialize the display update_time(); bluetooth_callback(connection_service_peek_pebble_app_connection()); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_layer = layer_create(layer_get_bounds(window_get_root_layer(window))); layer_add_child(window_get_root_layer(window), s_layer); layer_set_update_proc(s_layer, draw_watchface); s_time_layer = text_layer_create(GRect(0, 0, 24, 24)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); if (persist_read_int(KEY_BACKGROUND_COLOR)) { background_color = GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR)); window_set_background_color(window, GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR))); } else { background_color = GColorWhite; } setup_blocks(); if (persist_read_int(KEY_DEGREEOPTION)) { degreeOption = persist_read_int(KEY_DEGREEOPTION); } else { degreeOption = 0; } s_weather_layer = text_layer_create(GRect(0,152, 144, 14)); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight); text_layer_set_text(s_weather_layer, "Loading..."); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30)); layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc); bluetooth_path = gpath_create(&BLUETOOTH_INFO); layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer); //show the correct state of the bluetooth connection from the start #ifdef PBL_SDK_2 bluetooth_callback(bluetooth_connection_service_peek()); #elif PBL_SDK_3 bluetooth_callback(connection_service_peek_pebble_app_connection()); #endif s_date_layer = text_layer_create(GRect(0,0,144,14)); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); s_battery_layer = text_layer_create(PBL_IF_ROUND_ELSE( GRect(38, 12, bounds.size.w-76, 32), GRect(8, 6, bounds.size.w-16, 32))); text_layer_set_text_color(s_battery_layer, GColorBlack); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight); text_layer_set_text(s_battery_layer, "100%"); s_date_layer = text_layer_create(PBL_IF_ROUND_ELSE( GRect(38, 12, bounds.size.w-76, 32), GRect(8, 6, bounds.size.w-16, 32))); text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentLeft); text_layer_set_text(s_date_layer, "Jan 1"); s_time_layer = text_layer_create(GRect(0, 48, bounds.size.w, 56)); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_background_color(s_time_layer, GColorMidnightGreen); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); s_steps_layer = text_layer_create(GRect(0, 100, bounds.size.w, 32)); text_layer_set_text_color(s_steps_layer, GColorBlack); text_layer_set_background_color(s_steps_layer, GColorCadetBlue); text_layer_set_font(s_steps_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(s_steps_layer, GTextAlignmentCenter); text_layer_set_text(s_steps_layer, "0 steps"); s_connection_layer = text_layer_create(GRect(0, 136, bounds.size.w, 20)); text_layer_set_text_color(s_connection_layer, GColorBlack); text_layer_set_background_color(s_connection_layer, GColorClear); text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter); handle_bluetooth(connection_service_peek_pebble_app_connection()); time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_minute_tick(current_time, MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); battery_state_service_subscribe(handle_battery); connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = handle_bluetooth });
static void loading_retry_timer(void* data) { if (!loadingMode) return; if (!connection_service_peek_pebble_app_connection()) { show_disconnected_error(); return; } send_initial_packet(); app_timer_register(3000, loading_retry_timer, NULL); }
void main_reload_config() { // Must be before BT handle overwrites the BG color! #if defined(PBL_COLOR) pge_set_background_color(data_get_color(ColorBackground)); #elif defined(PBL_BW) pge_set_background_color(GColorBlack); #endif // If bluetooth alert enabled if(data_get_bluetooth_alert()) { connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = bt_handler }); bt_handler(connection_service_peek_pebble_app_connection()); } else {
// Initialise windows extern void init_windows(void) { splash_window_push(); // Load splash window // Prepare for data app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); // Check Bluetooth connectivity // *TO DO* there is latency in bluetooth peek function from Pebble if (connection_service_peek_pebble_app_connection()){ app_message_open(INBOX_SIZE, OUTBOX_SIZE); } else { snprintf(message_buffer, sizeof(message_buffer), "%s", "[Error] No bluetooth connection available"); splash_window_pull(); message_window_push(message_buffer); } }
void update_time() { time_t start; struct tm *t; start = time(NULL); t = localtime(&start); day = t->tm_mday; weekday = t->tm_wday; battlife = battery_state_service_peek().charge_percent; btstatus = connection_service_peek_pebble_app_connection(); #ifdef FORCESTARTAT daymin = FORCESTARTAT; #else daymin = (t->tm_hour * 60) + t->tm_min; #endif }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); // Format all layers s_time_layer = text_layer_create(GRect(0, 50, bounds.size.w, 50)); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); s_connection_layer = text_layer_create(GRect(0, 145, bounds.size.w, 34)); text_layer_set_text_color(s_connection_layer, GColorWhite); text_layer_set_background_color(s_connection_layer, GColorClear); text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter); s_weekday_layer = text_layer_create(GRect(0, 105, bounds.size.w, 34)); text_layer_set_text_color(s_weekday_layer, GColorWhite); text_layer_set_background_color(s_weekday_layer, GColorClear); text_layer_set_font(s_weekday_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_weekday_layer, GTextAlignmentCenter); s_date_layer = text_layer_create(GRect(0, 125, bounds.size.w, 34)); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); s_temperature_layer = text_layer_create(GRect(0, 20, bounds.size.w, 32)); text_layer_set_text_color(s_temperature_layer, GColorWhite); text_layer_set_background_color(s_temperature_layer, GColorClear); text_layer_set_font(s_temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(s_temperature_layer, GTextAlignmentCenter); s_city_layer = text_layer_create(GRect(0, 0, bounds.size.w, 32)); text_layer_set_text_color(s_city_layer, GColorWhite); text_layer_set_background_color(s_city_layer, GColorClear); text_layer_set_font(s_city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_city_layer, GTextAlignmentCenter); handle_bluetooth(connection_service_peek_pebble_app_connection()); connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = handle_bluetooth });
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_time_layer = text_layer_create(GRect(HOUR_X_OFFSET, HOUR_Y_OFFSET, bounds.size.w, HOUR_HEIGHT)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorWhite); if (BIG_NUMBERS) { s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SFSHC_74)); } else { s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SF_SQUARE_HEAD_45)); } text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight)); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); // Create date layer s_date_layer = text_layer_create(GRect(0, DATE_Y_OFFSET, bounds.size.w, 30)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorWhite); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SF_SQUARE_HEAD_20)); text_layer_set_font(s_date_layer, s_date_font); text_layer_set_text_alignment(s_date_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight)); layer_add_child(window_layer, text_layer_get_layer(s_date_layer)); // Create BT layer s_bt_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BT_WHITE); GRect bitmap_bounds = gbitmap_get_bounds(s_bt_bitmap); s_bt_layer = layer_create(GRect( (bounds.size.w - bitmap_bounds.size.w) / 2, BT_Y_OFFSET, bitmap_bounds.size.w, bitmap_bounds.size.h)); layer_set_update_proc(s_bt_layer, bt_update_proc); layer_add_child(window_layer, s_bt_layer); // Create bar layer s_bar_layer = layer_create(bounds); layer_add_child(window_layer,s_bar_layer); layer_set_update_proc(s_bar_layer, layer_update_proc); layer_set_hidden(s_bt_layer, connection_service_peek_pebble_app_connection()); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); bool hasToUpdate = (((tick_time->tm_hour * 60) + tick_time->tm_min) % freq_update_weather) == 0; // Actualiza el tiempo atmosferico cada cierto numero de minutos if(hasToUpdate){ // Se inicializa el diccionario DictionaryIterator *iter; app_message_outbox_begin(&iter); // Se agrega un par clave-valor dict_write_uint8(iter, 0, 0); // Se envia el mensaje app_message_outbox_send(); if(!connection_service_peek_pebble_app_connection()) text_layer_set_text(s_weather_layer, "--"); } }
static void create_bt(GRect bounds){ // Create temperature Layer bt_layer = text_layer_create( GRect(0, 0, bounds.size.w, 25)); // Style the text set_layer_defaults(bt_layer); // Apply to TextLayer text_layer_set_text(bt_layer, "BT"); text_layer_set_font(bt_layer, time_font_18); bool app_connection = connection_service_peek_pebble_app_connection(); if(app_connection){ text_layer_set_text_color(bt_layer, textColor); }else{ text_layer_set_text_color(bt_layer, GColorRed); } connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = app_connection_handler });
static void main_window_load(Window *window) { printf("main_window_load function"); //Create GBitmap, then set to created BitmapLayer s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); // Create time TextLayer s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text(s_time_layer, "00:00"); // Create temperature Layer s_weather_layer = text_layer_create(GRect(0, 130, 144, 25)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorWhite); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); text_layer_set_text(s_weather_layer, "Loading..."); // Create date TextLayer s_date_layer = text_layer_create(GRect(0, 115, 144, 30)); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_text(s_date_layer, "Date Load..."); //Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48)); text_layer_set_font(s_time_layer, s_time_font); s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); text_layer_set_font(s_weather_layer, s_weather_font); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_15)); text_layer_set_font(s_date_layer, s_date_font); // Create the Bluetooth icon GBitmap s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = bitmap_layer_create(GRect(59, 12, 30, 30)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer)); // Create battery meter Layer s_battery_layer = layer_create(GRect(14, 54, 115, 2)); layer_set_update_proc(s_battery_layer, battery_update_proc); // Add to Window layer_add_child(window_get_root_layer(window), s_battery_layer); // Make sure the time is displayed from the start update_time(); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_layer = layer_create(layer_get_bounds(window_get_root_layer(window))); layer_add_child(window_get_root_layer(window), s_layer); layer_set_update_proc(s_layer, draw_watchface); uint16_t vert_padding = (bounds.size.h - ((NUM_BARS - 1)*PADDING) - (NUM_BARS*HEIGHT)) / 2; uint16_t width = bounds.size.w - (2 * PADDING); //this is 120 on basalt //create the unary ticks image s_unary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_UNARY_TICKS); s_unary_ticks_layer = bitmap_layer_create(GRect(PADDING,vert_padding,width + 1,HEIGHT)); bitmap_layer_set_background_color(s_unary_ticks_layer, GColorClear); bitmap_layer_set_bitmap(s_unary_ticks_layer, s_unary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_unary_ticks_layer, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_unary_ticks_layer)); //create the ternary ticks image and layer for minutes s_ternary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TERNARY_TICKS); s_ternary_ticks_layer_minutes = bitmap_layer_create(GRect(PADDING, vert_padding + PADDING + HEIGHT, width + 1, HEIGHT)); bitmap_layer_set_background_color(s_ternary_ticks_layer_minutes, GColorClear); bitmap_layer_set_bitmap(s_ternary_ticks_layer_minutes, s_ternary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_minutes, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_minutes)); //create the ternary ticks layer for seconds s_ternary_ticks_layer_seconds = bitmap_layer_create(GRect(PADDING, vert_padding + (2*PADDING) + (2*HEIGHT), width + 1, HEIGHT)); bitmap_layer_set_background_color(s_ternary_ticks_layer_seconds, GColorClear); bitmap_layer_set_bitmap(s_ternary_ticks_layer_seconds, s_ternary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_seconds, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_seconds)); if (persist_read_int(KEY_TOP_BAR_COLOR)) { s_top_bar_color = GColorFromHEX(persist_read_int(KEY_TOP_BAR_COLOR)); /// set_background_and_text_color(background_color); } else { s_top_bar_color = GColorRed; } if (persist_read_int(KEY_MIDDLE_BAR_COLOR)) { s_middle_bar_color = GColorFromHEX(persist_read_int(KEY_MIDDLE_BAR_COLOR)); } else { s_middle_bar_color = GColorGreen; } if (persist_read_int(KEY_BOTTOM_BAR_COLOR)) { s_bottom_bar_color = GColorFromHEX(persist_read_int(KEY_BOTTOM_BAR_COLOR)); } else { s_bottom_bar_color = GColorBlue; } if (persist_read_int(KEY_BACKGROUND_COLOR)) { set_background_and_text_color(persist_read_int(KEY_BACKGROUND_COLOR)); } else { set_background_and_text_color(0xFFFFFF); } if (persist_read_int(KEY_DEGREEOPTION)) { degreeOption = persist_read_int(KEY_DEGREEOPTION); } else { degreeOption = 0; } s_weather_layer = text_layer_create(GRect(0,152, 144, 14)); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight); text_layer_set_text(s_weather_layer, "Loading..."); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30)); layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc); bluetooth_path = gpath_create(&BLUETOOTH_INFO); layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer); //show the correct state of the bluetooth connection from the start #ifdef PBL_SDK_2 bluetooth_callback(bluetooth_connection_service_peek()); #elif PBL_SDK_3 bluetooth_callback(connection_service_peek_pebble_app_connection()); #endif s_date_layer = text_layer_create(GRect(0,0,144,14)); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); }
// update display static void update_display() { // Getting Battery State BatteryChargeState current_battery_charge_state = battery_state_service_peek(); if (current_battery_charge_state.is_charging) { chargeState = -1; } else { chargeState = current_battery_charge_state.charge_percent; } //APP_LOG(APP_LOG_LEVEL_DEBUG, "Setting chargeState = %d", chargeState); // Get a tm structure time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); // Create a long-lived buffers static char buffer_hh[] = "00"; static char buffer_mm[] = "00"; static char buffer_dte[] = "ddd 00 mmm"; // Write the current hours into the buffer if(clock_is_24h_style() == true) { // Use 24 hour format strftime(buffer_hh, sizeof("00:00"), "%H", tick_time); } else { // Use 12 hour format strftime(buffer_hh, sizeof("00:00"), "%I", tick_time); } h1 = ascii_digit_to_int(buffer_hh[0]); h2 = ascii_digit_to_int(buffer_hh[1]); // hide leading zero if required if (h1 == 0 && hh_strip_zero) h1 = -1; // Write the current minuts into the buffer strftime(buffer_mm, sizeof("00"), "%M", tick_time); m1 = ascii_digit_to_int(buffer_mm[0]); m2 = ascii_digit_to_int(buffer_mm[1]); // debug //h1 = h2 = m1 = m2 = 0; // Write the current date into the buffer if (locale != locale_en) { // Ddd 00 Mmm //strftime(buffer_dte, sizeof("ddd 00 mmm"), "%a %d %b", tick_time); snprintf(buffer_dte, sizeof("ddd 00 mmm"), "%s %d %s", DAYS[locale][tick_time->tm_wday], tick_time->tm_mday, MONTHS[locale][tick_time->tm_mon]); } else { // Ddd Mmm 00 //strftime(buffer_dte, sizeof("ddd mmm 00"), "%a %b %d", tick_time); snprintf(buffer_dte, sizeof("ddd mmm 00"), "%s %s %d", DAYS[0][tick_time->tm_wday], MONTHS[0][tick_time->tm_mon], tick_time->tm_mday); } // undload and relaod time images unload_time_images(); load_time_images(); // Display values in TextLayers text_layer_set_text(s_time_layer_dte, buffer_dte); if (connection_service_peek_pebble_app_connection()) { // phone is connected layer_set_hidden(bitmap_layer_get_layer(s_warning_img_layer), true); //layer_set_hidden(text_layer_get_layer(s_time_layer_dte), false); lastBtStateConnected = true; } else { // phone is not connected //layer_set_hidden(text_layer_get_layer(s_time_layer_dte), true); layer_set_hidden(bitmap_layer_get_layer(s_warning_img_layer), false); // if we just lost the connection or if we want to have repeated vibrations, vibe twice if (lastBtStateConnected || repeat_vib) { lastBtStateConnected = false; vibes_double_pulse(); } } }
/***Handle Window***/ static void main_window_load(Window *window) { //Get information about the window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //Use platform specific background image s_bitmap = gbitmap_create_with_resource( PBL_IF_BW_ELSE(RESOURCE_ID_IMAGE_BACKGROUND_BW, RESOURCE_ID_IMAGE_BACKGROUND_COLOR)); s_bitmap_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); //size of image bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); window_set_background_color(s_main_window, GColorBlack); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); //Add custom font s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MONACO_14)); //Time layer s_time_layer = text_layer_create(GRect(5, 30, bounds.size.w, 40)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_font(s_time_layer, s_font); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); //Battery layer s_battery_layer = text_layer_create(GRect(5, 70, bounds.size.w, 50)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorWhite); text_layer_set_font(s_battery_layer, s_font); layer_add_child(window_layer, text_layer_get_layer(s_battery_layer)); //Connection layer s_connection_layer = text_layer_create(GRect(5, 100, bounds.size.w, 20)); text_layer_set_background_color(s_connection_layer, GColorClear); text_layer_set_text_color(s_connection_layer, GColorWhite); text_layer_set_font(s_connection_layer, s_font); handle_bluetooth(connection_service_peek_pebble_app_connection()); layer_add_child(window_layer, text_layer_get_layer(s_connection_layer)); //Other text layer s_text_layer = text_layer_create(GRect(5, 125, bounds.size.w, 20)); text_layer_set_background_color(s_text_layer, GColorClear); text_layer_set_text_color(s_text_layer, GColorWhite); text_layer_set_font(s_text_layer, s_font); text_layer_set_text(s_text_layer, "root@PC:/$"); layer_add_child(window_layer, text_layer_get_layer(s_text_layer)); //Platform-specific cursor animation //Stationary cursor for Aplite #if defined (PBL_BW) s_bitmap_cursor = gbitmap_create_with_resource(RESOURCE_ID_STATIC_CURSOR); //Blinking cursor for Basalt #elif defined (PBL_COLOR) s_sequence = gbitmap_sequence_create_with_resource(RESOURCE_ID_BLINKING_CURSOR); GSize frame_size = gbitmap_sequence_get_bitmap_size(s_sequence); s_bitmap_cursor = gbitmap_create_blank(frame_size, GBitmapFormat8Bit); //Start the animation uint32_t first_delay_ms = 1000; app_timer_register(first_delay_ms, timer_handler, NULL); #endif s_bitmap_cursor_layer = bitmap_layer_create(GRect(90, 125, 10, 15)); bitmap_layer_set_compositing_mode(s_bitmap_cursor_layer, GCompOpSet); bitmap_layer_set_bitmap(s_bitmap_cursor_layer, s_bitmap_cursor); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_cursor_layer)); }
static void window_load(Window *window) { set_color_data(); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); APP_LOG(APP_LOG_LEVEL_DEBUG, "---- window_load ----"); // Config //if (persist_read_bool(KEY_CONNECTION_LOST_VIBE)) { s_connection_lost_vibe = persist_read_bool(KEY_CONNECTION_LOST_VIBE); APP_LOG(APP_LOG_LEVEL_DEBUG, "s_connection_lost_vibe %d", s_connection_lost_vibe); /// } //if (persist_read_bool(KEY_SHOW_SECONDS_HAND)) { s_show_seconds_hand = persist_read_bool(KEY_SHOW_SECONDS_HAND); APP_LOG(APP_LOG_LEVEL_DEBUG, "s_show_seconds_hand %d", s_show_seconds_hand); // } //if (persist_read_bool(KEY_COLOR_REVERSE)) { s_color_reverse = persist_read_bool(KEY_COLOR_REVERSE); APP_LOG(APP_LOG_LEVEL_DEBUG, "s_color_reverse %d", s_color_reverse); set_color_data(); //} s_simple_bg_layer = layer_create(bounds); layer_set_update_proc(s_simple_bg_layer, bg_update_proc); layer_add_child(window_layer, s_simple_bg_layer); s_date_layer = layer_create(bounds); layer_set_update_proc(s_date_layer, date_update_proc); layer_add_child(window_layer, s_date_layer); //s_day_label = text_layer_create(PBL_IF_ROUND_ELSE( // GRect(63, 114, 27, 20), // GRect(46, 114, 27, 20))); s_day_label = text_layer_create( GRect((int)(bounds.size.w / 2) + 20, bounds.size.h -98, 27,20)); text_layer_set_text(s_day_label, s_day_buffer); text_layer_set_background_color(s_day_label, s_backColor); text_layer_set_text_color(s_day_label, s_textColor); text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_18)); layer_add_child(s_date_layer, text_layer_get_layer(s_day_label)); //s_num_label = text_layer_create(PBL_IF_ROUND_ELSE( // GRect(90, 114, 18, 20), // GRect(73, 114, 18, 20))); s_num_label = text_layer_create(GRect((int)(bounds.size.w / 2) + 47, bounds.size.h -98, 18,20)); text_layer_set_text(s_num_label, s_num_buffer); text_layer_set_background_color(s_num_label, s_backColor); text_layer_set_text_color(s_num_label, s_textColor); text_layer_set_font(s_num_label, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); // BT OK/NG s_connection_layer = text_layer_create(GRect((int)(bounds.size.w / 2) - 27,114, 20, 20)); text_layer_set_text_color(s_connection_layer, s_textColor); text_layer_set_background_color(s_connection_layer, GColorClear); text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_connection_layer, GTextAlignmentLeft); handle_bluetooth(connection_service_peek_pebble_app_connection()); // Battery s_battery_layer = text_layer_create(GRect((int)(bounds.size.w / 2) , 114,40,20)); text_layer_set_text_color(s_battery_layer, s_textColor); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); text_layer_set_text(s_battery_layer, "100%"); battery_state_service_subscribe(handle_battery); connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = handle_bluetooth });
/** * Window load handler function */ static void mainWindowLoad(Window *w) { init_hardware_icons(); // Get information about the root window Layer *windowLayer = window_get_root_layer(w); GRect bounds = layer_get_bounds(windowLayer); // Set sleepy time flag time_t temp_time = time(NULL); struct tm *cur_time = localtime(&temp_time); s_is_sleepy_time = (cur_time->tm_hour <= SLEEPY_TIME_END_HOUR && cur_time->tm_hour >= SLEEPY_TIME_START_HOUR); ////////////////////////////////////////// // Battery GRect bat_icon_bounds = get_battery_icon_bounds(); // Create BitmapLayer to display the GBitmap s_powerIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + 2), 0, bat_icon_bounds.size.w, bat_icon_bounds.size.h)); // set background colout and compositing mode bitmap_layer_set_background_color(s_powerIconLayer, POWER_ICON_BACK_COLOR); bitmap_layer_set_compositing_mode(s_powerIconLayer, GCompOpSet); update_power_status(battery_state_service_peek()); // add the bitmap layer to the window layer_add_child(windowLayer, bitmap_layer_get_layer(s_powerIconLayer)); ////////////////////////////////////////// // BT connection GRect bt_icon_bounds = get_bt_icon_bounds(); // Create BitmapLayer to display the GBitmap s_btIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + bt_icon_bounds.size.w + 4), 4, bt_icon_bounds.size.w, bt_icon_bounds.size.h)); // set background colout and compositing mode bitmap_layer_set_background_color(s_btIconLayer, BT_ICON_BACK_COLOR); bitmap_layer_set_compositing_mode(s_btIconLayer, GCompOpSet); update_bt_status(connection_service_peek_pebble_app_connection()); // add the bitmap layer to the window layer_add_child(windowLayer, bitmap_layer_get_layer(s_btIconLayer)); //////////////////////////////////// // Create the time text layers // time accuracy text layer s_timeAccText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(-2, -6), 94, 28)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_timeAccText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_timeAccText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42)); GFont timeFont = fonts_get_system_font(FONT_KEY_GOTHIC_24); text_layer_set_font(s_timeAccText, timeFont); text_layer_set_text_alignment(s_timeAccText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_timeAccText)); // time text layer s_timeText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(20, 16), bounds.size.w-4, 100)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_timeText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_timeText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); update_timeish(s_timeText,s_timeAccText); //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42)); timeFont = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK); text_layer_set_font(s_timeText, timeFont); text_layer_set_text_alignment(s_timeText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_timeText)); /////////////////////////////////// // Create the date text layer s_dateText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(128, 122), bounds.size.w-4, 16)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_dateText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_dateText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); update_date(s_dateText); //s_dateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_24)); GFont dateFont = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD); text_layer_set_font(s_dateText, dateFont); text_layer_set_text_alignment(s_dateText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_dateText)); ////////////////////////////////// // Create the weather text layer s_weatherText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(112, 108), bounds.size.w-4, 18)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_weatherText, TIME_TEXT_BACK_COLOR); update_weather((Tuple *)NULL,(Tuple *)NULL, (Tuple *)NULL); GFont weatherFont = fonts_get_system_font(FONT_KEY_GOTHIC_14); text_layer_set_font(s_weatherText, weatherFont); text_layer_set_text_alignment(s_weatherText, GTextAlignmentLeft); // Set weather text colour set_weather_text_colour(); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_weatherText)); ////////////////////////////////// // Create the news text layer s_newsText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(142, 136), bounds.size.w-4, 30)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_newsText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_newsText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); display_news_weather(); text_layer_set_font(s_newsText, weatherFont); text_layer_set_text_alignment(s_newsText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_newsText)); }
static void main_window_load(Window *window) { // Get information about the Window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); APP_LOG(APP_LOG_LEVEL_INFO, "Main window loading"); APP_LOG(APP_LOG_LEVEL_INFO, "battery time"); s_battery_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(0, 20), PBL_IF_ROUND_ELSE(0, 154), PBL_IF_ROUND_ELSE(180, 104), PBL_IF_ROUND_ELSE(180, 2))); s_weather_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(117, 120), bounds.size.w, 55)); s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(52, 46), bounds.size.w, 80)); s_date_layer = PBL_IF_BW_ELSE(text_layer_create(GRect(1, 2, bounds.size.w, 50)), text_layer_create(GRect(PBL_IF_ROUND_ELSE(42, 1), PBL_IF_ROUND_ELSE(15, 1), PBL_IF_ROUND_ELSE(97, 65), 55))); s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30))); int textcolor = persist_read_int(MESSAGE_KEY_TextColor); int background = persist_read_int(MESSAGE_KEY_BackgroundColor); GColor bg_color = GColorFromHEX(background); GColor text_color = GColorFromHEX(textcolor); window_set_background_color(s_main_window, bg_color); APP_LOG(APP_LOG_LEVEL_INFO, "Text Color is: %d", textcolor); APP_LOG(APP_LOG_LEVEL_INFO, "Background Color is: %d", background); // Battery Layer layer_set_update_proc(s_battery_layer, battery_update_proc); // Add Battery Layer to Window layer_add_child(window_get_root_layer(window), s_battery_layer); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: celsius"); if (persist_read_bool(MESSAGE_KEY_Celsius)) { celsius = persist_read_int(MESSAGE_KEY_Celsius); } /* APP_LOG(APP_LOG_LEVEL_INFO, "reading key: customLocation"); if (persist_read_string(KEY_CUSTOM_LOCATION)) { customLocation = persist_read_string(KEY_CUSTOM_LOCATION); }*/ APP_LOG(APP_LOG_LEVEL_INFO, "weather time"); // Weather Layer text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, text_color); //text_layer_set_text_color(s_weather_layer, GColorBlack); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); PBL_IF_BW_ELSE(text_layer_set_text(s_weather_layer, ""), text_layer_set_text(s_weather_layer, "Loading...")); s_weather_font = PBL_IF_ROUND_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20))); text_layer_set_font(s_weather_layer, s_weather_font); // Add Weather Layer to Window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); APP_LOG(APP_LOG_LEVEL_INFO, "time layer"); // Time Layer s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_53)); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, text_color); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: invert"); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: 24h"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Add Time Layer to Window layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); APP_LOG(APP_LOG_LEVEL_INFO, "date time"); // Date Layer s_date_font = PBL_IF_BW_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17))); text_layer_set_text_color(s_date_layer, text_color); //text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_font(s_date_layer, s_date_font); APP_LOG(APP_LOG_LEVEL_INFO, "updating time"); // Add Date Layer to Window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Create the Bluetooth icon GBitmap APP_LOG(APP_LOG_LEVEL_INFO, "Reading Bluetooth color: %d", persist_read_bool(MESSAGE_KEY_Bluetooth)); if (persist_read_int(MESSAGE_KEY_Bluetooth) == 102) { s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); } else { s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON_BLACK); } // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30))); layer_set_update_proc(s_bt_icon_layer, layer_update_proc); //bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); layer_add_child(window_layer, s_bt_icon_layer); APP_LOG(APP_LOG_LEVEL_INFO, "steps time"); // Steps Layer // subscribe to health events int goal_num = persist_read_int(MESSAGE_KEY_Step_Goal); int steps = persist_read_int(MESSAGE_KEY_Goal_Color); GColor steps_color = GColorFromHEX(steps); s_num_label = text_layer_create(GRect(PBL_IF_ROUND_ELSE(67, 90), PBL_IF_ROUND_ELSE(37, 1), 50, 45)); text_layer_set_background_color(s_num_label, GColorClear); text_layer_set_text_color(s_num_label, text_color); int s_step_count = (int)health_service_sum_today(HealthMetricStepCount); if (goal_num == 0 || s_step_count < goal_num) { int textcolor = persist_read_int(MESSAGE_KEY_TextColor); GColor text_color = GColorFromHEX(textcolor); text_layer_set_text_color(s_num_label, text_color); } else { text_layer_set_text_color(s_num_label, steps_color); } //text_layer_set_text_color(s_num_label, GColorBlack); text_layer_set_text_alignment(s_num_label, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight)); text_layer_set_font(s_num_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_num_label)); if(health_service_events_subscribe(health_handler, NULL)) { // force initial steps display health_handler(HealthEventMovementUpdate, NULL); } else { APP_LOG(APP_LOG_LEVEL_ERROR, "Health not available!"); } // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); APP_LOG(APP_LOG_LEVEL_INFO, "Main window loaded"); update_time(); }
//////////////////////////////////////////////////// Main Visuals ///////////////////////////// static void main_window_load(Window *window) { window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorBlack); time_color = GColorFromRGB(0, 170, 255); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // position battery and bluetooth icons depending on screen #ifdef PBL_ROUND int topright = bounds.size.w / 2; #else int topright = bounds.size.w - (bounds.size.w / 4); #endif // Create GFonts s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_Prototype_42)); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_Prototype_20)); // Create TIME TextLayer and set colour s_time_layer = text_layer_create(GRect(0, 40, bounds.size.w, bounds.size.h)); text_layer_set_background_color(s_time_layer, GColorClear); // Read saved config #if defined(PBL_BW) text_layer_set_text_color(s_time_layer, GColorWhite); #elif defined(PBL_COLOR) // Use background color setting red = persist_read_int(KEY_COLOR_RED); green = persist_read_int(KEY_COLOR_GREEN); blue = persist_read_int(KEY_COLOR_BLUE); time_color = GColorFromRGB(red, green, blue); text_layer_set_text_color(s_time_layer, time_color); #endif text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); // Create DATE TextLayer s_date_layer = text_layer_create(GRect(0, 115, bounds.size.w, bounds.size.h)); text_layer_set_text_color(s_date_layer, GColorFromHEX(0xFFFFFF)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_text(s_date_layer, "Sept 23"); text_layer_set_font(s_date_layer, s_date_font); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Create Divider GRect line_frame = GRect(20, 104, bounds.size.w -40, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, draw_line); layer_add_child(window_layer, line_layer); // Create the BitmapLayer to display the Bluetooth icon s_bt_icon_layer = bitmap_layer_create(GRect(topright - 12, bounds.origin.x + 10, 11, 10)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer)); // Create the BitmapLayer to display the Battery s_batt_icon_layer = bitmap_layer_create(GRect(topright + 5, bounds.origin.x + 10, 16, 10)); bitmap_layer_set_bitmap(s_batt_icon_layer, s_batt_icon_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_batt_icon_layer)); // Initialize the display update_time(); battery_callback(battery_state_service_peek()); bluetooth_callback(connection_service_peek_pebble_app_connection()); }
static void update_proc(Layer *layer, GContext *ctx) { // Custom drawing happens here! GRect bounds = layer_get_bounds(layer); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, 0); if(center){ return; } BatteryChargeState state = battery_state_service_peek(); char batteryT[5]; snprintf(batteryT, sizeof(batteryT), "%d%%", state.charge_percent); GSize size1 = graphics_text_layout_get_content_size(batteryT, fonts_get_system_font(FONT_KEY_GOTHIC_24), bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight); GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18); #ifdef PBL_COLOR graphics_context_set_text_color(ctx, state.charge_percent>20 ? GColorGreen : GColorRed); #else graphics_context_set_fill_color(ctx, GColorWhite); #endif graphics_draw_text(ctx, batteryT, font, GRect(bounds.size.w - BATT_PADING - size1.w, bounds.size.h/2-size1.h/2, size1.w, size1.h), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL); #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorGreen : GColorRed); #else graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorWhite : GColorBlack); #endif graphics_fill_circle(ctx, GPoint(bounds.size.w - CONNECTED_CIR_PADING - CONNECTED_CIR_RADIUS * PBL_IF_ROUND_ELSE(3, 1), PBL_IF_RECT_ELSE(CONNECTED_CIR_PADING + CONNECTED_CIR_RADIUS, bounds.size.h/2-size1.h/2-CONNECTED_CIR_RADIUS-CONNECTED_CIR_PADING)), CONNECTED_CIR_RADIUS); HealthValue steps = health_service_sum_today(HealthMetricStepCount); char steps_string[10]; if(steps >= 1000){ snprintf(steps_string, sizeof(steps_string), "%d.%dK", (int)steps/1000, (int)((float)(steps-(steps/1000)*1000)/100)); }else{ snprintf(steps_string, sizeof(steps_string), "%d", (int)steps); } GSize size2 = graphics_text_layout_get_content_size(steps_string, fonts_get_system_font(FONT_KEY_GOTHIC_24), bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight); graphics_context_set_text_color(ctx, GColorGreen); graphics_draw_text(ctx, steps_string, font, GRect(bounds.size.w - HEALTH_PADING * PBL_IF_ROUND_ELSE(3, 1) - size2.w, PBL_IF_RECT_ELSE(bounds.size.h-size2.h-HEALTH_PADING, bounds.size.h/2+HEALTH_PADING), size2.w, size2.h), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL); }