Ejemplo n.º 1
0
        public MATCH_ID Matcher(MATCH_ID count, String toMatch, out bool result)
        {
            bool found     = false;
            int  lastCount = 0;

            for (int i = (int)count; i < MatchStringsStart.Count; i++)
            {
                lastCount = i;
                List <String> matchList = MatchStringsStart[i];
                for (int j = 0; j < matchList.Count; j++)
                {
                    String s = matchList[j];
                    if (toMatch.StartsWith(s))
                    {
                        List <String> matchListEnd = MatchStringsEnd[i];
                        if (matchListEnd.Count == 0)
                        {
                            found = true;
                            break;
                        }
                        else
                        {
                            String es = matchListEnd[j];
                            if (toMatch.EndsWith(es))
                            {
                                found = true;
                                break;
                            }
                        }
                    }
                }
                if (found)
                {
                    break;
                }
            }
            result = found;
            return((MATCH_ID)lastCount);
        }
Ejemplo n.º 2
0
        public void Tester(String[] directories, String directoryType, ref List <DynamicResource> clearedDirectoryList)
        {
            foreach (String dirName in directories)
            {
                if (dirName == directoryType) //Lets always add this
                {
                    DynamicResource dr = new DynamicResource();
                    dr.orientation = DynamicResource.PORTRAIT | DynamicResource.LANDSCAPE;
                    dr.data        = dirName;
                    clearedDirectoryList.Add(dr);
                }
                else
                {
                    String[] dirResourceTypes = dirName.Split(new char[] { '-' });

                    MATCH_ID count       = 0;
                    bool     result      = false;
                    int      orientation = DynamicResource.PORTRAIT | DynamicResource.LANDSCAPE;
                    foreach (String toMatch in dirResourceTypes)
                    {
                        if (toMatch == directoryType)
                        {
                            continue;
                        }
                        result = false; //Lets check other guys
                        count  = Matcher(count, toMatch, out result);
                        if (result == false)
                        {
#if !NETFX_CORE
                            String replaced = System.Threading.Thread.CurrentThread.CurrentCulture.Name.Replace("-", "-r");
                            if (toMatch == System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName
#else
                            String replaced = CultureInfo.CurrentCulture.Name.Replace("-", "-r");
                            if (toMatch == CultureInfo.CurrentCulture.TwoLetterISOLanguageName
#endif
                                || dirName.Contains(replaced))
                            {
                                result = true;
                                count  = MATCH_ID.LANGUAGE;
                            }
                        }
                        else
                        {
                            switch (count)
                            {
                            case MATCH_ID.LAYOUT_DIRECTION:
                            {
                            } break;

                            case MATCH_ID.SMALLEST_WIDTH:
                            {
#if !NETFX_CORE
                                int height = (int)Application.Current.Host.Content.ActualHeight;
                                int width  = (int)Application.Current.Host.Content.ActualWidth;
#else
                                int height = (int)Window.Current.Bounds.Height;
                                int width  = (int)Window.Current.Bounds.Width;
#endif
                                int sw = width;
                                if (height < width)
                                {
                                    sw = height;
                                }
                                String swWidthS = toMatch.Substring(2, toMatch.Length - 2);
                                int    swWidth  = Convert.ToInt32(swWidthS);
                                if (sw >= swWidth)
                                {
                                    result = true;
                                }
                            } break;

                            case MATCH_ID.AVAILABLE_WIDTH:
                            {
#if !NETFX_CORE
                                int sw = (int)Application.Current.Host.Content.ActualWidth;
#else
                                int sw = (int)Window.Current.Bounds.Width;
#endif
                                String swWidthS = toMatch.Substring(1, toMatch.Length - 2);
                                int    swWidth  = Convert.ToInt32(swWidthS);
                                if (sw >= swWidth)
                                {
                                    result = true;
                                }
                            } break;

                            case MATCH_ID.AVAILABLE_HEIGHT:
                            {
#if !NETFX_CORE
                                int sh = (int)Application.Current.Host.Content.ActualHeight;
#else
                                int sh = (int)Window.Current.Bounds.Height;
#endif
                                String swWidthS = toMatch.Substring(1, toMatch.Length - 2);
                                int    swWidth  = Convert.ToInt32(swWidthS);
                                if (sh >= swWidth)
                                {
                                    result = true;
                                }
                            } break;

                            case MATCH_ID.SCREEN_SIZE:
                            {
#if WINDOWS_PHONE
                                if (toMatch == "large")
                                {
                                    if (System.Environment.OSVersion.Version.Major == 7)
                                    {
                                        result = true;
                                    }
                                }
                                else if (toMatch == "xlarge")
                                {
                                    if (System.Environment.OSVersion.Version.Major >= 8)
                                    {
                                        result = true;
                                    }
                                }
#elif NETFX_CORE
                                if (toMatch == "xlarge")
                                {
                                    result = true;
                                }
#else
                                //Add other platforms here
#endif
                            } break;

                            case MATCH_ID.SCREEN_ORIENTATION:
                            {
                                if (toMatch == "port")
                                {
                                    orientation = DynamicResource.PORTRAIT;
                                }
                                else
                                {
                                    orientation = DynamicResource.LANDSCAPE;
                                }
                                result = true;
                            } break;

                            case MATCH_ID.SCREEN_PIXEL_DENSITY:
                            {
#if NETFX_CORE
                                if (toMatch == "xhdpi")
                                {
                                    result = true;
                                }
#else
                                if (toMatch == "mdpi")
                                {
                                    if (ResolutionHelper.CurrentResolution == Resolution.WVGA)
                                    {
                                        result = true;
                                    }
                                }
                                else if (toMatch == "hdpi")
                                {
                                    if (ResolutionHelper.CurrentResolution == Resolution.WXGA || ResolutionHelper.CurrentResolution == Resolution.HD720p)
                                    {
                                        result = true;
                                    }
                                }
#endif
                            } break;

                            case MATCH_ID.VERSION:
                            {
                                String versionS = toMatch.Substring(1);
                                Int32  version  = Convert.ToInt32(versionS);
#if WINDOWS_PHONE
                                int major = System.Environment.OSVersion.Version.Major;
                                int minor = System.Environment.OSVersion.Version.Minor;

                                int tempVer = 0;
                                if (major == 7 && minor > 0 && minor < 10)
                                {
                                    tempVer = 9;
                                }
                                else if (major == 7 && minor >= 10)
                                {
                                    tempVer = 10;
                                }
                                else if (major == 8)
                                {
                                    tempVer = 11;
                                }

                                if (tempVer >= version)
                                {
                                    result = true;
                                }
#elif NETFX_CORE
                                if (11 >= version)         //WinRt has one version for now
                                {
                                    result = true;
                                }
#else
#endif
                            } break;
                            }
                            ;
                        }
                    }
                    if (result) //We found a match
                    {
                        DynamicResource dr = new DynamicResource();
                        dr.orientation = orientation;
                        dr.data        = dirName;
                        clearedDirectoryList.Add(dr);
                    }
                }
            }
        }