Esempio n. 1
0
        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 <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                try
                {
                    almeButton = e.NewElement as AlmeButton;
                    GradientDrawable gradientDrawable = new GradientDrawable();
                    gradientDrawable.SetShape(ShapeType.Rectangle);
                    gradientDrawable.SetCornerRadius(almeButton.BorderRadius * 2);
                    if (almeButton.CenterColor != Xamarin.Forms.Color.Transparent)
                    {
                        gradientDrawable.SetColors(new int[] { almeButton.EndColor.ToAndroid(),
                                                               almeButton.CenterColor.ToAndroid(), almeButton.StartColor.ToAndroid() });
                    }
                    else
                    {
                        gradientDrawable.SetColors(new int[] { almeButton.EndColor.ToAndroid(),
                                                               almeButton.StartColor.ToAndroid() });
                    }
                    gradientDrawable.SetGradientType(GradientType.LinearGradient);
                    gradientDrawable.SetOrientation(GradientDrawable.Orientation.RightLeft);
#pragma warning disable CS0618 // Type or member is obsolete
                    Control.SetBackgroundDrawable(gradientDrawable);
#pragma warning restore CS0618 // Type or member is obsolete
                    Control.SetTextColor(almeButton.TextColor.ToAndroid());
                    if (almeButton.FontFamily != null)
                    {
                        Control.Typeface = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, almeButton.FontFamily.Split('#')[0]);
                    }
                }
                catch { }
            }
        }
Esempio n. 3
0
 public override void Draw(Canvas canvas)
 {
     GradientDrawable.Bounds = canvas.ClipBounds;
     GradientDrawable.SetOrientation(EasyGradientView.Orientation == GradientOrientation.Vertical ? GradientDrawable.Orientation.TopBottom
         : GradientDrawable.Orientation.LeftRight);
     GradientDrawable.Draw(canvas);
 }
Esempio n. 4
0
        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);
            }
        }
        void UpdateStyle()
        {
            var view    = Control ?? Container;
            var bgColor = (Element as VisualElement)?.BackgroundColor ?? Color.Transparent;

            PaintDrawable    paint    = new PaintDrawable(bgColor.ToAndroid());
            GradientDrawable gradient = new GradientDrawable();

            paint.SetCornerRadius(Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.CornerRadiusProperty)));
            gradient.SetCornerRadius(Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.CornerRadiusProperty)));
            gradient.SetColor(Color.Transparent.ToAndroid());
            gradient.SetOrientation(GradientDrawable.Orientation.LeftRight);
            gradient.SetShape(ShapeType.Rectangle);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                view.Elevation    = Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.ShadowOffsetYProperty));
                view.TranslationZ = Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.ShadowOffsetYProperty));
            }

            gradient.SetStroke((int)Forms.Context.ToPixels(ViewEffect.GetBorderWidth(Element)), ((Color)Element.GetValue(ViewEffect.BorderColorProperty)).ToAndroid());
            LayerDrawable layer = new LayerDrawable(
                new Drawable[]
            {
                paint, gradient
            });

            view.SetBackground(layer);
        }
Esempio n. 6
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            //var resources = Control.Context.Resources;
            //var metrics = resources.DisplayMetrics;
            //float dp = 5 * ((float)metrics.DensityDpi / (float)DisplayMetricsDensity.Default);

            var formsButton      = Element as CustomGradientButton;
            var gradientDrawable = new GradientDrawable();

            gradientDrawable.SetCornerRadius(formsButton.BorderRadius);
            gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop);
            gradientDrawable.SetColors(new int[] { formsButton.EndColor.MultiplyAlpha(formsButton.AlphaMultiplier).ToAndroid().ToArgb(), formsButton.StartColor.MultiplyAlpha(formsButton.AlphaMultiplier).ToAndroid().ToArgb() });
            if (formsButton.HasBorder)
            {
                gradientDrawable.SetStroke((int)formsButton.BorderWidth, formsButton.BorderColor.ToAndroid());
            }

            if (Control != null)
            {
                Control.Background = gradientDrawable;
                Control.SetTextColor(formsButton.TextColor.ToAndroid());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Method triggered when changes occures on gradient parameters
        /// </summary>
        private void UpdateBackgroundColor(GradientDrawable gradientDrawable)
        {
            var customFrame       = (Element as CrossRoundedFrame);
            var startColor        = customFrame?.StartColor;
            var endColor          = customFrame?.EndColor;
            var gradientDirection = customFrame?.GradientDirection;

            if (startColor.Value.IsDefault && endColor.Value.IsDefault)
            {
                var aColor = customFrame.BackgroundColor.IsDefault ? Xamarin.Forms.Color.Accent.ToAndroid() : customFrame.BackgroundColor.ToAndroid();
                gradientDrawable.SetColor(aColor);
                return;
            }

            int[] colors = new int[2];

            colors[0] = startColor.Value.ToAndroid();
            colors[1] = endColor.Value.ToAndroid();

            switch (gradientDirection.Value)
            {
            default:
            case GradientDirections.ToRight:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.LeftRight);
                break;

            case GradientDirections.ToLeft:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.RightLeft);
                break;

            case GradientDirections.ToTop:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop);
                break;

            case GradientDirections.ToBottom:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.TopBottom);
                break;

            case GradientDirections.ToTopLeft:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.BrTl);
                break;

            case GradientDirections.ToTopRight:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.BlTr);
                break;

            case GradientDirections.ToBottomLeft:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.TrBl);
                break;

            case GradientDirections.ToBottomRight:
                gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr);
                break;
            }

            gradientDrawable.SetColors(colors);
        }
 protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
 {
     GradientDrawable.Bounds = canvas.ClipBounds;
     GradientDrawable.SetOrientation(GradientContentView.Orientation == GradientOrientation.Vertical ? GradientDrawable.Orientation.TopBottom
                         : GradientDrawable.Orientation.LeftRight);
     GradientDrawable.Draw(canvas);
     return(base.DrawChild(canvas, child, drawingTime));
 }
Esempio n. 9
0
        public static void SetOrientation(this GradientDrawable drawable, double angle)
        {
            var orientation = angle >= 0 && angle < 45 ? Orientation.LeftRight :
                              angle < 90 ? Orientation.BlTr :
                              angle < 135 ? Orientation.BottomTop :
                              angle < 180 ? Orientation.BrTl :
                              angle < 225 ? Orientation.RightLeft :
                              angle < 270 ? Orientation.TrBl :
                              angle < 315 ? Orientation.TopBottom : Orientation.TlBr;

            drawable.SetOrientation(orientation);
        }
Esempio n. 10
0
        protected override void OnElementChanged(ElementChangedEventArgs <GradientBoxView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                _drawable = new GradientDrawable();
                _drawable.SetOrientation(GradientDrawable.Orientation.TopBottom);

                this.SetBackground(_drawable);
            }

            UpdateColors();
        }
        void UpdateGradient()
        {
            var colors = Gradient.GetColors(Element);

            if (colors == null)
            {
                return;
            }

            _gradient.SetColors(colors.Select(x => (int)x.ToAndroid()).ToArray());
            _gradient.SetOrientation(ConvertOrientation());

            _view.ClipToOutline = true; //not to overflow children
            _view.SetBackground(_gradient);
        }
Esempio n. 12
0
        public static void UpdateFrom(this View nativeControl, Controls.RoundedBoxView.RoundedBoxView formsControl,
                                      string propertyChanged)
        {
            if (nativeControl == null || formsControl == null)
            {
                return;
            }

            if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.CornerRadiusProperty.PropertyName)
            {
                nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
            }
            if (propertyChanged == VisualElement.BackgroundColorProperty.PropertyName)
            {
                var background = nativeControl.Background as GradientDrawable;

                if (background != null)
                {
                    background.SetColor(formsControl.BackgroundColor.ToAndroid());
                }
                else
                {
                    var grad = new GradientDrawable();
                    grad.SetOrientation(GradientDrawable.Orientation.TopBottom);
                    grad.SetColors(new[]
                    {
                        formsControl.BackgroundColor.ToAndroid().ToArgb(),
                        formsControl.BackgroundColor.ToAndroid().ToArgb()
                    });

                    nativeControl.Background = grad;
                }

                nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
                nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness);
            }

            if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.BorderColorProperty.PropertyName)
            {
                nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness);
            }

            if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.BorderThicknessProperty.PropertyName)
            {
                nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness);
            }
        }
Esempio n. 13
0
        public static Drawable CreateBackgroundGradient(Color startColor, Color endColor, Color centerColor,
                                                        float cornerRadius, GradientDrawable.Orientation orientation)
        {
            GradientDrawable gradientDrawable = new GradientDrawable();

            gradientDrawable.SetShape(ShapeType.Rectangle);
            gradientDrawable.SetCornerRadius(cornerRadius);
            if (centerColor != Xamarin.Forms.Color.Transparent.ToAndroid())
            {
                gradientDrawable.SetColors(new int[] { startColor,
                                                       centerColor, endColor });
            }
            else
            {
                gradientDrawable.SetColors(new int[] { startColor, endColor });
            }
            gradientDrawable.SetGradientType(GradientType.LinearGradient);
            gradientDrawable.SetOrientation(orientation);
            return(gradientDrawable);
        }
Esempio n. 14
0
        internal static void SetGradientOrientation(this GradientDrawable drawable, double angle)
        {
            Orientation orientation = Orientation.LeftRight;

            switch (angle)
            {
            case 0:
                orientation = Orientation.LeftRight;
                break;

            case 45:
                orientation = Orientation.TlBr;
                break;

            case 90:
                orientation = Orientation.TopBottom;
                break;

            case 135:
                orientation = Orientation.TrBl;
                break;

            case 180:
                orientation = Orientation.RightLeft;
                break;

            case 225:
                orientation = Orientation.BrTl;
                break;

            case 270:
                orientation = Orientation.BottomTop;
                break;

            case 315:
                orientation = Orientation.BlTr;
                break;
            }

            drawable.SetOrientation(orientation);
        }
Esempio n. 15
0
        private void ApplyStyle()
        {
            var frame = Element as CustomFrame;

            var gradientDrawable = new GradientDrawable();

            gradientDrawable.SetCornerRadius(frame.CornerRadius);
            gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop);
            gradientDrawable.SetColors(new int[] { frame.EndColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(),
                                                   frame.StartColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb() });
            if (frame.HasBorder)
            {
                gradientDrawable.SetStroke((int)frame.StrokeThickness, frame.OutlineColor.ToAndroid());
            }

            var ld = default(LayerDrawable);

            if (frame.HasShadow)
            {
                var shadow = new GradientDrawable();

                int[] colors1 = { frame.ShadowColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(),
                                  Color.Transparent.ToAndroid().ToArgb() };
                shadow.SetOrientation(GradientDrawable.Orientation.TopBottom);
                //shadow.SetColors(colors1);
                shadow.SetStroke((int)frame.StrokeThickness + 5, frame.ShadowColor.ToAndroid());
                shadow.SetCornerRadius(frame.CornerRadius);

                ld = new LayerDrawable(new Drawable[] { shadow, gradientDrawable });

                ld.SetLayerInset(0, 0, 0, 0, 0);
                ld.SetLayerInset(1, 0, 6, 0, 0);
            }
            else
            {
                ld = new LayerDrawable(new Drawable[] { gradientDrawable });
                ld.SetLayerInset(0, 0, 0, 0, 0);
            }

            Background = ld;
        }
        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);
            }
        }
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            GradientDrawable.Bounds = canvas.ClipBounds;

            switch (GradientContentView.Orientation)
            {
            case GradientOrientation.Vertical:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.TopBottom);
                break;

            case GradientOrientation.Horizontal:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.LeftRight);
                break;

            case GradientOrientation.BrTl:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.BrTl);
                break;

            case GradientOrientation.BlTr:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.BlTr);
                break;

            case GradientOrientation.TlBr:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr);
                break;

            case GradientOrientation.TrBl:
                GradientDrawable.SetOrientation(GradientDrawable.Orientation.TrBl);
                break;

            default:
                break;
            }

            GradientDrawable.Draw(canvas);
            return(base.DrawChild(canvas, child, drawingTime));
        }
Esempio n. 18
0
        void SetGradientOrientation()
        {
            var control = (GradientTabbedPage)this.Element;

            gradient.SetGradientType(GradientType.LinearGradient);

            if (control.Orientation == GradientOrientation.Horizontal)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.LeftRight);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
            else if (control.Orientation == GradientOrientation.Vertical)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.TopBottom);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
            else if (control.Orientation == GradientOrientation.BlTr)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.BlTr);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
            else if (control.Orientation == GradientOrientation.BrTl)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.BlTr);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
            else if (control.Orientation == GradientOrientation.TlBr)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.TlBr);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
            else if (control.Orientation == GradientOrientation.TrBl)
            {
                gradient.SetOrientation(GradientDrawable.Orientation.TrBl);
                gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() });
            }
        }
Esempio n. 19
0
        public void UpdateHeader(UserProfileResponse profile)
        {
            if (profile == null)
            {
                return;
            }

            _profile    = profile;
            _userAvatar = profile.ProfileImage;
            if (!string.IsNullOrEmpty(_userAvatar))
            {
                Picasso.With(_context).Load(_userAvatar.GetImageProxy(_profileImage.LayoutParameters.Width, _profileImage.LayoutParameters.Height))
                .Placeholder(Resource.Drawable.ic_holder)
                .NoFade()
                .Into(_profileImage, null, OnError);
            }
            else
            {
                Picasso.With(_context).Load(Resource.Drawable.ic_holder).Into(_profileImage);
            }

            _transferButton.Visibility = AppSettings.User.HasPostingPermission ? ViewStates.Visible : ViewStates.Gone;

            if (profile.Username.Equals(AppSettings.User.Login, StringComparison.OrdinalIgnoreCase))
            {
                _votingPower.VotingPower    = (float)profile.VotingPower;
                _votingPower.Draw           = true;
                _followContainer.Visibility = ViewStates.Gone;
            }
            else
            {
                if (profile.FollowedChanging)
                {
                    _followBtnBackground.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 });
                    _followBtnBackground.SetOrientation(GradientDrawable.Orientation.LeftRight);
                    _followBtnBackground.SetStroke(0, Color.White);
                    _followButton.Text = string.Empty;
                    _followButton.SetTextColor(Color.White);
                    _followButton.Enabled      = false;
                    _loadingSpinner.Visibility = ViewStates.Visible;
                }
                else
                {
                    if (profile.HasFollowed)
                    {
                        _followBtnBackground.SetColors(new int[] { Color.White, Color.White });
                        _followBtnBackground.SetStroke(3, Style.R244G244B246);
                        _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Unfollow);
                        _followButton.SetTextColor(Style.R15G24B30);
                    }
                    else
                    {
                        _followBtnBackground.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 });
                        _followBtnBackground.SetOrientation(GradientDrawable.Orientation.LeftRight);
                        _followBtnBackground.SetStroke(0, Color.White);
                        _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Follow);
                        _followButton.SetTextColor(Color.White);
                    }
                    _followButton.Enabled      = true;
                    _loadingSpinner.Visibility = ViewStates.Gone;
                }
            }

            if (!string.IsNullOrEmpty(profile.Name))
            {
                _name.Text = profile.Name;
                _name.SetTextColor(Style.R15G24B30);
            }
            else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase))
            {
                _name.Visibility = ViewStates.Gone;
            }

            if (!string.IsNullOrEmpty(profile.Location))
            {
                _place.Text = profile.Location.Trim();
            }
            else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase))
            {
                _place.Visibility = ViewStates.Gone;
            }

            if (!string.IsNullOrEmpty(profile.About))
            {
                _description.Text = profile.About;
                _description.SetTextColor(Style.R15G24B30);
            }
            else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase))
            {
                _description.Visibility = ViewStates.Gone;
            }

            if (!string.IsNullOrEmpty(profile.Website))
            {
                _site.AutoLinkText = profile.Website;
                _site.SetTextColor(Style.R231G72B00);
            }
            else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase))
            {
                _site.Visibility = ViewStates.Gone;
            }

            _photosCount.Text    = profile.PostCount.ToString("N0");
            _followingCount.Text = profile.FollowingCount.ToString("#,##0");
            _followersCount.Text = profile.FollowersCount.ToString("#,##0");

            _balance.Text = StringHelper.ToFormatedCurrencyString(profile.EstimatedBalance, App.MainChain);
        }
Esempio n. 20
0
 public static void SetOrientation(this GradientDrawable drawable, float angle)
 {
     drawable.SetOrientation((double)angle);
 }
Esempio n. 21
0
        private void UpdateGradientColors()
        {
            var extendedButton = Element as ExtendedButton;
            var gradientColors = extendedButton?.GradientColors;

            if (gradientColors == null || !gradientColors.Any() || extendedButton.Width <= 0 || extendedButton.Height <= 0)
            {
                return;
            }

            /* ==================================================================================================
             * convert the colors to Android Color objects
             * ================================================================================================*/
            var androidColors = gradientColors.Select(arg => (int)arg.ToAndroid()).ToArray();

            /* ==================================================================================================
             * create the gradient
             * ================================================================================================*/
            _gradient = _gradient ?? new GradientDrawable(GradientDrawable.Orientation.LeftRight, androidColors);

            /* ==================================================================================================
             * set the flow
             * ================================================================================================*/
            switch (extendedButton.GradientFlow)
            {
            case ExtendedButton.Flows.LeftToRight:
                _gradient.SetOrientation(GradientDrawable.Orientation.LeftRight);
                break;

            case ExtendedButton.Flows.TopDown:
                _gradient.SetOrientation(GradientDrawable.Orientation.TopBottom);
                break;

            default:
                throw new ArgumentOutOfRangeException($"The {nameof(ExtendedButton.GradientFlow)}: {extendedButton?.GradientFlow.ToString() ?? "-"} is not supported yet!");
            }

            /* ==================================================================================================
             * update conrner radius
             * ================================================================================================*/
            var cornerRadius = extendedButton.CornerRadius;

            _gradient.SetCornerRadii(new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius });

            /* ==================================================================================================
             * finish up
             * ================================================================================================*/
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            {
                /* ==================================================================================================
                 * keep the built-in effect of button
                 * ================================================================================================*/
                var     bg     = Control.Background as RippleDrawable;
                int[][] states =
                {
                    new int[] { Android.Resource.Attribute.StateEnabled  }, // enabled
                    new int[] { Android.Resource.Attribute.OnClick       }, // hover
                    new int[] { -Android.Resource.Attribute.StateEnabled }, // Disabled
                };
                var colors = new int[] { Android.Graphics.Color.LightGray, Android.Graphics.Color.DarkGray, Android.Graphics.Color.DarkGray };
                bg.SetColor(new ColorStateList(states, colors));
                if (bg.NumberOfLayers < 2)
                {
                    bg?.AddLayer(_gradient);
                }
                Control.SetBackground(bg);
            }
            else
            {
                // todo: keep base hightlight effect
                Control?.SetBackground(_gradient);
                lock (_lockObj)
                {
                    if (!_isEventSet)
                    {
                        //Control.Touch += Control_Touch;
                        _isEventSet = true;
                    }
                }
            }
        }
Esempio n. 22
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            try
            {
                if (e.NewElement != null)
                {
                    var view = (BinEntry)Element;



                    //if (e.PropertyName == LineEntry.BorderColorProperty.PropertyName)
                    //{
                    //    Control.Background.SetColorFilter(element.BorderColor.ToAndroid(), PorterDuff.Mode.SrcAtop);
                    //}
                    //if (e.PropertyName == LineEntry.IconPaddingProperty.PropertyName)
                    //{
                    //    Control.SetPadding(Control.PaddingLeft + (element.IconPadding ? 68 : 0), Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom);
                    //}


                    if (view.IsCurvedCornersEnabled)
                    {
                        // creating gradient drawable for the curved background
                        var _gradientBackground = new GradientDrawable();
                        _gradientBackground.SetOrientation(GradientDrawable.Orientation.BottomTop);
                        _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)));

                        // set the background of the label

                        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);
                    }
                    else
                    {
                        //var _gradientBackground = new GradientDrawable();
                        //_gradientBackground.SetOrientation(GradientDrawable.Orientation.TopBottom);


                        //_gradientBackground.SetGradientCenter(0, (float)view.Height);

                        //_gradientBackground.SetShape(ShapeType.Line);
                        //_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)));

                        //// set the background of the label
                        //Control.SetBackground(_gradientBackground);

                        Control.Background.SetColorFilter(view.BorderColor.ToAndroid(), PorterDuff.Mode.SrcAtop);
                        //Control.SetPadding(Control.PaddingLeft + (element.IconPadding ? 68 : 0), Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom);
                        //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);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 23
0
            public void UpdateData(UserFriend userFriends)
            {
                _userFriends = userFriends;

                if (string.IsNullOrEmpty(userFriends.Name))
                {
                    _friendName.Visibility = ViewStates.Gone;
                }
                else
                {
                    _friendName.Visibility = ViewStates.Visible;
                    _friendName.Text       = userFriends.Name;
                }

                if (userFriends.AmountSbd != 0)
                {
                    _sbdAmount.Visibility = ViewStates.Visible;
                    _sbdAmount.Text       = $"{(userFriends.AmountSbd > 0 ? "+" : "-")}${Math.Abs(userFriends.AmountSbd)}";
                }
                else
                {
                    _sbdAmount.Visibility = ViewStates.Gone;
                }

                _friendLogin.Text = userFriends.Author;

                if (!string.IsNullOrEmpty(_userFriends.Avatar))
                {
                    Picasso.With(_context).Load(_userFriends.Avatar.GetProxy(_friendAvatar.LayoutParameters.Width, _friendAvatar.LayoutParameters.Height))
                    .Placeholder(Resource.Drawable.ic_holder)
                    .NoFade()
                    .Priority(Picasso.Priority.Normal)
                    .Into(_friendAvatar, null, OnError);
                }
                else
                {
                    Picasso.With(_context).Load(Resource.Drawable.ic_holder).Into(_friendAvatar);
                }

                _followButton.Visibility = AppSettings.User.Login == _friendLogin.Text
                    ? ViewStates.Gone
                    : ViewStates.Visible;

                if (string.Equals(AppSettings.User.Login, userFriends.Author, StringComparison.OrdinalIgnoreCase))
                {
                    _followButton.Visibility = ViewStates.Invisible;
                }
                else
                {
                    var background = new GradientDrawable();
                    _followButton.Background = null;

                    if (userFriends.FollowedChanging)
                    {
                        background.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 });
                        background.SetOrientation(GradientDrawable.Orientation.LeftRight);
                        background.SetStroke(0, Color.White);
                        _followButton.Text = string.Empty;
                        _followButton.SetTextColor(Color.White);
                        _followButton.Enabled = false;
                        _loader.Visibility    = ViewStates.Visible;
                    }
                    else
                    {
                        if (userFriends.HasFollowed)
                        {
                            background.SetColors(new int[] { Color.White, Color.White });
                            background.SetStroke(3, Style.R244G244B246);
                            _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Unfollow);
                            _followButton.SetTextColor(Style.R15G24B30);
                        }
                        else
                        {
                            background.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 });
                            background.SetOrientation(GradientDrawable.Orientation.LeftRight);
                            background.SetStroke(0, Color.White);
                            _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Follow);
                            _followButton.SetTextColor(Color.White);
                        }
                        _followButton.Enabled = true;
                        _loader.Visibility    = ViewStates.Gone;
                    }
                    background.SetCornerRadius(100);
                    _followButton.Background = background;
                }
            }