private void OnCheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
 {
     if (this.Control.Checked)
     {
         this.Element.IsToggled = true;
         this.Control.TrackDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
         this.Control.ThumbDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
     }
     else
     {
         this.Element.IsToggled = false;
         this.Control.TrackDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
         this.Control.ThumbDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
     }
 }
        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;

            var strokeWidth = Xamarin.Forms.Forms.Context.ToPixels(borderWidth);
            var radius      = Xamarin.Forms.Forms.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);
        }
 public void ChangeColor(Xamarin.Forms.Color color)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
     {
         CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(color.ToAndroid());
     }
 }
        public void SetColor(Color color)
        {
            _dirty = true;
            _color = color == Color.Default
                ? null : (AColor?)color.ToAndroid();

            InvalidateSelf();
        }
Example #5
0
        public void SetStatusBarColor(Xamarin.Forms.Color color)
        {
            if (_activity == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                return;
            }

            _activity.Window?.SetStatusBarColor(color.ToAndroid());
        }
        /// <summary>
        /// Gets the color of the span.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <param name="defaultColors">The default colors.</param>
        /// <returns>Android.Graphics.Color.</returns>
        public Android.Graphics.Color GetSpanColor(Xamarin.Forms.Color color, ColorStateList defaultColors)
        {
            if (color == Xamarin.Forms.Color.Default)
            {
                return(new Android.Graphics.Color(defaultColors.DefaultColor));
            }

            return(color.ToAndroid());
        }
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == CoreSwitch.IsToggledProperty.PropertyName)
     {
         if (this.Control.Checked)
         {
             this.Element.IsToggled = true;
             this.Control.TrackDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
             this.Control.ThumbDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
         }
         else
         {
             this.Element.IsToggled = false;
             this.Control.TrackDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
             this.Control.ThumbDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
         }
     }
     base.OnElementPropertyChanged(sender, e);
 }
Example #8
0
        public static NativeColor ToNative(this Color color)
        {
#if WINDOWS_PHONE || WINDOWS_UWP
            return(color.ToWindows());
#elif __IOS__
            return(color.ToUIColor());
#elif __ANDROID__
            return(color.ToAndroid());
#endif
        }
        public DragItemShadowBuilder(View v, Xamarin.Forms.Color highlightColor) : base(v)
        {
            v.DrawingCacheEnabled = true;
            Bitmap bm = v.DrawingCache;

            shadow = new BitmapDrawable(bm);


            shadow.SetColorFilter(highlightColor.ToAndroid(), PorterDuff.Mode.Multiply);
        }
Example #10
0
        public static void SetBorder(this MaterialCardView view, Context context, Color color, double width)
        {
            if (color != Color.Default)
            {
                view.StrokeColor = color == Color.White
                    ? new global::Android.Graphics.Color(254, 254, 254)
                    : color.ToAndroid();
            }

            view.StrokeWidth = (int)context.ToPixels(width);
        }
        public void SetStroke(double strokeWidth, Color strokeColor)
        {
            _dirty       = true;
            _strokeColor = strokeColor == Color.Default
                ? null : (AColor?)strokeColor.ToAndroid();
            _strokeWidth = (float)(strokeWidth * _density * 2);

            EnsureStrokeAlloc();

            InvalidateSelf();
        }
        public void ShowOverlay(string message, Xamarin.Forms.Color backgroundColor, float backgroundOpacity)
        {
            var alpha = (int)(255 * backgroundOpacity);

            dialog = new Dialog(Ctx, Resource.Style.ThemeNoTitleBar);
            Drawable d = new ColorDrawable(backgroundColor.ToAndroid());

            d.SetAlpha(alpha);
            dialog.Window.SetBackgroundDrawable(d);

            var layout = new LinearLayout(Ctx);

            layout.Orientation      = Widget.Orientation.Vertical;
            layout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);

            var header          = new LinearLayout(Ctx);
            var headerParameter = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

            headerParameter.Weight  = 1;
            header.LayoutParameters = headerParameter;

            var prg = new Widget.ProgressBar(Ctx);

            prg.Indeterminate = true;

            prg.IndeterminateDrawable.SetColorFilter(Graphics.Color.White, PorterDuff.Mode.Multiply);
            var parameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

            parameters.Gravity = Views.GravityFlags.Center;
            parameters.SetMargins(0, 10, 0, 10);
            prg.LayoutParameters = parameters;

            var txtField = new TextView(Ctx);

            txtField.Text     = message;
            txtField.TextSize = 22;
            txtField.SetTextColor(Graphics.Color.White);
            txtField.LayoutParameters = parameters;

            var footer          = new LinearLayout(Ctx);
            var footerParameter = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

            footerParameter.Weight  = 1;
            footer.LayoutParameters = footerParameter;

            layout.AddView(header);
            layout.AddView(prg);
            layout.AddView(txtField);
            layout.AddView(footer);
            dialog.SetContentView(layout);
            dialog.Show();
        }
Example #13
0
        static PaintDrawable CreateBadgeBackground(Context context, XColor color)
        {
            var badgeFrameLayoutBackground = new PaintDrawable();

            badgeFrameLayoutBackground.Paint.Color =
                color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

            badgeFrameLayoutBackground.Shape = new RectShape();
            badgeFrameLayoutBackground.SetCornerRadius(TypedValue.ApplyDimension(ComplexUnitType.Dip, 8,
                                                                                 context.Resources.DisplayMetrics));

            return(badgeFrameLayoutBackground);
        }
Example #14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
            ImageCircleRenderer.Init();
            Xamarin.Forms.Color color = (Xamarin.Forms.Color)App.Current.Resources["PrimaryColor"];
            Window.SetStatusBarColor(color.ToAndroid());
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Switch> e)
        {
            base.OnElementChanged(e);

            if (this.Control != null)
            {
                ctrl       = (CoreSwitch)e.NewElement;
                trueColor  = ctrl.TrueColor;
                falseColor = ctrl.FalseColor;

                if (this.Control.Checked)
                {
                    this.Control.TrackDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
                    this.Control.ThumbDrawable.SetColorFilter(trueColor.ToAndroid(), PorterDuff.Mode.Multiply);
                }
                else
                {
                    this.Control.TrackDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
                    this.Control.ThumbDrawable.SetColorFilter(falseColor.ToAndroid(), PorterDuff.Mode.Multiply);
                }

                this.Control.CheckedChange += this.OnCheckedChange;
            }
        }
Example #16
0
        static TextView CreateBadgeText(Context context, string text, XColor textColor, int textSize = 10)
        {
            var textView = new TextView(context)
            {
                Text             = text,
                LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                {
                    Gravity = GravityFlags.Center
                }
            };

            textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid());
            textView.SetTextSize(ComplexUnitType.Sp, textSize);

            return(textView);
        }
Example #17
0
    public void CreateGradient()
    {
        //Need to convert the colors to Android Color objects
        int[] androidColors = new int[gradientColors.Count()];
        for (int i = 0; i < gradientColors.Count(); i++)
        {
            Xamarin.Forms.Color temp = gradientColors[i];
            androidColors[i] = temp.ToAndroid();
        }
        GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.LeftRight, androidColors);

        if (roundCorners)
        {
            gradient.SetCornerRadii(new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius });
        }
        layout.SetBackground(gradient);
    }
Example #18
0
        /// <summary>
        /// The ApplyTinyBadge.
        /// </summary>
        /// <param name="bottomNavigationView">The bottomNavigationView<see cref="BottomNavigationItemView"/>.</param>
        /// <param name="textColor">The textColor<see cref="XColor"/>.</param>
        public static void ApplyTinyBadge(this BottomNavigationItemView bottomNavigationView, XColor textColor)
        {
            if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                bottomNavigationView.SetClipChildren(false);
                bottomNavigationView.SetClipToPadding(false);

                ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single();
                bottomNavigationView.RemoveView(imageView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                    {
                        Gravity = GravityFlags.CenterHorizontal
                    }
                };

                badgeContainerFrameLayout.AddView(imageView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context);
                badgeContainer.TopMargin  = 24;
                badgeContainer.Visibility = ViewStates.Visible;
                badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, XColor.Transparent);
                badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, "●", textColor, 20));

                badgeContainerFrameLayout.AddView(badgeContainer);

                bottomNavigationView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.TopMargin  = 24;
                badgeContainer.Visibility = ViewStates.Visible;
                ((PaintDrawable)badgeContainer.Background).Paint.Color = XColor.Transparent.ToAndroid();

                TextView textView = (TextView)badgeContainer.GetChildAt(0);
                textView.Text = "●";
                textView.SetTextSize(ComplexUnitType.Sp, 20);
                textView.SetTextColor(textColor.ToAndroid());
            }
        }
Example #19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
            base.OnCreate(savedInstanceState);

            Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            Window window = this.Window;

            window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            Xamarin.Forms.Color    xfColor = (Xamarin.Forms.Color)Xamarin.Forms.Application.Current.Resources["SecondaryColor"];
            Android.Graphics.Color color   = xfColor.ToAndroid();
            window.SetStatusBarColor(color);
        }
Example #20
0
        private void InitializePaints()
        {
            _gradientProvider?.DrawOrClearGradient(Paint, _width, _height);
            if (_color != Color.Default)
            {
                Paint.Color = _color.ToAndroid();
            }

            if (CanDrawBorder())
            {
                _strokePaint.StrokeWidth = _strokeWidth;
                _strokePaint.SetPathEffect(_strokePathEffect);

                _strokeGradientProvider?.DrawOrClearGradient(Paint, _width, _height);
                if (_strokeColor != Color.Default)
                {
                    _strokePaint.Color = _strokeColor.ToAndroid();
                }
            }
        }
 public void SetStroke(int strokeWidth, Color strokeColor)
 {
     _strokePaint.StrokeWidth = strokeWidth;
     _strokePaint.Color       = strokeColor.ToAndroid();
     InvalidateSelf();
 }
Example #22
0
        public static void ApplyBadge(this BottomNavigationItemView bottomNavigationView, XColor color, string text,
                                      XColor textColor)
        {
            if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                bottomNavigationView.SetClipChildren(false);
                bottomNavigationView.SetClipToPadding(false);

                ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single();
                bottomNavigationView.RemoveView(imageView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                    {
                        Gravity = GravityFlags.CenterHorizontal
                    }
                };

                badgeContainerFrameLayout.AddView(imageView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context);
                badgeContainer.TopMargin += 12;

                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, color);
                badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, text, textColor));

                badgeContainerFrameLayout.AddView(badgeContainer);

                bottomNavigationView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

                TextView textView = (TextView)badgeContainer.GetChildAt(0);
                textView.Text = text;
                textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid());
            }
        }
Example #23
0
        public static void SetColorFilter(this Drawable drawable, FormsColor color, ColorFilter defaultColorFilter, BlendModeCompat mode)
        {
            if (drawable is null)
            {
                return;
            }

            if (color.IsDefault && defaultColorFilter is null)
            {
                DrawableCompat.ClearColorFilter(drawable);
                return;
            }

            if (color.IsDefault)
            {
                drawable.SetColorFilter(defaultColorFilter);
                return;
            }

            var colorFilter = BlendModeColorFilterCompat.CreateBlendModeColorFilterCompat(color.ToAndroid(), mode);

            drawable.SetColorFilter(colorFilter);
        }
Example #24
0
        public static void ApplyBadge(this TabLayout.TabView tabView, XColor color, string text,
                                      XColor textColor)
        {
            if (!tabView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                tabView.SetClipChildren(false);
                tabView.SetClipToPadding(false);

                TextView tabTextView = tabView.GetChildrenOfType <TextView>().Single();
                tabView.RemoveView(tabTextView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(tabView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                };

                badgeContainerFrameLayout.AddView(tabTextView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(tabView.Context);
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                badgeContainer.Background = CreateBadgeBackground(tabView.Context, color);
                badgeContainer.AddView(CreateBadgeText(tabView.Context, text, textColor));

                badgeContainerFrameLayout.AddView(badgeContainer);

                tabView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = tabView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

                TextView textView = (TextView)badgeContainer.GetChildAt(0);
                textView.Text = text;
                textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid());
            }
        }
 public void SetStatusBarColor(Xamarin.Forms.Color color)
 {
     MainActivity.Instance.SetStatusBarColor(color.ToAndroid());
 }