void handle_init(void) { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); text_date_layer = text_layer_create(GRect(8, 68, 144-8, 168-68)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); text_time_layer = text_layer_create(GRect(7, 92, 144-7, 168-92)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_font(text_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); GRect line_frame = GRect(8, 97, 139, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_layer, line_layer); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); handle_minute_tick(NULL, MINUTE_UNIT); }
void handle_init(void) { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); text_date_layer = text_layer_create(GRect(8, 68, 144-8, 168-68)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21))); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); text_time_layer = text_layer_create(GRect(7, 92, 144-7, 168-92)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49))); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); GRect line_frame = GRect(8, 97, 139, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_layer, line_layer); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) 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); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Hebrew Text"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); // If you neglect to call this, all `resource_get_handle()` requests // will return NULL. resource_init_current_app(&RESOURCES); font42 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SIMPLE_42)); font36 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SIMPLE_36)); font28 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SIMPLE_28)); text_layer_init(&timeLayer, GRect(0, 0, window.layer.frame.size.w, window.layer.frame.size.h)); text_layer_set_text_color(&timeLayer, GColorWhite); text_layer_set_text_alignment(&timeLayer, GTextAlignmentRight); text_layer_set_background_color(&timeLayer, GColorClear); handle_minute_tick(ctx, NULL); layer_add_child(&window.layer, &timeLayer.layer); }
void handle_init(AppContextRef ctx) { srand(time(NULL));//seed randmoness! window_init(&window, "Window Name"); window_stack_push(&window, true /* Animated */); text_layer_init(&dateLayer, GRect(0, 0, 144, 50)); text_layer_set_text_alignment(&dateLayer, GTextAlignmentCenter); text_layer_set_font(&dateLayer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); text_layer_set_background_color(&dateLayer, GColorBlack); text_layer_set_text_color(&dateLayer, GColorWhite); text_layer_set_overflow_mode(&dateLayer, GTextOverflowModeWordWrap); layer_add_child(&window.layer, &dateLayer.layer); text_layer_init(&busLayer, GRect(0, 93, 144, 75)); text_layer_set_text_alignment(&busLayer, GTextAlignmentCenter); text_layer_set_font(&busLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(&busLayer, GColorBlack); text_layer_set_text_color(&busLayer, GColorWhite); text_layer_set_overflow_mode(&busLayer, GTextOverflowModeWordWrap); layer_add_child(&window.layer, &busLayer.layer); // Init the layer for the display layer_init(&display_layer, window.layer.frame); display_layer.update_proc = &display_layer_update_callback; layer_add_child(&window.layer, &display_layer); adjX = ((int) ( (144-((bitRect.size.w+BIT_SPACING)*ROW_WIDTH))/2)) -2;//change the -2 if needed adjY = ((int) ( ((168-YSTART)-((bitRect.size.h+BIT_SPACING)*COL_HEIGHT) )/2)) - YSHORT/2; handle_minute_tick(ctx, NULL); }
void handle_init(void) { load_config(); srand((uint32_t) time(NULL)); window = window_create(); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); text_layer = text_layer_create(GRect(0, -2, 144, 168)); text_layer_set_background_color(text_layer, GColorClear); text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_layer, text_layer_get_layer(text_layer)); update_colors(); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); handle_minute_tick(NULL, MINUTE_UNIT); app_message_register_inbox_received(in_received_handler); const uint32_t inbound_size = 64; const uint32_t outbound_size = 64; app_message_open(inbound_size, outbound_size); }
void handle_init(void) { // Create the window window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); ////Text Layers //Hour Layer text_hour_layer = text_layer_create(GRect(0, 25, 90, 168-25)); text_layer_set_text_color(text_hour_layer, GColorWhite); text_layer_set_background_color(text_hour_layer, GColorClear); text_layer_set_text_alignment(text_hour_layer, GTextAlignmentRight); text_layer_set_font(text_hour_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_REGULAR_60))); layer_add_child(window_layer, text_layer_get_layer(text_hour_layer)); //Minutes Layer text_min_layer = text_layer_create(GRect(90, 20, 144-90, 168-20)); text_layer_set_text_color(text_min_layer, GColorWhite); text_layer_set_background_color(text_min_layer, GColorClear); text_layer_set_text_alignment(text_min_layer, GTextAlignmentCenter); text_layer_set_font(text_min_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_LIGHT_43))); layer_add_child(window_layer, text_layer_get_layer(text_min_layer)); //Day of week text_day_layer = text_layer_create(GRect(0, 110, 144, 168-110)); text_layer_set_text_color(text_day_layer, GColorWhite); text_layer_set_background_color(text_day_layer, GColorClear); text_layer_set_text_alignment(text_day_layer, GTextAlignmentCenter); text_layer_set_font(text_day_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_LIGHT_18))); layer_add_child(window_layer, text_layer_get_layer(text_day_layer)); GRect line_frame = GRect(8, 135, 144-16, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_layer, line_layer); //Date Layer text_date_layer = text_layer_create(GRect(0, 140, 144, 168-140)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter); text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_LIGHT_18))); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); // Avoids a blank screen on watch start. time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_minute_tick(tick_time, MINUTE_UNIT); }
void init(void) { int i; static struct tm* now; time_t unix_now; window = window_create(); for(i = 0; i < 12; i++) { bs[i] = gbitmap_create_with_resource(bsh[i]); } bcolon = bs[10]; bdash = bs[11]; #if(DATE) bl[0] = bitmap_layer_create(GRect(0,(168/2)-56,30,51)); bl[1] = bitmap_layer_create(GRect(35,(168/2)-56,30,51)); bl[2] = bitmap_layer_create(GRect(67,(168/2)-56,9,51)); bl[3] = bitmap_layer_create(GRect(79,(168/2)-56,30,51)); bl[4] = bitmap_layer_create(GRect(114,(168/2)-56,30,51)); bl[5] = bitmap_layer_create(GRect(0,(168/2)+5,30,51)); bl[6] = bitmap_layer_create(GRect(35,(168/2)+5,30,51)); bl[7] = bitmap_layer_create(GRect(67,(168/2)+5,9,51)); bl[8] = bitmap_layer_create(GRect(79,(168/2)+5,30,51)); bl[9] = bitmap_layer_create(GRect(114,(168/2)+5,30,51)); for(i = 0; i < 10; i++) layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bl[i])); #else bl[0] = bitmap_layer_create(GRect(0,(168/2)-25,30,51)); bl[1] = bitmap_layer_create(GRect(35,(168/2)-25,30,51)); bl[2] = bitmap_layer_create(GRect(67,(168/2)-25,9,51)); bl[3] = bitmap_layer_create(GRect(79,(168/2)-25,30,51)); bl[4] = bitmap_layer_create(GRect(114,(168/2)-25,30,51)); for(i = 0; i < 5; i++) layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bl[i])); #endif window_set_background_color(window, GColorBlack); bitmap_layer_set_bitmap(bl[2], bcolon); #if(DATE) bitmap_layer_set_bitmap(bl[7], bdash); #endif tick_timer_service_subscribe(SECOND_UNIT, &handle_minute_tick); unix_now = time(NULL); now = localtime(&unix_now); handle_minute_tick(now, SECOND_UNIT); window_stack_push(window, true); }
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 });
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Window Name"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorWhite); //resource_init_current_app(&APP_RESOURCES); // Init the text layer used to show the weeks text_layer_init(&weekLayer, GRect(80, 0, 144-20 /* width */, 168-54 /* height */)); text_layer_set_text_color(&weekLayer, GColorBlack); text_layer_set_background_color(&weekLayer, GColorClear); text_layer_set_font(&weekLayer, fonts_get_system_font(FONT_KEY_GOTHAM_34_MEDIUM_NUMBERS)); // Init the text layer used to show the wife text_layer_init(&wifeLayer, GRect(5, 10, 144-20 /* width */, 168-54 /* height */)); text_layer_set_text_color(&wifeLayer, GColorBlack); text_layer_set_background_color(&wifeLayer, GColorClear); text_layer_set_font(&wifeLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Init the text layer used to show the baby text_layer_init(&papaLayer, GRect(0, 70, 144 /* width */, 168-54 /* height */)); text_layer_set_text_color(&papaLayer, GColorWhite); text_layer_set_background_color(&papaLayer, GColorBlack); text_layer_set_font(&papaLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(&papaLayer, GTextAlignmentCenter); // Init the text layer used to show the comparison text_layer_init(&compLayer, GRect(0, 97, 144 /* width */, 168-54 /* height */)); text_layer_set_text_color(&compLayer, GColorWhite); text_layer_set_background_color(&compLayer, GColorBlack); text_layer_set_font(&compLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(&compLayer, GTextAlignmentCenter); // Init the text layer used to show the fruit text_layer_init(&fruitLayer, GRect(0, 125, 144 /* width */, 168-54 /* height */)); text_layer_set_text_color(&fruitLayer, GColorWhite); text_layer_set_background_color(&fruitLayer, GColorBlack); text_layer_set_font(&fruitLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(&fruitLayer, GTextAlignmentCenter); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) handle_minute_tick(ctx, NULL); layer_add_child(&window.layer, &wifeLayer.layer); layer_add_child(&window.layer, &weekLayer.layer); layer_add_child(&window.layer, &papaLayer.layer); layer_add_child(&window.layer, &compLayer.layer); layer_add_child(&window.layer, &fruitLayer.layer); }
static void window_appear(Window *window){ tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); handle_minute_tick(NULL, MINUTE_UNIT); bool running = app_worker_is_running(); if (running) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Worker Running do nothing"); //result= app_worker_kill(); } else { APP_LOG(APP_LOG_LEVEL_DEBUG, "Worker stopped"); app_worker_launch(); } }
static void cb_in_received_handler(DictionaryIterator *iter, void *context) { autoconfig_in_received_handler(iter, context); Tuple *code_tuple = dict_find(iter, WEATHERCODE_KEY); if(code_tuple){ int32_t weather_code = code_tuple->value->int32; APP_LOG(APP_LOG_LEVEL_DEBUG, "code:%ld", weather_code); if(weather_code != 3200){ Tuple *temp_tuple = dict_find(iter, TEMPERATURE_KEY); if (temp_tuple) { int32_t temperature = temp_tuple->value->int32; // temperature = -99; snprintf(temp_text, sizeof(temp_text), "%ld°", temperature); layer_mark_dirty(text_layer_get_layer(text_temp_layer)); } Tuple *city_tuple = dict_find(iter, CITYNAME_KEY); if (city_tuple) { snprintf(city_text, sizeof(city_text), "%s", city_tuple->value->cstring); layer_mark_dirty(text_layer_get_layer(text_city_layer)); } // weather_code = 28; if(weather_code > 47){ weather_code = 0; } } else { weather_code = 0; } if(weather_image){ gbitmap_destroy(weather_image); } weather_image = gbitmap_create_with_resource(WEATHER_IMAGE_RESOURCE[weather_code]); bitmap_layer_set_bitmap(weather_layer, weather_image); } if(dict_find(iter, INTERVAL_PKEY)){ app_timer_cancel(weather_timer); weather_timer = app_timer_register(getInterval() * 1000 /* milliseconds */, timer_callback, NULL); } if(dict_find(iter, LANGUAGE_PKEY)){ time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_minute_tick(tick_time, MINUTE_UNIT); } }
void init() { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); app_message_register_inbox_received(in_received_handler); const int inbound_size = 64; const int outbound_size = 64; app_message_open(inbound_size, outbound_size); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); layer = layer_create(bounds); layer_add_child(window_layer, layer); icon_layer = bitmap_layer_create(ICON_FRAME); layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer)); time_layer = text_layer_create(TIME_FRAME); text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_PRO_49))); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(time_layer)); date_layer = text_layer_create(DATE_FRAME); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_PRO_23))); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(date_layer)); temperature_layer = text_layer_create(TEMPERATURE_FRAME); text_layer_set_font(temperature_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_PRO_35))); text_layer_set_text_color(temperature_layer, GColorWhite); text_layer_set_background_color(temperature_layer, GColorClear); text_layer_set_text(temperature_layer, "--"); layer_add_child(window_layer, text_layer_get_layer(temperature_layer)); 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); }
static void app_init(AppContextRef c) { s_data.current_icon = 0; resource_init_current_app(&WEATHER_APP_RESOURCES); Window* window = &s_data.window; window_init(window, "PebbleWeather"); window_set_background_color(window, GColorBlack); window_set_fullscreen(window, true); // Weather icon layer GRect icon_rect = (GRect) {(GPoint) {32, 10}, (GSize) { 80, 80 }}; bitmap_layer_init(&s_data.icon_layer, icon_rect); layer_add_child(&window->layer, &s_data.icon_layer.layer); // Temperature text layer text_layer_init(&s_data.temperature_layer, GRect(0, 100, 144, 34)); text_layer_set_text_color(&s_data.temperature_layer, GColorWhite); text_layer_set_background_color(&s_data.temperature_layer, GColorClear); text_layer_set_font(&s_data.temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(&s_data.temperature_layer, GTextAlignmentCenter); layer_add_child(&window->layer, &s_data.temperature_layer.layer); // Time text layer text_layer_init(&s_data.time_layer, GRect(0, 134, 144, 34)); text_layer_set_text_color(&s_data.time_layer, GColorWhite); text_layer_set_background_color(&s_data.time_layer, GColorClear); text_layer_set_font(&s_data.time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(&s_data.time_layer, GTextAlignmentCenter); handle_minute_tick(c, NULL); layer_add_child(&window->layer, &s_data.time_layer.layer); // Watch <--> Phone communication Tuplet initial_values[] = { TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1), TupletCString(WEATHER_TEMPERATURE_KEY, "-\u00B0C"), }; app_sync_init(&s_data.sync, s_data.sync_buffer, sizeof(s_data.sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL); request_weather_update(); window_stack_push(window, true); }
int main(void) { autoconfig_init(); app_message_register_inbox_received(in_received_handler); center = GPoint(72, 74); window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); layer = layer_create(bounds); layer_set_update_proc(layer, update_layer_callback); layer_add_child(window_layer, layer); inverter_layer = inverter_layer_create(bounds); layer_set_hidden(inverter_layer_get_layer(inverter_layer), !getInverted()); layer_add_child(window_layer, inverter_layer_get_layer(inverter_layer)); custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UNSTEADY_OVERSTEER_22)); image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PATTERN); time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_minute_tick(tick_time, MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); bluetooth_connection_service_subscribe(bluetooth_connection_handler); bluetooth_connected = bluetooth_connection_service_peek(); app_event_loop(); layer_destroy(layer); inverter_layer_destroy(inverter_layer); window_destroy(window); gbitmap_destroy(image); fonts_unload_custom_font(custom_font); tick_timer_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); autoconfig_deinit(); }
void handle_init(void) { int i; window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); text_time_layer = text_layer_create(GRect(7, 0, 144-14, 33)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_text_alignment(text_time_layer, GTextAlignmentRight); text_layer_set_font(text_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS)); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); text_date_layer = text_layer_create(GRect(9, 33, 144-18, 34)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_text_alignment(text_date_layer, GTextAlignmentRight); text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); GRect line_frame = GRect(0, 67, 144, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_layer, line_layer); for (i = 0; i < PROGRAM_LAYERS; i++) { text_program_layers[i] = text_layer_create(GRect(34, 70 + i*32, 110, 32)); text_layer_set_text_color(text_program_layers[i], GColorWhite); text_layer_set_background_color(text_program_layers[i], GColorClear); text_layer_set_font(text_program_layers[i], fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_layer, text_layer_get_layer(text_program_layers[i])); text_start_layers[i] = text_layer_create(GRect(0, 70 + i*32, 34, 16)); text_layer_set_text_color(text_start_layers[i], GColorWhite); text_layer_set_background_color(text_start_layers[i], GColorClear); text_layer_set_font(text_start_layers[i], fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_layer, text_layer_get_layer(text_start_layers[i])); } tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); handle_minute_tick(NULL, MINUTE_UNIT); }
void handle_init(AppContextRef ctx) { (void)ctx; PblTm currentTime; unsigned int unixTime; resource_init_current_app(&APP_RESOURCES); get_time(¤tTime); unixTime = GetUnixTime(¤tTime); SetRandomSeed(unixTime); InitializeExitConfirmationWindow(); handle_minute_tick(ctx, NULL); ResetGame(); ShowAdventureWindow(); }
/* Initialize the application. */ void handle_init(AppContextRef ctx) { PblTm tm; PebbleTickEvent t; ResHandle res_d; ResHandle res_h; ResHandle res_m; window_init(&window, "Futura Time"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); res_d = resource_get_handle(RESOURCE_ID_FUTURA_18); res_h = resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53); font_date = fonts_load_custom_font(res_d); font_hour = fonts_load_custom_font(res_h); font_minute = fonts_load_custom_font(res_h); time_layer_init(&time_layer, window.layer.frame); time_layer_set_text_color(&time_layer, GColorWhite); time_layer_set_background_color(&time_layer, GColorClear); time_layer_set_fonts(&time_layer, font_hour, font_minute); layer_set_frame(&time_layer.layer, TIME_FRAME); layer_add_child(&window.layer, &time_layer.layer); text_layer_init(&date_layer, window.layer.frame); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, font_date); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); layer_set_frame(&date_layer.layer, DATE_FRAME); layer_add_child(&window.layer, &date_layer.layer); // Refresh time get_time(&tm); t.tick_time = &tm; t.units_changed = SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT; handle_minute_tick(ctx, &t); }
// Handle the start-up of the app void handle_init_app(AppContextRef app_ctx) { // Create our app's base window window_init(&window, "RumbleTime"); window_stack_push(&window, true); window_set_background_color(&window, GColorBlack); // Init the text layer used to show the time // TODO: Wrap this boilerplate in a function? text_layer_init(&timeLayer, GRect(40, 54, 144-40 /* width */, 168-54 /* height */)); text_layer_set_text_color(&timeLayer, GColorWhite); text_layer_set_background_color(&timeLayer, GColorClear); text_layer_set_font(&timeLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) handle_minute_tick(app_ctx, NULL); layer_add_child(&window.layer, &timeLayer.layer); }
static void select_click_handler(ClickRecognizerRef recognizer, void *context) { if (mode_clock) // was clock - now get and display text { mode_clock = 0; // toggle to text options[TEXT_SELECTED] = persist_read_int(TEXT_SELECTED); text_select = options[TEXT_SELECTED]; // get stored mode swap_to_oclock(); } else // was displaying text - save choice then display clock { mode_clock = 1; // toggle back to clock options[TEXT_SELECTED] = text_select; // set stored mode persist_write_int(TEXT_SELECTED, options[TEXT_SELECTED]); time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_minute_tick(current_time, SECOND_UNIT); } }
void handle_init() { INFO_LOG("Starting MiniDungeon"); time_t now = time(NULL); srand(now); DEBUG_LOG("Srand"); handle_minute_tick(NULL, MINUTE_UNIT); DEBUG_LOG("First handle second"); InitializeGameData(); #if ALLOW_WORKER_APP app_worker_message_subscribe(WorkerMessageHandler); AppAwake(); #endif DEBUG_LOG("InitializeGameData"); ShowAdventureWindow(); tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick); app_focus_service_subscribe(focus_handler); }
// Handle the start-up of the app static void init(void) { // Create our app's base window window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorBlack); // Init the text layer used to show the time // TODO: Wrap this boilerplate in a function? timeLayer = text_layer_create(GRect(40, 54, 144-40 /* width */, 168-54 /* height */)); text_layer_set_text_color(timeLayer, GColorWhite); text_layer_set_background_color(timeLayer, GColorClear); text_layer_set_font(timeLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) handle_minute_tick(NULL, 0); layer_add_child(window_get_root_layer(window), text_layer_get_layer(timeLayer)); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); }
/* Initialize the application. */ void app_init(void) { const int inbound_size = 64; const int outbound_size = 64; app_message_open(inbound_size, outbound_size); // restore values from persistent storage in case the phone isn't around sunrise_time = persist_exists(SUNRISE_STORAGE_KEY) ? persist_read_int(SUNRISE_STORAGE_KEY) : DEFAULT_SUN_TIME; sunset_time = persist_exists(SUNSET_STORAGE_KEY) ? persist_read_int(SUNSET_STORAGE_KEY) : DEFAULT_SUN_TIME; Tuplet initial_values[] = { TupletInteger(SUNRISE_TIME_KEY, sunrise_time), TupletInteger(SUNSET_TIME_KEY, sunset_time), }; app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL); // get sunrise/set times from the phone send_cmd(); time_t t = time(NULL); struct tm *tick_time = localtime(&t); TimeUnits units_changed = SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT; ResHandle res_d; ResHandle res_t; Layer *window_layer; window = window_create(); window_layer = window_get_root_layer(window); window_set_background_color(window, GColorBlack); res_d = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21); res_t = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49); font_date = fonts_load_custom_font(res_d); font_time = fonts_load_custom_font(res_t); text_day_layer = text_layer_create(GRect(8, 44 + MOVE_AMOUNT, 144-8, 168-44- MOVE_AMOUNT)); text_layer_set_text_color(text_day_layer, GColorWhite); text_layer_set_background_color(text_day_layer, GColorClear); text_layer_set_font(text_day_layer, font_date); layer_add_child(window_layer, text_layer_get_layer(text_day_layer)); text_date_layer = text_layer_create(GRect(8, 68 + MOVE_AMOUNT, 144-8, 168-68- MOVE_AMOUNT)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_font(text_date_layer, font_date); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); text_time_layer = text_layer_create(GRect(7, 92 + MOVE_AMOUNT, 144-7, 168-92- MOVE_AMOUNT)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_font(text_time_layer, font_time); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); text_sun_layer = text_layer_create(GRect(80, 138, 144-45, 168-80)); text_layer_set_text_color(text_sun_layer, GColorWhite); text_layer_set_background_color(text_sun_layer, GColorClear); text_layer_set_font(text_sun_layer, font_date); layer_add_child(window_layer, text_layer_get_layer(text_sun_layer)); line_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_layer, line_layer); handle_minute_tick(tick_time, units_changed); update_sun_time(tick_time); window_stack_push(window, true /* Animated */); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); }
static void window_load(Window* window) { Layer* window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); // img_morning = gbitmap_create_with_resource(RESOURCE_ID_MORNING); img_noon = gbitmap_create_with_resource(RESOURCE_ID_NOON); img_night = gbitmap_create_with_resource(RESOURCE_ID_NIGHT); period_layer = bitmap_layer_create(GRect(0, 0, img_morning->bounds.size.w, img_morning->bounds.size.h)); layer_add_child(window_layer, bitmap_layer_get_layer(period_layer)); // img_hr_numbers[0] = gbitmap_create_with_resource(RESOURCE_ID_N0_BIG); img_hr_numbers[1] = gbitmap_create_with_resource(RESOURCE_ID_N1_BIG); img_hr_numbers[2] = gbitmap_create_with_resource(RESOURCE_ID_N2_BIG); img_hr_numbers[3] = gbitmap_create_with_resource(RESOURCE_ID_N3_BIG); img_hr_numbers[4] = gbitmap_create_with_resource(RESOURCE_ID_N4_BIG); img_hr_numbers[5] = gbitmap_create_with_resource(RESOURCE_ID_N5_BIG); img_hr_numbers[6] = gbitmap_create_with_resource(RESOURCE_ID_N6_BIG); img_hr_numbers[7] = gbitmap_create_with_resource(RESOURCE_ID_N7_BIG); img_hr_numbers[8] = gbitmap_create_with_resource(RESOURCE_ID_N8_BIG); img_hr_numbers[9] = gbitmap_create_with_resource(RESOURCE_ID_N9_BIG); img_hr_numbers[10] = gbitmap_create_with_resource(RESOURCE_ID_N10_BIG); img_hr = gbitmap_create_with_resource(RESOURCE_ID_HR_BIG); hr_layer = bitmap_layer_create(GRect(0, 0, BIG_W, BIG_H)); bitmap_layer_set_bitmap(hr_layer, img_hr); layer_add_child(window_layer, bitmap_layer_get_layer(hr_layer)); // img_min_prefix = gbitmap_create_with_resource(RESOURCE_ID_NUMBER_SMALL); min_prefix_layer = bitmap_layer_create(GRect(0, bounds.size.h - SMALL_H, SMALL_W, SMALL_H)); bitmap_layer_set_bitmap(min_prefix_layer, img_min_prefix); layer_add_child(window_layer, bitmap_layer_get_layer(min_prefix_layer)); img_min_numbers[0] = gbitmap_create_with_resource(RESOURCE_ID_N0_SMALL); img_min_numbers[1] = gbitmap_create_with_resource(RESOURCE_ID_N1_SMALL); img_min_numbers[2] = gbitmap_create_with_resource(RESOURCE_ID_N2_SMALL); img_min_numbers[3] = gbitmap_create_with_resource(RESOURCE_ID_N3_SMALL); img_min_numbers[4] = gbitmap_create_with_resource(RESOURCE_ID_N4_SMALL); img_min_numbers[5] = gbitmap_create_with_resource(RESOURCE_ID_N5_SMALL); img_min_numbers[6] = gbitmap_create_with_resource(RESOURCE_ID_N6_SMALL); img_min_numbers[7] = gbitmap_create_with_resource(RESOURCE_ID_N7_SMALL); img_min_numbers[8] = gbitmap_create_with_resource(RESOURCE_ID_N8_SMALL); img_min_numbers[9] = gbitmap_create_with_resource(RESOURCE_ID_N9_SMALL); img_min_numbers[10] = gbitmap_create_with_resource(RESOURCE_ID_N10_SMALL); img_min = gbitmap_create_with_resource(RESOURCE_ID_MIN_SMALL); min_layer = bitmap_layer_create(GRect(0, 0, SMALL_W, SMALL_H)); bitmap_layer_set_bitmap(min_layer, img_min); layer_add_child(window_layer, bitmap_layer_get_layer(min_layer)); for (int i = 0; i < 3; ++i) { hr_digits[i] = bitmap_layer_create(GRect(0, 0, BIG_W, BIG_H)); layer_add_child(window_layer, bitmap_layer_get_layer(hr_digits[i])); min_digits[i] = bitmap_layer_create(GRect(0, 0, SMALL_W, SMALL_H)); layer_add_child(window_layer, bitmap_layer_get_layer(min_digits[i])); } // Ensures time is displayed immediately time_t timestamp = time(NULL); struct tm *time = localtime(×tamp); handle_minute_tick(time, MINUTE_UNIT); }
// Watchface initialization static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); // Set Background color to Black (For testing only) window_set_background_color(window, GColorBlack); // Initialize Globals mincount = 0; use_uq_weather = true; batt_img = gbitmap_create_with_resource(RESOURCE_ID_BATT_100); cond_img = gbitmap_create_with_resource(RESOURCE_ID_COND_LOADING); GRect bounds = layer_get_bounds(window_layer); // For debugging static char boundtext[20]; snprintf(boundtext, 20, "w=%d, h=%d\ntest", bounds.size.w, bounds.size.h); // Build the time layer time_layer = text_layer_create(GRect(0, -10, 122, 50)); text_layer_set_text(time_layer, "TIME"); //text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_44))); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(time_layer)); // Build the ampm layer ampm_layer = text_layer_create(GRect(122, -4, 22, 44)); text_layer_set_font(ampm_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_20))); text_layer_set_text(ampm_layer, "A\nM"); text_layer_set_text_alignment(ampm_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(ampm_layer)); // Build the date layer date_layer = text_layer_create(GRect(0, 42, 144, 27)); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_20))); text_layer_set_text(date_layer, "Date"); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(date_layer)); // Build the weather icon layer icon_layer = bitmap_layer_create(GRect(0, 73, 40, 40)); bitmap_layer_set_background_color(icon_layer, GColorBlack); layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer)); // Build the temp layer temp_layer = text_layer_create(GRect(42, 71, 76, 43)); text_layer_set_background_color(temp_layer, GColorClear); text_layer_set_text_color(temp_layer, GColorWhite); text_layer_set_font(temp_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_32))); text_layer_set_text(temp_layer, "..."); text_layer_set_text_alignment(temp_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(temp_layer)); // Build the battery layer batt_layer = bitmap_layer_create(GRect(120, 73, 24, 40)); bitmap_layer_set_background_color(batt_layer, GColorBlack); layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer)); // Build the bitcoin price layer btc_layer = text_layer_create(GRect(0, 118, 144, 24)); text_layer_set_font(btc_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_18))); text_layer_set_text(btc_layer, "Loading..."); text_layer_set_text_alignment(btc_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(btc_layer)); // Build the fitbit layer fitbit_layer = text_layer_create(GRect(0, 144, 144, 24)); text_layer_set_font(fitbit_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_16))); text_layer_set_text(fitbit_layer, "Loading..."); text_layer_set_text_alignment(fitbit_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(fitbit_layer)); // Verify persistent storage for BTC daily value is setup check_bitcoin_persist(); // Setup AppMessage app_message_init(); // Subscribe to the minute tick tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); // Force initial tick to inialize values time_t then = time(NULL); struct tm *now = localtime(&then); handle_minute_tick(now, SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT | MONTH_UNIT | YEAR_UNIT); // Subscribed to battery change events battery_state_service_subscribe(handle_battery); // Force initial battery check handle_battery(battery_state_service_peek()); // Subscribe to bluetooth change events bluetooth_connection_service_subscribe(handle_bluetooth); // Force initial bluetooth state check handle_bluetooth(bluetooth_connection_service_peek()); /* // Build the debugging text layer text_layer = text_layer_create(GRect(2, 54, 140, 80)); text_layer_set_background_color(text_layer, GColorBlack); text_layer_set_text_color(text_layer, GColorWhite); text_layer_set_text(text_layer, boundtext); text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer)); */ }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Almanac"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); font_moon = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MOON_PHASES_SUBSET_30)); font_roboto = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)); text_layer_init(&timeLayer, GRect(0, 40, 144 /* width */, 168-40 /* height */)); text_layer_set_text_color(&timeLayer, GColorWhite); text_layer_set_background_color(&timeLayer, GColorClear); text_layer_set_font(&timeLayer, font_roboto); text_layer_set_text_alignment(&timeLayer, GTextAlignmentCenter); text_layer_init(&dateLayer, GRect(0, 0, 144 /* width */, 168 /* height */)); text_layer_set_text_color(&dateLayer, GColorWhite); text_layer_set_background_color(&dateLayer, GColorClear); text_layer_set_font(&dateLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(&dateLayer, GTextAlignmentCenter); text_layer_init(&location, GRect(0, 30, 144 /* width */, 168-30 /* height */)); text_layer_set_text_color(&location, GColorWhite); text_layer_set_background_color(&location, GColorClear); text_layer_set_font(&location, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(&location, GTextAlignmentCenter); text_layer_init(&riseLayer, GRect(0, 148, 144 /* width */, 168-148 /* height */)); text_layer_set_text_color(&riseLayer, GColorWhite); text_layer_set_background_color(&riseLayer, GColorClear); text_layer_set_font(&riseLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(&riseLayer, GTextAlignmentLeft); text_layer_init(&setLayer, GRect(0, 148, 144 /* width */, 168-148 /* height */)); text_layer_set_text_color(&setLayer, GColorWhite); text_layer_set_background_color(&setLayer, GColorClear); text_layer_set_font(&setLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(&setLayer, GTextAlignmentRight); text_layer_init(&moonLayer, GRect(0, 108, 144 /* width */, 168-108 /* height */)); text_layer_set_text_color(&moonLayer, GColorWhite); text_layer_set_background_color(&moonLayer, GColorClear); text_layer_set_font(&moonLayer, font_moon); text_layer_set_text_alignment(&moonLayer, GTextAlignmentCenter); text_layer_init(&moonPercent, GRect(0, 135, 144 /* width */, 168-135 /* height */)); text_layer_set_text_color(&moonPercent, GColorWhite); text_layer_set_background_color(&moonPercent, GColorClear); text_layer_set_font(&moonPercent, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(&moonPercent, GTextAlignmentCenter); text_layer_init(&moonLeft, GRect(0, 102, 50, 168-102 /* height */)); text_layer_set_text_color(&moonLeft, GColorWhite); text_layer_set_background_color(&moonLeft, GColorClear); text_layer_set_font(&moonLeft, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(&moonLeft, GTextAlignmentRight); text_layer_init(&moonRight, GRect(94, 102, 144-94, 168-102 /* height */)); text_layer_set_text_color(&moonRight, GColorWhite); text_layer_set_background_color(&moonRight, GColorClear); text_layer_set_font(&moonRight, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(&moonRight, GTextAlignmentLeft); handle_day(ctx, NULL); handle_minute_tick(ctx, NULL); text_layer_set_text(&location, LOC); layer_add_child(&window.layer, &timeLayer.layer); layer_add_child(&window.layer, &dateLayer.layer); layer_add_child(&window.layer, &riseLayer.layer); layer_add_child(&window.layer, &setLayer.layer); layer_add_child(&window.layer, &moonLayer.layer); layer_add_child(&window.layer, &moonLeft.layer); layer_add_child(&window.layer, &moonRight.layer); layer_add_child(&window.layer, &moonPercent.layer); layer_add_child(&window.layer, &location.layer); }
static void force_update(void) { last_index = -1; struct tm *local_now = get_time(); handle_minute_tick(local_now, 0); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); top_layer = layer_create(bounds); layer_set_update_proc(top_layer, update_top_callback); layer_add_child(window_layer, top_layer); weather_image = gbitmap_create_with_resource(WEATHER_IMAGE_RESOURCE[0]); weather_layer = bitmap_layer_create(GRect(0, 93, 72, 50)); bitmap_layer_set_bitmap(weather_layer, battery_image); bitmap_layer_set_alignment(weather_layer, GAlignCenter); bitmap_layer_set_compositing_mode(weather_layer,GCompOpAssignInverted); layer_add_child(window_layer, bitmap_layer_get_layer(weather_layer)); text_temp_layer = text_layer_create(GRect(65, 91, 79, 50)); text_layer_set_text_color(text_temp_layer, GColorWhite); text_layer_set_text_alignment(text_temp_layer,GTextAlignmentCenter); text_layer_set_background_color(text_temp_layer, GColorClear); text_layer_set_font(text_temp_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT)); text_layer_set_text(text_temp_layer, temp_text); layer_add_child(window_layer, text_layer_get_layer(text_temp_layer)); bottom_layer = layer_create(bounds); layer_set_update_proc(bottom_layer, update_bottom_callback); layer_add_child(window_layer, bottom_layer); for(int i=0; i<LAYER_NUMBER; i++){ layer_number[i] = flip_layer_create(GRect(3 + i * 69, 21, 69, 36 * 2)); flip_layer_set_images(layer_number[i], NUMBER_IMAGE_RESOURCE_UP_IDS, NUMBER_IMAGE_RESOURCE_DOWN_IDS, NUMBER_IMAGE_COUNT); layer_add_child(window_layer, flip_layer_get_layer(layer_number[i])); } text_city_layer = text_layer_create(GRect(2, -1, 90, 16)); text_layer_set_text_color(text_city_layer, GColorBlack); text_layer_set_text_alignment(text_city_layer,GTextAlignmentLeft); text_layer_set_background_color(text_city_layer, GColorClear); text_layer_set_font(text_city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text(text_city_layer, city_text); layer_add_child(window_layer, text_layer_get_layer(text_city_layer)); // text_temp_layer = text_layer_create(GRect(4, 144, 50, 20)); // text_layer_set_text_color(text_temp_layer, GColorBlack); // text_layer_set_text_alignment(text_temp_layer,GTextAlignmentLeft); // text_layer_set_background_color(text_temp_layer, GColorClear); // text_layer_set_font(text_temp_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); // text_layer_set_text(text_temp_layer, temp_text); // layer_add_child(window_layer, text_layer_get_layer(text_temp_layer)); text_date_layer = text_layer_create(GRect(4, 144, 138, 20)); text_layer_set_text_color(text_date_layer, GColorBlack); text_layer_set_text_alignment(text_date_layer,GTextAlignmentRight); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(text_date_layer, date_text); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); battery_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_100); battery_layer = bitmap_layer_create(GRect(144-18, 0, 16, 16)); bitmap_layer_set_bitmap(battery_layer, battery_image); bitmap_layer_set_alignment(battery_layer, GAlignCenter); bitmap_layer_set_compositing_mode(battery_layer,GCompOpClear); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_ON); bluetooth_layer = bitmap_layer_create(GRect(112, 2, 11, 12)); bitmap_layer_set_bitmap(bluetooth_layer, battery_image); bitmap_layer_set_alignment(bluetooth_layer, GAlignCenter); layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer)); time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_minute_tick(tick_time, MINUTE_UNIT); battery_state_handler(battery_state_service_peek()); bluetooth_connection_handler(bluetooth_connection_service_peek()); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Nanji"); // window_set_background_color(&window, GColorBlack); window_stack_push(&window, true /* Animated */); resource_init_current_app(&NANJI_DESUKA); /* Label for year */ bmp_init_container(RESOURCE_ID_IMG_YEAR1, &image_lbl_yr1); layer_set_frame(&image_lbl_yr1.layer.layer, GRect(SCREENW - SMALL_W, 0, SMALL_W, SMALL_H)); layer_add_child(&window.layer, &image_lbl_yr1.layer.layer); bmp_init_container(RESOURCE_ID_IMG_YEAR2, &image_lbl_yr2); layer_set_frame(&image_lbl_yr2.layer.layer, GRect(SCREENW - SMALL_W, SMALL_H, SMALL_W, SMALL_H)); layer_add_child(&window.layer, &image_lbl_yr2.layer.layer); bmp_init_container(RESOURCE_ID_IMG_FUJI, &image_bg); layer_set_frame(&image_bg.layer.layer, GRect(SCREENW - LANDS_W, SCREENH - LANDS_H, LANDS_W, LANDS_H)); layer_add_child(&window.layer, &image_bg.layer.layer); bmp_init_container(RESOURCE_ID_IMG_WEEKD1, &image_lbl_wd1); layer_set_frame(&image_lbl_wd1.layer.layer, GRect(SCREENW - 4*SMALL_W, 1*SMALL_H, SMALL_W, SMALL_H)); layer_add_child(&window.layer, &image_lbl_wd1.layer.layer); bmp_init_container(RESOURCE_ID_IMG_WEEKD2, &image_lbl_wd2); layer_set_frame(&image_lbl_wd2.layer.layer, GRect(SCREENW - 4*SMALL_W, 2*SMALL_H, SMALL_W, SMALL_H)); layer_add_child(&window.layer, &image_lbl_wd2.layer.layer); bmp_init_container(RESOURCE_ID_IMG_YEARS, &image_lbl_yr); layer_add_child(&window.layer, &image_lbl_yr.layer.layer); bmp_init_container(RESOURCE_ID_IMG_MONTHS, &image_lbl_mt); layer_add_child(&window.layer, &image_lbl_mt.layer.layer); bmp_init_container(RESOURCE_ID_IMG_DAYS, &image_lbl_dy); layer_add_child(&window.layer, &image_lbl_dy.layer.layer); // bmp_init_container(RESOURCE_ID_IMG_WMON, &image_lbl_wd); // layer_add_child(&window.layer, &image_lbl_wd.layer.layer); bmp_init_container(RESOURCE_ID_IMG_HOURS, &image_lbl_hr); layer_add_child(&window.layer, &image_lbl_hr.layer.layer); bmp_init_container(RESOURCE_ID_IMG_MINUTES, &image_lbl_mn); layer_add_child(&window.layer, &image_lbl_mn.layer.layer); bmp_init_container(RESOURCE_ID_IMG_MORNING, &img_morning); bmp_init_container(RESOURCE_ID_IMG_NOON, &img_noon); bmp_init_container(RESOURCE_ID_IMG_NIGHT, &img_night); layer_set_frame(&img_morning.layer.layer, GRect(SCREENW - 5*SMALL_W, digit_used*SMALL_H, SMALL_W, SMALL_H)); layer_set_frame(&img_noon.layer.layer, GRect(SCREENW - 5*SMALL_W, digit_used*SMALL_H, SMALL_W, SMALL_H)); layer_set_frame(&img_night.layer.layer, GRect(SCREENW - 5*SMALL_W, digit_used*SMALL_H, SMALL_W, SMALL_H)); layer_add_child(&window.layer, &img_morning.layer.layer); layer_add_child(&window.layer, &img_noon.layer.layer); layer_add_child(&window.layer, &img_night.layer.layer); bmp_init_container(RESOURCE_ID_IMG_S0, &image_numbers_small[0]); bmp_init_container(RESOURCE_ID_IMG_S1, &image_numbers_small[1]); bmp_init_container(RESOURCE_ID_IMG_S2, &image_numbers_small[2]); bmp_init_container(RESOURCE_ID_IMG_S3, &image_numbers_small[3]); bmp_init_container(RESOURCE_ID_IMG_S4, &image_numbers_small[4]); bmp_init_container(RESOURCE_ID_IMG_S5, &image_numbers_small[5]); bmp_init_container(RESOURCE_ID_IMG_S6, &image_numbers_small[6]); bmp_init_container(RESOURCE_ID_IMG_S7, &image_numbers_small[7]); bmp_init_container(RESOURCE_ID_IMG_S8, &image_numbers_small[8]); bmp_init_container(RESOURCE_ID_IMG_S9, &image_numbers_small[9]); bmp_init_container(RESOURCE_ID_IMG_S10, &image_numbers_small[10]); // bmp_init_container(RESOURCE_ID_IMG_L0, &image_numbers_large[0]); // bmp_init_container(RESOURCE_ID_IMG_L1, &image_numbers_large[1]); // bmp_init_container(RESOURCE_ID_IMG_L2, &image_numbers_large[2]); // bmp_init_container(RESOURCE_ID_IMG_L3, &image_numbers_large[3]); // bmp_init_container(RESOURCE_ID_IMG_L4, &image_numbers_large[4]); // bmp_init_container(RESOURCE_ID_IMG_L5, &image_numbers_large[5]); // bmp_init_container(RESOURCE_ID_IMG_L6, &image_numbers_large[6]); // bmp_init_container(RESOURCE_ID_IMG_L7, &image_numbers_large[7]); // bmp_init_container(RESOURCE_ID_IMG_L8, &image_numbers_large[8]); // bmp_init_container(RESOURCE_ID_IMG_L9, &image_numbers_large[9]); // bmp_init_container(RESOURCE_ID_IMG_L10, &image_numbers_large[10]); bmp_init_container(RESOURCE_ID_IMG_WSUN, &image_week_days[0]); bmp_init_container(RESOURCE_ID_IMG_WMON, &image_week_days[1]); bmp_init_container(RESOURCE_ID_IMG_WTUE, &image_week_days[2]); bmp_init_container(RESOURCE_ID_IMG_WWED, &image_week_days[3]); bmp_init_container(RESOURCE_ID_IMG_WTHU, &image_week_days[4]); bmp_init_container(RESOURCE_ID_IMG_WFRI, &image_week_days[5]); bmp_init_container(RESOURCE_ID_IMG_WSAT, &image_week_days[6]); for (int i = 0; i < 3; ++i) { bitmap_layer_init(&bml_year[i], GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_year[i].layer); bitmap_layer_init(&bml_month[i], GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_month[i].layer); bitmap_layer_init(&bml_day[i], GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_day[i].layer); bitmap_layer_init(&bml_hour[i], GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_hour[i].layer); bitmap_layer_init(&bml_minute[i], GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_minute[i].layer); } bitmap_layer_init(&bml_weekday, GRect(0, 0, SMALL_W, SMALL_W)); layer_add_child(&window.layer, &bml_weekday.layer); handle_minute_tick(ctx, NULL); }