static void inbox_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);
  Tuple *twenty_four_hour_format_t = dict_find(iter, KEY_TWENTY_FOUR_HOUR_FORMAT);

  if (background_color_t) {
    int background_color = background_color_t->value->int32;

    persist_write_int(KEY_BACKGROUND_COLOR, background_color);

    set_background_and_text_color(background_color);
  }

  if (twenty_four_hour_format_t) {
    twenty_four_hour_format = twenty_four_hour_format_t->value->int8;

    persist_write_int(KEY_TWENTY_FOUR_HOUR_FORMAT, twenty_four_hour_format);

    update_time();
  }
}
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_text_layer = text_layer_create(GRect(0, 55, bounds.size.w, 100));
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_LECO_38_BOLD_NUMBERS));
  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(s_text_layer, GColorClear);

  if (persist_read_int(KEY_BACKGROUND_COLOR)) {
    int background_color = persist_read_int(KEY_BACKGROUND_COLOR);
    set_background_and_text_color(background_color);
  }

  if (persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT)) {
    twenty_four_hour_format = persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT);
  }

  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));

  update_time();
}
Esempio n. 3
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
 
  battery_layer = layer_create(GRect(0, 0, 144, 30));
  
  outline_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LECO_16));
  
  bluetooth_connection_service_subscribe(bluetooth_handler);
  
  
  upper_text_layer = text_layer_create(GRect(0, 36, 144, 44));
  text_layer_set_font(upper_text_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS));
  text_layer_set_text_alignment(upper_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(upper_text_layer, GColorClear);
  
  outline_layer = text_layer_create(GRect(0, 36, 144, 168));
  text_layer_set_font(outline_layer, outline_font);
  text_layer_set_text_alignment(outline_layer, GTextAlignmentCenter);
  text_layer_set_text_color(outline_layer, GColorWhite);
  text_layer_set_background_color(outline_layer, GColorClear);

  lower_text_layer = text_layer_create(GRect(0, 84, 144, 100));
  text_layer_set_font(lower_text_layer, fonts_get_system_font(FONT_KEY_LECO_28_LIGHT_NUMBERS));
  text_layer_set_text_alignment(lower_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(lower_text_layer, GColorClear);
  text_layer_set_text(lower_text_layer, "");
  
  weekday_text = text_layer_create(GRect(0,144,144,25));
  text_layer_set_text_alignment(weekday_text, GTextAlignmentCenter);
  text_layer_set_background_color(weekday_text, GColorClear);
  text_layer_set_text_color(weekday_text, GColorWhite);
  text_layer_set_font(weekday_text, outline_font);
  
  battery_text = text_layer_create(GRect(0,0,144,25));
  text_layer_set_text_alignment(battery_text, GTextAlignmentCenter);
  text_layer_set_background_color(battery_text, GColorClear);
  text_layer_set_text_color(battery_text, GColorWhite);
  text_layer_set_font(battery_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  layer_add_child(window_layer, battery_layer);
  
  
  layer_add_child(window_layer, text_layer_get_layer(lower_text_layer));
  layer_add_child(window_layer, text_layer_get_layer(upper_text_layer));
  layer_add_child(window_layer, text_layer_get_layer(outline_layer));
  
  layer_add_child(battery_layer, text_layer_get_layer(battery_text));
  layer_add_child(window_layer, text_layer_get_layer(weekday_text));
  
  
 
  
  if (persist_read_int(KEY_TOP_COLOR)) {
   int top_color = persist_read_int(KEY_TOP_COLOR);
    set_background_and_text_color(top_color);
  }
  
  if (persist_read_int(KEY_BOTTOM_COLOR)) {
   int bottom_color = persist_read_int(KEY_BOTTOM_COLOR);
    set_layer1_color_and_text(bottom_color);
  }

  if (persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT)) {
    twenty_four_hour_format = persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT);
  }

  if (persist_read_int(KEY_TOP_TEXT_COLOR)) {
    int top_text_color = persist_read_int(KEY_TOP_TEXT_COLOR);
    set_top_text_color(top_text_color);
  }
  
  if(persist_read_int(KEY_BOTTOM_TEXT_COLOR)) {
    int bottom_text_color = persist_read_int(KEY_BOTTOM_TEXT_COLOR);
    set_bottom_text_color(bottom_text_color);
  }
  
  if(persist_exists(KEY_BLUETOOTH_VIBRATION)){
    bluetooth_vibration = persist_read_int(KEY_BLUETOOTH_VIBRATION);
    APP_LOG(APP_LOG_LEVEL_INFO,"Bluetooth read");
  }
  
  if(persist_exists(KEY_SHOW_BATTERY)){
    show_battery = persist_read_int(KEY_SHOW_BATTERY);
  }
  
  if(persist_exists(KEY_SHOW_WEEKDAY)){
  show_weekday = persist_read_int(KEY_SHOW_WEEKDAY);
  APP_LOG(APP_LOG_LEVEL_INFO,"Weekday read");
}
  
  if(persist_exists(KEY_DATE_FORMAT)){
    change_date_format = persist_read_int(KEY_DATE_FORMAT);
    APP_LOG(APP_LOG_LEVEL_INFO,"Date format read");
  }
  
  if(persist_read_int(KEY_WEEKDAY_COLOR)) {
    int weekday_color = persist_read_int(KEY_WEEKDAY_COLOR);
    set_weekday_color(weekday_color);
  }
  
  if(persist_read_int(KEY_BATTERY_COLOR)) {
    int battery_color = persist_read_int(KEY_BATTERY_COLOR);
    set_battery_color(battery_color);
  }
  
  if(persist_read_bool(KEY_HOUR_VIBRATE)) {
    hour_vibrate = persist_read_bool(KEY_HOUR_VIBRATE);
  }
  
  update_time();
  update_layers();
  battery_handler(battery_state_service_peek());
}
Esempio n. 4
0
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *top_color_t = dict_find(iter, KEY_TOP_COLOR);
  Tuple *twenty_four_hour_format_t = dict_find(iter, KEY_TWENTY_FOUR_HOUR_FORMAT);
  Tuple *bottom_color_t = dict_find(iter, KEY_BOTTOM_COLOR);
  Tuple *top_text_color_t = dict_find(iter, KEY_TOP_TEXT_COLOR);
  Tuple *bottom_text_color_t = dict_find(iter, KEY_BOTTOM_TEXT_COLOR);
  Tuple *bluetooth_vibration_t = dict_find(iter, KEY_BLUETOOTH_VIBRATION);
  Tuple *show_battery_t = dict_find(iter, KEY_SHOW_BATTERY);
  Tuple *show_weekday_t = dict_find(iter, KEY_SHOW_WEEKDAY);
  Tuple *change_date_format_t = dict_find(iter, KEY_DATE_FORMAT);
  Tuple *weekday_color_t = dict_find(iter, KEY_WEEKDAY_COLOR);
  Tuple *battery_color_t = dict_find(iter, KEY_BATTERY_COLOR);
  Tuple *hour_vibrate_t = dict_find(iter, KEY_HOUR_VIBRATE);


  if (top_color_t) {
    int top_color = top_color_t->value->int32;

    persist_write_int(KEY_TOP_COLOR, top_color);
    set_background_and_text_color(top_color);
  }

  if (bottom_color_t) {
    int bottom_color = bottom_color_t->value->int32;

    persist_write_int(KEY_BOTTOM_COLOR, bottom_color);
    set_layer1_color_and_text(bottom_color);
  }

  if (twenty_four_hour_format_t) {
    twenty_four_hour_format = twenty_four_hour_format_t->value->int8;
    persist_write_int(KEY_TWENTY_FOUR_HOUR_FORMAT, twenty_four_hour_format);

    update_time();
  } 
  
  if(top_text_color_t) {
  int top_text = top_text_color_t->value->int32;
    
    persist_write_int(KEY_TOP_TEXT_COLOR, top_text);
    set_top_text_color(top_text);
  }
  
  if(bottom_text_color_t) {
    int bottom_text = bottom_text_color_t->value->int32;
    
    persist_write_int(KEY_BOTTOM_TEXT_COLOR, bottom_text);
    set_bottom_text_color(bottom_text);
  }
  
  if(bluetooth_vibration_t){
    bluetooth_vibration = bluetooth_vibration_t->value->int8;
    persist_write_int(KEY_BLUETOOTH_VIBRATION, bluetooth_vibration);
  }
  
  if(show_battery_t){
    show_battery = show_battery_t->value->int8;
    persist_write_int(KEY_SHOW_BATTERY, show_battery);
  }
 
  if(show_weekday_t){
    show_weekday = show_weekday_t->value->int8;
    persist_write_int(KEY_SHOW_WEEKDAY, show_weekday);
  }
  
  if(change_date_format_t){
    change_date_format = change_date_format_t->value->int8;
    persist_write_int(KEY_DATE_FORMAT, change_date_format);
  }
  
  if(weekday_color_t){
    int weekday_color = weekday_color_t->value->int32;
    persist_write_int(KEY_WEEKDAY_COLOR, weekday_color);
    set_weekday_color(weekday_color);
  }
  
    if(battery_color_t){
    int battery_color = battery_color_t->value->int32;
    persist_write_int(KEY_BATTERY_COLOR, battery_color);
    set_battery_color(battery_color);
  }
  
  if(hour_vibrate_t){
    hour_vibrate = hour_vibrate_t->value->int8;
    persist_write_int(KEY_HOUR_VIBRATE, hour_vibrate);
  }
  
  
  update_layers();
  update_time();
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
    Tuple *top_bar_color_t = dict_find(iter, KEY_TOP_BAR_COLOR);
    Tuple *middle_bar_color_t = dict_find(iter, KEY_MIDDLE_BAR_COLOR);
    Tuple *bottom_bar_color_t = dict_find(iter, KEY_BOTTOM_BAR_COLOR);
    Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);

    Tuple *temp_t = dict_find(iter, KEY_TEMPERATURE);
    Tuple *conditions_t = dict_find(iter, KEY_CONDITIONS);

    Tuple *degreeOption_t = dict_find(iter, KEY_DEGREEOPTION);

    //Store incoming information
    static char temperature_buffer[8];
    static char conditions_buffer[32];
    static char weather_layer_buffer[42];

    if (degreeOption_t) {
        degreeOption = degreeOption_t->value->uint32;
        APP_LOG(APP_LOG_LEVEL_DEBUG, "degree Option : %d", degreeOption);
        persist_write_int(KEY_DEGREEOPTION, degreeOption);
    }

    if (temp_t) {
        int kelvin = (int) temp_t->value->int32;
        if (degreeOption == 0) {
            //celsius
            int celsius = kelvin - 273.15;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) celsius);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Celsius: %d", degreeOption);
        } else {
            //fahrenheit
            int fahrenheit = (kelvin - 273.15) * 1.8 + 32;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) fahrenheit);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Fahrenheit: %d", degreeOption);
        }
    }

    if (conditions_t) {
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_t->value->cstring);
    }

    if (conditions_t && temp_t) {
        snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
        text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
        text_layer_set_text(s_weather_layer, weather_layer_buffer);
    }

    if (top_bar_color_t) {
        int top_bar_color = top_bar_color_t->value->int32;
        if (top_bar_color == 0) { //quick fix so that black colour persists
            top_bar_color++;
        }

        persist_write_int(KEY_TOP_BAR_COLOR, top_bar_color);

        //set_background_and_text_color(background_color);
        s_top_bar_color = GColorFromHEX(top_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "top bar color:  %d", top_bar_color);
    }

    if (middle_bar_color_t) {
        int middle_bar_color = middle_bar_color_t->value->int32;
        if (middle_bar_color == 0) { //quick fix so that black colour persists
            middle_bar_color++;
        }

        persist_write_int(KEY_MIDDLE_BAR_COLOR, middle_bar_color);

        s_middle_bar_color = GColorFromHEX(middle_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "middle bar color:  %d", middle_bar_color);
    }

    if (bottom_bar_color_t) {
        int bottom_bar_color = bottom_bar_color_t->value->int32;
        if (bottom_bar_color == 0) { //quick fix so that black colour persists
            bottom_bar_color++;
        }

        persist_write_int(KEY_BOTTOM_BAR_COLOR, bottom_bar_color);

        s_bottom_bar_color = GColorFromHEX(bottom_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "bottom bar color:  %d", bottom_bar_color);
    }

    if (background_color_t) {
        int background_color = background_color_t->value->int32;
        if (background_color == 0) { //quick fix so that black colour persists
            background_color++;
        }

        persist_write_int(KEY_BACKGROUND_COLOR, background_color);

        APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color);

        set_background_and_text_color(background_color);
    }

    time_t start_time = time(NULL);
    update_time(localtime(&start_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));

}