protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            var colorFrom = Element.BackgroundGradientColorFrom;
            var colorTo   = Element.BackgroundGradientColorTo;

            if (colorFrom.HasValue && colorTo.HasValue)
            {
                var startColor = colorFrom.GetValueOrDefault().ToAndroid();
                var endColor   = colorTo.GetValueOrDefault().ToAndroid();

                var width  = 0;
                var height = Height;
                if (Element.IsHorizontalGradientBackground)
                {
                    width  = Width;
                    height = 0;
                }

                using (var gradient = new Android.Graphics.LinearGradient(
                           0, 0, width, height,
                           startColor,
                           endColor,
                           Android.Graphics.Shader.TileMode.Mirror))
                {
                    using (var paint = new Android.Graphics.Paint {
                        Dither = true
                    })
                    {
                        paint.SetShader(gradient);
                        canvas.DrawPaint(paint);
                    }
                }
            }
            base.DispatchDraw(canvas);
        }
Ejemplo n.º 2
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            Android.Graphics.LinearGradient gradient;

            int[] colors = new int[Colors.Length];

            for (int i = 0, l = Colors.Length; i < l; i++)
            {
                colors[i] = Colors[i].ToAndroid().ToArgb();
            }

            switch (Mode)
            {
            default:
            case GradientColorStackMode.ToRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTop:
                gradient = new Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottom:
                gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopLeft:
                gradient = new Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopRight:
                gradient = new Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
Ejemplo n.º 3
0
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            var gradients = new Android.Graphics.LinearGradient(0, 0, 0, Height, this.StarColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror);
            var paint     = new Android.Graphics.Paint()
            {
                Dither = true
            };

            paint.SetShader(gradients);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Ejemplo n.º 4
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            var gradient = new Android.Graphics.LinearGradient(0, 0, this.Width, 0, StartColor.ToAndroid(), EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Repeat);
            var paint    = new Android.Graphics.Paint()
            {
                Dither = true
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Ejemplo n.º 5
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Width,
                                                               //var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                               this.StartColor.ToAndroid(),
                                                               this.EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Clamp);//mirror
            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Ejemplo n.º 6
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            #region for Vertical Gradient
            var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                               this.StartColor.ToAndroid(),
                                                               this.EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };
            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
            #endregion
        }
 protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
 {
     try
     {
         var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror);
         var paint    = new Android.Graphics.Paint()
         {
             Dither = true,
         };
         paint.SetShader(gradient);
         canvas.DrawPaint(paint);
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
     }
     base.DispatchDraw(canvas);
 }
Ejemplo n.º 8
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            Android.Graphics.LinearGradient LinearGradient = null;

            if (Direction == ItemsLayoutOrientation.Vertical)
            {
                if (HasCenterColor)
                {
                    int[]   colors    = { this.StartColor.ToAndroid().ToArgb(), this.CenterColor.ToAndroid().ToArgb(), this.EndColor.ToAndroid().ToArgb() };
                    float[] positions = { 0.5F, YCenter, 1 };
                    LinearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, positions, Android.Graphics.Shader.TileMode.Mirror);
                }
                else
                {
                    int[]   colors    = { this.StartColor.ToAndroid().ToArgb(), this.EndColor.ToAndroid().ToArgb() };
                    float[] positions = { YCenter, 1 };
                    LinearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, positions, Android.Graphics.Shader.TileMode.Mirror);
                }
            }

            if (Direction == ItemsLayoutOrientation.Horizontal)
            {
                if (HasCenterColor)
                {
                    int[]   colors    = { this.StartColor.ToAndroid().ToArgb(), this.CenterColor.ToAndroid().ToArgb(), this.EndColor.ToAndroid().ToArgb() };
                    float[] positions = { 0.5F, YCenter, 1 };
                    LinearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Width, colors, positions, Android.Graphics.Shader.TileMode.Mirror);
                }
                else
                {
                    int[]   colors    = { this.StartColor.ToAndroid().ToArgb(), this.EndColor.ToAndroid().ToArgb() };
                    float[] positions = { YCenter, 1 };
                    LinearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Width, colors, positions, Android.Graphics.Shader.TileMode.Mirror);
                }
            }

            Android.Graphics.Paint paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };
            paint.SetShader(LinearGradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Ejemplo n.º 9
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            var gradientView = Element as GradientBackgroundView;
            var gradient     = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                                   gradientView.StartColor.ToAndroid(),
                                                                   gradientView.EndColor.ToAndroid(),
                                                                   Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);

            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
Ejemplo n.º 10
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            #region for Vertical Gradient
            //var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
            #endregion
            #region for Horizontal Gradient
            var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,
                                                               #endregion
                                                               this.StartColor.ToAndroid(),
                                                               this.EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };
            paint.SetShader(gradient);
            canvas.DrawRoundRect(0.0f, -LeftBottomCornerRadius, (float)Width + LeftBottomCornerRadius, (float)Height, LeftBottomCornerRadius, LeftBottomCornerRadius, paint);
            base.DispatchDraw(canvas);
        }
 protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
 {
     #region for Vertical Gradient
     //var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
     #endregion
     #region for Horizontal Gradient
     var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, new int[] {
         this.StartColor.ToAndroid(),
         this.MidOneColor.ToAndroid(),
         this.MidTwoColor.ToAndroid(),
         this.EndColor.ToAndroid()
     }, new float[] { 0.0f, 0.25f, 0.75f, 1.0f },
                                                        #endregion
                                                        Android.Graphics.Shader.TileMode.Mirror);
     var paint = new Android.Graphics.Paint()
     {
         Dither = true,
     };
     paint.SetShader(gradient);
     canvas.DrawPaint(paint);
     base.DispatchDraw(canvas);
 }
Ejemplo n.º 12
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            GradientLayout layout = (GradientLayout)this.Element;

            Color[] Colors = layout.Colors;
            GradientColorStackMode Mode = layout.Mode;

            int[] colors = new int[Colors.Length];

            for (int i = 0, l = Colors.Length; i < l; i++)
            {
                colors[i] = Colors[i].ToAndroid().ToArgb();
            }

            // temporary workaround for Android 9 PIE
            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.O)
            {
                GradientDrawable.Orientation orientation;

                switch (Mode)
                {
                default:
                case GradientColorStackMode.ToRight:
                    orientation = GradientDrawable.Orientation.LeftRight;
                    break;

                case GradientColorStackMode.ToTop:
                    orientation = GradientDrawable.Orientation.BottomTop;
                    break;

                case GradientColorStackMode.ToBottom:
                    orientation = GradientDrawable.Orientation.TopBottom;
                    break;

                case GradientColorStackMode.ToTopLeft:
                    orientation = GradientDrawable.Orientation.BrTl;
                    break;

                case GradientColorStackMode.ToTopRight:
                    orientation = GradientDrawable.Orientation.BlTr;
                    break;

                case GradientColorStackMode.ToBottomLeft:
                    orientation = GradientDrawable.Orientation.TrBl;
                    break;

                case GradientColorStackMode.ToBottomRight:
                    orientation = GradientDrawable.Orientation.TlBr;
                    break;
                }

                var gradient2 = new GradientDrawable(orientation, colors);
                ViewCompat.SetBackground(this, gradient2);
                base.DispatchDraw(canvas);
                return;
            }

            Android.Graphics.LinearGradient gradient;
            switch (Mode)
            {
            default:
            case GradientColorStackMode.ToRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTop:
                gradient = new Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottom:
                gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopLeft:
                gradient = new Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToTopRight:
                gradient = new Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientColorStackMode.ToBottomRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }