void init(IAttributeSet attrs)
		{
			if (attrs != null)
			{
				var a = Context.ObtainStyledAttributes (attrs, Resource.Styleable.FlatUI);

				var themeName = a.GetString (Resource.Styleable.FlatUI_theme) ?? string.Empty;

				theme = FlatUI.GetTheme (themeName);

				textColor = a.GetInt (Resource.Styleable.FlatUI_textColor, textColor);
				backgroundColor = a.GetInt (Resource.Styleable.FlatUI_backgroundColor, backgroundColor);
				customBackgroundColor = a.GetInt (Resource.Styleable.FlatUI_customBackgroundColor, customBackgroundColor);
				cornerRadius = a.GetInt (Resource.Styleable.FlatUI_cornerRadius, cornerRadius);

				Enum.TryParse<FlatUI.FlatFontFamily> (
					a.GetInt (Resource.Styleable.FlatUI_fontFamily, (int)fontFamily).ToString (), out fontFamily);
				Enum.TryParse<FlatUI.FlatFontWeight> (
					a.GetInt (Resource.Styleable.FlatUI_fontWeight, (int)fontWeight).ToString (), out fontWeight);

				a.Recycle ();
			}

			SetTheme (this, theme, fontFamily, fontWeight, textColor, backgroundColor, customBackgroundColor, cornerRadius);

		}
		void init(IAttributeSet attrs)
		{
			if (attrs != null)
			{
				var a = Context.ObtainStyledAttributes (attrs, Resource.Styleable.FlatUI);

				var themeName = a.GetString (Resource.Styleable.FlatUI_theme) ?? string.Empty;

				theme = FlatUI.GetTheme (themeName);

				style = a.GetInt (Resource.Styleable.FlatUI_fieldStyle, 0);
				radius = a.GetDimensionPixelSize (Resource.Styleable.FlatUI_cornerRadius, radius);
				padding = a.GetDimensionPixelSize (Resource.Styleable.FlatUI_textPadding, padding);

				Enum.TryParse<FlatUI.FlatTextAppearance> (
					a.GetInt (Resource.Styleable.FlatUI_textAppearance, (int)textAppearance).ToString (), out textAppearance);
				Enum.TryParse<FlatUI.FlatFontFamily> (
					a.GetInt (Resource.Styleable.FlatUI_fontFamily, (int)fontFamily).ToString (), out fontFamily);
				Enum.TryParse<FlatUI.FlatFontWeight> (
					a.GetInt (Resource.Styleable.FlatUI_fontWeight, (int)fontWeight).ToString (), out fontWeight);

				a.Recycle ();
			}

			SetTheme (this, theme, fontFamily, fontWeight, textAppearance, style, radius, padding, border);
		}
        void init(IAttributeSet attrs)
        {
            if (attrs != null)
            {
                var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.FlatUI);

                var themeName = a.GetString(Resource.Styleable.FlatUI_theme) ?? string.Empty;

                theme = FlatUI.GetTheme(themeName);

                style   = a.GetInt(Resource.Styleable.FlatUI_fieldStyle, 0);
                radius  = a.GetDimensionPixelSize(Resource.Styleable.FlatUI_cornerRadius, radius);
                padding = a.GetDimensionPixelSize(Resource.Styleable.FlatUI_textPadding, padding);

                Enum.TryParse <FlatUI.FlatTextAppearance> (
                    a.GetInt(Resource.Styleable.FlatUI_textAppearance, (int)textAppearance).ToString(), out textAppearance);
                Enum.TryParse <FlatUI.FlatFontFamily> (
                    a.GetInt(Resource.Styleable.FlatUI_fontFamily, (int)fontFamily).ToString(), out fontFamily);
                Enum.TryParse <FlatUI.FlatFontWeight> (
                    a.GetInt(Resource.Styleable.FlatUI_fontWeight, (int)fontWeight).ToString(), out fontWeight);

                a.Recycle();
            }

            SetTheme(this, theme, fontFamily, fontWeight, textAppearance, style, radius, padding, border);
        }
 static FlatUI()
 {
     DefaultTheme          = FlatTheme.Blood();
     DefaultFontWeight     = FlatFontWeight.Regular;
     DefaultFontFamily     = FlatFontFamily.Roboto;
     DefaultTextAppearance = FlatTextAppearance.Light;
 }
Exemple #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            //Ask for action bar to show
            Window.RequestFeature(WindowFeatures.ActionBar);

            //Setup our action bar title and icon
            ActionBar.Title = "FlatUI.Xamarin Sample";
            ActionBar.SetIcon(Android.Resource.Drawable.IcMenuInfoDetails);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.NormalMain);

            //Create a custom theme very easily!
            var customJabbrTheme = new FlatUI.FlatTheme()
            {
                DarkAccentColor      = Android.Graphics.Color.ParseColor("#00103f"),
                BackgroundColor      = Android.Graphics.Color.ParseColor("#003259"),
                LightAccentColor     = Android.Graphics.Color.ParseColor("#005191"),
                VeryLightAccentColor = Android.Graphics.Color.ParseColor("#719fc3")
            };

            //Register the them so it will show up when we ask FlatUI for all the available themes
            FlatUI.FlatUI.RegisterCustomTheme("jabbr", customJabbrTheme);

            //Change the theme to our custom one by default
            ChangeTheme(customJabbrTheme);
        }
Exemple #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            //Ask for action bar to show
            Window.RequestFeature (WindowFeatures.ActionBar);

            //Setup our action bar title and icon
            ActionBar.Title = "FlatUI.Xamarin Sample";
            ActionBar.SetIcon (Android.Resource.Drawable.IcMenuInfoDetails);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.NormalMain);

            //Create a custom theme very easily!
            var customJabbrTheme = new FlatUI.FlatTheme () {
                DarkAccentColor = Android.Graphics.Color.ParseColor("#00103f"),
                BackgroundColor = Android.Graphics.Color.ParseColor("#003259"),
                LightAccentColor = Android.Graphics.Color.ParseColor("#005191"),
                VeryLightAccentColor = Android.Graphics.Color.ParseColor("#719fc3")
            };

            //Register the them so it will show up when we ask FlatUI for all the available themes
            FlatUI.FlatUI.RegisterCustomTheme ("jabbr", customJabbrTheme);

            //Change the theme to our custom one by default
            ChangeTheme (customJabbrTheme);
        }
        public static void SetActionBarTheme(Activity context, FlatTheme theme, bool dark)
        {
            var color1 = theme.LightAccentColor;
            var color2 = theme.BackgroundColor;

            if (dark)
            {
                color1 = theme.BackgroundColor;
                color2 = theme.DarkAccentColor;
            }

            var front    = new PaintDrawable(color1);
            var bottom   = new PaintDrawable(color2);
            var d        = new Drawable[] { bottom, front };
            var drawable = new LayerDrawable(d);

            drawable.SetLayerInset(1, 0, 0, 0, 3);

            var actionBar = context.ActionBar;

            actionBar.SetBackgroundDrawable(drawable);

            // invalidating action bar
            actionBar.Title = actionBar.Title;
        }
		public static void SetTheme(SeekBar seekBar, FlatTheme theme)
		{
			// setting thumb
			var thumb = new PaintDrawable(theme.DarkAccentColor);
			thumb.SetCornerRadius(15);
			thumb.SetIntrinsicWidth(30);
			thumb.SetIntrinsicHeight(30);
			seekBar.SetThumb(thumb);

			// progress
			var progress = new PaintDrawable(theme.BackgroundColor);
			progress.SetCornerRadius(10);
			progress.SetIntrinsicHeight(10);
			progress.SetIntrinsicWidth(5);
			progress.SetDither(true);
			var progressClip = new ClipDrawable(progress, GravityFlags.Left, ClipDrawableOrientation.Horizontal);

			// secondary progress
			var secondary = new PaintDrawable(theme.LightAccentColor);
			secondary.SetCornerRadius(10);
			secondary.SetIntrinsicHeight(10);
			var secondaryProgressClip = new ClipDrawable(secondary, GravityFlags.Left, ClipDrawableOrientation.Horizontal);

			// background
			PaintDrawable background = new PaintDrawable(theme.VeryLightAccentColor);
			background.SetCornerRadius(10);
			background.SetIntrinsicHeight(10);

			// applying drawable
			LayerDrawable ld = (LayerDrawable) seekBar.ProgressDrawable;
			ld.SetDrawableByLayerId(Android.Resource.Id.Background, background);
			ld.SetDrawableByLayerId(Android.Resource.Id.Progress, progressClip);
			ld.SetDrawableByLayerId(Android.Resource.Id.SecondaryProgress, secondaryProgressClip);
		}
Exemple #9
0
        void init(IAttributeSet attrs)
        {
            if (attrs != null)
            {
                var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.FlatUI);

                var themeName = a.GetString(Resource.Styleable.FlatUI_theme) ?? string.Empty;

                theme = FlatUI.GetTheme(themeName);

                textColor             = a.GetInt(Resource.Styleable.FlatUI_textColor, textColor);
                backgroundColor       = a.GetInt(Resource.Styleable.FlatUI_backgroundColor, backgroundColor);
                customBackgroundColor = a.GetInt(Resource.Styleable.FlatUI_customBackgroundColor, customBackgroundColor);
                cornerRadius          = a.GetInt(Resource.Styleable.FlatUI_cornerRadius, cornerRadius);

                Enum.TryParse <FlatUI.FlatFontFamily> (
                    a.GetInt(Resource.Styleable.FlatUI_fontFamily, (int)fontFamily).ToString(), out fontFamily);
                Enum.TryParse <FlatUI.FlatFontWeight> (
                    a.GetInt(Resource.Styleable.FlatUI_fontWeight, (int)fontWeight).ToString(), out fontWeight);

                a.Recycle();
            }

            SetTheme(this, theme, fontFamily, fontWeight, textColor, backgroundColor, customBackgroundColor, cornerRadius);
        }
		public static void SetTheme(TextView textView, FlatTheme theme,
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int textColor, int backgroundColor,
			int customBackgroundColor, int cornerRadius)
		{

			if (backgroundColor != -1)
			{
				var bgColor = theme.DarkAccentColor;

				if (backgroundColor == 0)
					bgColor = theme.DarkAccentColor;
				else if (backgroundColor == 1)
					bgColor = theme.BackgroundColor;
				else if (backgroundColor == 2)
					bgColor = theme.LightAccentColor;
				else if (backgroundColor == 3)
					bgColor = theme.VeryLightAccentColor;

				GradientDrawable gradientDrawable = new GradientDrawable();
				gradientDrawable.SetColor(bgColor);
				gradientDrawable.SetCornerRadius(cornerRadius);
				textView.SetBackgroundDrawable(gradientDrawable);
			} 
			else if (customBackgroundColor != -1) 
			{
				var bgColor = theme.DarkAccentColor;

				if (customBackgroundColor == 0)
					bgColor = theme.DarkAccentColor;
				else if (customBackgroundColor == 1)
					bgColor = theme.BackgroundColor;
				else if (customBackgroundColor == 2)
					bgColor = theme.LightAccentColor;
				else if (customBackgroundColor == 3)
					bgColor = theme.VeryLightAccentColor;

				GradientDrawable gradientDrawable = new GradientDrawable();
				gradientDrawable.SetColor(bgColor);
				gradientDrawable.SetCornerRadius(cornerRadius);
				textView.SetBackgroundDrawable(gradientDrawable);
			}

			var txtColor = theme.VeryLightAccentColor;
			if (textColor == 0)
				txtColor = theme.DarkAccentColor;
			if (textColor == 1)
				txtColor = theme.BackgroundColor;
			if (textColor == 2)
				txtColor = theme.LightAccentColor;
			if (textColor == 3)
				txtColor = theme.VeryLightAccentColor;

			textView.SetTextColor(txtColor);

			var typeface = FlatUI.GetFont(textView.Context, fontFamily, fontWeight);
			if (typeface != null)
				textView.SetTypeface(typeface, TypefaceStyle.Normal);
		}
		public static void RegisterCustomTheme(string name, FlatTheme theme)
		{
			name = name.ToLower ();

			if (customThemes.ContainsKey (name))
				customThemes [name] = theme;
			else
				customThemes.Add (name, theme);
		}
        public static void SetTheme(EditText editText, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, FlatUI.FlatTextAppearance textAppearance,
                                    int style, int radius, int padding, int border)
        {
            float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };

            // creating normal state drawable
            var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            normalFront.SetPadding(padding, padding, padding, padding);

            var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            normalBack.SetPadding(border, border, border, border);

            if (style == 0)                           // flat
            {
                normalFront.Paint.Color = Color.Transparent;
                normalBack.Paint.Color  = theme.LightAccentColor;
                editText.SetTextColor(theme.VeryLightAccentColor);
            }
            else if (style == 1)                      // box
            {
                normalFront.Paint.Color = Color.White;
                normalBack.Paint.Color  = theme.LightAccentColor;
                editText.SetTextColor(theme.BackgroundColor);
            }
            else if (style == 2)                      // transparent
            {
                normalFront.Paint.Color = Color.Transparent;
                normalBack.Paint.Color  = Color.Transparent;
                editText.SetTextColor(theme.BackgroundColor);
            }

            Drawable[]    d      = { normalBack, normalFront };
            LayerDrawable normal = new LayerDrawable(d);

            editText.SetBackgroundDrawable(normal);

            editText.SetHintTextColor(theme.VeryLightAccentColor);

            if (textAppearance == FlatUI.FlatTextAppearance.Dark)
            {
                editText.SetTextColor(theme.DarkAccentColor);
            }
            else if (textAppearance == FlatUI.FlatTextAppearance.Light)
            {
                editText.SetTextColor(theme.VeryLightAccentColor);
            }

            var typeface = FlatUI.GetFont(editText.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                editText.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
Exemple #13
0
 void ChangeTheme(FlatTheme theme)
 {
     //Set default them
     FlatUI.FlatUI.DefaultTheme = theme;
     //Change the action bar
     FlatUI.FlatUI.SetActionBarTheme (this, FlatUI.FlatUI.DefaultTheme, false);
     //Change the activity theme
     FlatUI.FlatUI.SetActivityTheme (this, theme);
 }
        public static void SetActivityTheme(Activity activity, FlatTheme theme)         //, bool includeNormalViews)
        {
            ViewGroup vg = activity.FindViewById <View>(Android.Resource.Id.Content) as ViewGroup;

            if (vg == null)
            {
                return;
            }

            SetThemeOnChildren(vg, theme, false);
        }
        public static void RegisterCustomTheme(string name, FlatTheme theme)
        {
            name = name.ToLower();

            if (customThemes.ContainsKey(name))
            {
                customThemes [name] = theme;
            }
            else
            {
                customThemes.Add(name, theme);
            }
        }
		void init(IAttributeSet attrs)
		{
			if (attrs != null)
			{
				var a = Context.ObtainStyledAttributes (attrs, Resource.Styleable.FlatUI);

				var themeName = a.GetString (Resource.Styleable.FlatUI_theme) ?? string.Empty;

				theme = FlatUI.GetTheme (themeName);

				a.Recycle ();
			}

			SetTheme (this, theme);
		}
        void init(IAttributeSet attrs)
        {
            if (attrs != null)
            {
                var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.FlatUI);

                var themeName = a.GetString(Resource.Styleable.FlatUI_theme) ?? string.Empty;

                theme = FlatUI.GetTheme(themeName);

                a.Recycle();
            }

            SetTheme(this, theme);
        }
		public static void SetTheme(EditText editText, FlatTheme theme, 
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, FlatUI.FlatTextAppearance textAppearance,
			int style, int radius, int padding, int border)
		{
			float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

			// creating normal state drawable
			var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalFront.SetPadding(padding, padding, padding, padding);

			var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalBack.SetPadding(border, border, border, border);

			if (style == 0) {             // flat
				normalFront.Paint.Color = Color.Transparent;
				normalBack.Paint.Color = theme.LightAccentColor;
				editText.SetTextColor(theme.VeryLightAccentColor);

			} else if (style == 1) {      // box
				normalFront.Paint.Color = Color.White;
				normalBack.Paint.Color = theme.LightAccentColor;
				editText.SetTextColor(theme.BackgroundColor);

			} else if (style == 2) {      // transparent
				normalFront.Paint.Color = Color.Transparent;
				normalBack.Paint.Color = Color.Transparent;
				editText.SetTextColor(theme.BackgroundColor);
			}

			Drawable[] d = {normalBack, normalFront};
			LayerDrawable normal = new LayerDrawable(d);

			editText.SetBackgroundDrawable(normal);

			editText.SetHintTextColor(theme.VeryLightAccentColor);

			if (textAppearance == FlatUI.FlatTextAppearance.Dark) editText.SetTextColor(theme.DarkAccentColor);
			else if (textAppearance == FlatUI.FlatTextAppearance.Light) editText.SetTextColor(theme.VeryLightAccentColor);

			var typeface = FlatUI.GetFont(editText.Context, fontFamily, fontWeight);
			if (typeface != null)
				editText.SetTypeface(typeface, TypefaceStyle.Normal);
		}
        public static void SetTheme(SeekBar seekBar, FlatTheme theme)
        {
            // setting thumb
            var thumb = new PaintDrawable(theme.DarkAccentColor);

            thumb.SetCornerRadius(15);
            thumb.SetIntrinsicWidth(30);
            thumb.SetIntrinsicHeight(30);
            seekBar.SetThumb(thumb);

            // progress
            var progress = new PaintDrawable(theme.BackgroundColor);

            progress.SetCornerRadius(10);
            progress.SetIntrinsicHeight(10);
            progress.SetIntrinsicWidth(5);
            progress.SetDither(true);
            var progressClip = new ClipDrawable(progress, GravityFlags.Left, ClipDrawableOrientation.Horizontal);

            // secondary progress
            var secondary = new PaintDrawable(theme.LightAccentColor);

            secondary.SetCornerRadius(10);
            secondary.SetIntrinsicHeight(10);
            var secondaryProgressClip = new ClipDrawable(secondary, GravityFlags.Left, ClipDrawableOrientation.Horizontal);

            // background
            PaintDrawable background = new PaintDrawable(theme.VeryLightAccentColor);

            background.SetCornerRadius(10);
            background.SetIntrinsicHeight(10);

            // applying drawable
            LayerDrawable ld = (LayerDrawable)seekBar.ProgressDrawable;

            ld.SetDrawableByLayerId(Android.Resource.Id.Background, background);
            ld.SetDrawableByLayerId(Android.Resource.Id.Progress, progressClip);
            ld.SetDrawableByLayerId(Android.Resource.Id.SecondaryProgress, secondaryProgressClip);
        }
Exemple #20
0
 public static void SetTheme(TextView textView, FlatTheme theme)
 {
     SetTheme(textView, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight,
              DEFAULT_TEXTCOLOR, DEFAULT_BACKGROUNDCOLOR, DEFAULT_CUSTOMBACKGROUNDCOLOR, DEFAULT_CORNERRADIUS);
 }
 public static void SetTheme(Button button, FlatTheme theme)
 {
     SetTheme(button, theme, FlatUI.DefaultTextAppearance, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight,
              DEFAULT_ISFULLFLAT, DEFAULT_PADDING, DEFAULT_RADIUS);
 }
        public static void SetTheme(ToggleButton toggleButton, FlatTheme theme, int padding, int size)
        {
            toggleButton.SetWidth(size * 5);
            toggleButton.SetHeight(size);

            //setTextOff("");
            //setTextOn("");

            int radius = size - 4;

            float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };

            // creating unchecked-enabled state drawable
            var uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
            var uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, 5);

            var uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedEnabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            uncheckedEnabledBack.SetPadding(0, 0, size / 2 * 5, 0);

            Drawable[] d1 = { uncheckedEnabledBack, uncheckedEnabledFront };
            var        uncheckedEnabled = new LayerDrawable(d1);

            // creating checked-enabled state drawable
            var checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
            var checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, 5);

            ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedEnabledBack.Paint.Color = theme.VeryLightAccentColor;
            checkedEnabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

            Drawable[]    d2             = { checkedEnabledBack, checkedEnabledFront };
            LayerDrawable checkedEnabled = new LayerDrawable(d2);

            // creating unchecked-disabled state drawable
            ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedDisabledFrontCore.Paint.Color = Color.ParseColor("#d2d2d2");
            InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, 5);

            ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            uncheckedDisabledBack.SetPadding(0, 0, size / 2 * 5, 0);

            Drawable[]    d3 = { uncheckedDisabledBack, uncheckedDisabledFront };
            LayerDrawable uncheckedDisabled = new LayerDrawable(d3);

            // creating checked-disabled state drawable
            ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedDisabledFrontCore.Paint.Color = theme.VeryLightAccentColor;
            InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, 5);

            ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            checkedDisabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

            Drawable[]    d4 = { checkedDisabledBack, checkedDisabledFront };
            LayerDrawable checkedDisabled = new LayerDrawable(d4);

            toggleButton.SetPadding(0, padding, 0, padding);

            PaintDrawable paintDrawable = new PaintDrawable(theme.BackgroundColor);

            paintDrawable.SetIntrinsicHeight(size);
            paintDrawable.SetIntrinsicWidth(size);
            paintDrawable.SetPadding(size, 0, 0, 0);

            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(uncheckedEnabled, padding * 2));
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(checkedEnabled, padding * 2));
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(uncheckedDisabled, padding * 2));
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(checkedDisabled, padding * 2));

            toggleButton.SetBackgroundDrawable(states);

            toggleButton.SetTextSize(ComplexUnitType.Sp, 0);
        }
 public static void SetTheme(ToggleButton toggleButton, FlatTheme theme)
 {
     SetTheme(toggleButton, theme, DEFAULT_PADDING, DEFAULT_SIZE);
 }
		public static void SetTheme (ToggleButton toggleButton, FlatTheme theme, int padding, int size)
		{
			toggleButton.SetWidth(size * 5);
			toggleButton.SetHeight(size);

			//setTextOff("");
			//setTextOn("");

			int radius = size - 4;

			float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

			// creating unchecked-enabled state drawable
			var uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
			var uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, 5);

			var uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedEnabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			uncheckedEnabledBack.SetPadding(0, 0, size / 2 * 5, 0);

			Drawable[] d1 = {uncheckedEnabledBack, uncheckedEnabledFront};
			var uncheckedEnabled = new LayerDrawable(d1);

			// creating checked-enabled state drawable
			var checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
			var checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, 5);

			ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedEnabledBack.Paint.Color = theme.VeryLightAccentColor;
			checkedEnabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

			Drawable[] d2 = {checkedEnabledBack, checkedEnabledFront};
			LayerDrawable checkedEnabled = new LayerDrawable(d2);

			// creating unchecked-disabled state drawable
			ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedDisabledFrontCore.Paint.Color = Color.ParseColor("#d2d2d2");
			InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, 5);

			ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			uncheckedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			uncheckedDisabledBack.SetPadding(0, 0, size / 2 * 5, 0);

			Drawable[] d3 = {uncheckedDisabledBack, uncheckedDisabledFront};
			LayerDrawable uncheckedDisabled = new LayerDrawable(d3);

			// creating checked-disabled state drawable
			ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedDisabledFrontCore.Paint.Color = theme.VeryLightAccentColor;
			InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, 5);

			ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			checkedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
			checkedDisabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

			Drawable[] d4 = {checkedDisabledBack, checkedDisabledFront};
			LayerDrawable checkedDisabled = new LayerDrawable(d4);

			toggleButton.SetPadding(0, padding, 0, padding);

			PaintDrawable paintDrawable = new PaintDrawable(theme.BackgroundColor);
			paintDrawable.SetIntrinsicHeight(size);
			paintDrawable.SetIntrinsicWidth(size);
			paintDrawable.SetPadding(size, 0, 0, 0);

			StateListDrawable states = new StateListDrawable();

			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(uncheckedEnabled, padding * 2));
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(checkedEnabled, padding * 2));
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(uncheckedDisabled, padding * 2));
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled},
				new InsetDrawable(checkedDisabled, padding * 2));

			toggleButton.SetBackgroundDrawable(states);

			toggleButton.SetTextSize(ComplexUnitType.Sp, 0);
		}
		public static void SetTheme(CheckBox checkBox, FlatTheme theme, 
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int radius, int size, int border)
		{
			// creating unchecked-enabled state drawable
			GradientDrawable uncheckedEnabled = new GradientDrawable();
			uncheckedEnabled.SetCornerRadius(radius);
			uncheckedEnabled.SetSize(size, size);
			uncheckedEnabled.SetColor(Color.Transparent);
			uncheckedEnabled.SetStroke(border, theme.LightAccentColor);

			// creating checked-enabled state drawable
			GradientDrawable checkedOutside = new GradientDrawable();
			checkedOutside.SetCornerRadius(radius);
			checkedOutside.SetSize(size, size);
			checkedOutside.SetColor(Color.Transparent);
			checkedOutside.SetStroke(border, theme.LightAccentColor);

			PaintDrawable checkedCore = new PaintDrawable(theme.LightAccentColor);
			checkedCore.SetCornerRadius(radius);
			checkedCore.SetIntrinsicHeight(size);
			checkedCore.SetIntrinsicWidth(size);
			InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

			Drawable[] checkedEnabledDrawable = {checkedOutside, checkedInside};
			LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);

			// creating unchecked-enabled state drawable
			GradientDrawable uncheckedDisabled = new GradientDrawable();
			uncheckedDisabled.SetCornerRadius(radius);
			uncheckedDisabled.SetSize(size, size);
			uncheckedDisabled.SetColor(Color.Transparent);
			uncheckedDisabled.SetStroke(border, theme.VeryLightAccentColor);

			// creating checked-disabled state drawable
			GradientDrawable checkedOutsideDisabled = new GradientDrawable();
			checkedOutsideDisabled.SetCornerRadius(radius);
			checkedOutsideDisabled.SetSize(size, size);
			checkedOutsideDisabled.SetColor(Color.Transparent);
			checkedOutsideDisabled.SetStroke(border, theme.VeryLightAccentColor);

			PaintDrawable checkedCoreDisabled = new PaintDrawable(theme.VeryLightAccentColor);
			checkedCoreDisabled.SetCornerRadius(radius);
			checkedCoreDisabled.SetIntrinsicHeight(size);
			checkedCoreDisabled.SetIntrinsicWidth(size);
			InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

			Drawable[] checkedDisabledDrawable = {checkedOutsideDisabled, checkedInsideDisabled};
			LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);


			StateListDrawable states = new StateListDrawable();
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, uncheckedEnabled);
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, checkedEnabled);
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, uncheckedDisabled);
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, checkedDisabled);
			checkBox.SetButtonDrawable(states);

			// setting padding for avoiding text to be appear on icon
			checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
			checkBox.SetTextColor(theme.LightAccentColor);

			var typeface = FlatUI.GetFont(checkBox.Context, fontFamily, fontWeight);
			if (typeface != null) 
				checkBox.SetTypeface(typeface, TypefaceStyle.Normal);
		}
		public static void SetActivityTheme(Activity activity, FlatTheme theme) //, bool includeNormalViews)
		{
			ViewGroup vg = activity.FindViewById<View>(Android.Resource.Id.Content) as ViewGroup;

			if (vg == null)
				return;

			SetThemeOnChildren(vg, theme, false);

		}
 public static void SetTheme(EditText editText, FlatTheme theme)
 {
     SetTheme(editText, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, FlatUI.DefaultTextAppearance,
              DEFAULT_STYLE, DEFAULT_RADIUS, DEFAULT_PADDING, DEFAULT_BORDER);
 }
		static void SetThemeOnChildren(ViewGroup parentViewGroup, FlatTheme theme, bool includeNormalViews)
		{

			for (int i = 0; i < parentViewGroup.ChildCount; i++)
			{
				var view = parentViewGroup.GetChildAt (i);

				
				var vtype = view.GetType ();

				if (view is FlatButton)
					(view as FlatButton).Theme = theme;
				else if (view is FlatCheckBox)
					(view as FlatCheckBox).Theme = theme;
				else if (view is FlatEditText)
					(view as FlatEditText).Theme = theme;
				else if (view is FlatRadioButton)
					(view as FlatRadioButton).Theme = theme;
				else if (view is FlatSeekBar)
					(view as FlatSeekBar).Theme = theme;
				else if (view is FlatTextView)
					(view as FlatTextView).Theme = theme;
				else if (view is FlatToggleButton)
					(view as FlatToggleButton).Theme = theme;

				//TODO: Need to add code for settheme static method
				if (includeNormalViews)
				{
					if (vtype == typeof(CheckBox))
						FlatCheckBox.SetTheme(view as CheckBox, theme);
					else if (vtype == typeof(RadioButton))
						FlatRadioButton.SetTheme(view as RadioButton, theme);
					else if (vtype == typeof(ToggleButton))
						FlatToggleButton.SetTheme(view as ToggleButton, theme);
					else if (vtype == typeof(EditText))
						FlatEditText.SetTheme(view as EditText, theme);
					else if (vtype == typeof(TextView))
						FlatTextView.SetTheme(view as TextView, theme);
					else if (vtype == typeof(SeekBar))
						FlatSeekBar.SetTheme(view as SeekBar, theme);
					else if (vtype == typeof(Button))
						FlatButton.SetTheme(view as Button, theme);
				}

				var childViewGroup = view as ViewGroup;

				if (childViewGroup != null)
					SetThemeOnChildren (childViewGroup, theme, includeNormalViews);
			}
		}
        static void SetThemeOnChildren(ViewGroup parentViewGroup, FlatTheme theme, bool includeNormalViews)
        {
            for (int i = 0; i < parentViewGroup.ChildCount; i++)
            {
                var view = parentViewGroup.GetChildAt(i);


                var vtype = view.GetType();

                if (view is FlatButton)
                {
                    (view as FlatButton).Theme = theme;
                }
                else if (view is FlatCheckBox)
                {
                    (view as FlatCheckBox).Theme = theme;
                }
                else if (view is FlatEditText)
                {
                    (view as FlatEditText).Theme = theme;
                }
                else if (view is FlatRadioButton)
                {
                    (view as FlatRadioButton).Theme = theme;
                }
                else if (view is FlatSeekBar)
                {
                    (view as FlatSeekBar).Theme = theme;
                }
                else if (view is FlatTextView)
                {
                    (view as FlatTextView).Theme = theme;
                }
                else if (view is FlatToggleButton)
                {
                    (view as FlatToggleButton).Theme = theme;
                }

                //TODO: Need to add code for settheme static method
                if (includeNormalViews)
                {
                    if (vtype == typeof(CheckBox))
                    {
                        FlatCheckBox.SetTheme(view as CheckBox, theme);
                    }
                    else if (vtype == typeof(RadioButton))
                    {
                        FlatRadioButton.SetTheme(view as RadioButton, theme);
                    }
                    else if (vtype == typeof(ToggleButton))
                    {
                        FlatToggleButton.SetTheme(view as ToggleButton, theme);
                    }
                    else if (vtype == typeof(EditText))
                    {
                        FlatEditText.SetTheme(view as EditText, theme);
                    }
                    else if (vtype == typeof(TextView))
                    {
                        FlatTextView.SetTheme(view as TextView, theme);
                    }
                    else if (vtype == typeof(SeekBar))
                    {
                        FlatSeekBar.SetTheme(view as SeekBar, theme);
                    }
                    else if (vtype == typeof(Button))
                    {
                        FlatButton.SetTheme(view as Button, theme);
                    }
                }

                var childViewGroup = view as ViewGroup;

                if (childViewGroup != null)
                {
                    SetThemeOnChildren(childViewGroup, theme, includeNormalViews);
                }
            }
        }
		public static void SetActionBarTheme(Activity context, FlatTheme theme, bool dark)
		{
			var color1 = theme.LightAccentColor;
			var color2 = theme.BackgroundColor;

			if (dark) 
			{
				color1 = theme.BackgroundColor;
				color2 = theme.DarkAccentColor;
			}

			var front = new PaintDrawable(color1);
			var bottom = new PaintDrawable(color2);
			var d = new Drawable[] { bottom, front};
			var drawable = new LayerDrawable(d);
			drawable.SetLayerInset(1, 0, 0, 0, 3);

			var actionBar = context.ActionBar;
			actionBar.SetBackgroundDrawable(drawable);

			// invalidating action bar
			actionBar.Title = actionBar.Title;
		}
		public static void SetTheme(Button button, FlatTheme theme, FlatUI.FlatTextAppearance textAppearance,
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, bool isFullFlat, int padding, int radius)
		{
			var bottom = 5;

			float[] outerR = {radius, radius, radius, radius, radius, radius, radius, radius};

			// creating normal state drawable
			var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalFront.Paint.Color = theme.LightAccentColor;
			normalFront.SetPadding(padding, padding, padding, padding);

			var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			normalBack.Paint.Color = theme.BackgroundColor;

			if (isFullFlat) 
				bottom = 0;

			normalBack.SetPadding(0, 0, 0, bottom);

			Drawable[] d = {normalBack, normalFront};
			var normal = new LayerDrawable(d);

			// creating pressed state drawable
			var pressedFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			pressedFront.Paint.Color = theme.BackgroundColor;

			var pressedBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			pressedBack.Paint.Color = theme.DarkAccentColor;

			if (!isFullFlat) 
				pressedBack.SetPadding(0, 0, 0, 3);

			Drawable[] d2 = {pressedBack, pressedFront};
			var pressed = new LayerDrawable(d2);

			// creating disabled state drawable
			var disabledFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			disabledFront.Paint.Color = theme.VeryLightAccentColor;

			var disabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));
			disabledBack.Paint.Color = theme.LightAccentColor;
			if (!isFullFlat) disabledBack.SetPadding(0, 0, 0, padding);

			Drawable[] d3 = {disabledBack, disabledFront};
			var disabled = new LayerDrawable(d3);

			var states = new StateListDrawable();

			states.AddState(new []{ Android.Resource.Attribute.StatePressed, Android.Resource.Attribute.StateEnabled }, pressed);
			states.AddState(new []{ Android.Resource.Attribute.StateFocused, Android.Resource.Attribute.StateEnabled }, pressed);
			states.AddState(new []{ Android.Resource.Attribute.StateEnabled }, normal);
			states.AddState(new []{-Android.Resource.Attribute.StateEnabled}, disabled);

			button.SetBackgroundDrawable (states);

			if (textAppearance == FlatUI.FlatTextAppearance.Dark) 
				button.SetTextColor(theme.DarkAccentColor);
			else if (textAppearance == FlatUI.FlatTextAppearance.Light) 
				button.SetTextColor(theme.VeryLightAccentColor);
			else 
				button.SetTextColor(Android.Graphics.Color.White);

			var typeface = FlatUI.GetFont(button.Context, fontFamily, fontWeight);
			if (typeface != null)
				button.SetTypeface(typeface, Android.Graphics.TypefaceStyle.Normal);
		}
		public static void SetTheme(EditText editText, FlatTheme theme)
		{
			SetTheme (editText, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, FlatUI.DefaultTextAppearance,
				DEFAULT_STYLE, DEFAULT_RADIUS, DEFAULT_PADDING, DEFAULT_BORDER);
		}
Exemple #33
0
        public static void SetTheme(TextView textView, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int textColor, int backgroundColor,
                                    int customBackgroundColor, int cornerRadius)
        {
            if (backgroundColor != -1)
            {
                var bgColor = theme.DarkAccentColor;

                if (backgroundColor == 0)
                {
                    bgColor = theme.DarkAccentColor;
                }
                else if (backgroundColor == 1)
                {
                    bgColor = theme.BackgroundColor;
                }
                else if (backgroundColor == 2)
                {
                    bgColor = theme.LightAccentColor;
                }
                else if (backgroundColor == 3)
                {
                    bgColor = theme.VeryLightAccentColor;
                }

                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.SetColor(bgColor);
                gradientDrawable.SetCornerRadius(cornerRadius);
                textView.SetBackgroundDrawable(gradientDrawable);
            }
            else if (customBackgroundColor != -1)
            {
                var bgColor = theme.DarkAccentColor;

                if (customBackgroundColor == 0)
                {
                    bgColor = theme.DarkAccentColor;
                }
                else if (customBackgroundColor == 1)
                {
                    bgColor = theme.BackgroundColor;
                }
                else if (customBackgroundColor == 2)
                {
                    bgColor = theme.LightAccentColor;
                }
                else if (customBackgroundColor == 3)
                {
                    bgColor = theme.VeryLightAccentColor;
                }

                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.SetColor(bgColor);
                gradientDrawable.SetCornerRadius(cornerRadius);
                textView.SetBackgroundDrawable(gradientDrawable);
            }

            var txtColor = theme.VeryLightAccentColor;

            if (textColor == 0)
            {
                txtColor = theme.DarkAccentColor;
            }
            if (textColor == 1)
            {
                txtColor = theme.BackgroundColor;
            }
            if (textColor == 2)
            {
                txtColor = theme.LightAccentColor;
            }
            if (textColor == 3)
            {
                txtColor = theme.VeryLightAccentColor;
            }

            textView.SetTextColor(txtColor);

            var typeface = FlatUI.GetFont(textView.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                textView.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
		public static void SetTheme(TextView textView, FlatTheme theme)
		{
			SetTheme (textView, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight,
				DEFAULT_TEXTCOLOR, DEFAULT_BACKGROUNDCOLOR, DEFAULT_CUSTOMBACKGROUNDCOLOR, DEFAULT_CORNERRADIUS);
		}
		public static void SetTheme(CheckBox checkBox, FlatTheme theme)
		{
			SetTheme (checkBox, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, DEFAULT_RADIUS, DEFAULT_SIZE, DEFAULT_BORDER);
		}
		public static void SetTheme(RadioButton radioButton, FlatTheme theme)
		{
			SetTheme(radioButton, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, DEFAULT_RADIUS, DEFAULT_SIZE, DEFAULT_BORDER);
		}
Exemple #37
0
 public static void SetTheme(RadioButton radioButton, FlatTheme theme)
 {
     SetTheme(radioButton, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, DEFAULT_RADIUS, DEFAULT_SIZE, DEFAULT_BORDER);
 }
        public static void SetTheme(Button button, FlatTheme theme, FlatUI.FlatTextAppearance textAppearance,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, bool isFullFlat, int padding, int radius)
        {
            var bottom = 5;

            float[] outerR = { radius, radius, radius, radius, radius, radius, radius, radius };

            // creating normal state drawable
            var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            normalFront.Paint.Color = theme.LightAccentColor;
            normalFront.SetPadding(padding, padding, padding, padding);

            var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            normalBack.Paint.Color = theme.BackgroundColor;

            if (isFullFlat)
            {
                bottom = 0;
            }

            normalBack.SetPadding(0, 0, 0, bottom);

            Drawable[] d      = { normalBack, normalFront };
            var        normal = new LayerDrawable(d);

            // creating pressed state drawable
            var pressedFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            pressedFront.Paint.Color = theme.BackgroundColor;

            var pressedBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            pressedBack.Paint.Color = theme.DarkAccentColor;

            if (!isFullFlat)
            {
                pressedBack.SetPadding(0, 0, 0, 3);
            }

            Drawable[] d2      = { pressedBack, pressedFront };
            var        pressed = new LayerDrawable(d2);

            // creating disabled state drawable
            var disabledFront = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            disabledFront.Paint.Color = theme.VeryLightAccentColor;

            var disabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            disabledBack.Paint.Color = theme.LightAccentColor;
            if (!isFullFlat)
            {
                disabledBack.SetPadding(0, 0, 0, padding);
            }

            Drawable[] d3       = { disabledBack, disabledFront };
            var        disabled = new LayerDrawable(d3);

            var states = new StateListDrawable();

            states.AddState(new [] { Android.Resource.Attribute.StatePressed, Android.Resource.Attribute.StateEnabled }, pressed);
            states.AddState(new [] { Android.Resource.Attribute.StateFocused, Android.Resource.Attribute.StateEnabled }, pressed);
            states.AddState(new [] { Android.Resource.Attribute.StateEnabled }, normal);
            states.AddState(new [] { -Android.Resource.Attribute.StateEnabled }, disabled);

            button.SetBackgroundDrawable(states);

            if (textAppearance == FlatUI.FlatTextAppearance.Dark)
            {
                button.SetTextColor(theme.DarkAccentColor);
            }
            else if (textAppearance == FlatUI.FlatTextAppearance.Light)
            {
                button.SetTextColor(theme.VeryLightAccentColor);
            }
            else
            {
                button.SetTextColor(Android.Graphics.Color.White);
            }

            var typeface = FlatUI.GetFont(button.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                button.SetTypeface(typeface, Android.Graphics.TypefaceStyle.Normal);
            }
        }
Exemple #39
0
 public static void SetTheme(CheckBox checkBox, FlatTheme theme)
 {
     SetTheme(checkBox, theme, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, DEFAULT_RADIUS, DEFAULT_SIZE, DEFAULT_BORDER);
 }
		public static void SetTheme (ToggleButton toggleButton, FlatTheme theme)
		{
			SetTheme (toggleButton, theme, DEFAULT_PADDING, DEFAULT_SIZE);
		}
Exemple #41
0
        public static void SetTheme(CheckBox checkBox, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int radius, int size, int border)
        {
            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedEnabled = new GradientDrawable();

            uncheckedEnabled.SetCornerRadius(radius);
            uncheckedEnabled.SetSize(size, size);
            uncheckedEnabled.SetColor(Color.Transparent);
            uncheckedEnabled.SetStroke(border, theme.LightAccentColor);

            // creating checked-enabled state drawable
            GradientDrawable checkedOutside = new GradientDrawable();

            checkedOutside.SetCornerRadius(radius);
            checkedOutside.SetSize(size, size);
            checkedOutside.SetColor(Color.Transparent);
            checkedOutside.SetStroke(border, theme.LightAccentColor);

            PaintDrawable checkedCore = new PaintDrawable(theme.LightAccentColor);

            checkedCore.SetCornerRadius(radius);
            checkedCore.SetIntrinsicHeight(size);
            checkedCore.SetIntrinsicWidth(size);
            InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedEnabledDrawable = { checkedOutside, checkedInside };
            LayerDrawable checkedEnabled         = new LayerDrawable(checkedEnabledDrawable);

            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedDisabled = new GradientDrawable();

            uncheckedDisabled.SetCornerRadius(radius);
            uncheckedDisabled.SetSize(size, size);
            uncheckedDisabled.SetColor(Color.Transparent);
            uncheckedDisabled.SetStroke(border, theme.VeryLightAccentColor);

            // creating checked-disabled state drawable
            GradientDrawable checkedOutsideDisabled = new GradientDrawable();

            checkedOutsideDisabled.SetCornerRadius(radius);
            checkedOutsideDisabled.SetSize(size, size);
            checkedOutsideDisabled.SetColor(Color.Transparent);
            checkedOutsideDisabled.SetStroke(border, theme.VeryLightAccentColor);

            PaintDrawable checkedCoreDisabled = new PaintDrawable(theme.VeryLightAccentColor);

            checkedCoreDisabled.SetCornerRadius(radius);
            checkedCoreDisabled.SetIntrinsicHeight(size);
            checkedCoreDisabled.SetIntrinsicWidth(size);
            InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
            LayerDrawable checkedDisabled         = new LayerDrawable(checkedDisabledDrawable);


            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, uncheckedEnabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, checkedEnabled);
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, uncheckedDisabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, checkedDisabled);
            checkBox.SetButtonDrawable(states);

            // setting padding for avoiding text to be appear on icon
            checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
            checkBox.SetTextColor(theme.LightAccentColor);

            var typeface = FlatUI.GetFont(checkBox.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                checkBox.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
		public static void SetTheme(Button button, FlatTheme theme)
		{
			SetTheme (button, theme, FlatUI.DefaultTextAppearance, FlatUI.DefaultFontFamily, FlatUI.DefaultFontWeight, 
				DEFAULT_ISFULLFLAT, DEFAULT_PADDING, DEFAULT_RADIUS);
		}