Skip to content

Instantly share code, notes, and snippets.

@dekzitfz
Created May 6, 2017 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekzitfz/999080c5e2ca605db62b3dc88e70f651 to your computer and use it in GitHub Desktop.
Save dekzitfz/999080c5e2ca605db62b3dc88e70f651 to your computer and use it in GitHub Desktop.
public final class SunshineWeatherUtils {
private final static String TAG = SunshineWeatherUtils.class.getSimpleName();
public static String formatTemperature(Context context, double temperature) {
int temperatureFormatResourceId = R.string.format_temperature;
return String.format(context.getString(temperatureFormatResourceId), temperature);
}
public static int getSmallArtResourceIdForWeatherCondition(int weatherId) {
/*
* Based on weather code data for Open Weather Map.
*/
if (weatherId >= 200 && weatherId <= 232) {
return R.drawable.ic_storm;
} else if (weatherId >= 300 && weatherId <= 321) {
return R.drawable.ic_light_rain;
} else if (weatherId >= 500 && weatherId <= 504) {
return R.drawable.ic_rain;
} else if (weatherId == 511) {
return R.drawable.ic_snow;
} else if (weatherId >= 520 && weatherId <= 531) {
return R.drawable.ic_rain;
} else if (weatherId >= 600 && weatherId <= 622) {
return R.drawable.ic_snow;
} else if (weatherId >= 701 && weatherId <= 761) {
return R.drawable.ic_fog;
} else if (weatherId == 761 || weatherId == 771 || weatherId == 781) {
return R.drawable.ic_storm;
} else if (weatherId == 800) {
return R.drawable.ic_clear;
} else if (weatherId == 801) {
return R.drawable.ic_light_clouds;
} else if (weatherId >= 802 && weatherId <= 804) {
return R.drawable.ic_cloudy;
} else if (weatherId >= 900 && weatherId <= 906) {
return R.drawable.ic_storm;
} else if (weatherId >= 958 && weatherId <= 962) {
return R.drawable.ic_storm;
} else if (weatherId >= 951 && weatherId <= 957) {
return R.drawable.ic_clear;
}
Log.e(TAG, "Unknown Weather: " + weatherId);
return R.drawable.ic_storm;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment