コード例 #1
0
		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);
		}
コード例 #2
0
ファイル: XTool.cs プロジェクト: bny-mobile/COPILOT
        public static Drawable RandomGreyGradient(Color start, Color end)
        {
            PaintDrawable gradient = new PaintDrawable ();
            gradient.Shape = new RectShape ();
            gradient.SetShaderFactory (new RandomGradient (start, end));

            return gradient;
        }
コード例 #3
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);
		}
コード例 #4
0
		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);
		}
コード例 #5
0
		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;
		}