Created
May 22, 2015 22:27
-
-
Save haristhohir/3a805ccc5e056e1ba5bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getFormattedWind(Context context, float windSpeed, float degrees) { | |
int windFormat; | |
if (Utility.isMetric(context)) { | |
windFormat = R.string.format_wind_kmh; | |
} else { | |
windFormat = R.string.format_wind_mph; | |
windSpeed = .621371192237334f * windSpeed; | |
} | |
// From wind direction in degrees, determine compass direction as a string (e.g NW) | |
// You know what's fun, writing really long if/else statements with tons of possible | |
// conditions. Seriously, try it! | |
String direction = "Unknown"; | |
if (degrees >= 337.5 || degrees < 22.5) { | |
direction = "N"; | |
} else if (degrees >= 22.5 && degrees < 67.5) { | |
direction = "NE"; | |
} else if (degrees >= 67.5 && degrees < 112.5) { | |
direction = "E"; | |
} else if (degrees >= 112.5 && degrees < 157.5) { | |
direction = "SE"; | |
} else if (degrees >= 157.5 && degrees < 202.5) { | |
direction = "S"; | |
} else if (degrees >= 202.5 && degrees < 247.5) { | |
direction = "SW"; | |
} else if (degrees >= 247.5 && degrees < 292.5) { | |
direction = "W"; | |
} else if (degrees >= 292.5 && degrees < 337.5) { | |
direction = "NW"; | |
} | |
return String.format(context.getString(windFormat), windSpeed, direction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment