Exemplo n.º 1
0
        public UserViewCell()
        {
            var mainLayout = new RelativeLayout();

            _profileImage = new RoundedImage {
                Aspect      = Aspect.AspectFill,
                BorderColor = Styles.Colors.SecondaryColor,
                BorderWidth = 1,
                Source      = "ic_user_picture_placeholder.png",
            };
            mainLayout.Children.Add(_profileImage,
                                    Constraint.Constant(20),
                                    Constraint.Constant(20),
                                    Constraint.Constant(40),
                                    Constraint.Constant(40)
                                    );

            _nameLabel = new Label {
                Style          = Styles.Subtitle,
                FontAttributes = FontAttributes.Bold,
            };
            mainLayout.Children.Add(_nameLabel,
                                    Constraint.RelativeToView(_profileImage, (p, v) => v.X + v.Width + 5),
                                    Constraint.RelativeToView(_profileImage, (p, v) => v.Y),
                                    Constraint.RelativeToView(_profileImage, (p, v) => p.Width - (v.X + v.Width) - 20),
                                    Constraint.Constant(40)
                                    );

            View = mainLayout;
        }
Exemplo n.º 2
0
        public ReviewViewCell()
        {
            var mainLayout = new RelativeLayout();

            _profileImage = new RoundedImage {
                Aspect      = Aspect.AspectFill,
                BorderColor = Styles.Colors.SecondaryColor,
                BorderWidth = 1,
                Source      = "ic_user_picture_placeholder.png",
            };
            mainLayout.Children.Add(_profileImage,
                                    Constraint.Constant(20),
                                    Constraint.Constant(20),
                                    Constraint.Constant(40),
                                    Constraint.Constant(40)
                                    );

            _nameLabel = new Label {
                FontSize              = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),
                FontAttributes        = FontAttributes.Bold,
                TextColor             = Styles.Colors.SecondaryColor,
                VerticalTextAlignment = TextAlignment.Start,
            };
            mainLayout.Children.Add(_nameLabel,
                                    Constraint.RelativeToView(_profileImage, (p, v) => v.X + v.Width + 5),
                                    Constraint.RelativeToView(_profileImage, (p, v) => v.Y),
                                    Constraint.RelativeToView(_profileImage, (p, v) => p.Width - (v.X + v.Width) - 20),
                                    Constraint.Constant(30)
                                    );

            _commentLabel = new Label {
                FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),
                VerticalTextAlignment = TextAlignment.Start,
            };
            mainLayout.Children.Add(_commentLabel,
                                    Constraint.RelativeToView(_nameLabel, (p, v) => v.X),
                                    Constraint.RelativeToView(_nameLabel, (p, v) => v.Y + v.Height),
                                    Constraint.RelativeToView(_nameLabel, (p, v) => v.Width),
                                    Constraint.Constant(30)
                                    );

            _dateLabel = new Label {
                FontSize              = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),
                FontAttributes        = FontAttributes.Italic,
                VerticalTextAlignment = TextAlignment.Start,
                TextColor             = Styles.Colors.SecondaryColor,
            };
            mainLayout.Children.Add(_dateLabel,
                                    Constraint.RelativeToView(_commentLabel, (p, v) => v.X),
                                    Constraint.RelativeToView(_commentLabel, (p, v) => v.Y + v.Height),
                                    Constraint.RelativeToView(_commentLabel, (p, v) => v.Width),
                                    Constraint.Constant(20)
                                    );

            View = mainLayout;
        }
        void Draw()
        {
            RoundedImage roundedImage = this.Element as RoundedImage;

            if (roundedImage != null)
            {
                Control.Layer.CornerRadius  = (float)roundedImage.CornerRadius;
                Control.Layer.MasksToBounds = false;
                Control.ClipsToBounds       = true;
            }
        }
        public override void Draw(CGRect rect)
        {
            RoundedImage roundedImage = (RoundedImage)this.Element;

            var width  = Layer.Bounds.Width / 2.0;
            var height = Layer.Bounds.Height / 2.0;


            var topLeftRect     = new CGRect(0, 0, width, height);
            var topRightRect    = new CGRect(width, 0, width, height);
            var bottomRightRect = new CGRect(width, height, width, height);
            var bottomLeftRect  = new CGRect(0, height, width, height);


            var topLeftPath     = UIBezierPath.FromRoundedRect(topLeftRect, UIRectCorner.TopLeft, new CGSize(roundedImage.TopLeftCornerRadius, roundedImage.TopLeftCornerRadius));
            var topRightPath    = UIBezierPath.FromRoundedRect(topRightRect, UIRectCorner.TopRight, new CGSize(roundedImage.TopRightCornerRadius, roundedImage.TopRightCornerRadius));
            var bottomRightPath = UIBezierPath.FromRoundedRect(bottomRightRect, UIRectCorner.BottomRight, new CGSize(roundedImage.BottomRightCornerRadius, roundedImage.BottomRightCornerRadius));
            var bottomLeftPath  = UIBezierPath.FromRoundedRect(bottomLeftRect, UIRectCorner.BottomLeft, new CGSize(roundedImage.BottomLeftCornerRadius, roundedImage.BottomLeftCornerRadius));


            CAShapeLayer topLeftMaskLayer = new CAShapeLayer();

            topLeftMaskLayer.Frame = Layer.Bounds;
            topLeftMaskLayer.Path  = topLeftPath.CGPath;

            CAShapeLayer topRightMaskLayer = new CAShapeLayer();

            topRightMaskLayer.Frame = Layer.Bounds;
            topRightMaskLayer.Path  = topRightPath.CGPath;

            CAShapeLayer bottomRightMaskLayer = new CAShapeLayer();

            bottomRightMaskLayer.Frame = Layer.Bounds;
            bottomRightMaskLayer.Path  = bottomRightPath.CGPath;

            CAShapeLayer bottomLeftMaskLayer = new CAShapeLayer();

            bottomLeftMaskLayer.Frame = Layer.Bounds;
            bottomLeftMaskLayer.Path  = bottomLeftPath.CGPath;


            CALayer maskLayer = new CALayer();

            maskLayer.AddSublayer(topLeftMaskLayer);
            maskLayer.AddSublayer(topRightMaskLayer);
            maskLayer.AddSublayer(bottomRightMaskLayer);
            maskLayer.AddSublayer(bottomLeftMaskLayer);

            Layer.Mask = maskLayer;

            base.Draw(rect);
        }
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            RoundedImage roundedImage = (RoundedImage)Element;

            this.SetClipChildren(true);
            Control.ClipToOutline = true;

            float[] radii = new float[8];

            radii[0] = DpToPixels(this.Context, (float)roundedImage.TopLeftCornerRadius) * 10;
            radii[1] = radii[0];

            radii[2] = DpToPixels(this.Context, (float)roundedImage.TopRightCornerRadius) * 10;
            radii[3] = radii[2];

            radii[4] = DpToPixels(this.Context, (float)roundedImage.BottomRightCornerRadius) * 10;
            radii[5] = radii[4];

            radii[6] = DpToPixels(this.Context, (float)roundedImage.BottomLeftCornerRadius) * 10;
            radii[7] = radii[6];



            Path path = new Path();

            {
                int radius = Math.Min(Width, Height) / 2;

                path.AddRoundRect(0, 0, Width, Height, radii, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);


                var result = base.DrawChild(canvas, child, drawingTime);

                path.Dispose();

                return(result);
            }
        }
Exemplo n.º 6
0
        private void InitializeComponents()
        {
            Icon  = "drawer_button.png";
            Title = "Starving";

            _mainLayout = new RelativeLayout {
                BackgroundColor = Color.White,
            };

            var headerBoxview = new BoxView {
                BackgroundColor = Styles.Colors.PrimaryColor,
            };

            _mainLayout.Children.Add(headerBoxview,
                                     Constraint.Constant(0),
                                     Constraint.Constant(0),
                                     Constraint.RelativeToParent(p => p.Width),
                                     Constraint.RelativeToParent(p => p.Height / 3)
                                     );

            _picture = new RoundedImage {
                Aspect      = Aspect.AspectFill,
                BorderColor = Styles.Colors.SecondaryColor,
                BorderWidth = 1,
                Source      = "ic_user_picture_placeholder.png",
            };
            _mainLayout.Children.Add(_picture,
                                     Constraint.RelativeToParent(p => p.Width / 2 - 50),
                                     Constraint.RelativeToParent(p => p.Height / 3 - 150),
                                     Constraint.Constant(100),
                                     Constraint.Constant(100)
                                     );

            _nameLabel = new Label {
                Style                   = Styles.Subtitle,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                TextColor               = Color.White,
            };
            _mainLayout.Children.Add(_nameLabel,
                                     Constraint.Constant(20),
                                     Constraint.RelativeToView(_picture, (p, v) => v.Y + v.Height),
                                     Constraint.RelativeToParent(p => p.Width - 40),
                                     Constraint.Constant(40)
                                     );

            SearchPlaces = new Button {
                Style = Styles.ActiveButtonStyle,
                Text  = AppResources.SearchPlaces
            };
            _mainLayout.Children.Add(SearchPlaces,
                                     Constraint.RelativeToView(headerBoxview, (p, v) => v.X + 20),
                                     Constraint.RelativeToView(headerBoxview, (p, v) => v.Y + v.Height + 10),
                                     Constraint.RelativeToParent(p => p.Width - 40),
                                     Constraint.Constant(40)
                                     );
            var separator = new BoxView {
                BackgroundColor = Styles.Colors.PlaceholderColor,
            };

            _mainLayout.Children.Add(separator,
                                     Constraint.RelativeToView(SearchPlaces, (p, v) => v.X - 20),
                                     Constraint.RelativeToView(SearchPlaces, (p, v) => v.Y + v.Height + 10),
                                     Constraint.RelativeToView(SearchPlaces, (p, v) => v.Width + 40),
                                     Constraint.Constant(1)
                                     );

            _latestReviewsTitleLabel = new Label {
                Style                   = Styles.Subtitle,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                TextColor               = Styles.Colors.PrimaryColor,
            };
            _mainLayout.Children.Add(_latestReviewsTitleLabel,
                                     Constraint.RelativeToView(SearchPlaces, (p, v) => v.X),
                                     Constraint.RelativeToView(separator, (p, v) => v.Y + v.Height + 10),
                                     Constraint.RelativeToView(SearchPlaces, (p, v) => v.Width),
                                     Constraint.Constant(40)
                                     );

            _emptyReviews = new Label {
                IsVisible = false,
                Style     = Styles.Subtitle,
                HorizontalTextAlignment = TextAlignment.Center
            };
            _mainLayout.Children.Add(_emptyReviews,
                                     Constraint.Constant(0),
                                     Constraint.RelativeToView(_latestReviewsTitleLabel, (p, v) => v.Y + v.Height),
                                     Constraint.RelativeToParent(p => p.Width),
                                     Constraint.RelativeToView(_latestReviewsTitleLabel, (p, v) => p.Height - (v.Y + v.Height))
                                     );

            ReviewsList = new ListView {
                RowHeight       = 100,
                ItemTemplate    = new DataTemplate(typeof(ReviewViewCell)),
                BackgroundColor = Color.White,
                IsVisible       = false,
            };
            ReviewsList.ItemsSource = _reviewsCollection;
            _mainLayout.Children.Add(ReviewsList,
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.X),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Y),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Width),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Height)
                                     );

            _reviewsPlaceholderLayout = DynamicsLayouts.Loading(AppResources.RetrievingReviews, Color.Transparent);
            _mainLayout.Children.Add(_reviewsPlaceholderLayout,
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.X),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Y),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Width),
                                     Constraint.RelativeToView(_emptyReviews, (p, v) => v.Height)
                                     );

            Content = _mainLayout;
        }