Exemplo n.º 1
0
        public Drawable GetBorderBackground(Xamarin.Forms.Color borderColor, Xamarin.Forms.Color backgroundColor, float borderWidth, float borderRadius)
        {
            if (_background != null)
            {
                _background.Dispose();
                _background = null;
            }

            borderWidth     = borderWidth > 0 ? borderWidth : 0;
            borderRadius    = borderRadius > 0 ? borderRadius : 0;
            borderColor     = borderColor != Xamarin.Forms.Color.Default ? borderColor : Xamarin.Forms.Color.Transparent;
            backgroundColor = backgroundColor != Xamarin.Forms.Color.Default ? backgroundColor : Xamarin.Forms.Color.Transparent;

            float strokeWidth = Application.Context.ToPixels(borderWidth);
            float radius      = Application.Context.ToPixels(borderRadius);

            _background = new GradientDrawable();
            _background.SetColor(backgroundColor.ToAndroid());

            if (radius > 0)
            {
                _background.SetCornerRadius(radius);
            }

            if (borderColor != Xamarin.Forms.Color.Transparent && strokeWidth > 0)
            {
                _background.SetStroke((int)strokeWidth, borderColor.ToAndroid());
            }

            return(_background);
        }
Exemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (Element != null)
                {
                    Element.PropertyChanged -= OnElementPropertyChanged;
                }

                if (_visualElementTracker != null)
                {
                    _visualElementTracker.Dispose();
                    _visualElementTracker = null;
                }

                if (_visualElementPackager != null)
                {
                    _visualElementPackager.Dispose();
                    _visualElementPackager = null;
                }

                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }

                if (_visualElementRenderer != null)
                {
                    _visualElementRenderer.Dispose();
                    _visualElementRenderer = null;
                }

                while (ChildCount > 0)
                {
                    AView child = GetChildAt(0);
                    child.RemoveFromParent();
                    child.Dispose();
                }

                if (Element != null)
                {
                    if (Platform.GetRenderer(Element) == this)
                    {
                        Element.ClearValue(Platform.RendererProperty);
                    }
                }
            }

            base.Dispose(disposing);
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_background != null)
         {
             _background.Dispose();
             _background = null;
         }
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                MaterialFrame?.Unsubscribe();
                Destroy();

                _mainDrawable = null;

                _acrylicLayer?.Dispose();
                _acrylicLayer = null;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }

                if (Element != null)
                {
                    Element.PropertyChanged -= OnElementPropertyChanged;

                    if (AppCompat.Platform.GetRenderer(Element) == this)
                    {
                        Element.ClearValue(AppCompat.Platform.RendererProperty);
                    }
                }
            }

            base.Dispose(disposing);
        }
Exemplo n.º 6
0
        void UpdateCornerRadius()
        {
            var cornerRadius = Element.CornerRadius;

            if (cornerRadius == new CornerRadius(0d))
            {
                _backgroundDrawable?.Dispose();
                _backgroundDrawable = null;
            }
            else
            {
                this.SetBackground(_backgroundDrawable = new GradientDrawable());
                if (Background is GradientDrawable backgroundGradient)
                {
                    var cornerRadii = new[] {
                        (float)(Context.ToPixels(cornerRadius.TopLeft)),
                        (float)(Context.ToPixels(cornerRadius.TopLeft)),

                        (float)(Context.ToPixels(cornerRadius.TopRight)),
                        (float)(Context.ToPixels(cornerRadius.TopRight)),

                        (float)(Context.ToPixels(cornerRadius.BottomRight)),
                        (float)(Context.ToPixels(cornerRadius.BottomRight)),

                        (float)(Context.ToPixels(cornerRadius.BottomLeft)),
                        (float)(Context.ToPixels(cornerRadius.BottomLeft))
                    };

                    backgroundGradient.SetCornerRadii(cornerRadii);
                }
            }

            UpdateBackgroundColor();
        }
Exemplo n.º 7
0
        protected override void OnDetached()
        {
            var renderer = Container as IVisualElementRenderer;

            if (renderer?.Element != null)
            {
                NativeButton.Background                = OrgBackground;
                NativeButton.StateListAnimator         = OrgStateListAnimator;
                NativeButton.SupportBackgroundTintList = OrgBackgroundTint;
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;
            OrgBackgroundTint    = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
        }
Exemplo n.º 8
0
        protected override void OnDetachedOverride()
        {
            if (!IsDisposed)      // Check disposed
            {
                if (Control is FormsEditTextBase editText)
                {
                    editText.Background = _orgTextBackground;
                }

                if (Element is Label label)
                {
                    (_view as FormsTextView).SetBackgroundColor(label.BackgroundColor.ToAndroid());
                }
                else if (Element is Image image)
                {
                    (_view as ImageView).SetBackgroundColor(image.BackgroundColor.ToAndroid());
                }
                else
                {
                    _view.Background = _orgDrawable;
                }

                _view.SetPadding(0, 0, 0, 0);
                _view.ClipToOutline = false;

                System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
            }
            _border?.Dispose();
            _border            = null;
            _orgDrawable       = null;
            _orgTextBackground = null;
            _view = null;
            System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
        }
        protected override void OnDetached()
        {
            if (!IsDisposed)
            {
                NativeButton.Background        = OrgBackground;
                NativeButton.StateListAnimator = OrgStateListAnimator;
                System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
            System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");

            base.OnDetached();
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _mainDrawable = null;

                _acrylicLayer?.Dispose();
                _acrylicLayer = null;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 11
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (_visualElementTracker != null)
                {
                    _visualElementTracker.Dispose();
                    _visualElementTracker = null;
                }

                if (_visualElementPackager != null)
                {
                    _visualElementPackager.Dispose();
                    _visualElementPackager = null;
                }

                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }

                _visualElementRenderer?.Dispose();
                _visualElementRenderer = null;

                int count = ChildCount;
                for (var i = 0; i < count; i++)
                {
                    AView child = GetChildAt(i);
                    child.Dispose();
                }

                if (Element != null)
                {
                    Element.PropertyChanged -= OnElementPropertyChanged;

                    if (Platform.GetRenderer(Element) == this)
                    {
                        Element.ClearValue(Platform.RendererProperty);
                    }
                }
            }

            base.Dispose(disposing);
        }
Exemplo n.º 12
0
        private void Destroy()
        {
            InternalLogger.Debug("AndroidMaterialFrameRenderer", "Destroy()");

            _mainDrawable = null;

            DestroyBlur();

            if (!_acrylicLayer.IsNullOrDisposed())
            {
                _acrylicLayer.Dispose();
                _acrylicLayer = null;
            }
        }
Exemplo n.º 13
0
        protected override void OnDetachedOverride()
        {
            if (!IsDisposed)
            {
                _view.Background    = _orgDrawable;
                _view.ClipToOutline = false;
                System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
            }

            _gradient?.Dispose();
            _gradient = null;
            _view     = null;
            System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
        }
Exemplo n.º 14
0
 protected override void OnDetached()
 {
     if (!IsDisposed)      // Check disposed
     {
         _view.Background = _orgDrawable;
         if (Control == null)
         {
             _view.SetPadding(0, 0, 0, 0);
             _view.ClipToOutline = false;
         }
     }
     _border?.Dispose();
     _border = null;
     _view   = null;
 }
        protected override void OnDetachedOverride()
        {
            if (!IsDisposed)      // Check disposed
            {
                _view.Background = _orgDrawable;

                _view.SetPadding(0, 0, 0, 0);
                _view.ClipToOutline = false;

                System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
            }
            _border?.Dispose();
            _border = null;
            _view   = null;
            System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
        }
Exemplo n.º 16
0
        protected override void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;

            if (disposing)
            {
                _gradientBackground.Dispose();
                _gradientBackground = null;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 17
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            _disposed = true;

            if (disposing)
            {
                _gestureManager?.Dispose();

                _visualElementTracker?.Dispose();
                _visualElementTracker = null;

                _visualElementPackager?.Dispose();
                _visualElementPackager = null;

                _defaultBackgroundDrawable?.Dispose();
                _defaultBackgroundDrawable = null;

                _backgroundGradientDrawable?.Dispose();
                _backgroundGradientDrawable = null;

                var count = ChildCount;
                for (var i = 0; i < count; i++)
                {
                    var child = GetChildAt(i);
                    child.Dispose();
                }

                if (Element != null)
                {
                    Element.PropertyChanged -= OnElementPropertyChanged;

                    if (Platform.Android.Platform.GetRenderer(Element) == this)
                    {
                        Element.ClearValue(Platform.Android.Platform.RendererProperty);
                    }
                }
            }

            base.Dispose(disposing);
        }
Exemplo n.º 18
0
        protected override void OnDetached()
        {
            if (!IsDisposed)
            {
                NativeButton.Background        = OrgBackground;
                NativeButton.StateListAnimator = OrgStateListAnimator;
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
        }