def hex_to_rgba(hex_str):
    """
    Converts hexadecimal number to RGBA tuple in following formats:
        - "RRGGBB" (2F2F2F)
        - "AARRGGBB" (882F2F2F)
        - "RGB" (CCC)
    :param hex_str: str, hexadecimal string
    :return: tuple(float, float, float, float), color tuple (R, G, B, A)
    """
    if hex_str.startswith('#'):
        hex_str = hex_str[1:]
    if len(hex_str) == 8:
        return int(hex_str[2:4], 16), int(hex_str[4:6], 16), int(hex_str[6:
            8], 16), int(hex_str[0:2], 16)
    elif len(hex_str) == 6:
        return int(hex_str[0:2], 16), int(hex_str[2:4], 16), int(hex_str[4:
            6], 16), 255
    elif len(hex_str) == 3:
        return int(hex_str[0:1] * 2, 16), int(hex_str[1:2] * 2, 16), int(
            hex_str[2:3] * 2, 16), 255
    else:
        raise Exception('Invalid hex length: {} ({})'.format(hex_str, len(
            hex_str)))
