コード例 #1
0
        public override void Draw(CoreGraphics.CGRect rect)
        {
            base.Draw(rect);
            this.LayoutIfNeeded();
            RoundedCornerView rcv = (RoundedCornerView)Element;

            //rcv.HasShadow = false;
            rcv.Padding = new Thickness(0, 0, 0, 0);
            //this.BackgroundColor = rcv.FillColor.ToUIColor();
            this.ClipsToBounds         = true;
            this.Layer.BackgroundColor = rcv.FillColor.ToCGColor();
            this.Layer.MasksToBounds   = true;
            this.Layer.CornerRadius    = (nfloat)rcv.RoundedCornerRadius;
            if (rcv.MakeCircle)
            {
                this.Layer.CornerRadius = (int)(Math.Min(Element.Width, Element.Height) / 2);
            }
            this.Layer.BorderWidth = 0;
            if (rcv.BorderWidth > 0 && rcv.BorderColor.A > 0.0)
            {
                this.Layer.BorderWidth = rcv.BorderWidth;

                /*
                 * this.Layer.BorderColor = newUIColor(
                 *  (nfloat)rcv.BorderColor.R,
                 *  (nfloat)rcv.BorderColor.G,
                 *  (nfloat)rcv.BorderColor.B,
                 *  (nfloat)rcv.BorderColor.A).CGColor;
                 */
            }
        }
コード例 #2
0
        private static void DrawBorder(Canvas canvas, RoundedCornerView control, Path path)
        {
            if (control.BorderColor == Xamarin.Forms.Color.Transparent || control.BorderWidth <= 0)
            {
                return;
            }

            var paint = new Paint();

            paint.AntiAlias   = true;
            paint.StrokeWidth = control.BorderWidth;
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = control.BorderColor.ToAndroid();

            canvas.DrawPath(path, paint);

            paint.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// Drawables the state changed.
        /// </summary>
        protected override void DrawableStateChanged()
        {
            base.DrawableStateChanged();

            RoundedCornerView rcv = ((RoundedCornerView)Element);
            var shape             = new GradientDrawable();

            if (rcv.MakeCircle)
            {
                shape.SetCornerRadius(Math.Min(Width, Height) / 2);
            }
            else
            {
                shape.SetCornerRadius((float)rcv.RoundedCornerRadius);
            }
            shape.SetColor(rcv.FillColor.ToAndroid());
            shape.SetStroke((int)rcv.BorderWidth, (((RoundedCornerView)Element)).BorderColor.ToAndroid());
            this.SetBackground(shape);
        }
コード例 #4
0
        private static float[] GetRadii(RoundedCornerView control)
        {
            var radius = (float)(control.CornerRadius);

            radius *= 2;

            var topLeft     = control.TopLeft ? radius : 0;
            var topRight    = control.TopRight ? radius : 0;
            var bottomLeft  = control.BottomLeft ? radius : 0;
            var bottomRight = control.BottomRight ? radius : 0;

            if (!control.BottomLeft && !control.BottomRight && !control.TopLeft && !control.TopRight)
            {
                topLeft = topRight = bottomLeft = bottomRight = radius;
            }

            var radii = new[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft };

            return(radii);
        }
コード例 #5
0
        private static float[] GetRadii(RoundedCornerView control)
        {
            var radius = (float)(control.CornerRadius);

            radius *= 2;

            var topLeft     = control.RoundedCorners.ToLower().Contains("topleft") ? radius : 0;
            var topRight    = control.RoundedCorners.ToLower().Contains("topright") ? radius : 0;
            var bottomLeft  = control.RoundedCorners.ToLower().Contains("bottomleft") ? radius : 0;
            var bottomRight = control.RoundedCorners.ToLower().Contains("bottomright") ? radius : 0;

            if (control.RoundedCorners.ToLower().Contains("all"))
            {
                topLeft = topRight = bottomLeft = bottomRight = radius;
            }

            var radii = new[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft };

            return(radii);
        }
コード例 #6
0
        public static Drawable GenerateBackgroundWithShadow(RoundedCornerView control, Android.Views.View child, Android.Graphics.Color backgroundColor,
                                                            Android.Graphics.Color shadowColor,
                                                            int elevation,
                                                            GravityFlags shadowGravity)
        {
            var radii = GetRadii(control);

            int DY;

            switch (shadowGravity)
            {
            case GravityFlags.Center:
                DY = 0;
                break;

            case GravityFlags.Top:
                DY = -1 * elevation / 3;
                break;

            default:
            case GravityFlags.Bottom:
                DY = elevation / 3;
                break;
            }

            var shapeDrawable = new ShapeDrawable();

            shapeDrawable.Paint.Color = backgroundColor;
            shapeDrawable.Paint.SetShadowLayer(elevation, 0, DY, shadowColor);

            child.SetLayerType(LayerType.Software, shapeDrawable.Paint);

            shapeDrawable.Shape = new RoundRectShape(radii, null, null);

            var drawable = new LayerDrawable(new Drawable[] { shapeDrawable });

            drawable.SetLayerInset(0, elevation, elevation, elevation, elevation);

            child.Background = drawable;
            return(drawable);
        }
コード例 #7
0
        /// <summary>
        /// ,
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement == null && e.NewElement != null)
            {
                RoundedCornerView rcv = ((RoundedCornerView)e.NewElement);
                var shape             = new GradientDrawable();

                if (rcv.MakeCircle)
                {
                    shape.SetCornerRadius(Math.Min(Width, Height) / 2);
                }
                else
                {
                    shape.SetCornerRadius((float)rcv.RoundedCornerRadius);
                }
                shape.SetColor(rcv.FillColor.ToAndroid());
                shape.SetStroke((int)rcv.BorderWidth, (((RoundedCornerView)Element)).BorderColor.ToAndroid());
                this.SetBackground(shape);
            }
        }
コード例 #8
0
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (Element == null)
            {
                return(false);
            }
            RoundedCornerView rcv = (RoundedCornerView)Element;

            this.SetClipChildren(true);
            rcv.Padding = new Thickness(0, 0, 0, 0);
            //rcv.HasShadow = false;
            int radius = (int)(rcv.RoundedCornerRadius);

            // Check if make circle is set to true. If so, then we just use the width and
            // height of the control to calculate the radius. RoundedCornerRadius will be ignored
            // in this case.
            if (rcv.MakeCircle)
            {
                radius = Math.Min(Width, Height) / 2;
            }
            // When we create a round rect, we will have to double the radius since it is not
            // the same as creating a circle.
            radius *= 2;
            try
            {
                //Create path to clip the child
                var path = new Path();
                path.AddRoundRect(new RectF(0, 0, Width, Height), new float[] {
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius
                }, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);
                // Draw the child first so that the border shows up above it.
                var result = base.DrawChild(canvas, child, drawingTime);
                canvas.Restore();

                /*
                 * If a border is specified, we use the same path created above to stroke
                 * with the border color.
                 * */
                if (rcv.BorderWidth > 0)
                {
                    // Draw a filled circle.
                    var paint = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = rcv.BorderWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = rcv.BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }
                //Properly dispose
                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
            return(base.DrawChild(canvas, child, drawingTime));
        }
コード例 #9
0
        public async Task GetSnacksMethod(bool Loaded, bool favourites)     //ottiene la lista degli snack e la applica alla ListView
        {
            result = await snackServiceManager.GetSnacksAsync();

            SnackFavarray        = new object[result.data.snacks.Count];
            ListView.ItemsSource = result.data.snacks;
            int FavIndex = 0;
            int index    = 0;

            if (!Loaded) //!WORKAROUND!   in questo modo si evita il crash ma la griglia non si aggiorna, urge investigazione sul vero problema
            {
                for (int i = 0; i <= result.data.snacks.Count; i++)
                {
                    bool addfav     = false; //variabile di appoggio
                    bool visibilità = true;
                    if (favourites && !Check_Favourites(result.data.snacks[i].id))
                    {
                        addfav = true;
                    }
                    else if (favourites && Check_Favourites(result.data.snacks[i].id))
                    {
                        visibilità = false;
                    }

                    ColorRandom c = new ColorRandom();
                    var         mainDisplayInfo = DeviceDisplay.MainDisplayInfo;



                    double latoCubo = App.Current.MainPage.Width / 2;

                    double box = 170;

                    var star19 = new Image
                    {
                        Aspect = Aspect.AspectFill,
                        Source = ImageSource.FromResource("fondomerende.image.Star19.png"),
                        Margin = new Thickness(5),
                    };

                    var imageSnack = new Image
                    {
                        Aspect = Aspect.AspectFill,
                        Margin = new Thickness(35),
                        Source = ImageSource.FromUri(new Uri("http://fondomerende.madeinapp.net/api/getphoto.php?name=" + result.data.snacks[i].friendly_name)),
                    };


                    var stackGrid = new StackLayout
                    {
                        WidthRequest  = box,
                        HeightRequest = box,

                        InputTransparent = true,
                    };

                    var griglia = new Grid()
                    {
                    };

                    var BordiSmussatiAndroid = new RoundedCornerView
                    {
                        HeightRequest       = box,
                        WidthRequest        = box,
                        RoundedCornerRadius = box / 2,
                        BorderColor         = c.GetRandomColor(),
                        BorderWidth         = 3,
                        InputTransparent    = true,
                        Margin = new Thickness(10, 10, 10, 0)
                    };

                    var BordiSmussatiiOS = new RoundedCornerView
                    {
                        HeightRequest       = box,
                        WidthRequest        = box,
                        RoundedCornerRadius = box / 4,
                        BorderColor         = c.GetRandomColor(),
                        BorderWidth         = 1,
                        InputTransparent    = true,
                        Margin = new Thickness(10, 10, 10, 0)
                    };

                    var label = new Label
                    {
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.End,
                        Margin           = new Thickness(0, 0, 0, 5),
                        Text             = result.data.snacks[i].friendly_name,
                        FontAttributes   = FontAttributes.Bold,
                        FontSize         = 16,
                        InputTransparent = true,
                    };

                    string e;
                    if (Check_Favourites(result.data.snacks[i].id))
                    {
                        e = "fondomerende.image.star_empty.png";
                    }
                    else
                    {
                        e = "fondomerende.image.star_fill.png";
                    }

                    var star = new ImageButton
                    {
                        HeightRequest     = 20,
                        WidthRequest      = 20,
                        Margin            = new Thickness(0, 15, 15, 0),
                        Scale             = 1,
                        Aspect            = Aspect.Fill,
                        Source            = ImageSource.FromResource(e),
                        HorizontalOptions = LayoutOptions.EndAndExpand,
                        VerticalOptions   = LayoutOptions.StartAndExpand,
                        BackgroundColor   = Color.Transparent
                    };

                    var starAnimation = new AnimationView
                    {
                        Animation         = "star.json",
                        Scale             = 1,
                        Loop              = false,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        AutoPlay          = false,
                        InputTransparent  = true,
                        IsVisible         = false,
                    };

                    var eatAnimation = new AnimationView
                    {
                        Animation         = "LoadingEating.json",
                        Scale             = 1.2,
                        Rotation          = 180,
                        Loop              = false,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        AutoPlay          = false,
                        InputTransparent  = true,
                        IsVisible         = false,
                    };


                    var app = new StackLayout
                    {
                        Orientation = StackOrientation.Vertical,
                        IsVisible   = visibilità,
                    };

                    var sfondo = new StackLayout
                    {
                        BackgroundColor = Color.FromHex("#ece0ce"),
                        Opacity         = 0.99
                    };
                    starAnimation.OnFinish -= StopAnimation;
                    starAnimation.OnFinish += StopAnimation;

                    griglia.Children.Add(sfondo);
                    griglia.Children.Add(star19);
                    griglia.Children.Add(imageSnack);
                    if (!TabletManager.Instance.tablet)
                    {
                        griglia.Children.Add(star);
                    }
                    griglia.Children.Add(starAnimation);


                    stackGrid.Children.Add(griglia);
                    app.Children.Add(stackGrid);
                    app.Children.Add(label);


                    TapGestureRecognizer tg1 = new TapGestureRecognizer();
                    tg1.NumberOfTapsRequired = 1;
                    tg1.Tapped += Tgr_Tapped;
                    app.GestureRecognizers.Add(tg1);

                    if (!TabletManager.Instance.tablet)
                    {
                        TapGestureRecognizer tg2 = new TapGestureRecognizer();
                        tg2.NumberOfTapsRequired = 2;
                        tg2.Tapped += Tgr2_Tapped;
                        app.GestureRecognizers.Add(tg2);
                    }



                    if (addfav && favourites)
                    {
                        if (FavIndex % 2 == 0)
                        {
                            Column0Fav.Children.Add(app);
                        }
                        else
                        {
                            Column1Fav.Children.Add(app);
                        }


                        Snackarray[FavIndex] = app;
                        FavIndex++;
                    }
                    else
                    {
                        if (i % 2 == 0)
                        {
                            Column0.Children.Add(app);
                        }
                        else
                        {
                            Column1.Children.Add(app);
                        }

                        SnackFavarray[index] = app;
                        index++;
                    }
                }
            }
        }
コード例 #10
0
        private void PopupBuy()
        {
            Altezza   = (GetAltezzaPagina() * 30) / 100;
            Larghezza = GetLarghezzaPagina() - 80;
            double banner = 50;

            Round = new RoundedCornerView  //coso che stonda
            {
                RoundedCornerRadius = 20,
                HorizontalOptions   = LayoutOptions.CenterAndExpand,
                VerticalOptions     = LayoutOptions.Center,
                HeightRequest       = Altezza,
                WidthRequest        = Larghezza,
            };

            var stackFondoAndroid = new StackLayout() //per android
            {
                HeightRequest   = banner,
                WidthRequest    = Larghezza,
                BackgroundColor = GetPrimaryAndroidColor(),
                Orientation     = StackOrientation.Horizontal,
            };

            var stackFondoiOS = new StackLayout()  //per ios
            {
                HeightRequest   = banner,
                WidthRequest    = Larghezza,
                BackgroundColor = Color.Orange,
                Orientation     = StackOrientation.Horizontal,
            };

            var fondomerende = new Label  //Label per Il titolo banner
            {
                Text = "Fondo merende",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                FontSize          = 20,
                FontAttributes    = FontAttributes.Bold,
                TextColor         = Color.White,
            };

            lineAndroid = new LineEntry
            {
                Placeholder             = "Quanti snack vuoi acquistare?",
                WidthRequest            = 250,
                Keyboard                = Keyboard.Numeric,
                Margin                  = new Thickness(0, 5, 0, 0),
                VerticalOptions         = LayoutOptions.StartAndExpand,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            prezzoAndroid = new LineEntry
            {
                Placeholder             = "Inserire il prezzo",
                Keyboard                = Keyboard.Numeric,
                WidthRequest            = 250,
                IsVisible               = false,
                VerticalOptions         = LayoutOptions.StartAndExpand,
                Margin                  = new Thickness(0, 5, 0, 0),
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            scadenzaAndroid = new LineEntry
            {
                Placeholder             = "Inserire la scadenza",
                Keyboard                = Keyboard.Numeric,
                WidthRequest            = 250,
                Margin                  = new Thickness(0, 5, 0, 0),
                IsVisible               = false,
                VerticalOptions         = LayoutOptions.StartAndExpand,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };



            lineiOs = new LineEntry
            {
                Placeholder             = "Quanti snack vuoi acquistare?",
                WidthRequest            = 250,
                FontSize                = 18,
                HeightRequest           = 35,
                Margin                  = new Thickness(0, 10, 0, 0),
                Keyboard                = Keyboard.Numeric,
                VerticalOptions         = LayoutOptions.StartAndExpand,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            prezzoiOs = new LineEntry
            {
                Placeholder             = "Inserire il prezzo",
                Keyboard                = Keyboard.Numeric,
                WidthRequest            = 250,
                FontSize                = 18,
                HeightRequest           = 35,
                VerticalOptions         = LayoutOptions.StartAndExpand,
                IsVisible               = false,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            scadenzaiOs = new LineEntry
            {
                Placeholder             = "Inserire la scadenza",
                Keyboard                = Keyboard.Numeric,
                WidthRequest            = 250,
                FontSize                = 18,
                HeightRequest           = 35,
                VerticalOptions         = LayoutOptions.StartAndExpand,
                IsVisible               = false,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
            };



            stackBody = new StackLayout  //stack principale dove è contenuto l'interno di tutto (tranne round che stonda)

            {
                HeightRequest   = Altezza,
                WidthRequest    = Larghezza,
                BackgroundColor = Color.White,
            };

            var stackBottoni = new StackLayout  //stack che contiene la gridlia dei bottoni
            {
                VerticalOptions      = LayoutOptions.EndAndExpand,
                WidthRequest         = Larghezza,
                HeightRequest        = banner,
                MinimumHeightRequest = banner,
            };

            var griglia = new Grid //griglia che contiene i bottoni
            {
            };


            immagine = new ImageButton
            {
                Source          = ImageSource.FromResource("fondomerende.image.Edit_Icon_32x32.png"),
                CornerRadius    = 20,
                Scale           = 1.5,
                BackgroundColor = Color.Transparent,
                Margin          = new Thickness(0, 0, 15, 0),
                Aspect          = Aspect.AspectFit,
            };



            buttonCancel = new Button
            {
                Text              = "Annulla",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                BackgroundColor   = Color.Transparent,
            };

            buttonConfirm = new Button
            {
                Text              = "Conferma",
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                BackgroundColor   = Color.Transparent,
            };

            stackBottoni.Children.Add(griglia);
            griglia.Children.Add((buttonCancel));  //inzia nella prima colonna
            griglia.Children.Add((buttonConfirm)); //inizia seconda colonna

            Grid.SetColumn(buttonCancel, 0);       //mi è toccato farlo qui
            Grid.SetColumn(buttonConfirm, 1);



            switch (Device.RuntimePlatform)
            {
            case Device.Android:

                stackFondoAndroid.Children.Add(fondomerende);
                stackFondoAndroid.Children.Add(immagine);
                stackBody.Children.Add(stackFondoAndroid);
                immagine.Clicked          += Immagine_Clicked;
                prezzoAndroid.TextChanged += EntrataPrezzoAndroid;
                buttonCancel.Clicked      += Discard_Clicked;
                buttonConfirm.Clicked     += Apply_ClickedAndroid;
                stackBody.Children.Add(lineAndroid);
                stackBody.Children.Add(prezzoAndroid);
                stackBody.Children.Add(scadenzaAndroid);


                stackBody.Children.Add(stackBottoni);
                Round.Children.Add(stackBody);
                break;


            case Device.iOS:
                stackFondoiOS.Children.Add(fondomerende);
                stackFondoiOS.Children.Add(immagine);
                stackBody.Children.Add(stackFondoiOS);
                immagine.Clicked          += Immagine_Clicked;
                prezzoAndroid.TextChanged += EntrataPrezzoiOs;
                buttonCancel.Clicked      += Discard_Clicked;
                buttonConfirm.Clicked     += Apply_ClickediOs;
                stackBody.Children.Add(lineiOs);
                stackBody.Children.Add(prezzoiOs);
                stackBody.Children.Add(scadenzaiOs);


                stackBody.Children.Add(stackBottoni);
                Round.Children.Add(stackBody);

                break;
            }
            //  entry.TextChanged += Entrata;



            PopupBuySnack.Content = Round;
        }