protected ShapeDrawable GradientConverter(String Gradient)
        {
            float[] array = new float[] { 250, 250, 250, 250, 250, 250, 250, 250 };

            if (Base.CornerRadius != "-1")
            {
                var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                array = new float[] { BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[0])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[1])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[2])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[3])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[4])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[5])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[6])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[7])) };
            }

            ShapeDrawable sf = new ShapeDrawable(new RoundRectShape(array, null, null));

            // sf.SetIntrinsicHeight(100);
            //sf.SetIntrinsicWidth(200);

            sf.SetShaderFactory(new GradientShader(Gradient));

            if (Base.HasBorder)
            {
                sf.Paint.StrokeWidth = 1;
                sf.Paint.Color       = Base.BorderColor.ToAndroid();
            }


            return(sf);
        }
        void CreateShapeDrawable(MvvmAspire.Controls.Button element)
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);

            if (element.CornerRadius != 0)
            {
                shape.SetCornerRadii(new float[]
                {
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Top),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Top),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Right),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Right),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Bottom),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Bottom),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Left),
                    BaseUIHelper.ConvertDPToPixels(element.Corner.Left)
                });
            }
            if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(Element.BackgroundColor.ToAndroid());
            }

            if (element.BorderColor != Xamarin.Forms.Color.Default)
            {
                shape.SetStroke(2, element.BorderColor.ToAndroid());
            }
            Control.Background = shape;
        }
Exemple #3
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            //if (changed)
            {
                //var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);
                if (actionBarCustomView != null)
                {
                    var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);

                    AddCustomMenuView();

                    int x2 = r - l;
                    if (msw <= 0)
                    {
                        msw = (int)Globals.ScreenWidth;
                    }
                    if (x2 <= 0)
                    {
                        x2 = (int)Globals.ScreenWidth;
                    }

                    actionBarCustomView.Measure(msw, BaseUIHelper.ConvertDPToPixels(50));     //MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly));
                    actionBarCustomView.Layout(0, 0, x2, BaseUIHelper.ConvertDPToPixels(50)); //b - t);

                    actionBarCustomView.Visibility = ViewStates.Visible;
                }
            }
        }
 void SetPadding()
 {
     cell.SetPadding(BaseUIHelper.ConvertDPToPixels(Base.Padding.Left),
                     BaseUIHelper.ConvertDPToPixels(Base.Padding.Top),
                     BaseUIHelper.ConvertDPToPixels(Base.Padding.Right),
                     BaseUIHelper.ConvertDPToPixels(Base.Padding.Bottom));
 }
        void SetImagePadding(int drawableWidth)
        {
            var button = this.Control as Android.Widget.Button;

            Android.Graphics.Rect bounds = new Android.Graphics.Rect();
            Paint p = button.Paint;

            float textWidth = 0;

            if (!string.IsNullOrWhiteSpace(Element.Text))
            {
                p.GetTextBounds(Element.Text, 0, Element.Text.Length, bounds);
                textWidth = p.MeasureText(Element.Text);
            }

            var paddingRight = BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Right);

            var left = Control.MeasuredWidth - ((Control.MeasuredWidth + textWidth + drawableWidth) / 2 + paddingRight);

            if (textWidth > 0)
            {
                left /= 2;
            }

            if (BaseElement.Padding.Top > 0 || BaseElement.Padding.Bottom > 0)
            {
                Control.SetPadding((int)left, (int)BaseElement.Padding.Top, (int)left, (int)BaseElement.Padding.Bottom);
            }
            else
            {
                Control.SetPadding((int)left, Control.PaddingTop, (int)left, Control.PaddingBottom);
            }
        }
 void SetPadding(MvvmAspire.Controls.Button element)
 {
     Control.SetPadding(BaseUIHelper.ConvertDPToPixels(element.Padding.Left),
                        BaseUIHelper.ConvertDPToPixels(element.Padding.Top),
                        BaseUIHelper.ConvertDPToPixels(element.Padding.Right),
                        BaseUIHelper.ConvertDPToPixels(element.Padding.Bottom));
 }
Exemple #7
0
 public static Android.Graphics.Color Convert(Color color)
 {
     return(Android.Graphics.Color.Argb(BaseUIHelper.ConvertDoubleToByteColor(color.A),
                                        BaseUIHelper.ConvertDoubleToByteColor(color.R),
                                        BaseUIHelper.ConvertDoubleToByteColor(color.G),
                                        BaseUIHelper.ConvertDoubleToByteColor(color.B)));
 }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Label> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || this.Element == null)
            {
                return;
            }

            var labelControl = (MvvmAspire.Controls.Label)Element;

            labelControl.PropertyChanged += (s, ev) =>
            {
                //if (labelControl != null)
                //    UpdateInputType(labelControl);

                switch (ev.PropertyName)
                {
                case "Font": SetTypeface(); break;

                case "MaxLines": SetMaxLines(); break;

                case "Text": SetTypeface(); break;

                case "TextStyle": SetTextStyle(); break;

                case "Command": SetCommand(); break;

                case "MaxWidth": SetMaxWidth(); break;

                case "IsSelectable": IsSelectable(); break;
                }
            };
            SetTypeface();
            SetMaxLines();
            SetCommand();
            SetMaxWidth();
            IsSelectable();
            if (Base.RefitTextEnabled)
            {
                minSize = convertFromDp(Resources.GetDimension(UIHelper.GetDimensionResource("text_size")));
            }

            UpdateInputType();

            currentWidth = Control.Width;

            Control.SetPadding(BaseUIHelper.ConvertDPToPixels(labelControl.Padding.Left),
                               BaseUIHelper.ConvertDPToPixels(labelControl.Padding.Top),
                               BaseUIHelper.ConvertDPToPixels(labelControl.Padding.Right),
                               BaseUIHelper.ConvertDPToPixels(labelControl.Padding.Bottom));

            //if (Base.MaxCharacters.HasValue)
            //{
            //    Control.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(Base.MaxCharacters.Value) });
            //}

            SetTextStyle();
            SetAccessibilityTraits();
        }
        void SetImageSize()
        {
            int width  = BaseUIHelper.ConvertDPToPixels(Base.ImageWidth),
                height = BaseUIHelper.ConvertDPToPixels(Base.ImageHeight);

            imageView.LayoutParameters.Width  = width;
            imageView.LayoutParameters.Height = height;
        }
 void SetMaxWidth()
 {
     if (Base.MaxWidth.HasValue)
     {
         Control.SetMaxWidth(BaseUIHelper.ConvertDPToPixels(Base.MaxWidth.Value));
     }
     else
     {
         Control.SetMaxWidth(int.MaxValue);
     }
 }
Exemple #11
0
        void CreateShapeDrawable(MvvmAspire.Controls.SearchBar element)
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);
            shape.SetCornerRadius(BaseUIHelper.ConvertDPToPixels(element.CornerRadius));

            if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(Element.BackgroundColor.ToAndroid());
            }

            Control.Background = shape;
        }
        protected override void OnDraw(Canvas canvas)
        {
            var cornerRadius = BaseUIHelper.ConvertDPToPixels(Element.CornerRadius);

            if (cornerRadius > 0)
            {
                Path    clipPath = new Path();
                RectF   rect     = new RectF(0, 0, BaseUIHelper.ConvertDPToPixels(Element.WidthRequest), BaseUIHelper.ConvertDPToPixels(Element.HeightRequest));
                float[] radii    = new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius };
                clipPath.AddRoundRect(rect, radii, Path.Direction.Cw);
                canvas.ClipPath(clipPath);
            }
            base.OnDraw(canvas);
        }
        private ShapeDrawable CreateMyDrawable(Android.Graphics.Color color)
        {
            ShapeDrawable shapeDrawable = new ShapeDrawable();

            shapeDrawable.Paint.Color = color;
            if (color != Android.Graphics.Color.LightGray || color != Android.Graphics.Color.LightBlue || color != Android.Graphics.Color.Transparent)
            {
                shapeDrawable.SetBounds(BaseUIHelper.ConvertDPToPixels(15), 0, Control.Width, 1);
            }

            if (color == Android.Graphics.Color.Transparent)
            {
                shapeDrawable.SetBounds(0, 0, 0, 0);
            }
            return(shapeDrawable);
        }
        private void SetSeparator()
        {
            if (BaseControl.SeparatorVisibility != SeparatorVisibility.None)
            {
                if (BaseControl.SeparatorBackground != null && BaseControl.SeparatorBackground.File != null)
                {
                    Control.Divider = this.Resources.GetDrawable(UIHelper.GetDrawableResource(BaseControl.SeparatorBackground));
                }
                else
                {
                    Control.Divider = CreateMyDrawable(BaseControl.SeparatorColor.ToAndroid());
                }

                Control.DividerHeight = BaseUIHelper.ConvertDPToPixels(BaseControl.SeparatorHeight);
            }
        }
Exemple #15
0
        void SetImage(int height)
        {
            Drawable drawableRight = null;
            Drawable drawableLeft  = null;

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                var element = Element.ImageRight;
                drawableRight = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawableRight.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth));
            }

            if (Element.ImageLeft != null && Element.ImageLeft.File != null)
            {
                drawableLeft = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageLeft));
                drawableLeft.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageLeftHeight));
            }

            textView.SetCompoundDrawablesRelative(drawableLeft, null, drawableRight, null);
        }
Exemple #16
0
 void SetCorners()
 {
     if (BaseElement.CornerRadius != 0)
     {
         CornerRadiusArray = new float[]
         {
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Top),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Top),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Right),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Right),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Bottom),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Bottom),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Left),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Left)
         };
     }
     else
     {
         CornerRadiusArray = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
     }
 }
Exemple #17
0
        //private void CheckEnabled()
        //{
        //    if (Element.IsEnabled)
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            Control.RequestFocus();
        //            UIHelper.OpenSoftKeyboard(Control);
        //        }

        //    }
        //    else
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            UIHelper.CloseSoftKeyboard(Control);
        //        }
        //  }
        //}
        private void CreateShapeDrawable()
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);
            shape.SetCornerRadius(BaseUIHelper.ConvertDPToPixels(Element.CornerRadius));

            if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(Element.BackgroundColor.ToAndroid());
            }

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                Drawable drawable = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawable.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth),
                                   BaseUIHelper.ConvertDPToPixels(Element.ImageRightHeight));
                Control.SetCompoundDrawablesRelative(null, null, drawable, null);
            }
            //if (Element.CornerRadius > 0)
            //    this.SetPadding(5, 2, 5, 2);

            Control.Background = shape;
        }
        void CreateShapeDrawable()
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);

            float[] cornerRadii = new float[] { 10, 10, 10, 10, 10, 10, 10, 10 };

            if (Base.CornerRadius != "-1")
            {
                var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                cornerRadii = new float[] { BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[0])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[1])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[2])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[3])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[4])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[5])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[6])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[7])) };
            }



            shape.SetCornerRadii(cornerRadii);

            var element = Element as RoundedFrame;

            if (element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(element.BackgroundColor.ToAndroid());
            }

            if (Base.HasBorder)
            {
                shape.SetStroke(1, Base.BorderColor.ToAndroid());
            }

            Control.Background = shape;
        }
Exemple #19
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var propertyName = e.PropertyName;

            switch (propertyName)
            {
            case "ItemsSource":
                SetItemsSource(); break;

            case "Padding": SetPadding(); break;

            case "SeparatorVisibility": SetSeparator(); break;

            case "Selector": SetSelector(); break;

            case "EmptyText":
                if (_emptyViewTv != null && BaseControl != null)
                {
                    _emptyViewTv.Text = BaseControl.EmptyText;
                }
                break;

            case "IsRefreshing":

                UpdateEmptyLabelVisibility();
                //if (Element.IsRefreshing)
                //    shouldExecuteCommand = false;
                if (_swipeContainer != null && Element != null)
                {
                    if (Control != null)
                    {
                        Control.Post(() =>
                        {
                            if (Element != null)
                            {
                                _swipeContainer.Refreshing = Element.IsRefreshing;
                            }
                        });
                    }
                }
                break;

            case "Height":
                if (!isRefreshEnabled)
                {
                    if (Element != null && _emptyViewTv != null && !string.IsNullOrWhiteSpace(BaseControl.EmptyText))
                    {
                        _emptyViewTv.SetHeight(BaseUIHelper.ConvertDPToPixels(Element.Height));
                    }
                }

                break;

            case "ScrollToTopChange":
                ScrollToTop();
                break;

            case "ScrollToIndex":
                if (BaseControl.ScrollToIndex > 0)
                {
                    DeterminedScrollTo(BaseControl.ScrollToIndex, 3);
                    //Control.SmoothScrollToPosition(BaseControl.ScrollToIndex, 100);
                }
                break;
            }
        }
 void SetTitlePadding(MvvmAspire.Controls.Button element)
 {
     Control.CompoundDrawablePadding = BaseUIHelper.ConvertDPToPixels(element.TextPadding.Left);
 }
        void SetImages(MvvmAspire.Controls.Button element)
        {
            try
            {
                ButtonText = Element.Text;

                if (!HaseResource(element.ImageLeft) && !HaseResource(element.ImageTop) && !HaseResource(element.ImageRight) && !HaseResource(element.ImageBottom))
                {
                    Control.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                    Control.Invalidate();
                    return;
                }

                Drawable leftResource = null, topResource = null, rightResource = null, bottomResource = null;

                if (element.ImageLeft != null && element.ImageLeft.File != null)
                {
                    leftResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageLeft));
                }
                if (element.ImageTop != null && element.ImageTop.File != null)
                {
                    topResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageTop));
                }
                if (element.ImageRight != null && element.ImageRight.File != null)
                {
                    rightResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageRight));
                }
                if (element.ImageBottom != null && element.ImageBottom.File != null)
                {
                    bottomResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageBottom));
                }

                bool hasResource = leftResource != null || rightResource != null || topResource != null || bottomResource != null;
                if (hasResource && !element.CenterImage)
                {
                    Control.SetCompoundDrawablesWithIntrinsicBounds(leftResource, topResource, rightResource, bottomResource);
                }

                if (hasResource && element.CenterImage)
                {
                    Xamarin.Forms.Size size = new Xamarin.Forms.Size();

                    if (leftResource != null)
                    {
                        if (element.ImageLeftHeight > 0 && element.ImageLeftWidth > 0)
                        {
                            size.Width  = element.ImageLeftWidth;
                            size.Height = element.ImageLeftHeight;
                        }
                        else
                        {
                            var maxWidth  = BaseUIHelper.ConvertDPToPixels(element.Padding.Left) - BaseUIHelper.ConvertDPToPixels(element.Padding.Right) - Control.MeasuredWidth;
                            var maxHeight = BaseUIHelper.ConvertDPToPixels(element.Padding.Top) - BaseUIHelper.ConvertDPToPixels(element.Padding.Bottom) - Control.MeasuredHeight;

                            var temp = GetSize(leftResource.IntrinsicWidth, leftResource.IntrinsicHeight, Math.Abs(maxWidth), Math.Abs(maxHeight));
                            size.Width  = temp.Width;
                            size.Height = temp.Height;
                        }

                        var scaledDrawable = new ScaleDrawable(leftResource, 0, (int)size.Width, (int)size.Height).Drawable;
                        scaledDrawable.SetBounds(0, 0, (int)size.Width, (int)size.Height);

                        Control.SetCompoundDrawables(scaledDrawable, null, null, null);
                    }

                    if (rightResource != null)
                    {
                        if (element.ImageRightHeight > 0 && element.ImageRightWidth > 0)
                        {
                            size.Width  = element.ImageRightWidth;
                            size.Height = element.ImageRightHeight;
                        }
                        else
                        {
                            var maxWidth  = BaseUIHelper.ConvertDPToPixels(element.Padding.Left) - BaseUIHelper.ConvertDPToPixels(element.Padding.Right) - Control.MeasuredWidth;
                            var maxHeight = BaseUIHelper.ConvertDPToPixels(element.Padding.Top) - BaseUIHelper.ConvertDPToPixels(element.Padding.Bottom) - Control.MeasuredHeight;
                            var temp      = GetSize(rightResource.IntrinsicWidth, rightResource.IntrinsicHeight, Math.Abs(maxWidth), Math.Abs(maxHeight));
                            size.Width  = temp.Width;
                            size.Height = temp.Height;
                        }

                        var scaledDrawable = new ScaleDrawable(rightResource, 0, (int)size.Width, (int)size.Height).Drawable;
                        scaledDrawable.SetBounds(0, 0, (int)size.Width, (int)size.Height);

                        Control.SetCompoundDrawables(null, null, scaledDrawable, null);
                    }

                    if (!element.CenterImage)
                    {
                        SetImagePadding((int)size.Width);
                    }

                    Control.Invalidate();
                }
            }
            catch (Exception e)
            {
            }
        }
Exemple #22
0
        public override void Draw(Canvas canvas)
        {
            //RoundedBoxView rbv = (RoundedBoxView)this.Element;

            //int value;
            //try
            //{
            //    value = int.Parse(rbv.Text.Trim());
            //}
            //catch (Exception)
            //{
            //    value = 0;
            //}

            //if (value <= 0) return;

            //if (value < 10)
            //{
            //    rbv.WidthRequest = 20;
            //}
            //else if (value >= 10 && value < 100)
            //{
            //    rbv.WidthRequest = 25;
            //}
            //else
            //{
            //    rbv.WidthRequest = 30;
            //}

            //Rect rc = new Rect(0, 0, BaseUIHelper.ConvertDPToPixels(rbv.WidthRequest), BaseUIHelper.ConvertDPToPixels(rbv.HeightRequest));

            //GetDrawingRect(rc);

            //Rect interior = rc;
            //interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness);

            ////            paint.Color = Android.Graphics.Color.White;
            ////            paint.TextSize = BaseUIHelper.ConvertDPToPixels(rbv.TextSize);
            ////            paint.AntiAlias = true;
            ////            paint.TextAlign = Paint.Align.Center;
            ////
            ////            Rect bounds = new Rect();
            ////            paint.GetTextBounds(rbv.Text, 0, rbv.Text.Length, bounds);

            //int radius = BaseUIHelper.ConvertDPToPixels(rbv.CornerRadius);
            ////int radius = bounds.Width();

            circlePaint.Color     = Base.BackgroundColor.ToAndroid();
            circlePaint.AntiAlias = true;
            circlePaint.SetStyle(Paint.Style.Fill);

            //canvas.DrawRoundRect(new RectF(interior), radius, radius, circlePaint);
            ////canvas.DrawCircle(x, y - (bounds.Height() / 2), radius, circlePaint);

            //circlePaint.Color = rbv.Stroke.ToAndroid();
            //circlePaint.StrokeWidth = (float)rbv.StrokeThickness;
            //circlePaint.SetStyle(Paint.Style.Stroke);

            //canvas.DrawRoundRect(new RectF(interior), radius, radius, circlePaint);
            ////canvas.DrawCircle(x, y - (bounds.Height() / 2), radius, circlePaint); //FOR the border

            ////canvas.DrawText(rbv.Text, rc.CenterX(), (BaseUIHelper.ConvertDPToPixels(rbv.HeightRequest) / 2) + (bounds.Height() / 2), paint);

            RectF rect         = new RectF(0, 0, this.Width, this.Height);
            int   cornerRadius = BaseUIHelper.ConvertDPToPixels(Base.CornerRadius);

            canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, circlePaint);
        }
        private void AttachPageEvents(Element element)
        {
            var viewCell = BaseUIHelper.GetContainingViewCell(element);

            if (viewCell != null)
            {
                viewCell.PropertyChanged += (s, ev) =>
                {
                    var propertyName = ev.PropertyName;

                    var test  = viewCell.BindingContext;
                    var test1 = Element.BindingContext;
                    var test2 = Control;

                    if (ev.PropertyName == "Renderer")
                    {
                        if (test == null || test1 == null)
                        {
                            return;
                        }

                        SetImageSource();
                    }
                };

                var listView = BaseUIHelper.GetContainingListView(element);
                if (listView != null)
                {
                    listView.PropertyChanged += (s, e) =>
                    {
                        if (e.PropertyName == "Renderer")
                        {
                            if (listView.Parent == null)
                            {
                                this.Dispose(true);
                            }
                        }
                    };
                }

                page = BaseUIHelper.GetContainingPage(element);
                if (page == null)
                {
                    var root = BaseUIHelper.GetRootElement(element);
                    root.PropertyChanged += (s, e) =>
                    {
                        if (e.PropertyName == "Parent")
                        {
                            AttachPageEvents(root);
                        }
                    };
                    return;
                }

                navigPage = BaseUIHelper.GetContainingNavigationPage(page);
                if (navigPage != null)
                {
                    navigPage.Popped += OnPagePopped;
                }
            }
        }
        async void SetImageSource()
        {
            if (Element.Source != null)
            {
                if (Element.Source is UriImageSource)
                {
                    isImageInitialSet = true;


                    var uri = Element.Source.GetValue(UriImageSource.UriProperty) as Uri;

                    var bitmap = await imageDownloader.GetImageAsync(uri);

                    SetImageCorners(bitmap);
                }
                else if (Element.Source is FileImageSource)
                {
                    if ((Element.Width > 0 && Element.Height > 0) || (Element.WidthRequest > 0 && Element.HeightRequest > 0))
                    {
                        isImageInitialSet = true;

                        var source = Element.Source as FileImageSource;
                        if (source != null && source.File != null)
                        {
                            var resourceID = UIHelper.GetDrawableResource(source);
                            if (resourceID > 0)
                            {
                                Bitmap imageBitmap = ImageCache.Instance.Get(resourceID.ToString());
                                if (imageBitmap == null)
                                {
                                    var width             = BaseUIHelper.ConvertDPToPixels(Element.Width <= 0 ? Element.WidthRequest : Element.Width);
                                    var height            = BaseUIHelper.ConvertDPToPixels(Element.Height <= 0 ? Element.HeightRequest : Element.Height);
                                    BitmapWorkerTask task = new BitmapWorkerTask(imageView, width, height, ImageCache.Instance);
                                    imageView.SetImageDrawable(new AsyncDrawable(imageView.Resources, null, task));
                                    task.Execute(resourceID);
                                    task.Finished += (s, e) =>
                                                     SetImageCorners(e);
                                }
                                else
                                {
                                    SetImageCorners(imageBitmap);
                                }
                            }
                            else
                            {
                                var imageBitmap = await BitmapFactory.DecodeFileAsync(source.File);

                                SetImageCorners(imageBitmap);
                            }
                        }
                    }
                }
                else if (Element.Source is StreamImageSource)
                {
                    isImageInitialSet = true;
                    var source = Element.Source as StreamImageSource;
                    var cts    = new System.Threading.CancellationTokenSource();
                    var str    = await source.Stream(cts.Token);

                    using (var reader = new System.IO.BinaryReader(str))
                    {
                        var data   = reader.ReadBytes((int)str.Length);
                        var bitmap = await BitmapFactory.DecodeByteArrayAsync(data, 0, data.Length);

                        SetImageCorners(bitmap);
                    }
                }
            }
            else
            {
                if (Element.ImagePlaceholder == null)
                {
                    imageView.SetImageBitmap(null);
                }
            }
        }
        private void AttachPageEvents(Xamarin.Forms.Element element)
        {
            var viewCell = BaseUIHelper.GetContainingViewCell(element);

            if (viewCell != null)
            {
                viewCell.PropertyChanged += (s, ev) =>
                {
                    var propertyName = ev.PropertyName;
                };

                var listView = BaseUIHelper.GetContainingListView(element);
                if (listView != null)
                {
                    listView.PropertyChanged += (s, e) =>
                    {
                        if (e.PropertyName == "Renderer")
                        {
                            if (listView.Parent == null)
                            {
                                this.Dispose(true);
                            }
                        }
                    };
                }

                page = BaseUIHelper.GetContainingPage(element);

                if (page != null)
                {
                    page.Disappearing += (s, ev) =>
                    {
                        //if (imageLoader != null)
                        {
                            //imageLoader.CancelDisplayTask(imageView);
                        }
                    };
                }

                if (page == null)
                {
                    var root = BaseUIHelper.GetRootElement(element);
                    root.PropertyChanged += (s, e) =>
                    {
                        if (e.PropertyName == "Parent")
                        {
                            AttachPageEvents(root);
                        }
                    };
                    return;
                }
                // As of Xamarin.Forms 1.4+, image will be reused when moving from tabs.
                // Uncomment this if using Xamarin.Forms < 1.4.
                //if (page.Parent is TabbedPage)
                //{
                //    page.Disappearing += PageContainedInTabbedPageDisapearing;
                //    return;
                //}

                navigPage = BaseUIHelper.GetContainingNavigationPage(page);
                if (navigPage != null)
                {
                    navigPage.Popped += OnPagePopped;

                    // As of Xamarin.Forms 1.4+, image will be reused when moving from tabs.
                    // Uncomment this if using Xamarin.Forms < 1.4.
                    //if (navigPage.Parent is TabbedPage)
                    //{
                    //    navigPage.Disappearing += PageContainedInTabbedPageDisapearing;
                    //}
                }
            }
            // As of Xamarin.Forms 1.4+, image will be reused when moving from tabs.
            // Uncomment this if using Xamarin.Forms < 1.4.
            //else if ((page = GetContainingTabbedPage(element)) != null)
            //{
            //    page.Disappearing += PageContainedInTabbedPageDisapearing;
            //}
        }
Exemple #26
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);


            if (e.OldElement != null || e.NewElement == null)
            {
                return;
            }

            var buttonControl = (RoundedButton)Element;

            gradientDrawable = new StateListDrawable();
            SetCorners();

            Control.Focusable = false;

            buttonControl.PropertyChanged += (s, ev) =>
            {
                if (Control == null || Element == null)
                {
                    return;
                }

                var element = (RoundedButton)s;
                switch (ev.PropertyName)
                {
                case "IsEnabled":
                    Control.SetTextColor(element.TextColor.ToAndroid());     // for samsung s4 and note5
                    break;

                case "Text":
                    Control.Text = element.Text;
                    var width = Control.Width;
                    Control.SetWidth(width);
                    break;

                case "HoverColor":
                    SetHoverColor();
                    Control.Background = gradientDrawable;
                    break;

                case "PressedColor":
                    SetPressedColor();
                    Control.Background = gradientDrawable;
                    break;

                case "GradientColor":
                    UpdateStateDrawable();

                    break;

                case "DisableColor":
                    SetDisabledColor();
                    Control.Background = gradientDrawable;
                    break;

                case "BorderColor":
                    UpdateStateDrawable();
                    break;

                //case "Width":
                //    SetImages(buttonControl);
                //    break;
                case "DisabledTextColor":
                    SetDisabledTextColor();
                    break;
                }
            };



            //SetTypeface(buttonControl);
            //SetBackground(buttonControl);
            //SetImages(buttonControl);
            //SetPadding(buttonControl);
            //SetTitlePadding(buttonControl);
            //SetTextAlignment(buttonControl);

            currentWidth = Control.Width;

            if (buttonControl.WidthRequest > 0)
            {
                Control.SetWidth(BaseUIHelper.ConvertDPToPixels(buttonControl.WidthRequest));
            }

            if (buttonControl.HeightRequest > 0)
            {
                Control.SetHeight(BaseUIHelper.ConvertDPToPixels(buttonControl.HeightRequest));
            }

            SetPressedColor();
            SetHoverColor();
            SetDisabledColor();
            SetGradientColor();
            SetDisabledTextColor();
            SetTextAlignment();
            Control.Background = gradientDrawable;

            var thisButton = Control as Android.Widget.Button;

            thisButton.Touch += async(object sender, TouchEventArgs args) =>
            {
                if (args.Event.Action == MotionEventActions.Down)
                {
                    await buttonControl.ScaleTo(0.9, 100);
                }
                else if (args.Event.Action == MotionEventActions.Up)
                {
                    await buttonControl.ScaleTo(1, 100);

                    Control.CallOnClick();
                }
            };

            this.SetWillNotDraw(false);
        }
Exemple #27
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Entry> e)
        {
            bool hasSet = false;

            if (e.OldElement == null && this.Element != null)
            {
                //SetNativeControl(new EditTextCustom(Context));
                //SetNativeControl(new EditTextCustom());
                hasSet = true;
            }

            if (inputMethodManager == null)
            {
                inputMethodManager = base.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
            }

            base.OnElementChanged(e);

            if (!hasSet)
            {
                return;
            }

            var entryControl = (MvvmAspire.Controls.Entry)Element;


            DefaultKeyListener = Control.KeyListener;

            entryControl.PropertyChanged += (s, ev) =>
            {
                var element = (MvvmAspire.Controls.Entry)s;

                switch (ev.PropertyName)
                {
                case "TextPadding":
                case "ImageLeft":
                case "ImageRight":
                case "ImageTop":
                case "ImageBottom":
                    SetImages(element);
                    break;

                case "ClearFocusTrigger": HideSoftKeyBoardOnTextChanged(element); break;

                case "IsFocused": element.ClearFocus = !element.IsFocused; break;

                case "BackgroundImage": SetBackground(element); break;

                case "FontFamily": SetTypeface(element); break;

                case "FontSize": SetTextSize(element); break;

                case "SuppressKeyboard": SetShowSoftInputOnFocus(element); break;

                case "Text":
                    if (element.ClearFocus)
                    {
                        HideSoftKeyBoardOnTextChanged(element);
                    }
                    break;

                case "ClearFocus":
                    //if (!EntryControl.IsNumeric) break;
                    if (element.ClearFocus)
                    {
                        //inputMethodManager.HideSoftInputFromWindow(base.Control.WindowToken, HideSoftInputFlags.None);
                        //Control.Focusable = false;
                        //Control.ClearFocus();
                        HideSoftKeyBoardOnTextChanged(element);
                    }
                    break;

                case "NextFocus":
                    inputMethodManager.ShowSoftInput(Control, ShowFlags.Implicit);
                    //inputMethodManager.ToggleSoftInput(ShowFlags.Forced, InputMethodManager.ShowImplicit);
                    break;

                case "IsEnabled":
                    if (base.Control == null)
                    {
                        return;
                    }

                    if (!element.IsEnabled)
                    {
                        base.Control.KeyListener = null;
                    }
                    else
                    {
                        base.Control.KeyListener = DefaultKeyListener;
                    }
                    break;

                case "IsReadOnly":
                    SetIsReadOnly(element);
                    break;

                    //case "Padding": SetPadding(element); break;
                }
            };

            //if (EntryControl.IsNumeric)
            //    Control.Touch += Control_Touch;

            SetBackground(entryControl);
            SetImages(entryControl);
            SetTypeface(entryControl);
            SetTextSize(entryControl);
            SetShowSoftInputOnFocus(entryControl);
            SetHintColor(entryControl);
            SetIsReadOnly(entryControl);
            SetTextAlignment();
            //SetPadding(entryControl);
            SetGravity(entryControl);

            if (BaseElement.NextElement != null)
            {
                Control.ImeOptions = ImeAction.Next;
            }
            if (BaseElement.NextElement == null && BaseElement.Command != null)
            {
                Control.ImeOptions = ImeAction.Done;
            }

            if (BaseElement.MaxCharacter.HasValue)
            {
                var filter = new InputFilterLengthFilter(BaseElement.MaxCharacter.Value);
                Control.SetFilters(new IInputFilter[] { filter });
            }

            Control.ViewAttachedToWindow += Control_ViewAttachedToWindow;
            Control.SetPadding(BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Left),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Top),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Right),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Bottom));

            if (BaseElement.NextElement != null || BaseElement.Command != null)
            {
                Control.SetOnEditorActionListener(this);
            }

            SetTextInputTypes(entryControl);

            if (!entryControl.IsEnabled)
            {
                base.Control.KeyListener = null;
            }

            base.Control.Focusable = !BaseElement.IsReadOnly;

            //Control.Touch += Control_Touch;
            //Control.FocusChange += Control_FocusChange;
            if (BaseElement.IsSingleLine)
            {
                Control.SetMaxLines(1);
                Control.SetSingleLine(true);
                Control.Ellipsize = TextUtils.TruncateAt.End;
            }
            //Control.Gravity = GravityFlags.CenterVertical;
            Control.Background.SetColorFilter(Android.Graphics.Color.Transparent, PorterDuff.Mode.SrcIn);
        }
 private void SetPadding()
 {
     Control.SetPadding(BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Left), BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Top),
                        BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Right), BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Bottom));
 }
Exemple #29
0
        protected override void OnElementChanged(ElementChangedEventArgs <RoundedEntry> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            var editText = new EditText(this.Context);

            // will remove cursor and not scrollable for tablet
            //editText.MovementMethod = null;

            editText.Ellipsize = TextUtils.TruncateAt.End;
            editText.SetCursorVisible(Element.ShowCursor);

            if (!Element.AllowCutCopyPaste)
            {
                editText.LongClickable = false;
            }

            if (Element.MaxCharacter.HasValue)
            {
                var filter = new InputFilterLengthFilter(Element.MaxCharacter.Value);
                editText.SetFilters(new IInputFilter[] { filter });
            }

            SetNativeControl(editText);

            CreateShapeDrawable();
            this.Background = new ColorDrawable(Color.Transparent.ToAndroid());

            //if (Element.IsPassword)
            //    Control.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;

            if (Element.IsReadOnly)
            {
                Control.KeyListener = null;
            }

            if (Element.IsSingleLine)
            {
                editText.SetMaxLines(1);
                editText.SetSingleLine(true);

                if (Element.NextElement != null)
                {
                    Control.ImeOptions = ImeAction.Next;
                }

                if (Element.NextElement == null && Element.Command != null)
                {
                    Control.ImeOptions = ImeAction.Done;
                }

                if (Element.NextElement != null || (Element.NextElement == null && Element.Command != null))
                {
                    Control.SetOnEditorActionListener(this);
                }
                else
                {
                    Control.ImeOptions = ImeAction.Done;
                }
            }


            //int selectionStart = -1;
            //string previousText = "";

            editText.AfterTextChanged += (s, ev) =>
            {
                //if (editText.Text.Length > previousText.Length)
                //    selectionStart = editText.CursorPosition + 1;
                //else
                //    selectionStart = editText.CursorPosition - 1;
                ////if (!editText.Text.ToString().Replace(Environment.NewLine, "").Equals(editText.Text.ToString()))
                ////editText.Text = editText.Text.ToString().Replace(Environment.NewLine, "");

                //if (selectionStart > editText.Text.Length || selectionStart < 0)
                //    selectionStart = editText.Text.Length;

                //editText.SetSelection(selectionStart);

                ((IElementController)Element).SetValueFromRenderer(Xamarin.Forms.Entry.TextProperty, editText.Text);
                //previousText = editText.Text;
            };

            Control.SetPadding(BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Left),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Top),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Right),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Bottom));

            SetText();
            SetTextColor();
            SetTextAlignment();
            SetHint();
            SetTextInputTypes();
            ShowKeyboard();
            //CheckEnabled();
        }
Exemple #30
0
        void SetImages(MvvmAspire.Controls.Entry element)
        {
            int leftResourceId = 0, topResourceId = 0, rightResourceId = 0, bottomResourceId = 0;

            if (element.ImageLeft != null && element.ImageLeft.File != null)
            {
                leftResourceId = UIHelper.GetDrawableResource(element.ImageLeft);
            }
            if (element.ImageTop != null && element.ImageTop.File != null)
            {
                topResourceId = UIHelper.GetDrawableResource(element.ImageTop);
            }
            if (element.ImageRight != null && element.ImageRight.File != null)
            {
                rightResourceId = UIHelper.GetDrawableResource(element.ImageRight);
            }
            if (element.ImageBottom != null && element.ImageBottom.File != null)
            {
                bottomResourceId = UIHelper.GetDrawableResource(element.ImageBottom);
            }

            bool hasResource = leftResourceId > 0 || rightResourceId > 0 || topResourceId > 0 || bottomResourceId > 0;

            if (hasCompoundDrawable || hasResource)
            {
                hasCompoundDrawable = true;

                //Android.Graphics.Drawables.Drawable leftDrawable = leftResourceId > 0 ? Resources.GetDrawable(leftResourceId) : null;
                //if (leftDrawable != null)
                //    leftDrawable.SetBounds(0, 0, leftDrawable.IntrinsicWidth, leftDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable topDrawable = topResourceId > 0 ? Resources.GetDrawable(topResourceId) : null;
                //if (topDrawable != null)
                //    topDrawable.SetBounds(0, 0, topDrawable.IntrinsicWidth, topDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable rightDrawable = rightResourceId > 0 ? Resources.GetDrawable(rightResourceId) : null;
                //if (rightDrawable != null)
                //    rightDrawable.SetBounds(0, 0, rightDrawable.IntrinsicWidth, rightDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable bottomDrawable = bottomResourceId > 0 ? Resources.GetDrawable(bottomResourceId) : null;
                //if (bottomDrawable != null)
                //    bottomDrawable.SetBounds(0, 0, bottomDrawable.IntrinsicWidth, bottomDrawable.IntrinsicHeight);

                //Control.SetCompoundDrawablesRelative(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                //Control.SetCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable);


                var leftDrawable = (leftResourceId > 0) ? Resources.GetDrawable(leftResourceId) : null;
                if (leftDrawable != null)
                {
                    if (element.ImageLeftWidth > 0)
                    {
                        leftDrawable = ResizeImage(leftDrawable, BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth));
                    }
                    else
                    {
                        Resources.GetDrawable(leftResourceId);
                    }
                }

                var topDrawable    = (topResourceId > 0) ? Resources.GetDrawable(topResourceId) : null;
                var rightDrawable  = (rightResourceId > 0) ? Resources.GetDrawable(rightResourceId) : null;
                var bottomDrawable = (bottomResourceId > 0) ? Resources.GetDrawable(bottomResourceId) : null;

                //Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topResourceId, rightResourceId, bottomResourceId);
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                Control.CompoundDrawablePadding = 20;

                if (!hasResource)
                {
                    hasCompoundDrawable = false;
                }
            }

            if (element.ImageCenter != null)
            {
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(base.Resources.GetDrawable(UIHelper.GetDrawableResource(element.ImageCenter)), null, null, null);
                Control.Gravity = GravityFlags.Center;
            }
        }