/* * Copyright (c) 2015 joshua stein * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include static Window *s_main_window; static TextLayer *s_time_layer; static TextLayer *s_date_layer; static BitmapLayer *s_background_layer; static GBitmap *s_background_bitmap; static void update_time() { static char buffer[] = " : "; static char dbuffer[] = " / / "; time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); if (clock_is_24h_style() == true) { strftime(buffer, sizeof(buffer), "%H:%M", tick_time); text_layer_set_text(s_time_layer, buffer); } else { strftime(buffer, sizeof(buffer), "%I:%M %p", tick_time); text_layer_set_text(s_time_layer, buffer); } strftime(dbuffer, sizeof(dbuffer), "%m/%d/%y", tick_time); text_layer_set_text(s_date_layer, dbuffer); } static void main_window_load(Window *window) { 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)); s_time_layer = text_layer_create(GRect(0, 65, 144, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); if (clock_is_24h_style() == true) { layer_set_frame(text_layer_get_layer(s_time_layer), GRect(0, 70, 144, 50)); text_layer_set_text(s_time_layer, " : "); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS)); } else { text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(s_time_layer, " : "); } text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); s_date_layer = text_layer_create(GRect(0, 95, 144, 50)); if (clock_is_24h_style() == true) layer_set_frame(text_layer_get_layer(s_date_layer), GRect(0, 100, 144, 50)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_text(s_date_layer, " / / "); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); update_time(); } static void main_window_unload(Window *window) { text_layer_destroy(s_time_layer); gbitmap_destroy(s_background_bitmap); bitmap_layer_destroy(s_background_layer); } static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); } static void init() { s_main_window = window_create(); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload }); window_stack_push(s_main_window, true); tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); } static void deinit() { window_destroy(s_main_window); } int main(void) { init(); app_event_loop(); deinit(); }