protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.NewElement != null) { var view = (CustomEntry)Element; if (view.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); _gradientBackground.SetColor(view.BackgroundColor.ToAndroid()); // Thickness of the stroke line _gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); _gradientBackground.SetGradientRadius(0); // Radius for the curves _gradientBackground.SetCornerRadius( DpToPixels(this.Context, 0)); // set the background of the Control.SetBackground(_gradientBackground); } // Set padding for the internal text from border Control.SetPadding( (int)DpToPixels(this.Context, Convert.ToSingle(5)), Control.PaddingTop, (int)DpToPixels(this.Context, Convert.ToSingle(5)), Control.PaddingBottom); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (Element != null) { var view = (CustomEntry)Element; Control.Background.SetColorFilter(App.Current.UserAppTheme == OSAppTheme.Dark ? Color.Black : Color.White, PorterDuff.Mode.SrcAtop); if (view.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); _gradientBackground.SetColor(view.BackgroundColor.ToAndroid()); // Thickness of the stroke line _gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); // Radius for the curves _gradientBackground.SetCornerRadius(DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius))); _gradientBackground.SetGradientRadius(DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius))); // set the background of the Control.SetBackground(_gradientBackground); } // Set padding for the internal text from border Control.SetPadding((int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingTop, (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingBottom); } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { var button = Control; // See ButtonRendererWithNavFix.cs CustomClickHandler(button); // Applies a "blue" gradient to our Android navigation buttons var gradientDrawable = new GradientDrawable(); gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr); gradientDrawable.SetColors(new int[] { Color.Argb(255, 20, 143, 194), Color.Argb(255, 0, 44, 119) }); gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientRadius(300); gradientDrawable.SetGradientCenter(0.5f, 0); button.SetBackgroundDrawable(gradientDrawable); // Sets a small drop shadow to the buttons' text button.SetShadowLayer(1, 1, 1, Color.Black); } }
public static void UpdateBackground(this GradientDrawable gradientDrawable, Brush brush, int height, int width) { if (gradientDrawable == null || brush == null || brush.IsEmpty) { return; } if (brush is SolidColorBrush solidColorBrush) { Color bgColor = solidColorBrush.Color; gradientDrawable.SetColor(bgColor.IsDefault ? Color.Default.ToAndroid() : bgColor.ToAndroid()); } if (brush is LinearGradientBrush linearGradientBrush) { var p1 = linearGradientBrush.StartPoint; var x1 = (float)p1.X; var y1 = (float)p1.Y; var p2 = linearGradientBrush.EndPoint; var x2 = (float)p2.X; var y2 = (float)p2.Y; const double Rad2Deg = 180.0 / Math.PI; var angle = Math.Atan2(y2 - y1, x2 - x1) * Rad2Deg; var gradientBrushData = linearGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.LinearGradient); gradientDrawable.SetColors(colors); gradientDrawable.SetGradientOrientation(angle); } if (brush is RadialGradientBrush radialGradientBrush) { var center = radialGradientBrush.Center; float centerX = (float)center.X; float centerY = (float)center.Y; float radius = (float)radialGradientBrush.Radius; var gradientBrushData = radialGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientCenter(centerX, centerY); gradientDrawable.SetGradientRadius(Math.Max(height, width) * radius); gradientDrawable.SetColors(colors); } }
void ApplyBorder() { GradientDrawable gd = new GradientDrawable(); gd.SetCornerRadius(0); gd.SetGradientRadius(0); gd.SetStroke(2, Color.FromHex("#50B1FF").ToAndroid()); this.Control.Background = gd; }
private void InitilizeBorderEntry(Android.Graphics.Color color) { var gd = new GradientDrawable(); gd.SetColor(supportEntry.BackgroundColorInside.ToAndroid()); // Changes this drawbale to use a single color instead of a gradient gd.SetCornerRadius((float)supportEntry.CornerRadius); gd.SetGradientRadius((float)supportEntry.CornerWidth); gd.SetStroke((int)supportEntry.CornerWidth, color); Control.SetBackground(gd); }
private void InitilizeBorderEntry(Android.Graphics.Color color) { var gd = new GradientDrawable(); gd.SetColor(supportEntry.BackgroundColorInside.ToAndroid()); gd.SetCornerRadius((float)supportEntry.CornerRadius); gd.SetGradientRadius((float)supportEntry.CornerWidth); gd.SetStroke((int)supportEntry.CornerWidth, color); Control.SetBackground(gd); }
void ApplyBorder() { if (Control == null) { return; } GradientDrawable gd = new GradientDrawable(); gd.SetCornerRadius(0); gd.SetGradientRadius(0); gd.SetStroke(2, Xamarin.Forms.Color.FromHex("#50B1FF").ToAndroid()); this.Control.Background = gd; }
protected override void OnAttached() { if (gradientDrawable == null) { gradientDrawable = new GradientDrawable(); Control.Background = gradientDrawable; var effect = (PQGradiantEffect)Element.Effects.FirstOrDefault(e => e is PQGradiantEffect); if (effect == null) { return; } SetColors(); if (!effect.IsRadial) { switch (effect.Oriantaion) { case Helpers.Shared.GradiantOriantaion.LeftToRight: gradientDrawable.SetOrientation(GradientDrawable.Orientation.LeftRight); break; case Helpers.Shared.GradiantOriantaion.RightToLeft: gradientDrawable.SetOrientation(GradientDrawable.Orientation.RightLeft); break; case Helpers.Shared.GradiantOriantaion.TopToBottom: gradientDrawable.SetOrientation(GradientDrawable.Orientation.TopBottom); break; case Helpers.Shared.GradiantOriantaion.BottomToTop: gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); break; default: gradientDrawable.SetOrientation(GradientDrawable.Orientation.LeftRight); break; } } gradientDrawable.SetGradientRadius(150); gradientDrawable.SetShape(ShapeType.Rectangle); gradientDrawable.SetCornerRadius(effect.Radius); gradientDrawable.SetGradientType(effect.IsRadial ? GradientType.RadialGradient : GradientType.LinearGradient); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var gradientDarawable = new GradientDrawable(); gradientDarawable.SetCornerRadius(8f); gradientDarawable.SetStroke(6, global::Android.Graphics.Color.Black); gradientDarawable.SetColor(global::Android.Graphics.Color.White); gradientDarawable.SetGradientRadius(8f); Control.SetBackground(gradientDarawable); Control.SetPadding(10, Control.PaddingTop, Control.PaddingRight, 50); /* Control.SetBackgroundColor(global::Android.Graphics.Color.White); * Control.SetTextColor(global::Android.Graphics.Color.Black);*/ } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { var button = Control; // Applies a "gray" gradient to our Android popup buttons var gradientDrawable = new GradientDrawable(); gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr); gradientDrawable.SetColors(new int[] { Color.Argb(255, 167, 169, 172), Color.Argb(255, 76, 76, 76) }); gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientRadius(300); gradientDrawable.SetGradientCenter(0.5f, 0); button.SetBackgroundDrawable(gradientDrawable); // Sets a small drop shadow to the buttons' text button.SetShadowLayer(1, 1, 1, Color.Black); } }
void InitilizeSeekBar(int width, bool valueChnaged = false) { if (Control != null) { //convert details from CustomGradientSlider to android values var slider = Element as CustomGradientSlider; var startColor = control.TrackStartColor.ToAndroid(); //var centerColor = Android.Graphics.Color.Orange; var endColor = control.TrackEndColor.ToAndroid(); var cornerRadiusInPx = ((float)(slider.HeightRequest / 2.0)).DpToPixels(Context); var heightPx = (12.0f).DpToPixels(Context); var gradientWidth = ((width - 45) / Element.Maximum) * Element.Value; //create minimum track var p = new GradientDrawable(GradientDrawable.Orientation.LeftRight, new int[] { startColor, endColor }); p.SetCornerRadius(cornerRadiusInPx); //create maximum track var background = new GradientDrawable(); background.SetColor(control.TrackColor.ToAndroid()); background.SetCornerRadius(cornerRadiusInPx); var shapes = new List <Drawable>(); var shadow = new GradientDrawable(); shadow.SetColor(Android.Graphics.Color.ParseColor("#E8E8E8")); shadow.SetCornerRadius(cornerRadiusInPx); shadow.SetGradientRadius(40f); if (control.HasSegment) { for (int i = 0; i < ((int)(Element.Maximum / control.Interval)) + 1; i++) { var shapeDrawable = i * control.Interval < Element.Value ? Android.App.Application.Context.GetDrawable(Resource.Drawable.whitePoint) : Android.App.Application.Context.GetDrawable(Resource.Drawable.bluePoint); shapes.Add(shapeDrawable); } } var drawables = new List <Drawable> { background, p }; if (control.HasShadow) { drawables.Insert(0, shadow); } drawables.AddRange(shapes); var pd = new LayerDrawable(drawables.ToArray()); if (control.HasShadow) { pd.SetLayerHeight(0, (int)heightPx + 3); } pd.SetLayerHeight(drawables.IndexOf(background), (int)heightPx); pd.SetLayerHeight(drawables.IndexOf(p), (int)heightPx); pd.SetLayerWidth(drawables.IndexOf(p), (int)gradientWidth); int intervalStartsFrom = 2; if (control.HasShadow) { intervalStartsFrom = 3; } if (control.HasSegment) { var segmentDelay = (width - (int)40.0f.DpToPixels(Context)) / (int)(Element.Maximum / (int)control.Interval); for (int i = intervalStartsFrom; i < drawables.Count; i++) { pd.SetLayerHeight(i, (int)5.0f.DpToPixels(Context)); pd.SetLayerWidth(i, (int)5.0f.DpToPixels(Context)); pd.SetLayerInset(i, i == intervalStartsFrom ? 10 : i == drawables.Count - 1 ? ((i - intervalStartsFrom) * segmentDelay) - (int)10.0f.DpToPixels(Context) : (i - intervalStartsFrom) * segmentDelay, (int)4.0f.DpToPixels(Context), 0, 0); } } Control.ProgressDrawable = pd; LayoutInflater inflater = (LayoutInflater)Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService); thumbView = inflater.Inflate(Resource.Layout.layout_seekbar_thumb, null, false); var thumbText = ((TextView)thumbView.FindViewById(Resource.Id.thumbText)); thumbText.TextSize = (float)control.ThumbTextFontSize; thumbText.SetTextColor(Android.Graphics.Color.White); var iconName = (control.ThumbImageSource as Xamarin.Forms.FileImageSource).File; var thumbViewIcon = ((LinearLayout)thumbView.FindViewById(Resource.Id.seekBarIcon)); thumbViewIcon.SetBackgroundDrawable(Android.App.Application.Context.GetDrawable(iconName)); var thumb = GetThumb((int)Element.Value); Control.SetThumb(thumb); if (valueChnaged) { thumb.SetBounds(thumb.Bounds.Left, 0, thumb.Bounds.Right, thumb.IntrinsicHeight); } Control.Background = null; } }