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); }
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); }
protected override void DispatchDraw(global::Android.Graphics.Canvas canvas) { global::Android.Graphics.LinearGradient gradient; var colors = new int[] { StartColor.ToAndroid().ToArgb(), EndColor.ToAndroid().ToArgb() }; switch (Direction) { default: case GradientDirection.ToRight: gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToLeft: gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToTop: gradient = new global::Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToBottom: gradient = new global::Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToTopLeft: gradient = new global::Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToTopRight: gradient = new global::Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToBottomLeft: gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; case GradientDirection.ToBottomRight: gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror); break; } var paint = new global::Android.Graphics.Paint() { Dither = true, }; paint.SetShader(gradient); canvas.DrawPaint(paint); base.DispatchDraw(canvas); }
protected override void DispatchDraw(global::Android.Graphics.Canvas canvas) { var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, 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); }
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); }
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); }
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 = newGraphics.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.DrawPaint(paint); base.DispatchDraw(canvas); }
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); }
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); }