Example #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e)
        {
            base.OnElementChanged(e);



            RoundRectShape i = new RoundRectShape(
                new float[] { 15, 15, 15, 15, 15, 15, 15, 15 },
                null,
                new float[] { 15, 15, 15, 15, 15, 15, 15, 15 });

            var shape = new ShapeDrawable(i);

            shape.Paint.Color = Xamarin.Forms.Color.White.ToAndroid();
            shape.Paint.SetStyle(Paint.Style.Stroke);
            Control.Background = shape;
            Control.SetPadding(15, 15, 15, 15);

            DatePickerBorderCtrl element = Element as DatePickerBorderCtrl;

            if (!string.IsNullOrWhiteSpace(element.Placeholder))
            {
                this.Control.SetTextColor(Android.Graphics.Color.Gray);
                Control.Text = element.Placeholder;
            }

            this.Control.TextChanged += (sender, arg) => {
                var selectedDate = arg.Text.ToString();
                if (selectedDate == element.Placeholder)
                {
                    Control.Text = DateTime.Now.ToString("dd/MM/yyyy");
                    //this.Control.SetTextColor(Android.Graphics.Color.Gray);
                }
            };
        }
Example #2
0
        public GraphicsPath GetContourPath(Rectangle bounds)
        {
            GraphicsPath path = new GraphicsPath();

            if (bounds.Height <= 0 || bounds.Width <= 0)
            {
                return(path);
            }
            if (bounds.Height < 10 || bounds.Width < 10)
            {
                RoundRectShape rrs = new RoundRectShape(5);
                path = rrs.CreatePath(bounds);
                return(path);
            }


            GraphicsPath res = new GraphicsPath();

            Point[] points = null;

            if (this.RoundedBottom)
            {
                points = GetRoundedBottomContour(bounds);
            }
            else
            {
                points = GetCutBottomContour(bounds);
            }

            res.AddLines(points);

            return(res);
        }
Example #3
0
        private void radGridView1_RowPaint(object sender, GridViewRowPaintEventArgs e)
        {
            if (e.Row is GridDataRowElement)
            {
                GridDataRowElement rowElement = (GridDataRowElement)e.Row;
                int startIndex = (int)e.Row.RowInfo.Cells["StartCell"].Value;
                int endIndex   = (int)e.Row.RowInfo.Cells["EndCell"].Value;
                GridDataCellElement startCell = GetCell(e.Row, startIndex);
                GridDataCellElement endCell   = GetCell(e.Row, endIndex);

                if (startCell != null || endCell != null)
                {
                    int left  = startCell == null ? rowElement.ScrollableColumns.BoundingRectangle.Left - 10 : startCell.ControlBoundingRectangle.Left;
                    int right = endCell == null ? rowElement.ScrollableColumns.BoundingRectangle.Right + 10 : endCell.ControlBoundingRectangle.Right;

                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    Region clipRegion = e.Graphics.Clip;

                    e.Graphics.SetClip(rowElement.ScrollableColumns.BoundingRectangle);

                    int randomColor = (int)e.Row.RowInfo.Cells["Color"].Value;

                    using (RoundRectShape shape = new RoundRectShape(5))
                        using (GraphicsPath path = shape.CreatePath(new RectangleF(left + 5, 5, (right - left) - 10, e.Row.Size.Height - 10)))
                            using (Brush brush = new SolidBrush(fills[randomColor]))
                                using (Pen pen = new Pen(borders[randomColor], 2))
                                {
                                    e.Graphics.FillPath(brush, path);
                                    e.Graphics.DrawPath(pen, path);
                                }

                    e.Graphics.Clip = clipRegion;
                }
            }
        }
Example #4
0
        /// <summary>Greates the path.</summary>
        public override GraphicsPath CreatePath(Rectangle bounds)
        {
            GraphicsPath path = new GraphicsPath();

            if (bounds.Height <= 0 || bounds.Width <= 0)
            {
                return(path);
            }
            if (bounds.Height < 10 || bounds.Width < 10)
            {
                RoundRectShape rrs = new RoundRectShape(5);
                path = rrs.CreatePath(bounds);
                return(path);
            }

            Rectangle[] rects = GetRectangles(bounds);
            path.AddRectangles(rects);

            //Point[] points = GetRoundedBottomContour(bounds);
            //path.AddLines(points);

            //path.CloseFigure();

            return(path);
        }
        private void SetBorder(ColorDatePicker view)
        {
            if (view.HasCorner)
            {
                int lefttop     = (int)(view.CornerWidth * disp.Density);
                int righttop    = lefttop;
                int leftbottom  = lefttop;
                int rightbottom = lefttop;

                RoundRectShape rect = new RoundRectShape(
                    new float[]
                {
                    lefttop, lefttop,
                    righttop, righttop,
                    rightbottom, rightbottom,
                    leftbottom, leftbottom
                }, null, null);
                ShapeDrawable bg = new ShapeDrawable(rect);
                bg.Paint.Color     = view.BackgroundColor.ToAndroid();
                Control.Background = bg;
            }
            else
            {
                Control.Background = originalDrawable;
            }
        }
Example #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'furnitureDataSet2.Products' table. You can move, or remove it, as needed.
            this.productsTableAdapter1.Fill(this.furnitureDataSet2.Products);

            this.BackgroundImage       = this.LoadImage("Telerik.Examples.WinControls.GridView.FirstLook.Images.bg.png");
            this.BackgroundImageLayout = ImageLayout.Stretch;

            this.newButton.Image                    = this.LoadImage("Telerik.Examples.WinControls.GridView.FirstLook.Images.buttonNew.png");
            this.deleteButton.Image                 = this.LoadImage("Telerik.Examples.WinControls.GridView.FirstLook.Images.buttonDelete.png");
            this.radPanel2.BackgroundImage          = this.LoadImage("Telerik.Examples.WinControls.GridView.FirstLook.Images.f1.PNG");
            this.radTitleBar1.BackgroundImage       = this.LoadImage("Telerik.Examples.WinControls.GridView.FirstLook.Images.logo.png");
            this.radTitleBar1.BackgroundImageLayout = ImageLayout.Center;
            ((TextPrimitive)this.radTitleBar1.TitleBarElement.Children[2].Children[1]).Text   = String.Empty;
            ((ImagePrimitive)this.radTitleBar1.TitleBarElement.Children[2].Children[0]).Image = null;

            RoundRectShape panelShapeTopRounded = new RoundRectShape(3);

            panelShapeTopRounded.BottomRightRounded = false;
            panelShapeTopRounded.BottomLeftRounded  = false;
            radPanel4.PanelElement.Shape            = panelShapeTopRounded;

            RoundRectShape panelShapeBottomRounded = new RoundRectShape(3);

            panelShapeBottomRounded.TopLeftRounded  = false;
            panelShapeBottomRounded.TopRightRounded = false;
            radPanel1.PanelElement.Shape            = panelShapeBottomRounded;

            radPanel3.PanelElement.Shape = panelShapeTopRounded;

            radTextBoxDimension.Font    = segoeFont;
            radTextBoxManufacturer.Font = segoeFont;
            radTextBoxMaterial.Font     = segoeFont;
            radTextBoxProductName.Font  = segoeFont;
            updateButton.Font           = segoeFont;
            cancelButton.Font           = segoeFont;
            radLabel2.Font = segoeFont;
            radLabel3.Font = segoeFont;
            radLabel4.Font = segoeFont;
            radLabel5.Font = segoeFont;
            radLabel6.Font = segoeFont;

            this.radGridView1.TableElement.Padding     = new Padding(0);
            this.radGridView1.TableElement.DrawBorder  = false;
            this.radGridView1.TableElement.CellSpacing = -1;
            this.radGridView1.TableElement.Text        = "";

            this.radGridView1.MasterTemplate.BestFitColumns();
            this.radGridView1.Columns["Photo"].Width       = 106;
            this.radGridView1.Columns["ProductName"].Width = 104;

            this.FillComboBox();
            this.UpdatePanelInfo(this.radGridView1.CurrentRow);
        }
Example #7
0
        private void SetShapes()
        {
            this.radRadioCustShape.RootElement.Children[0].Children[1].Children[1].Shape = customShape1;
            this.radRadioDonut.RootElement.Children[0].Children[1].Children[1].Shape     = new DonutShape();
            RoundRectShape square = new RoundRectShape();

            square.Radius = 0;
            this.radRadioSquare.RootElement.Children[0].Children[1].Children[1].Shape = square;
            this.radRadioRound.RootElement.Children[0].Children[1].Children[1].Shape  = new RoundRectShape();
            this.radRadioOffice.RootElement.Children[0].Children[1].Children[1].Shape = new OfficeShape();
        }
Example #8
0
        private void setBottomCorners(View llBtnGroup)
        {
            int radius = DisplayUtil.dp2px(Context, DEFAULT_RADIUS);

            float[]        outerRadii     = new float[] { 0, 0, 0, 0, radius, radius, radius, radius };
            RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null);
            ShapeDrawable  shapeDrawable  = new ShapeDrawable(roundRectShape);

            shapeDrawable.Paint.Color = Color.White;
            shapeDrawable.Paint.SetStyle(Paint.Style.Fill);
            llBtnGroup.Background = shapeDrawable;
        }
        private ShapeDrawable getDefaultBackground()
        {
            int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP);

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

            var           rr       = new RoundRectShape(outerR, null, null);
            ShapeDrawable drawable = new ShapeDrawable(rr);

            drawable.Paint.Color = badgeColor;

            return(drawable);
        }
Example #10
0
        protected virtual Padding GetContentMargin()
        {
            if (this.panelElement.Border.Visibility != ElementVisibility.Visible)
            {
                return(Padding.Empty);
            }
            Padding p2 = this.panelElement.BorderThickness;

            if (this.RootElement.Shape != null && this.RootElement.ApplyShapeToControl && this.RootElement.Shape is RoundRectShape)
            {
                RoundRectShape shape = this.RootElement.Shape as RoundRectShape;
                p2 = Padding.Add(new Padding((int)((double)shape.Radius - Math.Sqrt((double)(shape.Radius * shape.Radius / 2)))), p2);
            }
            return(p2);
        }
Example #11
0
        private void initView()
        {
            View contentView = View.Inflate(Context, Resource.Layout.layout_promptdialog, null);

            SetContentView(contentView);
            resizeDialog();

            mDialogView  = Window.DecorView.FindViewById(Android.Resource.Id.Content);
            mTitleTv     = (TextView)contentView.FindViewById(Resource.Id.tvTitle);
            mContentTv   = (TextView)contentView.FindViewById(Resource.Id.tvContent);
            mPositiveBtn = (TextView)contentView.FindViewById(Resource.Id.btnPositive);

            View      llBtnGroup = FindViewById(Resource.Id.llBtnGroup);
            ImageView logoIv     = (ImageView)contentView.FindViewById(Resource.Id.logoIv);

            logoIv.SetBackgroundResource(getLogoResId(mDialogType));

            LinearLayout topLayout  = (LinearLayout)contentView.FindViewById(Resource.Id.topLayout);
            ImageView    triangleIv = new ImageView(Context);

            triangleIv.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, DisplayUtil.dp2px(Context, 10));

            triangleIv.SetImageBitmap(createTriangel((int)(DisplayUtil.getScreenSize(_context).X * 0.7), DisplayUtil.dp2px(_context, 10)));

            topLayout.AddView(triangleIv);

            setBtnBackground(mPositiveBtn);
            setBottomCorners(llBtnGroup);


            int radius = DisplayUtil.dp2px(Context, DEFAULT_RADIUS);

            float[]        outerRadii     = new float[] { radius, radius, radius, radius, 0, 0, 0, 0 };
            RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null);
            ShapeDrawable  shapeDrawable  = new ShapeDrawable(roundRectShape);

            shapeDrawable.Paint.SetStyle(Paint.Style.Fill);
            shapeDrawable.Paint.Color = Context.Resources.GetColor(getColorResId(mDialogType));
            LinearLayout llTop = (LinearLayout)FindViewById(Resource.Id.llTop);

            llTop.Background = shapeDrawable;

            mTitleTv.Text     = mTitle;
            mContentTv.Text   = mContent;
            mPositiveBtn.Text = mBtnText;
        }
Example #12
0
        private void setBackgroundColor()
        {
            if (0 == mBackgroundColor)
            {
                return;
            }

            int radius = DisplayUtil.dp2px(Context, 6);

            float[]        outerRadii     = new float[] { radius, radius, radius, radius, 0, 0, 0, 0 };
            RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null);
            ShapeDrawable  shapeDrawable  = new ShapeDrawable(roundRectShape);

            shapeDrawable.Paint.Color = mBackgroundColor;

            shapeDrawable.Paint.SetStyle(Paint.Style.Fill);
            mBkgView.Background = shapeDrawable;
        }
Example #13
0
        /// <summary>
        /// Calculates the non-client margin of the control
        /// based on the radius of the round rect shape.
        /// </summary>
        /// <returns>An instance of the <see cref="System.Windows.Forms.Padding"/> struct
        /// which represents the left, top, right and bottom margin.</returns>
        protected virtual Padding GetContentMargin()
        {
            if (this.panelElement.Border.Visibility == ElementVisibility.Visible)
            {
                Padding result = this.panelElement.BorderThickness;

                if (this.RootElement.Shape != null && this.RootElement.ApplyShapeToControl &&
                    this.RootElement.Shape is RoundRectShape)
                {
                    RoundRectShape rRectShape = this.RootElement.Shape as RoundRectShape;
                    int            ncOffset   = (int)(rRectShape.Radius - Math.Sqrt(rRectShape.Radius * rRectShape.Radius / 2));
                    result = Padding.Add(new Padding(ncOffset), result);
                }

                return(result);
            }

            return(Padding.Empty);
        }
        public override string ToString()
        {
            object value = Value;

            if (value != null)
            {
                if (value.GetType() == typeof(Color))
                {
                    return(((Color)value).Name);
                }
                else if (value.GetType() == typeof(RoundRectShape))
                {
                    RoundRectShape shape = (RoundRectShape)value;
                    return(shape.Radius.ToString());
                }
                return(value.ToString());
            }
            return("");
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Editor> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var nativeEditText = (global::Android.Widget.EditText)Control;

                RoundRectShape i = new RoundRectShape(
                    new float[] { 15, 15, 15, 15, 15, 15, 15, 15 },
                    null,
                    new float[] { 15, 15, 15, 15, 15, 15, 15, 15 });

                var shape = new ShapeDrawable(i);
                shape.Paint.Color = Xamarin.Forms.Color.White.ToAndroid();
                shape.Paint.SetStyle(Paint.Style.Stroke);
                nativeEditText.Background = shape;
                nativeEditText.SetPadding(15, 15, 15, 15);
            }
        }
        private void SetBorder(ColorTimePicker view)
        {
            int lefttop     = 1;
            int righttop    = lefttop;
            int leftbottom  = lefttop;
            int rightbottom = lefttop;

            RoundRectShape rect = new RoundRectShape(
                new float[]
            {
                lefttop, lefttop,
                righttop, righttop,
                rightbottom, rightbottom,
                leftbottom, leftbottom
            }, null, null);
            ShapeDrawable bg = new ShapeDrawable(rect);

            bg.Paint.Color     = view.BackgroundColor.ToAndroid();
            Control.Background = bg;
        }
Example #17
0
        private void FrmLoginLoad(object sender, EventArgs e)
        {
            RoundRectShape shape = new RoundRectShape
            {
                BottomLeftRounded  = true,
                BottomRightRounded = true,
                TopLeftRounded     = true,
                TopRightRounded    = true,
                Radius             = 5
            };

            //txtLogin.RootElement.StretchVertically = true;
            //txtLogin.TextBoxElement.StretchVertically = true;
            //txtLogin.TextBoxElement.TextBoxItem.Alignment = ContentAlignment.MiddleLeft;

            //txtPassword.RootElement.StretchVertically = true;
            //txtPassword.TextBoxElement.StretchVertically = true;
            //txtPassword.TextBoxElement.TextBoxItem.Alignment = ContentAlignment.MiddleLeft;

            txtLogin.Height    = 25;
            txtPassword.Height = 25;

            //txtLogin.TextBoxElement.Shape = shape;
            //txtPassword.TextBoxElement.Shape = shape;

            lblStatus.Location  = new Point(6, (Height - lblStatus.Height) - 8);
            lblVersion.Location = new Point((Width - lblVersion.Width) - 10, (Height - lblVersion.Height) - 8);

            LoadStatus(Program.LanguageDefault.DictionaryLogin["InsertLogin"]);

            txtLogin.TabIndex    = 0;
            txtPassword.TabIndex = 1;

            cbxOffline.Checked = true;

            txtLogin.Focus();
            txtLogin.Select();

            BtnOkClick(new object(), new EventArgs());
        }
Example #18
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var nativeEditText = (global::Android.Widget.EditText)Control;

                RoundRectShape i = new RoundRectShape(
                    new float[] { 15, 15, 15, 15, 15, 15, 15, 15 },
                    null,
                    new float[] { 15, 15, 15, 15, 15, 15, 15, 15 });

                var shape = new ShapeDrawable(i);
                shape.Paint.Color = Xamarin.Forms.Color.FromHex("#c786d3").ToAndroid();
                shape.Paint.SetStyle(Paint.Style.Stroke);
                nativeEditText.Background = shape;
                nativeEditText.SetPadding(25, 25, 25, 25);

                //nativeEditText.FocusedByDefault = true; not working
            }
        }
Example #19
0
        protected LayerDrawable GradientConverter(String Gradient)
        {
            var roundRect = new RoundRectShape(CornerRadiusArray, null, null);

            ShapeDrawable sf = new ShapeDrawable(roundRect);

            sf.SetIntrinsicHeight(100);
            sf.SetIntrinsicWidth(200);
            sf.SetShaderFactory(new GradientShader(Gradient));

            ShapeDrawable shadow = new ShapeDrawable(roundRect);

            shadow.SetIntrinsicHeight(100);
            shadow.SetIntrinsicWidth(200);
            shadow.SetShaderFactory(new ShadowShader(BaseControl));

            LayerDrawable ld = null;

            if (Element.BorderColor != Xamarin.Forms.Color.Default)
            {
                GradientDrawable stroke = new GradientDrawable();
                stroke.SetCornerRadii(CornerRadiusArray);
                stroke.SetStroke(2, Element.BorderColor.ToAndroid());

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

                ld.SetLayerInset(0, 0, 0, 3, 3);
                ld.SetLayerInset(1, 5, 5, 0, 0); // inset the shadow so it doesn't start right at the left/top
                ld.SetLayerInset(2, 2, 2, 5, 5);
            }
            else
            {
                ld = new LayerDrawable(new Drawable[] { shadow, sf });
                ld.SetLayerInset(0, 5, 5, 0, 0); // inset the shadow so it doesn't start right at the left/top
                ld.SetLayerInset(1, 0, 0, 5, 5);
            }

            return(ld);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var nativeEditText = (global::Android.Widget.SearchView)Control;

                var plateId = Resources.GetIdentifier("android:id/search_plate", null, null);
                var plate   = Control.FindViewById(plateId);
                plate.SetBackgroundColor(Android.Graphics.Color.Transparent);

                RoundRectShape i = new RoundRectShape(
                    new float[] { 30, 30, 30, 30, 30, 30, 30, 30 },
                    null,
                    new float[] { 30, 30, 30, 30, 30, 30, 30, 30 });


                var shape = new ShapeDrawable(i);
                shape.Paint.Color = Xamarin.Forms.Color.Transparent.ToAndroid();
                shape.Paint.SetStyle(Paint.Style.Stroke);
                nativeEditText.Background = shape;
            }
        }
 void UpdateShape( )
 {
     // if there's a border width or corner radius, create a shape to render that represents the border.
     // This will allow either a bordered button, or a rounded button.
     if (_BorderWidth > 0 || _Radius > 0)
     {
         Shape = new RoundRectShape(new float[]
         {
             _Radius,
             _Radius,
             _Radius,
             _Radius,
             _Radius,
             _Radius,
             _Radius,
             _Radius
         }, null, null);
     }
     else
     {
         // otherwise, delete our shape so we don't render anything for a border.
         Shape = null;
     }
 }
Example #22
0
        private Drawable CreateNativeBorder(Brush background, Brush borderBrush, Thickness borderThickness,
                                            CornerRadius cornerRadius)
        {
            var cornerRadiusArray = new[]
            {
                (float)cornerRadius.TopLeft, (float)cornerRadius.TopLeft,
                (float)cornerRadius.TopRight, (float)cornerRadius.TopRight,
                (float)cornerRadius.BottomRight, (float)cornerRadius.BottomRight,
                (float)cornerRadius.BottomLeft, (float)cornerRadius.BottomLeft
            };
            Paint backgroundPaint = new Paint();
            Paint borderPaint     = new Paint();

            backgroundPaint.SetStyle(Paint.Style.Fill);
            borderPaint.SetStyle(Paint.Style.Fill);
            if (borderBrush == null)
            {
                borderPaint.Color = Color.Transparent;
            }
            else
            {
                if (borderBrush is SolidColorBrush)
                {
                    var color = ((SolidColorBrush)borderBrush).Color;
                    borderPaint.Color = new Color(color.R, color.G, color.B, color.A);
                }
                else
                {
                    throw new Exception("SolidColorBrush BorderBrush is supported.");
                }
            }
            if (background == null)
            {
                backgroundPaint.Color = Color.Transparent;
            }
            else
            {
                if (background is SolidColorBrush)
                {
                    var color = ((SolidColorBrush)background).Color;
                    backgroundPaint.Color = new Color(color.R, color.G, color.B, color.A);
                }
                else
                {
                    throw new Exception("SolidColorBrush Background is supported.");
                }
            }
            var rs      = new RoundRectShape(cornerRadiusArray, null, null);
            var noChild =
                (this.Child == null || this.Child.Height.Equals(0) || this.Child.Width.Equals(0)) &&
                (this.ActualHeight.Equals(0) || this.ActualWidth.Equals(0));
            var    left   = ScreenProperties.ConvertDPIToPixels((float)(borderThickness.Left));
            var    top    = ScreenProperties.ConvertDPIToPixels((float)(borderThickness.Top));
            var    right  = ScreenProperties.ConvertDPIToPixels((float)(borderThickness.Right));
            var    bottom = ScreenProperties.ConvertDPIToPixels((float)(borderThickness.Bottom));
            var    pixelBorderThickness = new Thickness(left, top, right, bottom);
            Bitmap bitmap = null;

            using (ShapeDrawable sd = new CustomShapeDrawable(rs, backgroundPaint, borderPaint, cornerRadiusArray, pixelBorderThickness, noChild))
            {
                var width  = ScreenProperties.ConvertDPIToPixels((float)(this.ActualWidth));
                var height = ScreenProperties.ConvertDPIToPixels((float)(this.ActualHeight));
                if (height <= 0 || width <= 0)
                {
                    return(new BitmapDrawable());
                }
                bitmap = Bitmap.CreateBitmap((int)width, (int)height, Bitmap.Config.Argb8888);
                var canvas = new Android.Graphics.Canvas(bitmap);
                sd.SetBounds(0, 0, canvas.Width, canvas.Height);
                sd.Draw(canvas);
            }
            return(new BitmapDrawable(bitmap));
        }
Example #23
0
        /// <summary>
        ///     Inits the control.
        /// </summary>
        /// <param name="dataCollection">Data collection of TData.</param>
        /// <param name="viewInflater">
        ///     Method which will return view of page inflated with TData. Background of result view should
        ///     be transparent and setted through BackgroundColor parameter.
        /// </param>
        /// <param name="wm">Window manager.</param>
        /// <param name="fm">Fragment manager.</param>
        /// <param name="pageGapDistance">Distance between two pages in px.</param>
        /// <param name="activePageSideOffset">Distance from side of control to side of page in px.</param>
        /// <param name="animationType"></param>
        /// <param name="darkenMultiplier">
        ///     How much inactive pages should be darkened. Value from 0.0f to 1.0f, where 0.0f is not
        ///     darkened at all and 1.0f completely black.
        /// </param>
        /// <param name="shrinkedViewScale">
        ///     Size of inactive pages respectively to active page. Value from 0.0f to 1.0f, where 0.0f
        ///     shrinkes page to invisible and 1.0f doesn't resize inactive page.
        /// </param>
        /// <param name="backgroundColor">Background color. Transparent if null.</param>
        /// <param name="cornerRadius">Corner radius.</param>
        /// <typeparam name="TData">Type of each item in collection, from which pages will be inflated.</typeparam>
        public void InitControl <TData>(IList <TData> dataCollection,
                                        PagerAnimatedAdapter <TData> .ViewInflatHandler viewInflater,
                                        IWindowManager wm,
                                        FragmentManager fm,
                                        int pageGapDistance         = 0,
                                        int activePageSideOffset    = 0,
                                        AnimationType animationType = AnimationType.None,
                                        float darkenMultiplier      = 0.4f,
                                        float shrinkedViewScale     = 0.8f,
                                        Color?backgroundColor       = null,
                                        int cornerRadius            = 0)
        {
            PageMargin         = pageGapDistance;
            OffscreenPageLimit = 3;
            SetClipToPadding(false);
            SetPadding(activePageSideOffset, 0, activePageSideOffset, 0);
            var displaySize = new Point();

            wm.DefaultDisplay.GetSize(displaySize);

            var backgroundShape = new RoundRectShape(
                new float[]
            {
                cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius,
                cornerRadius
            },
                null, null);

            var backgroundShapeDrawable = new ShapeDrawable(backgroundShape);
            var backgroundPaint         = backgroundShapeDrawable.Paint;

            backgroundPaint.Color = backgroundColor ?? Color.Transparent;
            backgroundPaint.SetStyle(Paint.Style.Fill);

            ShapeDrawable foregroundShapeDrawable = null;

            switch (animationType)
            {
            case AnimationType.None:
                PageTransformer = null;
                break;

            case AnimationType.Revealing:
                foregroundShapeDrawable = new ShapeDrawable(backgroundShape);
                var foregroundPaint = foregroundShapeDrawable.Paint;
                foregroundPaint.Color = Color.Black;
                foregroundPaint.SetStyle(Paint.Style.Fill);
                PageTransformer = new RevealingPageTransformer(darkenMultiplier, shrinkedViewScale,
                                                               AnimationHorizontalPositionOffset);
                break;

            default:
                break;
            }

            AnimationHorizontalPositionOffset = (float)(PageMargin + PaddingLeft) / displaySize.X;
            SetPageTransformer(true, PageTransformer);

            var adapter = new PagerAnimatedAdapter <TData>(dataCollection, viewInflater, backgroundShapeDrawable,
                                                           foregroundShapeDrawable, fm);

            Adapter = adapter;
        }
Example #24
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (container == null)
            {
                // Currently in a layout without a container, so no reason to create our view.
                return(null);
            }

            Point displaySize = new Point( );

            Activity.WindowManager.DefaultDisplay.GetSize(displaySize);
            ScreenSize = new System.Drawing.SizeF(displaySize.X, displaySize.Y);

            // scale the image to match the view's width
            ScreenToImageScalar = (float)SourceImage.Width / (float)ScreenSize.Width;

            // get the scaled dimensions, maintaining aspect ratio
            float scaledWidth  = (float)SourceImage.Width * (1.0f / ScreenToImageScalar);
            float scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar);

            // now, if the scaled height is too large, re-calc with Height is the dominant,
            // so we guarantee a fit within the view.
            if (scaledHeight > ScreenSize.Height)
            {
                ScreenToImageScalar = (float)SourceImage.Height / (float)ScreenSize.Height;

                scaledWidth  = (float)SourceImage.Width * (1.0f / ScreenToImageScalar);
                scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar);
            }

            ScaledSourceImage = Bitmap.CreateScaledBitmap(SourceImage, (int)scaledWidth, (int)scaledHeight, false);


            // setup our layout for touch input
            RelativeLayout view = inflater.Inflate(Resource.Layout.ImageCrop, container, false) as RelativeLayout;

            view.SetOnTouchListener(this);


            // create the view that will display the image to crop
            ImageView = new AspectScaledImageView(Rock.Mobile.PlatformSpecific.Android.Core.Context);
            ImageView.LayoutParameters        = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
            ImageView.LayoutParameters.Width  = ScaledSourceImage.Width;
            ImageView.LayoutParameters.Height = ScaledSourceImage.Height;

            // center the image
            ImageView.SetX((ScreenSize.Width - ImageView.LayoutParameters.Width) / 2);
            ImageView.SetY((ScreenSize.Height - ImageView.LayoutParameters.Height) / 2);

            view.AddView(ImageView);

            // create the draggable crop view that will let the user pic which part of the image to use.
            CropView = new View(Rock.Mobile.PlatformSpecific.Android.Core.Context);
            CropView.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            // the crop view's dimensions should be based on what the user wanted to crop to. We'll do width, and then height as a scale of width.
            CropView.LayoutParameters.Width  = (int)(scaledWidth < scaledHeight ? scaledWidth : scaledHeight);
            CropView.LayoutParameters.Height = (int)((float)CropView.LayoutParameters.Width * CropAspectRatio);

            // the crop view should be a nice outlined rounded rect
            float          _Radius   = 3.0f;
            RoundRectShape rectShape = new RoundRectShape(new float[] { _Radius,
                                                                        _Radius,
                                                                        _Radius,
                                                                        _Radius,
                                                                        _Radius,
                                                                        _Radius,
                                                                        _Radius,
                                                                        _Radius }, null, null);
            // configure its paint
            ShapeDrawable border = new ShapeDrawable(rectShape);

            border.Paint.SetStyle(Paint.Style.Stroke);
            border.Paint.StrokeWidth = 8;
            border.Paint.Color       = Color.WhiteSmoke;
            CropView.Background      = border;


            // set our clamp values
            CropViewMinPos = new PointF((ScreenSize.Width - scaledWidth) / 2,
                                        (ScreenSize.Height - scaledHeight) / 2);

            CropViewMaxPos = new PointF(CropViewMinPos.X + (scaledWidth - CropView.LayoutParameters.Width),
                                        CropViewMinPos.Y + (scaledHeight - CropView.LayoutParameters.Height));
            view.AddView(CropView);

            // create a mask layer that will block out the parts of the image that will be cropped
            MaskLayer = new Rock.Mobile.PlatformSpecific.Android.Graphics.MaskLayer((int)ScreenSize.Width, (int)ScreenSize.Height, CropView.LayoutParameters.Width, CropView.LayoutParameters.Height, Rock.Mobile.PlatformSpecific.Android.Core.Context);
            MaskLayer.LayoutParameters = new RelativeLayout.LayoutParams((int)ScreenSize.Width, (int)ScreenSize.Height);
            MaskLayer.Opacity          = 0.00f;
            view.AddView(MaskLayer);

            // Now setup our bottom area with cancel, crop, and text to explain
            RelativeLayout bottomBarLayout = new RelativeLayout(Rock.Mobile.PlatformSpecific.Android.Core.Context);

            bottomBarLayout.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
            ((RelativeLayout.LayoutParams)bottomBarLayout.LayoutParameters).AddRule(LayoutRules.AlignParentBottom);

            // set the nav subBar color (including opacity)
            Color navColor = Rock.Mobile.UI.Util.GetUIColor(PrivateSubNavToolbarConfig.BackgroundColor);

            navColor.A = (Byte)((float)navColor.A * PrivateSubNavToolbarConfig.Opacity);
            bottomBarLayout.SetBackgroundColor(navColor);
            view.AddView(bottomBarLayout);

            // setup the cancel button (which will undo cropping or take you back to the picture taker)
            CancelButton = new Button(Rock.Mobile.PlatformSpecific.Android.Core.Context);
            CancelButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
            CancelButton.Gravity          = GravityFlags.Left;
            ((RelativeLayout.LayoutParams)CancelButton.LayoutParameters).AddRule(LayoutRules.AlignParentLeft);

            // set the crop button's font
            Android.Graphics.Typeface fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont(PrivateControlStylingConfig.Icon_Font_Secondary);
            CancelButton.SetTypeface(fontFace, Android.Graphics.TypefaceStyle.Normal);
            CancelButton.SetTextSize(Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropCancelButton_Size);
            CancelButton.Text = PrivateImageCropConfig.CropCancelButton_Text;

            CancelButton.Click += (object sender, EventArgs e) =>
            {
                // don't allow button presses while animations are going on
                if (Animating == false)
                {
                    // if they hit cancel while previewing, go back to editing
                    if (Mode == CropMode.Previewing)
                    {
                        SetMode(CropMode.Editing);
                    }
                    else
                    {
                        // they pressed it while they're in editing mode, so go back to camera mode
                        Activity.OnBackPressed( );
                    }
                }
            };

            bottomBarLayout.AddView(CancelButton);

            // setup the Confirm button, which will use a font to display its graphic
            ConfirmButton = new Button(Rock.Mobile.PlatformSpecific.Android.Core.Context);
            ConfirmButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
            ConfirmButton.Gravity          = GravityFlags.Right;
            ((RelativeLayout.LayoutParams)ConfirmButton.LayoutParameters).AddRule(LayoutRules.AlignParentRight);

            // set the crop button's font
            fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont(PrivateControlStylingConfig.Icon_Font_Secondary);
            ConfirmButton.SetTypeface(fontFace, Android.Graphics.TypefaceStyle.Normal);
            ConfirmButton.SetTextSize(Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropOkButton_Size);
            ConfirmButton.Text = PrivateImageCropConfig.CropOkButton_Text;

            // when clicked, we should crop the image.
            ConfirmButton.Click += (object sender, EventArgs e) =>
            {
                // don't allow button presses while animations are going on
                if (Animating == false)
                {
                    // if they pressed confirm while editing, go to preview
                    if (Mode == CropMode.Editing)
                    {
                        SetMode(CropMode.Previewing);
                    }
                    else
                    {
                        // notify the caller
                        SpringboardParent.ModalFragmentDone(CroppedImage);
                    }
                }
            };

            bottomBarLayout.AddView(ConfirmButton);

            // start in editing mode (obviously)
            SetMode(CropMode.Editing);

            // start the cropper centered
            MoveCropView(new PointF((ScreenSize.Width - CropView.LayoutParameters.Width) / 2, (ScreenSize.Height - CropView.LayoutParameters.Height) / 2));

            MaskLayer.Position = new PointF(CropView.GetX( ), CropView.GetY( ));

            return(view);
        }