Ejemplo n.º 1
0
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, 50, bounds.size.w, 100));
  text_layer_set_text(s_text_layer, "App configuration choices will be reflected here!");
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(s_text_layer, GColorClear);
  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));

  // Read saved config 
  if(persist_read_bool(KEY_HIGH_CONTRAST)) {
    // Apply high contrast mode
    window_set_background_color(s_main_window, GColorBlack);
    text_layer_set_text_color(s_text_layer, GColorWhite);
  } else {
#ifdef PBL_SDK_2
    // Not available, use normal colors
#elif PBL_SDK_3
    // Use background color setting
    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);
    text_layer_set_text_color(s_text_layer, gcolor_is_dark(bg_color) ? GColorWhite : GColorBlack);    
#endif
  }
}
Ejemplo n.º 2
0
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
  // High contrast selected?
  Tuple *high_contrast_t = dict_find(iter, KEY_HIGH_CONTRAST);
  if(high_contrast_t && high_contrast_t->value->int32 > 0) {
    // Change color scheme
    window_set_background_color(s_main_window, GColorBlack);
    text_layer_set_text_color(s_text_layer, GColorWhite);

    // Persist value
    persist_write_bool(KEY_HIGH_CONTRAST, true);
  } else {
    persist_write_bool(KEY_HIGH_CONTRAST, false);
  }

  // Color scheme?
  Tuple *color_red_t = dict_find(iter, KEY_COLOR_RED);
  Tuple *color_green_t = dict_find(iter, KEY_COLOR_GREEN);
  Tuple *color_blue_t = dict_find(iter, KEY_COLOR_BLUE);
  if(color_red_t && color_green_t && color_blue_t) {
    // Apply the color if available
#ifdef PBL_SDK_2
    window_set_background_color(s_main_window, GColorWhite);
    text_layer_set_text_color(s_text_layer, GColorBlack);
#elif PBL_SDK_3 
    int red = color_red_t->value->int32;
    int green = color_green_t->value->int32;
    int blue = color_blue_t->value->int32;

    // Persist values
    persist_write_int(KEY_COLOR_RED, red);
    persist_write_int(KEY_COLOR_GREEN, green);
    persist_write_int(KEY_COLOR_BLUE, blue);

    GColor bg_color = GColorFromRGB(red, green, blue);
    window_set_background_color(s_main_window, bg_color);
    text_layer_set_text_color(s_text_layer, gcolor_is_dark(bg_color) ? GColorWhite : GColorBlack);    
#endif
  }
}
Ejemplo n.º 3
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
	// Weather -------------------------------------------------------------------
	static char temperature_buffer[8];
	static char weather_layer_buffer[8];
	int temperature = 0;
	Tuple *temp_tuple = dict_find(iterator, KEY_TEMPERATURE);
	static int temp_in_c;
	if( temp_tuple ) {
		temp_in_c = (int)temp_tuple->value->int32;
		if( persist_read_bool(KEY_WEATHER_UNIT) == true ) {
			temperature = convert_to_fahrenheit(temp_in_c);
		} else {
			temperature = temp_in_c;
		}
	}
	Tuple *unit_tuple = dict_find(iterator, KEY_WEATHER_UNIT);
	if( unit_tuple && unit_tuple->value->int8 > 0 ) {
		// USE CELCIOUS UNITS
		persist_write_bool(KEY_WEATHER_UNIT, false);
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Units are C\n");
		temperature = temp_in_c;
	} else if( unit_tuple && unit_tuple->value->int8 <= 0 ) {
		// USEFARIENHEIT
		persist_write_bool(KEY_WEATHER_UNIT, true);
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Units are F\n");
		temperature = convert_to_fahrenheit(temp_in_c);
	}
	snprintf(temperature_buffer, sizeof(temperature_buffer), "%d", temperature);
	snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s°", temperature_buffer);
	text_layer_set_text(s_weather_textLayer, weather_layer_buffer);
	// End Weather ---------------------------------------------------------------

	// Configuration -------------------------------------------------------------
	// Color ===================
	#if defined(PBL_COLOR)
	  Tuple *color_red_accent = dict_find(iterator, KEY_COLOR_RED_ACCENT);
	  Tuple *color_green_accent = dict_find(iterator, KEY_COLOR_GREEN_ACCENT);
	  Tuple *color_blue_accent = dict_find(iterator, KEY_COLOR_BLUE_ACCENT);
	  Tuple *color_red_time = dict_find(iterator, KEY_COLOR_RED_TIME);
	  Tuple *color_green_time = dict_find(iterator, KEY_COLOR_GREEN_TIME);
	  Tuple *color_blue_time = dict_find(iterator, KEY_COLOR_BLUE_TIME);
	  if(color_red_accent && color_green_accent && color_blue_accent) {
	    // Apply the color if available
	  
	    int red_accent = color_red_accent->value->int32;
	    int green_accent = color_green_accent->value->int32;
	    int blue_accent = color_blue_accent->value->int32;

	    // Persist values
	    persist_write_int(KEY_COLOR_RED_ACCENT, red_accent);
	    persist_write_int(KEY_COLOR_GREEN_ACCENT, green_accent);
	    persist_write_int(KEY_COLOR_BLUE_ACCENT, blue_accent);

	    GColor bg_color_accent = GColorFromRGB(red_accent, green_accent, blue_accent);
	    text_layer_set_background_color(s_ui_top, bg_color_accent);
	    text_layer_set_background_color(s_ui_bottom, bg_color_accent);

	    text_layer_set_text_color(s_dayOfWeek_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	    text_layer_set_text_color(s_date_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	    text_layer_set_text_color(s_weather_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	  }
	  
	  if(color_red_time && color_green_time && color_blue_time) {
	    // Apply the color if available
	    int red_time = color_red_time->value->int32;
	    int green_time = color_green_time->value->int32;
	    int blue_time = color_blue_time->value->int32;

	    // Persist values
	    persist_write_int(KEY_COLOR_RED_TIME, red_time);
	    persist_write_int(KEY_COLOR_GREEN_TIME, green_time);
	    persist_write_int(KEY_COLOR_BLUE_TIME, blue_time);

	    GColor bg_color_time = GColorFromRGB(red_time, green_time, blue_time);
	    window_set_background_color(s_main_window, bg_color_time);

	    text_layer_set_text_color(s_time_textLayer, gcolor_is_dark(bg_color_time) ? GColorWhite : GColorBlack);
	  }
	 #endif
	// End Color ===============

	// Date Format
	static char temporary_date_holder_callback[32];
	Tuple *date_format_tuple = dict_find(iterator, KEY_DATE_FORMAT);
	if( date_format_tuple ) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date Tuple Worked!\n");
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Value Recieved from Date Tuple: %d\n", (int)date_format_tuple->value->int8);
	} else {
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date Tuple Failed\n");
	}
	if( date_format_tuple && date_format_tuple->value->int8 == 49 ) {
		snprintf(temporary_date_holder_callback, sizeof(temporary_date_holder_callback), "%s.%s", day_tickTime, month_tickTime);
		// snprintf(dateWithoutYear, sizeof(dateWithoutYear), "\0");
		snprintf(ddmm_dateWithoutYear, sizeof(ddmm_dateWithoutYear), "%s", temporary_date_holder_callback);
		persist_write_int(KEY_DATE_FORMAT, 1);
		text_layer_set_text(s_date_textLayer, temporary_date_holder_callback);
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date was updated as DD-MM 1\n");
	} else if( date_format_tuple && date_format_tuple->value->int8 == 48 ){
		snprintf(temporary_date_holder_callback, sizeof(temporary_date_holder_callback), "%s.%s", month_tickTime, day_tickTime);
		// snprintf(dateWithoutYear, sizeof(dateWithoutYear), "\0");
		snprintf(dateWithoutYear, sizeof(dateWithoutYear), "%s", temporary_date_holder_callback);
		persist_write_int(KEY_DATE_FORMAT, 0);
		text_layer_set_text(s_date_textLayer, temporary_date_holder_callback);
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date was updated as MM-DD 1\n");
	}

	// Add year or not
	static char temporary_dateWithoutYear_holder_update[32];
	Tuple *year_is_displayed_tuple = dict_find(iterator, KEY_DATE_ADD_YEAR);
	if( year_is_displayed_tuple && year_is_displayed_tuple->value->int8 > 0 ) {
		if( persist_read_int(KEY_DATE_FORMAT) == 1 ) {
			strcpy(temporary_dateWithoutYear_holder_update, ddmm_dateWithoutYear);
		}
		else if( persist_read_int(KEY_DATE_FORMAT) == 0 ) {
			strcpy(temporary_dateWithoutYear_holder_update, dateWithoutYear);
		}
		strcat(temporary_dateWithoutYear_holder_update, year_tickTime);
		persist_write_bool(KEY_DATE_ADD_YEAR, true);
		text_layer_set_text(s_date_textLayer, temporary_dateWithoutYear_holder_update);
	} else if( year_is_displayed_tuple && year_is_displayed_tuple->value->int8 <= 0 ) {
		persist_write_bool(KEY_DATE_ADD_YEAR, false);
		if( persist_read_int(KEY_DATE_FORMAT) == 1 )
			text_layer_set_text(s_date_textLayer, ddmm_dateWithoutYear);
		else
			text_layer_set_text(s_date_textLayer, dateWithoutYear);
	}

	// Language Handing On Callback			
	Tuple *lang_is_eng_tuple = dict_find(iterator, KEY_LANGUAGE);
	if( lang_is_eng_tuple ) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: lang Tuple Worked!\n");
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Value Recieved from lang Tuple: %d\n", (int)lang_is_eng_tuple->value->int8);
	} else {
		APP_LOG(APP_LOG_LEVEL_INFO, "Callback: lang Tuple Failed\n");
	}
	if( lang_is_eng_tuple && lang_is_eng_tuple->value->int8 == 49 ) {
		// Time to convert this to spanish
		int dayOfWeekInt = atoi(dayOfWeekNumber_tickTime);
		static char temporary_day_of_week_holder_callback[8];
		switch(dayOfWeekInt) {
			case 0:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Dom");
			break;
			case 1:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Lun");
			break;
			case 2:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Mar");
			break;
			case 3:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Mie");
			break;
			case 4:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Jue");
			break;
			case 5:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Vie");
			break;
			case 6:
				snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Sab");
			break;
			default:
				text_layer_set_text(s_dayOfWeek_textLayer, temporary_day_of_week_holder_callback);
			break;
		}
		persist_write_int(KEY_LANGUAGE, 1);
		text_layer_set_text(s_dayOfWeek_textLayer, temporary_day_of_week_holder_callback);
	} else if( lang_is_eng_tuple && lang_is_eng_tuple->value->int8 == 48 ) {
		persist_write_int(KEY_LANGUAGE, 0);
		// English
		text_layer_set_text(s_dayOfWeek_textLayer, engDayOfWeek_tickTime);
	}
	// End Configuration ---------------------------------------------------------
}
Ejemplo n.º 4
0
static void main_window_load(Window *window) {
	// Get information about the Window
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);

	// Create Layers
	s_time_textLayer = text_layer_create(
	    GRect(0, PBL_IF_ROUND_ELSE(58, 52), bounds.size.w, 50));
	s_weather_textLayer = text_layer_create(
		GRect(PBL_IF_ROUND_ELSE(65, 5), PBL_IF_ROUND_ELSE(0, 2), PBL_IF_ROUND_ELSE(70, bounds.size.w), 50));
	s_dayOfWeek_textLayer = text_layer_create(
		GRect(PBL_IF_ROUND_ELSE(30, -5), PBL_IF_ROUND_ELSE(25, 2), bounds.size.w, 50));
	s_date_textLayer = text_layer_create(
		GRect(0, PBL_IF_ROUND_ELSE(105, 115), PBL_IF_ROUND_ELSE(bounds.size.w-31, bounds.size.w-3), 50));
	// UI Layers
	s_ui_top = text_layer_create(
		GRect(0,0,bounds.size.w,PBL_IF_ROUND_ELSE(70,52)));
	s_ui_bottom = text_layer_create(
		GRect(0,PBL_IF_ROUND_ELSE(110,117),bounds.size.w,100));

	// Setup Background colors
	text_layer_set_background_color(s_time_textLayer, 		GColorClear);
	text_layer_set_background_color(s_weather_textLayer, 	GColorClear);
	text_layer_set_background_color(s_dayOfWeek_textLayer,	GColorClear);
	text_layer_set_background_color(s_date_textLayer,		GColorClear);

	// Setup Text Colors
	text_layer_set_text_color(s_time_textLayer, 			GColorBlack);
	text_layer_set_text_color(s_weather_textLayer,			GColorWhite);
	text_layer_set_text_color(s_dayOfWeek_textLayer,		GColorWhite);
	text_layer_set_text_color(s_date_textLayer,				GColorWhite);

	// Setup Font Styles
	time_font = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
	nonTime_font = fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT);
	text_layer_set_font(s_time_textLayer, time_font);
	// text_layer_set_font(s_time_textLayer, s_time_gfont);
	text_layer_set_font(s_weather_textLayer, nonTime_font);
	text_layer_set_font(s_dayOfWeek_textLayer, nonTime_font);
	text_layer_set_font(s_date_textLayer, nonTime_font);

	// Format Text alignments
	text_layer_set_text_alignment(s_time_textLayer, 		GTextAlignmentCenter);
	text_layer_set_text_alignment(s_weather_textLayer,		GTextAlignmentRight);
	text_layer_set_text_alignment(s_dayOfWeek_textLayer,	GTextAlignmentLeft);
	text_layer_set_text_alignment(s_date_textLayer,			GTextAlignmentRight);

	// Optionally, Add Text to the layer as a placeholder
	text_layer_set_text(s_weather_textLayer, "...");
		
	// Perform Color Changes!
	#if defined(PBL_BW)
		text_layer_set_background_color(s_ui_top,				GColorBlack);
		text_layer_set_background_color(s_ui_bottom,			GColorBlack);
  	#elif defined(PBL_COLOR)
	    // Accent Color Setting
	    int red_accent = persist_read_int(KEY_COLOR_RED_ACCENT);
	    int green_accent = persist_read_int(KEY_COLOR_GREEN_ACCENT);
	    int blue_accent = persist_read_int(KEY_COLOR_BLUE_ACCENT);

	    // APP_LOG(APP_LOG_LEVEL_INFO, "color is %d". bg_color_accent);
		// APP_LOG(APP_LOG_LEVEL_INFO, "accent color is rgb %d %d %d", red_accent, green_accent,blue_accent);
	    if(red_accent >= 0 && green_accent >= 0 && blue_accent >= 0) {
	    	GColor bg_color_accent = GColorFromRGB(red_accent, green_accent, blue_accent);
	    	
	    	text_layer_set_background_color(s_ui_top, bg_color_accent);
	    	text_layer_set_background_color(s_ui_bottom, bg_color_accent);
	    	text_layer_set_text_color(s_dayOfWeek_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	    	text_layer_set_text_color(s_date_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	    	text_layer_set_text_color(s_weather_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack);
	    }
	    // Time Color Setting
	    int red_time = persist_read_int(KEY_COLOR_RED_TIME);
	    int green_time = persist_read_int(KEY_COLOR_GREEN_TIME);
	    int blue_time = persist_read_int(KEY_COLOR_BLUE_TIME);

	    if(red_time >= 0 && green_time >= 0 && blue_time >= 0) {
	    	GColor bg_color_time = GColorFromRGB(red_time, green_time, blue_time);
	    	
	    	window_set_background_color(s_main_window, bg_color_time);
	    	text_layer_set_text_color(s_time_textLayer, gcolor_is_dark(bg_color_time) ? GColorWhite : GColorBlack);
	    }
    #endif

	// UI
	layer_add_child(window_layer, text_layer_get_layer(s_ui_top));
	layer_add_child(window_layer, text_layer_get_layer(s_ui_bottom));
	// Add Layers as Children to window.
	layer_add_child(window_layer, text_layer_get_layer(s_time_textLayer));
	layer_add_child(window_layer, text_layer_get_layer(s_weather_textLayer));
	layer_add_child(window_layer, text_layer_get_layer(s_dayOfWeek_textLayer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_textLayer));
	// Don't forget to destroy all layers below.
}