Esempio n. 1
0
        public static void SetColorFilter(this ADrawable drawable, Graphics.Color color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            drawable.SetColorFilter(color.ToPlatform(), mode);
        }
Esempio n. 2
0
        public static void UpdateTextColor(this TextView textView, ITextStyle textStyle, Graphics.Color?defaultColor)
        {
            var textColor = textStyle.TextColor?.ToPlatform() ?? defaultColor?.ToPlatform();

            if (textColor != null)
            {
                textView.SetTextColor(textColor.Value);
            }
        }
Esempio n. 3
0
        public static void UpdateThumbColor(this UISwitch uiSwitch, ISwitch view, UIColor?defaultThumbColor)
        {
            if (view == null)
            {
                return;
            }

            Graphics.Color thumbColor = view.ThumbColor;
            uiSwitch.ThumbTintColor = thumbColor?.ToPlatform() ?? defaultThumbColor;
        }
Esempio n. 4
0
 public static void UpdateTextColor(this EditText editText, Graphics.Color textColor)
 {
     if (textColor != null)
     {
         var androidColor = textColor.ToPlatform();
         if (!editText.TextColors.IsOneColor(ColorStates.EditText, androidColor))
         {
             editText.SetTextColor(ColorStateListExtensions.CreateEditText(androidColor));
         }
     }
 }
Esempio n. 5
0
 public static void UpdatePlaceholderColor(this EditText editText, Graphics.Color placeholderTextColor)
 {
     if (placeholderTextColor != null)
     {
         var androidColor = placeholderTextColor.ToPlatform();
         if (!editText.HintTextColors.IsOneColor(ColorStates.EditText, androidColor))
         {
             editText.SetHintTextColor(ColorStateListExtensions.CreateEditText(androidColor));
         }
     }
 }
Esempio n. 6
0
        public static void UpdateThumbColor(this UISwitch uiSwitch, ISwitch view)
        {
            if (view == null)
            {
                return;
            }

            Graphics.Color thumbColor = view.ThumbColor;
            if (thumbColor != null)
            {
                uiSwitch.ThumbTintColor = thumbColor?.ToPlatform();
            }
        }
Esempio n. 7
0
        public static void SetColorFilter(this ADrawable drawable, Graphics.Color color, FilterMode mode, AColorFilter?defaultColorFilter)
        {
            if (drawable == null)
            {
                return;
            }

            if (color == null)
            {
                SetColorFilter(drawable, defaultColorFilter);
            }
            else
            {
                drawable.SetColorFilter(color.ToPlatform(), mode);
            }
        }
Esempio n. 8
0
        internal static ColorStateList GetColorStateList(this AppCompatCheckBox platformCheckBox, ICheckBox check)
        {
            AColor tintColor;

            // For the moment, we're only supporting solid color Paint for the Android Checkbox
            if (check.Foreground is SolidPaint solid)
            {
                var color = solid.Color;
                tintColor = color.ToPlatform();
            }
            else
            {
                Graphics.Color accent = platformCheckBox.Context?.GetAccentColor() ?? Graphics.Color.FromArgb("#ff33b5e5");
                tintColor = accent.ToPlatform();
            }

            return(ColorStateListExtensions.CreateCheckBox(tintColor));
        }
Esempio n. 9
0
        void DrawShadow(Canvas canvas)
        {
            if (_shadowCanvas == null)
            {
                _shadowCanvas = new Canvas();
            }

            if (_shadowPaint == null)
            {
                _shadowPaint = new Android.Graphics.Paint
                {
                    AntiAlias    = true,
                    Dither       = true,
                    FilterBitmap = true
                }
            }
            ;

            Graphics.Color solidColor = null;

            // If need to redraw shadow
            if (_invalidateShadow)
            {
                var viewHeight = _viewBounds.Height();
                var viewWidth  = _viewBounds.Width();

                if (GetChildAt(0) is AView child)
                {
                    if (viewHeight == 0)
                    {
                        viewHeight = child.MeasuredHeight;
                    }

                    if (viewWidth == 0)
                    {
                        viewWidth = child.MeasuredWidth;
                    }
                }

                // If bounds is zero
                if (viewHeight != 0 && viewWidth != 0)
                {
                    var bitmapHeight = viewHeight + MaximumRadius;
                    var bitmapWidth  = viewWidth + MaximumRadius;

                    // Reset bitmap to bounds
                    _shadowBitmap = Bitmap.CreateBitmap(
                        bitmapWidth, bitmapHeight, Bitmap.Config.Argb8888
                        );

                    // Reset Canvas
                    _shadowCanvas.SetBitmap(_shadowBitmap);

                    _invalidateShadow = false;

                    // Create the local copy of all content to draw bitmap as a
                    // bottom layer of natural canvas.
                    base.DispatchDraw(_shadowCanvas);

                    // Get the alpha bounds of bitmap
                    Bitmap extractAlpha = _shadowBitmap.ExtractAlpha();

                    // Clear past content content to draw shadow
                    _shadowCanvas.DrawColor(Android.Graphics.Color.Black, PorterDuff.Mode.Clear);

                    var shadowOpacity = (float)Shadow.Opacity;

                    if (Shadow.Paint is LinearGradientPaint linearGradientPaint)
                    {
                        var linearGradientShaderFactory = PaintExtensions.GetLinearGradientShaderFactory(linearGradientPaint, shadowOpacity);
                        _shadowPaint.SetShader(linearGradientShaderFactory.Resize(bitmapWidth, bitmapHeight));
                    }
                    if (Shadow.Paint is RadialGradientPaint radialGradientPaint)
                    {
                        var radialGradientShaderFactory = PaintExtensions.GetRadialGradientShaderFactory(radialGradientPaint, shadowOpacity);
                        _shadowPaint.SetShader(radialGradientShaderFactory.Resize(bitmapWidth, bitmapHeight));
                    }
                    if (Shadow.Paint is SolidPaint solidPaint)
                    {
                        solidColor = solidPaint.ToColor();
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
                        _shadowPaint.Color = solidColor.WithAlpha(shadowOpacity).ToPlatform();
#pragma warning restore CA1416
                    }

                    // Apply the shadow radius
                    var radius = Shadow.Radius;

                    if (radius <= 0)
                    {
                        radius = 0.01f;
                    }

                    if (radius > 100)
                    {
                        radius = MaximumRadius;
                    }

                    _shadowPaint.SetMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.Normal));

                    float shadowOffsetX = (float)Shadow.Offset.X;
                    float shadowOffsetY = (float)Shadow.Offset.Y;

                    if (Clip == null)
                    {
                        _shadowCanvas.DrawBitmap(extractAlpha, shadowOffsetX, shadowOffsetY, _shadowPaint);
                    }
                    else
                    {
                        var bounds = new Graphics.RectF(0, 0, canvas.Width, canvas.Height);
                        var path   = Clip.PathForBounds(bounds)?.AsAndroidPath();

                        path.Offset(shadowOffsetX, shadowOffsetY);

                        _shadowCanvas.DrawPath(path, _shadowPaint);
                    }

                    // Recycle and clear extracted alpha
                    extractAlpha.Recycle();
                }
                else
                {
                    // Create placeholder bitmap when size is zero and wait until new size coming up
                    _shadowBitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Rgb565 !);
                }
            }

            // Reset alpha to draw child with full alpha
            if (solidColor != null)
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
            {
                _shadowPaint.Color = solidColor.ToPlatform();
            }
#pragma warning restore CA1416

            // Draw shadow bitmap
            if (_shadowCanvas != null && _shadowBitmap != null && !_shadowBitmap.IsRecycled)
            {
                canvas.DrawBitmap(_shadowBitmap, 0.0F, 0.0F, _shadowPaint);
            }
        }

        void ClearShadowResources()
        {
            _shadowCanvas?.Dispose();
            _shadowPaint?.Dispose();
            _shadowBitmap?.Dispose();
            _shadowCanvas = null;
            _shadowPaint  = null;
            _shadowBitmap = null;
        }
    }
Esempio n. 10
0
 public static void UpdateTextColor(this EditText editText, Graphics.Color textColor)
 {
     if (textColor != null)
     {
         if (PlatformInterop.CreateEditTextColorStateList(editText.TextColors, textColor.ToPlatform()) is ColorStateList c)
         {
             editText.SetTextColor(c);
         }
     }
 }
Esempio n. 11
0
 public static void UpdatePlaceholderColor(this EditText editText, Graphics.Color placeholderTextColor)
 {
     if (placeholderTextColor != null)
     {
         if (PlatformInterop.CreateEditTextColorStateList(editText.HintTextColors, placeholderTextColor.ToPlatform()) is ColorStateList c)
         {
             editText.SetHintTextColor(c);
         }
     }
 }