private Drawable CreateBackgroundButton()
        {
            var layer1 = BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                      button.EndColor.ToAndroid(),
                                                                      button.CenterColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid());
            var layer1Disabled = BackgroundExtension.CreateBackgroundGradient(Android.Graphics.Color.Gray,
                                                                              Android.Graphics.Color.Gray,
                                                                              Android.Graphics.Color.Gray, button.CornerRadius, button.Angle.ToAndroid());
            var layer2Temp = BackgroundExtension.CreateBackgroundGradient(backgroundColor.ToAndroid(),
                                                                          backgroundColor.ToAndroid(),
                                                                          backgroundColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid());
            int borderWidth = (int)button.BorderWidth;
            var layer2      = new InsetDrawable(layer2Temp, borderWidth, borderWidth, borderWidth, borderWidth);

            Drawable[]    drawables          = new Drawable[] { layer1, layer2 };
            Drawable[]    drawablesDisabled  = new Drawable[] { layer1Disabled, layer2 };
            LayerDrawable layer              = new LayerDrawable(drawables);
            LayerDrawable layerDisabled      = new LayerDrawable(drawablesDisabled);
            var           statesListDrawable = new StateListDrawable();

            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, layerDisabled);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, layer);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateEnabled }, layer);
            return(statesListDrawable);
        }
        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();
        }
Exemple #3
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;
        }
        void UpdateRippleColor()
        {
            var rippleColor = ToFlatButton.GetRippleColor(Element).ToAndroid();

            if (Ripple == null)
            {
                Inset  = new InsetDrawable(Shape, 0, 1, 0, 1);
                Ripple = new RippleDrawable(getPressedColorSelector(rippleColor.ToArgb()), Inset, null);
            }
            else
            {
                Ripple.SetColor(getPressedColorSelector(rippleColor.ToArgb()));
            }
        }
Exemple #5
0
        public override void OnStart()
        {
            base.OnStart();
            Dialog dialog = Dialog;

            if (dialog != null)
            {
                dialog.Window.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
                int width  = ViewGroup.LayoutParams.MatchParent;
                int height = ViewGroup.LayoutParams.WrapContent;
                dialog.Window.SetLayout(width, height);
                InsetDrawable inset = new InsetDrawable(new ColorDrawable(color: Color.Transparent), 20, 20, 20, 20);
                dialog.Window.SetBackgroundDrawable(inset);
            }
        }
        private void MoveDialogToRightTopCorner()
        {
            Window window = _loadingDialog.Window;
            WindowManagerLayoutParams wlp = window.Attributes;

            wlp.Gravity       = GravityFlags.Top | GravityFlags.Right;
            wlp.Width         = LayoutParams.MatchParent;
            wlp.Flags        &= WindowManagerFlags.DimBehind;
            window.Attributes = wlp;

            int size = CalculateSizeOfToolbar();

            ColorDrawable back  = new ColorDrawable(Color.White);
            InsetDrawable inset = new InsetDrawable(back, 0, size, 100, 0);

            _loadingDialog.Window.SetBackgroundDrawable(inset);
        }
Exemple #7
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            View view = inflater.Inflate(Resource.Layout.history_fragment, container, false);

            nohistory = view.FindViewById <CardView>(Resource.Id.noHistoryGroup);

            if (historyViewModels.Any())
            {
                nohistory.Visibility = ViewStates.Gone;
            }
            else
            {
                nohistory.Visibility = ViewStates.Visible;
            }

            HistoryAdapter historyAdapter = new HistoryAdapter(historyViewModels, mainActivity);

            layoutManager = new AndroidX.RecyclerView.Widget.LinearLayoutManager(this.Context);
            recyclerView  = view.FindViewById <AndroidX.RecyclerView.Widget.RecyclerView>(Resource.Id.historyRecyclerView);
            recyclerView.SetLayoutManager(layoutManager);
            recyclerView.NestedScrollingEnabled = false;
            recyclerView.HasFixedSize           = true;

            var           decoration    = new AndroidX.RecyclerView.Widget.DividerItemDecoration(this.Context, layoutManager.Orientation);
            var           inset         = Resources.GetDimensionPixelSize(Resource.Dimension.divider_margin_vertical);
            InsetDrawable insetDrawable = new InsetDrawable(ContextCompat.GetDrawable(this.Context, Resource.Drawable.abc_list_divider_material)
                                                            , 0, inset, 0, inset);

            decoration.Drawable = (insetDrawable);
            AndroidX.RecyclerView.Widget.ItemTouchHelper itemTouchHelper = new AndroidX.RecyclerView.Widget.ItemTouchHelper(new HistoryTouchCallback(
                                                                                                                                0, ItemTouchHelper.Right | ItemTouchHelper.Left, recyclerView, historyViewModels, this));

            itemTouchHelper.AttachToRecyclerView(recyclerView);

            recyclerView.SetAdapter(historyAdapter);

            historyAdapter.ItemClick     += HistoryAdapter_ItemClick;
            historyAdapter.ItemLongClick += HistoryAdapter_ItemLongClick;

            mainActivity.SupportActionBar.Subtitle = $"Stored {historyViewModels.Count} items";

            return(view);
        }
Exemple #8
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;
        }
Exemple #9
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && !this.IsDisposed)
            {
                this.IsDisposed = true;

                if (this.Dab != null)
                {
                    this.Dab.Dispose();
                    this.Dab = null;
                }
                if (this.InsetDab != null)
                {
                    this.InsetDab.Dispose();
                    this.InsetDab = null;
                }
                if (this.ClipPath != null)
                {
                    this.ClipPath.Dispose();
                    this.ClipPath = null;
                }
            }
            base.Dispose(disposing);
        }
Exemple #10
0
        //protected override void UpdateBackgroundColor() {
        //    //base.UpdateBackgroundColor();
        //}


        private void UpdateBackground(Android.Views.View view)
        {
            var border  = this.Element;
            var stroke  = border.StrokeThickness;
            var corner  = border.CornerRadius;
            var padding = border.Padding;

            var context = view.Context;

            if (this.Dab == null)
            {
                this.Dab = new GradientDrawable();
                this.Dab.SetShape(ShapeType.Rectangle);
            }
            var maxWidth = (int)context.ToPixels(Max(stroke));

            if (maxWidth > 0)
            {
                this.Dab.SetStroke(maxWidth, border.Stroke.ToAndroid(), 0, 0);
            }

            if ((int)Build.VERSION.SdkInt < 21)
            {
                //Android 4.4 SetCornerRadii ╩А╨зр╩ф╛
                this.Dab.SetCornerRadius(context.ToPixels(Max(corner)));
            }
            else
            {
                var ctl = context.ToPixels(corner.TopLeft);
                var ctr = context.ToPixels(corner.TopRight);
                var cbr = context.ToPixels(corner.BottomRight);
                var cbl = context.ToPixels(corner.BottomLeft);

                var corners = new float[] {
                    ctl, ctl,
                    ctr, ctr,
                    cbr, cbr,
                    cbl, cbl
                };

                this.Dab.SetCornerRadii(corners);
            }

            this.Dab.SetColor(border.BackgroundColor.ToAndroid());

            var left   = -(int)(maxWidth - context.ToPixels(stroke.Left));
            var top    = -(int)(maxWidth - context.ToPixels(stroke.Top));
            var right  = -(int)(maxWidth - context.ToPixels(stroke.Right));
            var bottom = -(int)(maxWidth - context.ToPixels(stroke.Bottom));

            if (this.InsetDab == null)
            {
                this.InsetDab = new InsetDrawable(this.Dab, left, top, right, bottom);
            }

            view.Background = InsetDab;

            view.SetPadding(
                (int)context.ToPixels(stroke.Left + padding.Left),
                (int)context.ToPixels(stroke.Top + padding.Top),
                (int)context.ToPixels(stroke.Right + padding.Right),
                (int)context.ToPixels(stroke.Bottom + padding.Bottom));
        }
        public static void SetTheme(ToggleButton toggleButton, FlatTheme theme, int padding, int size)
        {
            toggleButton.SetWidth(size * 5);
            toggleButton.SetHeight(size);

            //setTextOff("");
            //setTextOn("");

            int radius = size - 4;

            float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };

            // creating unchecked-enabled state drawable
            var uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
            var uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, 5);

            var uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedEnabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            uncheckedEnabledBack.SetPadding(0, 0, size / 2 * 5, 0);

            Drawable[] d1 = { uncheckedEnabledBack, uncheckedEnabledFront };
            var        uncheckedEnabled = new LayerDrawable(d1);

            // creating checked-enabled state drawable
            var checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedEnabledFrontCore.Paint.Color = theme.LightAccentColor;
            var checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, 5);

            ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedEnabledBack.Paint.Color = theme.VeryLightAccentColor;
            checkedEnabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

            Drawable[]    d2             = { checkedEnabledBack, checkedEnabledFront };
            LayerDrawable checkedEnabled = new LayerDrawable(d2);

            // creating unchecked-disabled state drawable
            ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedDisabledFrontCore.Paint.Color = Color.ParseColor("#d2d2d2");
            InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, 5);

            ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            uncheckedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            uncheckedDisabledBack.SetPadding(0, 0, size / 2 * 5, 0);

            Drawable[]    d3 = { uncheckedDisabledBack, uncheckedDisabledFront };
            LayerDrawable uncheckedDisabled = new LayerDrawable(d3);

            // creating checked-disabled state drawable
            ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedDisabledFrontCore.Paint.Color = theme.VeryLightAccentColor;
            InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, 5);

            ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null));

            checkedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2");
            checkedDisabledBack.SetPadding(size / 2 * 5, 0, 0, 0);

            Drawable[]    d4 = { checkedDisabledBack, checkedDisabledFront };
            LayerDrawable checkedDisabled = new LayerDrawable(d4);

            toggleButton.SetPadding(0, padding, 0, padding);

            PaintDrawable paintDrawable = new PaintDrawable(theme.BackgroundColor);

            paintDrawable.SetIntrinsicHeight(size);
            paintDrawable.SetIntrinsicWidth(size);
            paintDrawable.SetPadding(size, 0, 0, 0);

            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(uncheckedEnabled, padding * 2));
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(checkedEnabled, padding * 2));
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(uncheckedDisabled, padding * 2));
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled },
                            new InsetDrawable(checkedDisabled, padding * 2));

            toggleButton.SetBackgroundDrawable(states);

            toggleButton.SetTextSize(ComplexUnitType.Sp, 0);
        }
Exemple #12
0
        public static void SetTheme(CheckBox checkBox, FlatTheme theme,
                                    FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int radius, int size, int border)
        {
            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedEnabled = new GradientDrawable();

            uncheckedEnabled.SetCornerRadius(radius);
            uncheckedEnabled.SetSize(size, size);
            uncheckedEnabled.SetColor(Color.Transparent);
            uncheckedEnabled.SetStroke(border, theme.LightAccentColor);

            // creating checked-enabled state drawable
            GradientDrawable checkedOutside = new GradientDrawable();

            checkedOutside.SetCornerRadius(radius);
            checkedOutside.SetSize(size, size);
            checkedOutside.SetColor(Color.Transparent);
            checkedOutside.SetStroke(border, theme.LightAccentColor);

            PaintDrawable checkedCore = new PaintDrawable(theme.LightAccentColor);

            checkedCore.SetCornerRadius(radius);
            checkedCore.SetIntrinsicHeight(size);
            checkedCore.SetIntrinsicWidth(size);
            InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedEnabledDrawable = { checkedOutside, checkedInside };
            LayerDrawable checkedEnabled         = new LayerDrawable(checkedEnabledDrawable);

            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedDisabled = new GradientDrawable();

            uncheckedDisabled.SetCornerRadius(radius);
            uncheckedDisabled.SetSize(size, size);
            uncheckedDisabled.SetColor(Color.Transparent);
            uncheckedDisabled.SetStroke(border, theme.VeryLightAccentColor);

            // creating checked-disabled state drawable
            GradientDrawable checkedOutsideDisabled = new GradientDrawable();

            checkedOutsideDisabled.SetCornerRadius(radius);
            checkedOutsideDisabled.SetSize(size, size);
            checkedOutsideDisabled.SetColor(Color.Transparent);
            checkedOutsideDisabled.SetStroke(border, theme.VeryLightAccentColor);

            PaintDrawable checkedCoreDisabled = new PaintDrawable(theme.VeryLightAccentColor);

            checkedCoreDisabled.SetCornerRadius(radius);
            checkedCoreDisabled.SetIntrinsicHeight(size);
            checkedCoreDisabled.SetIntrinsicWidth(size);
            InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
            LayerDrawable checkedDisabled         = new LayerDrawable(checkedDisabledDrawable);


            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, uncheckedEnabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, checkedEnabled);
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, uncheckedDisabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, checkedDisabled);
            checkBox.SetButtonDrawable(states);

            // setting padding for avoiding text to be appear on icon
            checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
            checkBox.SetTextColor(theme.LightAccentColor);

            var typeface = FlatUI.GetFont(checkBox.Context, fontFamily, fontWeight);

            if (typeface != null)
            {
                checkBox.SetTypeface(typeface, TypefaceStyle.Normal);
            }
        }
Exemple #13
0
        public static void SetTheme(Android.Widget.CheckBox checkBox,
                                    int radius, int size, int border, Android.Graphics.Color background)
        {
            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedEnabled = new GradientDrawable();

            uncheckedEnabled.SetCornerRadius(radius);
            uncheckedEnabled.SetSize(size, size);
            uncheckedEnabled.SetColor(Android.Graphics.Color.Transparent);
            uncheckedEnabled.SetStroke(border, Android.Graphics.Color.Black);

            // creating checked-enabled state drawable
            GradientDrawable checkedOutside = new GradientDrawable();

            checkedOutside.SetCornerRadius(radius);
            checkedOutside.SetSize(size, size);
            checkedOutside.SetColor(Android.Graphics.Color.Transparent);
            checkedOutside.SetStroke(border, Android.Graphics.Color.Black);

            PaintDrawable checkedCore = new PaintDrawable(background);

            checkedCore.SetCornerRadius(radius);
            checkedCore.SetIntrinsicHeight(size);
            checkedCore.SetIntrinsicWidth(size);
            InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedEnabledDrawable = { checkedOutside, checkedInside };
            LayerDrawable checkedEnabled         = new LayerDrawable(checkedEnabledDrawable);

            // creating unchecked-enabled state drawable
            GradientDrawable uncheckedDisabled = new GradientDrawable();

            uncheckedDisabled.SetCornerRadius(radius);
            uncheckedDisabled.SetSize(size, size);
            uncheckedDisabled.SetColor(Android.Graphics.Color.Transparent);
            uncheckedDisabled.SetStroke(border, Android.Graphics.Color.Black);

            // creating checked-disabled state drawable
            GradientDrawable checkedOutsideDisabled = new GradientDrawable();

            checkedOutsideDisabled.SetCornerRadius(radius);
            checkedOutsideDisabled.SetSize(size, size);
            checkedOutsideDisabled.SetColor(Android.Graphics.Color.Transparent);
            checkedOutsideDisabled.SetStroke(border, Android.Graphics.Color.Black);

            PaintDrawable checkedCoreDisabled = new PaintDrawable(background);

            checkedCoreDisabled.SetCornerRadius(radius);
            checkedCoreDisabled.SetIntrinsicHeight(size);
            checkedCoreDisabled.SetIntrinsicWidth(size);
            InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

            Drawable[]    checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
            LayerDrawable checkedDisabled         = new LayerDrawable(checkedDisabledDrawable);


            StateListDrawable states = new StateListDrawable();

            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, uncheckedEnabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled }, checkedEnabled);
            states.AddState(new int[] { -Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, uncheckedDisabled);
            states.AddState(new int[] { Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled }, checkedDisabled);
            checkBox.SetButtonDrawable(states);

            // setting padding for avoiding text to be appear on icon
            checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
            checkBox.SetTextColor(Android.Graphics.Color.LightYellow);
            checkBox.SetTextSize(Android.Util.ComplexUnitType.Sp, 10);
            checkBox.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
        }