Advertisement
Guest User

Untitled

a guest
May 28th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <pebble.h>
  2. static Window *s_main_window;
  3. static TextLayer *s_time_layer;
  4. static void tick_handler(struct tm *tick_time, TimeUnits units_changed){
  5. tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  6. }
  7. static void update_time() {
  8. time_t temp = time(NULL);
  9. struct tm *tick_time = localtime(&temp);
  10. static char buffer[] = "00;00";
  11. if(clock_is_24h_style()== true){
  12. strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
  13.  
  14. }else{
  15. strftime(buffer, sizeof("00:00"), "%I:%M", tick_time);
  16. }
  17.  
  18. }
  19. static void main_window_load(Window *window){
  20. s_time_layer = text_layer_create(GRect(0, 55, 144, 50));
  21. text_layer_set_background_color(s_time_layer, GColorClear);
  22. text_layer_set_text_color(s_time_layer, GColorBlack);
  23. text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  24. text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  25. layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  26. }
  27. static void main_window_unload(Window *window){
  28. text_layer_destroy(s_time_layer);
  29. }
  30. static void init() {
  31. s_main_window = window_create();
  32. window_set_window_handlers(s_main_window, (WindowHandlers) {
  33. .load = main_window_load,
  34. .unload = main_window_unload
  35. });
  36. window_stack_push(s_main_window, true);
  37. tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  38. update_time();
  39. }
  40.  
  41. static void deinit() {
  42. window_destroy(s_main_window);
  43. }
  44.  
  45. int main(void) {
  46. init();
  47. app_event_loop();
  48. deinit();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement