// Update the bottom half of the screen: icon and temperature
void weather_layer_update(WeatherData *weather_data) 
{
  // We have no weather data yet... don't update until we do
  if (weather_data->updated == 0) {
    return;
  }

  WeatherLayerData *wld = layer_get_data(weather_layer);

  if (weather_animation_timer && animation_timer_enabled) {
    app_timer_cancel(weather_animation_timer);
    // this is only needed to stop the error message when cancelling an already cancelled timer... 
    animation_timer_enabled = false;
    layer_set_hidden(wld->loading_layer, true);
  }

  time_t current_time = time(NULL);

  bool stale = false;
  if (current_time - weather_data->updated > WEATHER_STALE_TIMEOUT) {
    stale = true;
  }

  //APP_LOG(APP_LOG_LEVEL_DEBUG, "ct:%i wup:%i, stale:%i", 
  //  (int)current_time, (int)weather_data->updated, (int)WEATHER_STALE_TIMEOUT);

  // Update the weather icon and temperature
  if (weather_data->error) {
    // Only update the error icon if the weather data is stale
    if (stale) {
      weather_layer_clear_temperature();
      switch (weather_data->error) {
        case WEATHER_E_NETWORK:
          weather_layer_set_error();
          debug_update_message("Network error");
          break;
        case WEATHER_E_DISCONNECTED:
        case WEATHER_E_PHONE:
        default:
          weather_layer_set_error();
          debug_update_message("Phone disco / error");
          break;
      }
    }
  } else {

    layer_set_frame(bitmap_layer_get_layer(wld->primary_icon_layer), PRIMARY_ICON_NORMAL_FRAME);

    // Show the temperature as 'stale' if it has not been updated in WEATHER_STALE_TIMEOUT
    weather_layer_set_temperature(weather_data->temperature, stale);

    // Day/night check
    time_t utc = current_time;
//    time_t utc = current_time + weather_data->tzoffset;                                ///////// Change utc value to current_time for SDK3 by ktagjp
    bool night_time = is_night_time(weather_data->sunrise, weather_data->sunset, utc);

    /*
    APP_LOG(APP_LOG_LEVEL_DEBUG, 
       "ct:%i, utc:%i sr:%i, ss:%i, nt:%i", 
       (int)current_time, (int)utc, weather_data->sunrise, weather_data->sunset, night_time);
    */

	if (strcmp(weather_data->service, SERVICE_OPEN_WEATHER) == 0) {
		weather_layer_set_icon(open_weather_icon_for_condition(weather_data->condition, night_time), AREA_PRIMARY);
	} else if (strcmp(weather_data->service, SERVICE_YAHOO_WEATHER) == 0) {
		weather_layer_set_icon(yahoo_weather_icon_for_condition(weather_data->condition, night_time), AREA_PRIMARY);
	} else {
		weather_layer_set_icon(wunder_weather_icon_for_condition(weather_data->condition, night_time), AREA_PRIMARY);
	}

	if (weather_data->hourly_updated != 0 && weather_data->hourly_enabled) {
		time_t h1t = weather_data->h1_time;
		time_t h2t = weather_data->h2_time;
//      time_t h1t = weather_data->h1_time - weather_data->tzoffset;      ///////// Change time value for SDK3 by ktagjp
//      time_t h2t = weather_data->h2_time - weather_data->tzoffset;      ///////// Change time value for SDK3 by ktagjp
      strftime(time_h1, sizeof(time_h1), "%I%p", localtime(&h1t));
      strftime(time_h2, sizeof(time_h2), "%I%p", localtime(&h2t));

      if (time_h1[0] == '0') {
        memmove(time_h1, &time_h1[1], sizeof(time_h1) - 1);
      }
      if (time_h2[0] == '0') {
        memmove(time_h2, &time_h2[1], sizeof(time_h2) - 1);
      }

      text_layer_set_text(wld->h1_time_layer, time_h1);
      text_layer_set_text(wld->h2_time_layer, time_h2);

      localtime(&current_time);

      night_time = is_night_time(weather_data->sunrise, weather_data->sunset, weather_data->h1_time);
      weather_layer_set_icon(wunder_weather_icon_for_condition(weather_data->h1_cond, night_time), AREA_HOURLY1);
      
      night_time = is_night_time(weather_data->sunrise, weather_data->sunset, weather_data->h2_time);
      weather_layer_set_icon(wunder_weather_icon_for_condition(weather_data->h2_cond, night_time), AREA_HOURLY2);
      
      snprintf(wld->h1_temp_str, sizeof(wld->h1_temp_str), 
        "%i%s", weather_data->h1_temp, "°");
      snprintf(wld->h2_temp_str, sizeof(wld->h2_temp_str), 
        "%i%s", weather_data->h2_temp, "°");

      text_layer_set_text(wld->h1_temp_layer, wld->h1_temp_str);
      text_layer_set_text(wld->h2_temp_layer, wld->h2_temp_str);
    }
  }
}
Exemplo n.º 2
0
void init() {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));
	
  const int inbound_size = 160;
  const int outbound_size = 160;
  app_message_open(inbound_size, outbound_size);  

  window = window_create();
  if (window == NULL) {
      return;
  }
	
    window_stack_push(window, true);
  
	background_color  = GColorBlack;
    window_set_background_color(window, background_color);
		
	Layer *window_layer = window_get_root_layer(window);

    GRect bounds = layer_get_frame(window_layer);
    path_layer = layer_create(bounds);
    layer_set_update_proc(path_layer, path_layer_update_callback);
    layer_add_child(window_layer, path_layer);

    // Pass the corresponding GPathInfo to initialize a GPath
    batt10 = gpath_create(&BATT10);
    batt20 = gpath_create(&BATT20);
    batt30 = gpath_create(&BATT30);
    batt40 = gpath_create(&BATT40);
    batt50 = gpath_create(&BATT50);
    batt60 = gpath_create(&BATT60);
    batt70 = gpath_create(&BATT70);
    batt80 = gpath_create(&BATT80);
    batt90 = gpath_create(&BATT90);
    batt100 = gpath_create(&BATT100);
  
	// Create time and date layers
    GRect dummy_frame = { {0, 0}, {0, 0} };
	
  for (int i = 0; i < TOTAL_TIME_DIGITS; ++i) {
    time_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i]));
  }

  time1_text_layer = text_layer_create(GRect(0, 64, 147, 30));
  text_layer_set_background_color(time1_text_layer, GColorClear);
  text_layer_set_text_color(time1_text_layer, GColorWhite);
  text_layer_set_text_alignment(time1_text_layer, GTextAlignmentCenter);
  text_layer_set_font(time1_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_BOLD_24)));
  text_layer_set_text(time1_text_layer, time1_buffer);
  layer_add_child(window_get_root_layer(window), (Layer*) time1_text_layer);
  

  date_text_layer = text_layer_create(GRect(0, 128, 144, 20));
  text_layer_set_background_color(date_text_layer, GColorClear);
  text_layer_set_text_color(date_text_layer, GColorWhite);
  text_layer_set_text_alignment(date_text_layer, GTextAlignmentCenter);
  text_layer_set_font(date_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_16)));
  text_layer_set_text(date_text_layer, date_buffer);
  layer_add_child(window_get_root_layer(window), (Layer*) date_text_layer);
  
  toggle_bluetooth(bluetooth_connection_service_peek());
  battery_state_service_subscribe(&update_battery_state);

  Tuplet initial_values[] = {
    TupletInteger(SWAP_KEY, persist_read_bool(SWAP_KEY)),
    TupletInteger(INVERT_KEY, persist_read_bool(INVERT_KEY)),
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
  };
  
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, NULL, NULL);
   
  appStarted = true;
  
  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  tick_handler(localtime(&now), DAY_UNIT + HOUR_UNIT + MINUTE_UNIT);
  tick_timer_service_subscribe(MINUTE_UNIT, (TickHandler) tick_handler);
	
  // update the battery on launch
  update_battery_state(battery_state_service_peek());
  bluetooth_connection_service_subscribe(bluetooth_connection_callback);
		
}
void weather_layer_create(GRect frame, Window *window)
{
  // Create a new layer with some extra space to save our custom Layer infos
  weather_layer = layer_create_with_data(frame, sizeof(WeatherLayerData));
  WeatherLayerData *wld = layer_get_data(weather_layer);

  large_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_30));
  small_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_17));

  wld->primary_icon_size = 45;
  wld->hourly_icon_size = 30;

  // Add background layer
  wld->temp_layer_background = text_layer_create(GRect(0, 0, 144, 80));
  text_layer_set_background_color(wld->temp_layer_background, GColorCyan);
  layer_add_child(weather_layer, text_layer_get_layer(wld->temp_layer_background));

  // Primary temperature layer
  wld->primary_temp_layer = text_layer_create(GRect(2, 38, 70, 35));
  text_layer_set_background_color(wld->primary_temp_layer, GColorClear);
  text_layer_set_text_alignment(wld->primary_temp_layer, GTextAlignmentCenter);
  text_layer_set_font(wld->primary_temp_layer, large_font);
  layer_add_child(weather_layer, text_layer_get_layer(wld->primary_temp_layer));

  
  wld->h1_time_layer = text_layer_create(GRect(68, 5, 30, 20));
  text_layer_set_text_color(wld->h1_time_layer, GColorBlack);
  text_layer_set_background_color(wld->h1_time_layer, GColorClear);
  text_layer_set_text_alignment(wld->h1_time_layer, GTextAlignmentCenter);
  layer_add_child(weather_layer, text_layer_get_layer(wld->h1_time_layer));

  wld->h1_temp_layer = text_layer_create(GRect(67, 47, 38, 20));
  text_layer_set_text_color(wld->h1_temp_layer, GColorBlack);
  text_layer_set_background_color(wld->h1_temp_layer, GColorClear);
  text_layer_set_text_alignment(wld->h1_temp_layer, GTextAlignmentCenter);
  text_layer_set_font(wld->h1_temp_layer, small_font);
  layer_add_child(weather_layer, text_layer_get_layer(wld->h1_temp_layer));
  
  // Hour1 bitmap layer
  wld->h1_icon_layer = bitmap_layer_create(GRect(68, 20, wld->hourly_icon_size, wld->hourly_icon_size));
  bitmap_layer_set_background_color(wld->h1_icon_layer, GColorClear);
  layer_add_child(weather_layer, bitmap_layer_get_layer(wld->h1_icon_layer));

  
  wld->h2_time_layer = text_layer_create(GRect(108, 5, 30, 20));
  text_layer_set_text_color(wld->h2_time_layer, GColorBlack);
  text_layer_set_background_color(wld->h2_time_layer, GColorClear);
  text_layer_set_text_alignment(wld->h2_time_layer, GTextAlignmentCenter);
  layer_add_child(weather_layer, text_layer_get_layer(wld->h2_time_layer));

  wld->h2_temp_layer = text_layer_create(GRect(106, 47, 38, 20));
  text_layer_set_text_color(wld->h2_temp_layer, GColorBlack);
  text_layer_set_background_color(wld->h2_temp_layer, GColorClear);
  text_layer_set_text_alignment(wld->h2_temp_layer, GTextAlignmentCenter);
  text_layer_set_font(wld->h2_temp_layer, small_font);
  layer_add_child(weather_layer, text_layer_get_layer(wld->h2_temp_layer));
   
  // Hour2 bitmap layer
  wld->h2_icon_layer = bitmap_layer_create(GRect(107, 20, wld->hourly_icon_size, wld->hourly_icon_size));
  bitmap_layer_set_background_color(wld->h2_icon_layer, GColorClear);
  layer_add_child(weather_layer, bitmap_layer_get_layer(wld->h2_icon_layer));

  // Primary bitmap layer
  wld->primary_icon_layer = bitmap_layer_create(PRIMARY_ICON_NORMAL_FRAME);
  bitmap_layer_set_background_color(wld->primary_icon_layer, GColorClear);
  layer_add_child(weather_layer, bitmap_layer_get_layer(wld->primary_icon_layer));

  wld->loading_layer = layer_create(GRect(43, 27, 50, 20));
  layer_set_update_proc(wld->loading_layer, weather_animate_update);
  layer_add_child(weather_layer, wld->loading_layer);

  wld->primary_icons = gbitmap_create_with_resource(RESOURCE_ID_ICON_45X45);
  wld->hourly_icons  = gbitmap_create_with_resource(RESOURCE_ID_ICON_30X30);

  wld->primary_icon = NULL;
  wld->h1_icon = NULL;
  wld->h2_icon = NULL;

  layer_add_child(window_get_root_layer(window), weather_layer);
}
Exemplo n.º 4
0
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  char y_offset_time_layer = PBL_IF_ROUND_ELSE(14, 8);
  char x_offset_battery_layer = PBL_IF_ROUND_ELSE(17, 17);
  char y_offset_battery_layer = PBL_IF_ROUND_ELSE((bounds.size.h / 2) - 11, bounds.size.h - 22);
  char x_offset_date_layer = PBL_IF_ROUND_ELSE(bounds.size.w - 62, bounds.size.w - 64);
  char y_offset_date_layer = PBL_IF_ROUND_ELSE((bounds.size.h / 2) - 12 , bounds.size.h - 15);
  char x_offset_weather_layer = PBL_IF_ROUND_ELSE(bounds.size.w - 65, bounds.size.w - 56);
  char y_offset_weather_layer = PBL_IF_ROUND_ELSE((bounds.size.h / 2) + 22, (bounds.size.h / 2) - 18);
  GColor color_blue = GColorFromHEX(0x007cb2);
  static char lastWeatherBuffer[32] = "--";
  persist_read_string(KEY_LAST_WEATHER_BUFFER, lastWeatherBuffer, 32);
                                                  
  layer_set_update_proc(window_layer, my_layer_draw);
    
  // Creacion del layer con las horas
  s_time_layer_hours = text_layer_create(
      GRect(0, y_offset_time_layer, (bounds.size.w / 2 - 4), 52));
  
  // Creacion del layer con los minutos
  s_time_layer_minutes = text_layer_create(
      GRect((bounds.size.w / 2) + 4, y_offset_time_layer, (bounds.size.w / 2) - 4, 52));

  // Creacion del layer para el nivel de bateria
  s_battery_layer = text_layer_create(
      GRect(x_offset_battery_layer, y_offset_battery_layer, 40, 18));
  
  // Creacion del layer para la fecha
  s_date_layer = text_layer_create(
      GRect(x_offset_date_layer, y_offset_date_layer, 64, PBL_IF_ROUND_ELSE(36, 18)));
  
  // Creacion del layer para mostrar el tiempo atmosferico
  s_weather_layer = text_layer_create(
    GRect(x_offset_weather_layer, y_offset_weather_layer, 72, 72));
  
  // Estilo del layer del tiempo atmosferico
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, GColorWhite);
  text_layer_set_font(s_weather_layer, s_font_temperature);
  text_layer_set_text(s_weather_layer, lastWeatherBuffer);
  //xt_layer_set_text(s_weather_layer, "--");
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  
  // Estilo del layer con la hora
  text_layer_set_background_color(s_time_layer_hours, GColorClear);
  text_layer_set_text_color(s_time_layer_hours, color_blue);
  text_layer_set_text(s_time_layer_hours, "--");
  text_layer_set_font(s_time_layer_hours, s_font_time);
  text_layer_set_text_alignment(s_time_layer_hours, GTextAlignmentRight);
  
  // Estilo del layer con los minutos
  text_layer_set_background_color(s_time_layer_minutes, GColorClear);
  text_layer_set_text_color(s_time_layer_minutes, GColorWhite);
  text_layer_set_text(s_time_layer_minutes, "--");
  text_layer_set_font(s_time_layer_minutes, s_font_time);
  text_layer_set_text_alignment(s_time_layer_minutes, GTextAlignmentLeft);
  
  // Estilo del layer con el porcentaje de bateria
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_text_color(s_battery_layer, color_blue);
  text_layer_set_text(s_battery_layer, "---");
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft);
  
  // Estilo del layer con la fecha
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_text(s_date_layer, "---");
  text_layer_set_font(s_date_layer, s_font_date);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);

  GSize text_size = text_layer_get_content_size(s_time_layer_hours);

  // Adicion de los layers a la ventana principal
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer_hours));
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer_minutes));
  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
  layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
  layer_add_child(window_layer, text_layer_get_layer(s_weather_layer));
  
  #if defined(PBL_COLOR)
    // Se carga la imagen del escudo en color
    s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ESCUDO_PONFE);
    GSize image_size = gbitmap_get_bounds(s_bitmap).size;
    char image_offsetX = (bounds.size.w - image_size.w) / 2; 
    GRect image_frame = GRect(image_offsetX, text_size.h + y_offset_time_layer + 6, image_size.w, image_size.h);
    s_layer = bitmap_layer_create(image_frame);
  
    bitmap_layer_set_bitmap(s_layer, s_bitmap);
    bitmap_layer_set_compositing_mode(s_layer, GCompOpSet);
    bitmap_layer_set_alignment(s_layer, GAlignBottom);
 #elif defined(PBL_BW)
    // Se carga la imagen del escudo en blanco y negro
    s_bitmap_bw = gbitmap_create_with_resource(RESOURCE_ID_ESCUDO_BN);
    GSize image_size = gbitmap_get_bounds(s_bitmap_bw).size;
    char image_offsetX = (bounds.size.w - image_size.w) / 2; 
    GRect image_frame = GRect(image_offsetX, text_size.h + y_offset_time_layer + 6, image_size.w, image_size.h);
    s_layer = bitmap_layer_create(image_frame);
  
    bitmap_layer_set_bitmap(s_layer, s_bitmap_bw);
    bitmap_layer_set_compositing_mode(s_layer, GCompOpSet);
    bitmap_layer_set_alignment(s_layer, GAlignBottom);
  #endif
  
  // Create the Bluetooth icon GBitmap
  s_bitmap_bt = gbitmap_create_with_resource(RESOURCE_ID_BT_ICON);

  // Create the BitmapLayer to display the GBitmap
  s_layer_bt = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(22, 8), PBL_IF_ROUND_ELSE((bounds.size.h / 2) + 18, bounds.size.h / 2), 24, 24));
  bitmap_layer_set_bitmap(s_layer_bt, s_bitmap_bt);
  bitmap_layer_set_compositing_mode(s_layer_bt, GCompOpSet);
  bitmap_layer_set_alignment(s_layer_bt, GAlignLeft);
  
  layer_add_child(window_layer, bitmap_layer_get_layer(s_layer_bt));
  layer_add_child(window_layer, bitmap_layer_get_layer(s_layer));
}
Exemplo n.º 5
0
static void main_window_load(Window *window) {
	
#if defined(PBL_BW)
    window_set_background_color(s_main_window, GColorWhite);
#elif defined(PBLE_COLOR)
  int red = persist_read_int(KEY_COLOR_RED);
  int green = persist_read_int(KEY_COLOR_GREEN);
  int blue = persist_read_int(KEY_COLOR_BLUE);
  
  GColor bg_color = GColorFromRGB(red, green, blue);
  window_set_background_color(s_main_window, bg_color);
#endif
  
  // Get the Window's root layer and the bounds
  GRect bounds = layer_get_bounds(window_get_root_layer(window));
  
  // Load the image
  #ifdef PBL_COLOR
    logo_bitmap = gbitmap_create_with_resource(RESOURCE_ID_LOGO);
  #else
    logo_bitmap = gbitmap_create_with_resource(RESOURCE_ID_LOGO_BW);
  #endif

// Create a BitmapLayer
logo_layer = bitmap_layer_create(bounds);

// Set the bitmap and center it
bitmap_layer_set_bitmap(logo_layer, logo_bitmap);
bitmap_layer_set_alignment(logo_layer, GAlignCenter);
bitmap_layer_set_compositing_mode(logo_layer, GCompOpSet);

// Add to the Window
layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(logo_layer));
	
	// Set font hour TextLayer
	s_hour_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYNC_BOLD_50));
	// Set font minutes TextLayer
	s_minutes_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYNC_BOLD_50));
	
	//Hour Layer
  #if defined(PBL_RECT) 
	  s_hour_layer = text_layer_create(GRect (0, 30, 144, 54));
  #elif defined(PBL_ROUND)
    s_hour_layer = text_layer_create(GRect (0, 35, 180, 54));
  #endif
	text_layer_set_background_color(s_hour_layer, GColorClear);
  text_layer_set_text_color(s_hour_layer, GColorBlack);
	text_layer_set_text(s_hour_layer, "00");
	
	//Minute Layer
	#if defined(PBL_RECT) 
    s_minutes_layer = text_layer_create(GRect (0, 74, 144, 54));
  #elif defined(PBL_ROUND) 
    s_minutes_layer = text_layer_create(GRect (0, 79, 180, 54));
  #endif
	text_layer_set_background_color(s_minutes_layer, GColorClear);
	text_layer_set_text_color(s_minutes_layer, GColorBlack);
	text_layer_set_text(s_minutes_layer, "00");
  
	//Make it look more like a watch
	text_layer_set_font(s_hour_layer, s_hour_font);
	text_layer_set_font(s_minutes_layer, s_minutes_font);
	text_layer_set_text_alignment(s_hour_layer, GTextAlignmentCenter);
	text_layer_set_text_alignment(s_minutes_layer, GTextAlignmentCenter);
	
	//Add hour, miuntes, and weather layers as child windows to the Window's root layer
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_minutes_layer));
}
Exemplo n.º 6
0
bool trend_arrow_component_hidden(TrendArrowComponent *c) {
  return layer_get_hidden(bitmap_layer_get_layer(c->icon_layer));
}
Exemplo n.º 7
0
void window_load(Window *window) {//------------------------------------------------------------------------------------------------ window_load

  Layer *layer = window_get_root_layer(window);
  
  s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_EVBG_APLITE);
  s_bitmap_layer = bitmap_layer_create(GRect(0,0,144,168));
  bitmap_layer_set_bitmap(s_bitmap_layer,s_bg_bitmap);
  
	hp_num_layer = text_layer_create(GRect(0,66,32,32));
  atk_num_layer = text_layer_create(GRect(32+3, 66, 32, 32));
  def_num_layer = text_layer_create(GRect(64+6, 66, 32, 32));
  spatk_num_layer = text_layer_create(GRect(0, 98, 32, 32));
  spdef_num_layer = text_layer_create(GRect(32+3, 98, 32, 32));
  spd_num_layer = text_layer_create(GRect(64+6, 98, 32, 32));
  total_num_layer = text_layer_create(GRect(64+6, 123, 32, 32));
  
  text_layer_set_font(hp_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(hp_num_layer, GColorClear);
	text_layer_set_text_alignment(hp_num_layer, GTextAlignmentCenter);
	
  text_layer_set_font(atk_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(atk_num_layer, GColorClear);
	text_layer_set_text_alignment(atk_num_layer, GTextAlignmentCenter);
  
  text_layer_set_font(def_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(def_num_layer, GColorClear);
	text_layer_set_text_alignment(def_num_layer, GTextAlignmentCenter);
  
  text_layer_set_font(spatk_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(spatk_num_layer, GColorClear);
	text_layer_set_text_alignment(spatk_num_layer, GTextAlignmentCenter);
  
  text_layer_set_font(spdef_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(spdef_num_layer, GColorClear);
	text_layer_set_text_alignment(spdef_num_layer, GTextAlignmentCenter);
  
  text_layer_set_font(spd_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
	text_layer_set_background_color(spd_num_layer, GColorClear);
	text_layer_set_text_alignment(spd_num_layer, GTextAlignmentCenter);
  
  text_layer_set_font(total_num_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_color(total_num_layer, GColorWhite);
	text_layer_set_background_color(total_num_layer, GColorClear);
	text_layer_set_text_alignment(total_num_layer, GTextAlignmentCenter);
  
  inv_layer = inverter_layer_create(GRect(0, 60, 32, 15));
  
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bitmap_layer));
  layer_add_child(layer, text_layer_get_layer(hp_num_layer));
  layer_add_child(layer, text_layer_get_layer(atk_num_layer));
  layer_add_child(layer, text_layer_get_layer(def_num_layer));
  layer_add_child(layer, text_layer_get_layer(spatk_num_layer));
  layer_add_child(layer, text_layer_get_layer(spdef_num_layer));
  layer_add_child(layer, text_layer_get_layer(spd_num_layer));
  layer_add_child(layer, text_layer_get_layer(total_num_layer));
  
  layer_add_child(window_get_root_layer(window), (Layer*) inv_layer);
  
  action_bar = action_bar_layer_create();
	action_bar_layer_add_to_window(action_bar, window);
	action_bar_layer_set_click_config_provider(action_bar, click_config_provider);

	action_bar_layer_set_icon(action_bar, BUTTON_ID_UP, action_icon_plus);
	action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, action_icon_next);
	action_bar_layer_set_icon(action_bar, BUTTON_ID_DOWN, action_icon_minus);
  
  update();
}
Exemplo n.º 8
0
//Обработка загрузки "окна"
void window_load(Window *window)
{
  //Инициализация ресурсов (шрифты/картинки блютуза/батареи)
  ResHandle font_handle42 = resource_get_handle(RESOURCE_ID_IMAGINE_42);
  ResHandle fontv_handle42 = resource_get_handle(RESOURCE_ID_VISITOR_62);
  bt_disconn = gbitmap_create_with_resource(RESOURCE_ID_BT_DISCONNECTED);
  batt_low = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_LOW);
  batt_charg = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING);
  batt_full = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGED);
  //Создание слоёв батареи и блютуза  
  bt_layer = bitmap_layer_create(GRect(5,124,32,32));
  batt_layer = bitmap_layer_create(GRect(107,124,32,32));
  //batp_layer = layer_create(GRect(2,110,140,1));
  //Слой времени
    time_layer = text_layer_create(GRect(4, 56, 144, 56));
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_text_color(time_layer, GColorBlack);
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  text_layer_set_font(time_layer,fonts_load_custom_font(font_handle42));
  //Слой даты  
    date_layer = text_layer_create(GRect(4, 0, 144, 56));
  text_layer_set_background_color(date_layer, GColorClear);
  text_layer_set_text_color(date_layer, GColorBlack);
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  text_layer_set_font(date_layer,fonts_load_custom_font(font_handle42));
  //Слой дня недели    
    wday_layer = text_layer_create(GRect(4, 100, 144, 56));
  text_layer_set_background_color(wday_layer, GColorClear);
  text_layer_set_text_color(wday_layer, GColorBlack);
  text_layer_set_text_alignment(wday_layer, GTextAlignmentCenter);
  text_layer_set_font(wday_layer,fonts_load_custom_font(fontv_handle42));
  //Начальное состояние блютуза
  bt_handler(bluetooth_connection_service_peek());
  //Начальное состояние батареи
  batt_handler(battery_state_service_peek());
  //layer_mark_dirty(batp_layer);
   //"Вывод" слоёв в окно
  layer_add_child(window_get_root_layer(window), (Layer*) time_layer);
  layer_add_child(window_get_root_layer(window), (Layer*) date_layer);
  layer_add_child(window_get_root_layer(window), (Layer*) wday_layer);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bt_layer));
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(batt_layer));
  //layer_set_update_proc(batp_layer,batp_layer_update_callback);
  
  //layer_add_child(window_get_root_layer(window), batp_layer);
  
  
  
  bool lang_rus = persist_read_bool(KEY_LANG);
  //bool show_bb = persist_read_bool(KEY_BATTBAR);
  
  if (lang_rus==true) {
        dow[0]="ВС";
        dow[1]="ПН";
        dow[2]="ВТ";
        dow[3]="СР";
        dow[4]="ЧТ";
        dow[5]="ПТ";
        dow[6]="СБ";
  }
  else {
        dow[0]="SU";
        dow[1]="MO";
        dow[2]="TU";
        dow[3]="WE";
        dow[4]="TH";
        dow[5]="FR";
        dow[6]="SA"; 
  }
   //Ручное начальнок срабатывание "тика", чтобы время не было пустым при открытии
  struct tm *t;
  time_t temp;
  temp = time(NULL);
  t = localtime(&temp);
  tick_handler(t, MINUTE_UNIT);
  //Создание и вывод инвертера
  inv_layer = inverter_layer_create(GRect(0, 56, 144, 56));
  layer_add_child(window_get_root_layer(window), (Layer*) inv_layer);
}
Exemplo n.º 9
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());
}
Exemplo n.º 10
0
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect window_bounds = layer_get_bounds(window_layer);
  
    //Create GFont for clock| Font: Control Freak [by Apostrophic Labs ]
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_time_48));
  
  //create font for date/dow  |Font: NovaSquare [by wmk69 ]
  s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_date_22));
  
  
  //Create background
  s_frame_1 = gbitmap_create_with_resource(RESOURCE_ID_mm_frame_1);
  s_frame_2 = gbitmap_create_with_resource(RESOURCE_ID_mm_frame_2);
  s_frame_3 = gbitmap_create_with_resource(RESOURCE_ID_mm_frame_3);
  s_bg_layer = bitmap_layer_create(window_bounds);
  bitmap_layer_set_bitmap(s_bg_layer,  s_frame_2 );
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bg_layer));
  
  // Create Time 
  s_time_layer = text_layer_create(GRect(1, 12, 148, 50));
  text_layer_set_background_color(s_time_layer, GColorClear);
    text_layer_set_text_color(s_time_layer,GColorWhite); /// black text
  text_layer_set_text(s_time_layer, "00:00");
  

  
  /**
  //battery setup
  s_battery_layer = text_layer_create(GRect(20, 150, window_bounds.size.w, window_bounds.size.h));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); //left align the text in this layer
  text_layer_set_background_color(s_battery_layer, GColorClear); //clear background
  #ifdef PBL_PLATFORM_APLITE //if running on older pebble
    text_layer_set_text_color(s_battery_layer, GColorWhite); /// black text
   #elif PBL_PLATFORM_BASALT  //if running on pebble time
    text_layer_set_text_color(s_battery_layer,GColorBulgarianRose); //red text
  #endif
  text_layer_set_font(s_battery_layer, s_battery_font); //change the font
  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));//Add battery layer to our window
 
  // Get the current battery level
  battery_handler(battery_state_service_peek());
  **/
  
  
  //Create Date layer:
  //s_date_layer = text_layer_create(GRect(20,49, 136, 100)); old
  s_date_layer = text_layer_create(GRect(69,0,130,100));
  text_layer_set_background_color(s_date_layer, GColorClear);
    text_layer_set_text_color(s_date_layer,GColorWhite); /// black text
  
  text_layer_set_font(s_date_layer,  s_date_font);
  layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
  
  
  //Create 'DAY OF WEEK layer:
 // s_dow_layer = text_layer_create(GRect(83,100, 136, 100)); old
  s_dow_layer = text_layer_create(GRect(5,0, 136, 100));
  text_layer_set_background_color(s_dow_layer, GColorClear);
  text_layer_set_text_color(s_dow_layer,  GColorWhite); /// black text

  
  text_layer_set_font(s_dow_layer, s_date_font);
  layer_add_child(window_layer, text_layer_get_layer(s_dow_layer));
 




  //time
  //Apply to TextLayer
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  

  
  // Make sure the time is displayed from the start
  update_time();
}