public void ChangeTheme(String themeName)
        {
            // Ensure to be on Main UI Thread
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => ChangeTheme(themeName));
                return;
            }
            try
            {
                if (String.IsNullOrEmpty(themeName))
                {
                    return;
                }

                String validThemeName = themeName.ToLower();
                if (validThemeName == CurrentThemeName)
                {
                    return;
                }

                ResourceDictionary resourceDictionary = null;
                switch (validThemeName)
                {
                case "light":
                    resourceDictionary = new ThemeLight();
                    break;

                case "dark":
                    resourceDictionary = new ThemeDark();
                    break;

                default:
                    validThemeName     = "light";
                    resourceDictionary = new ThemeLight();
                    break;
                }

                // Clear and set new theme
                ThemeDictionary.Clear();
                ThemeDictionary.Add(resourceDictionary);

                // Store specified theme name
                CurrentThemeName = validThemeName;
            }
            catch { }
        }
Example #2
0
        private void read_config(string path)
        {
            // Read Text file to get responses
            // If config.txt DNE, then create a default one
            if (!System.IO.File.Exists(path))
            {
                using (System.IO.File.Create(path)) { }
                System.IO.File.AppendAllText(path, "theme=dark");
            }

            System.IO.StreamReader file = new System.IO.StreamReader(path);

            // Read line and put into list
            string line;
            string categ;
            string content;

            while ((line = file.ReadLine()) != null)
            {
                categ   = line.Substring(0, line.IndexOf("="));
                content = line.ToLower().Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1);
                if (categ == "theme")
                {
                    switch (content)
                    {
                    case "dark":
                        ThemeDark.PerformClick();
                        break;

                    case "light":
                        ThemeLight.PerformClick();
                        break;

                    case "cute":
                        CuteTheme.PerformClick();
                        break;

                    case "autumn":
                        AutumnTheme.PerformClick();
                        break;
                    }
                }
            }

            file.Close();
        }
Example #3
0
        // Constructor
        private MaterialSkinManager()
        {
            Theme       = new ThemeLight(this);
            ColorScheme = new ColorScheme(Primary.Indigo500, Primary.Indigo700, Primary.Indigo100, Accent.Pink200, TextShade.WHITE);

            // Create and cache Roboto fonts
            // Thanks https://www.codeproject.com/Articles/42041/How-to-Use-a-Font-Without-Installing-it
            // And https://www.codeproject.com/Articles/107376/Embedding-Font-To-Resources

            // Add font to system table in memory and save the font family
            addFont(Resources.Roboto_Thin);
            addFont(Resources.Roboto_Light);
            addFont(Resources.Roboto_Regular);
            addFont(Resources.Roboto_Medium);
            addFont(Resources.Roboto_Bold);
            addFont(Resources.Roboto_Black);

            RobotoFontFamilies = new Dictionary <string, FontFamily>();
            foreach (FontFamily ff in privateFontCollection.Families.ToArray())
            {
                RobotoFontFamilies.Add(ff.Name.Replace(' ', '_'), ff);
            }

            // create and save font handles for GDI
            logicalFonts = new Dictionary <string, IntPtr>(18);
            logicalFonts.Add("H1", createLogicalFont("Roboto Light", 96, NativeTextRenderer.logFontWeight.FW_LIGHT));
            logicalFonts.Add("H2", createLogicalFont("Roboto Light", 60, NativeTextRenderer.logFontWeight.FW_LIGHT));
            logicalFonts.Add("H3", createLogicalFont("Roboto", 48, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("H4", createLogicalFont("Roboto", 34, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("H5", createLogicalFont("Roboto", 24, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("H6", createLogicalFont("Roboto Medium", 20, NativeTextRenderer.logFontWeight.FW_MEDIUM));
            logicalFonts.Add("Subtitle1", createLogicalFont("Roboto", 16, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("Subtitle2", createLogicalFont("Roboto Medium", 14, NativeTextRenderer.logFontWeight.FW_MEDIUM));
            logicalFonts.Add("Body1", createLogicalFont("Roboto", 16, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("Body2", createLogicalFont("Roboto", 14, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("Button", createLogicalFont("Roboto Medium", 14, NativeTextRenderer.logFontWeight.FW_MEDIUM));
            logicalFonts.Add("Caption", createLogicalFont("Roboto", 12, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("Overline", createLogicalFont("Roboto", 10, NativeTextRenderer.logFontWeight.FW_REGULAR));
            // Logical fonts for textbox animation
            logicalFonts.Add("textBox16", createLogicalFont("Roboto", 16, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("textBox15", createLogicalFont("Roboto", 15, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("textBox14", createLogicalFont("Roboto", 14, NativeTextRenderer.logFontWeight.FW_REGULAR));
            logicalFonts.Add("textBox13", createLogicalFont("Roboto Medium", 13, NativeTextRenderer.logFontWeight.FW_MEDIUM));
            logicalFonts.Add("textBox12", createLogicalFont("Roboto Medium", 12, NativeTextRenderer.logFontWeight.FW_MEDIUM));
        }