Guest User

Code

a guest
May 12th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.23 KB | None | 0 0
  1. #include <pebble.h>
  2.  
  3.  
  4. static Window *s_main_window;
  5.  
  6. static BitmapLayer *s_background_layer;
  7. static GBitmap *s_background_bitmap;
  8. static int hour;
  9.  
  10.  
  11. static void update_time() {
  12.  
  13.  // Get a tm structure
  14.   time_t temp = time(NULL);
  15.   struct tm *tick_time = localtime(&temp);
  16.  
  17.   // Create a long-lived buffer
  18.   static char buffer[] = "00:00";
  19.  
  20.   // Write the current hours and minutes into the buffer
  21.   if(clock_is_24h_style() == true) {
  22.     //Use 2h hour format
  23.     strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
  24.   } else {
  25.     //Use 12 hour format
  26.     strftime(buffer, sizeof("00:00"), "%I:%M", tick_time);
  27.  
  28. hour = &ticktime.tm_hour;
  29.  
  30. }
  31.  
  32. static void main_window_load(Window *window) {
  33.  
  34.   //Create GBitmap, then set to created BitmapLayer
  35.  
  36.  
  37. switch(hour){
  38.  
  39. case 00:
  40. s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_12);
  41. break;
  42.  
  43. case 01:
  44. s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_12);
  45. break;
  46.  
  47. case 02:
  48. s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_12);
  49. break;
  50.  
  51. case 03:
  52. s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_12);
  53. break;
  54.  
  55. default:
  56. break;
  57. }
  58.   s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  59.   bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  60.   layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
  61.  
  62.  
  63.  
  64. }
  65.  
  66. static void main_window_unload(Window *window) {
  67.  
  68.   //Destroy GBitmap
  69.   gbitmap_destroy(s_background_bitmap);
  70.  
  71.   //Destroy BitmapLayer
  72.   bitmap_layer_destroy(s_background_layer);
  73.  
  74.  // Make sure the time is displayed from the start
  75.   update_time();
  76. }
  77.  
  78. static void init() {
  79.   // Create main Window element and assign to pointer
  80.   s_main_window = window_create();
  81.  
  82.   // Set handlers to manage the elements inside the Window
  83.   window_set_window_handlers(s_main_window, (WindowHandlers) {
  84.     .load = main_window_load,
  85.     .unload = main_window_unload
  86.   });
  87.  
  88.   // Show the Window on the watch, with animated=true
  89.   window_stack_push(s_main_window, true);
  90.  
  91. }
  92.  
  93. static void deinit() {
  94.   // Destroy Window
  95.   window_destroy(s_main_window);
  96. }
  97.  
  98. int main(void) {
  99.   init();
  100.   app_event_loop();
  101.   deinit();
  102. }
Advertisement
Add Comment
Please, Sign In to add comment