Inheritance: IResourceCandidate
Esempio n. 1
0
        public static string Convert(ResourceCandidate resourceCandidate, string defaultLanguage)
        {
            try
            {
                ValidatePlatform(resourceCandidate);

                var language  = GetLanguage(resourceCandidate);
                var directory = Path.GetDirectoryName(resourceCandidate.LogicalPath);
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(resourceCandidate.LogicalPath);
                var scale     = GetScale(resourceCandidate);
                var extension = Path.GetExtension(resourceCandidate.LogicalPath).ToLowerInvariant();

                return(Path.Combine(language, directory, $"{fileNameWithoutExtension}{scale}{extension}"));
            }
#if HAS_UNO
            catch (Exception ex)
            {
                ex.Log().Info($"Couldn't convert {resourceCandidate.ValueAsString} to an iOS resource path.", ex);
#else
            catch (Exception)
            {
#endif
                return(null);
            }
        }
Esempio n. 2
0
        private static void ValidatePlatform(ResourceCandidate resourceCandidate)
        {
            var custom = resourceCandidate.GetQualifierValue("custom");

            if (custom != null && custom != "ios")
            {
                throw new NotSupportedException($"Custom qualifier of value {custom} is not supported on iOS.");
            }
        }
Esempio n. 3
0
        private static void ValidateResourceName(ResourceCandidate resourceCandidate)
        {
            var resourceName = Path.GetFileName(resourceCandidate.LogicalPath).Split(new char[] { '.' })[0];

            if (string.IsNullOrWhiteSpace(resourceName) || !ValidResourceName.IsMatch(resourceName))
            {
                throw new NotSupportedException($"Resource name {resourceName} is not supported on Android.");
            }
        }
Esempio n. 4
0
        private static string GetLanguage(ResourceCandidate resourceCandidate)
        {
            var language = resourceCandidate.GetQualifierValue("language");

            if (language == null)
            {
                return("");
            }

            if (language.Contains("-"))
            {
                language = language.Replace("-", "_");
            }

            return($"{language}.lproj");
        }
Esempio n. 5
0
        public static string?Convert(ResourceCandidate resourceCandidate, string defaultLanguage)
        {
            try
            {
                ValidatePlatform(resourceCandidate);

                var language = GetLanguage(resourceCandidate.GetQualifierValue("language"), defaultLanguage);
                var dpi      = GetDpi(resourceCandidate.GetQualifierValue("scale"));
                var fileName = AndroidResourceNameEncoder.Encode(Path.GetFileNameWithoutExtension(resourceCandidate.LogicalPath)) + Path.GetExtension(resourceCandidate.LogicalPath);
                return(Path.Combine($"drawable{language}{dpi}", fileName));
            }
            catch (Exception ex)
            {
                ex.Log().Info($"Couldn't convert {resourceCandidate.ValueAsString} to an Android resource path.", ex);
                return(null);
            }
        }
Esempio n. 6
0
        private static string GetScale(ResourceCandidate resourceCandidate)
        {
            var scale = resourceCandidate.GetQualifierValue("scale");

            switch (scale)
            {
            case null:
            case "100":
                return("");

            case "200":
                return("@2x");

            case "300":
                return("@3x");

            default:
                throw new NotSupportedException($"Scale qualifier of value {scale} is not supported on iOS.");
            }
        }
Esempio n. 7
0
        public static string?Convert(ResourceCandidate resourceCandidate, string defaultLanguage)
        {
            try
            {
                ValidatePlatform(resourceCandidate);

                var language = GetLanguage(resourceCandidate.GetQualifierValue("language"), defaultLanguage);
                var dpi      = GetDpi(resourceCandidate.GetQualifierValue("scale"));
                var theme    = GetTheme(resourceCandidate.GetQualifierValue("theme"));
                var fileName = AndroidResourceNameEncoder.EncodeDrawablePath(resourceCandidate.LogicalPath);

                return(Path.Combine($"drawable{language}{theme}{dpi}", fileName));
            }
#if HAS_UNO
            catch (Exception ex)
            {
                ex.Log().Info($"Couldn't convert {resourceCandidate.ValueAsString} to an Android resource path.", ex);
#else
            catch (Exception)
            {
#endif
                return(null);
            }
        }